1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "tests/unittests/validation/ValidationTest.h" 16 17 #include "utils/WGPUHelpers.h" 18 19 #include <cmath> 20 21 namespace { 22 23 class SamplerValidationTest : public ValidationTest {}; 24 25 // Test NaN and INFINITY values are not allowed TEST_F(SamplerValidationTest,InvalidLOD)26 TEST_F(SamplerValidationTest, InvalidLOD) { 27 { device.CreateSampler(); } 28 { 29 wgpu::SamplerDescriptor samplerDesc; 30 samplerDesc.lodMinClamp = NAN; 31 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 32 } 33 { 34 wgpu::SamplerDescriptor samplerDesc; 35 samplerDesc.lodMaxClamp = NAN; 36 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 37 } 38 { 39 wgpu::SamplerDescriptor samplerDesc; 40 samplerDesc.lodMaxClamp = INFINITY; 41 device.CreateSampler(&samplerDesc); 42 } 43 { 44 wgpu::SamplerDescriptor samplerDesc; 45 samplerDesc.lodMaxClamp = INFINITY; 46 samplerDesc.lodMinClamp = INFINITY; 47 device.CreateSampler(&samplerDesc); 48 } 49 } 50 TEST_F(SamplerValidationTest,InvalidFilterAnisotropic)51 TEST_F(SamplerValidationTest, InvalidFilterAnisotropic) { 52 wgpu::SamplerDescriptor kValidAnisoSamplerDesc = {}; 53 kValidAnisoSamplerDesc.maxAnisotropy = 2; 54 kValidAnisoSamplerDesc.minFilter = wgpu::FilterMode::Linear; 55 kValidAnisoSamplerDesc.magFilter = wgpu::FilterMode::Linear; 56 kValidAnisoSamplerDesc.mipmapFilter = wgpu::FilterMode::Linear; 57 { 58 // when maxAnisotropy > 1, min, mag, mipmap filter should be linear 59 device.CreateSampler(&kValidAnisoSamplerDesc); 60 } 61 { 62 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 63 samplerDesc.maxAnisotropy = 0; 64 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 65 } 66 { 67 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 68 samplerDesc.minFilter = wgpu::FilterMode::Nearest; 69 samplerDesc.magFilter = wgpu::FilterMode::Nearest; 70 samplerDesc.mipmapFilter = wgpu::FilterMode::Nearest; 71 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 72 } 73 { 74 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 75 samplerDesc.minFilter = wgpu::FilterMode::Nearest; 76 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 77 } 78 { 79 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 80 samplerDesc.magFilter = wgpu::FilterMode::Nearest; 81 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 82 } 83 { 84 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 85 samplerDesc.mipmapFilter = wgpu::FilterMode::Nearest; 86 ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); 87 } 88 } 89 TEST_F(SamplerValidationTest,ValidFilterAnisotropic)90 TEST_F(SamplerValidationTest, ValidFilterAnisotropic) { 91 wgpu::SamplerDescriptor kValidAnisoSamplerDesc = {}; 92 kValidAnisoSamplerDesc.maxAnisotropy = 2; 93 kValidAnisoSamplerDesc.minFilter = wgpu::FilterMode::Linear; 94 kValidAnisoSamplerDesc.magFilter = wgpu::FilterMode::Linear; 95 kValidAnisoSamplerDesc.mipmapFilter = wgpu::FilterMode::Linear; 96 { device.CreateSampler(); } 97 { 98 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 99 samplerDesc.maxAnisotropy = 16; 100 device.CreateSampler(&samplerDesc); 101 } 102 { 103 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 104 samplerDesc.maxAnisotropy = 32; 105 device.CreateSampler(&samplerDesc); 106 } 107 { 108 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 109 samplerDesc.maxAnisotropy = 0x7FFF; 110 device.CreateSampler(&samplerDesc); 111 } 112 { 113 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 114 samplerDesc.maxAnisotropy = 0x8000; 115 device.CreateSampler(&samplerDesc); 116 } 117 { 118 wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; 119 samplerDesc.maxAnisotropy = 0xFFFF; 120 device.CreateSampler(&samplerDesc); 121 } 122 } 123 124 } // anonymous namespace 125