diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 96a716b19f..6d24609ef8 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -292,26 +292,6 @@ namespace dawn_native { std::isnan(colorAttachment.clearColor.a)) { return DAWN_VALIDATION_ERROR("Color clear value cannot contain NaN"); } - - if (attachment->GetFormat().HasComponentType(Format::Type::Uint) && - (colorAttachment.clearColor.r < 0 || colorAttachment.clearColor.g < 0 || - colorAttachment.clearColor.b < 0 || colorAttachment.clearColor.a < 0)) { - return DAWN_VALIDATION_ERROR( - "Clear values less than zero are invalid for unsigned integer formats."); - } - - constexpr double k2ToThe24 = 16777216.0; - - if ((attachment->GetFormat().HasComponentType(Format::Type::Uint) || - attachment->GetFormat().HasComponentType(Format::Type::Sint)) && - (std::abs(colorAttachment.clearColor.r) > k2ToThe24 || - std::abs(colorAttachment.clearColor.g) > k2ToThe24 || - std::abs(colorAttachment.clearColor.b) > k2ToThe24 || - std::abs(colorAttachment.clearColor.a) > k2ToThe24)) { - return DAWN_VALIDATION_ERROR( - "Clear values with an absolute value of more than 16777216.0 (2^24) " - "are invalid for integer formats."); - } } DAWN_TRY(ValidateOrSetColorAttachmentSampleCount(attachment, sampleCount)); diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp index d75afac6fc..ee8dcd050d 100644 --- a/src/tests/end2end/RenderPassLoadOpTests.cpp +++ b/src/tests/end2end/RenderPassLoadOpTests.cpp @@ -236,39 +236,46 @@ TEST_P(RenderPassLoadOpTests, LoadOpClearOnIntegerFormats) { } } -// This test verifies that input double values are being rounded to floats internally when -// clearing. -TEST_P(RenderPassLoadOpTests, LoadOpClear2ToThe24IntegerFormats) { - constexpr double k2ToThe24Double = 16777216.0; - constexpr uint32_t k2ToThe24Uint = static_cast(k2ToThe24Double); +// This test verifies that input double values are being rendered correctly when clearing. +TEST_P(RenderPassLoadOpTests, LoadOpClearIntegerFormatsToLargeValues) { + // TODO(http://crbug.com/dawn/537): Implemement a workaround to enable clearing integer formats + // to large values on D3D12. + DAWN_SKIP_TEST_IF(IsD3D12()); - // RGBA32Uint + constexpr double kUint32MaxDouble = 4294967295.0; + constexpr uint32_t kUint32Max = static_cast(kUint32MaxDouble); + // RGBA32Uint for UINT32_MAX { - constexpr wgpu::Color kClearColor = {k2ToThe24Double, k2ToThe24Double, k2ToThe24Double, - k2ToThe24Double}; - constexpr std::array kExpectedPixelValue = {k2ToThe24Uint, k2ToThe24Uint, - k2ToThe24Uint, k2ToThe24Uint}; + constexpr wgpu::Color kClearColor = {kUint32MaxDouble, kUint32MaxDouble, kUint32MaxDouble, + kUint32MaxDouble}; + constexpr std::array kExpectedPixelValue = {kUint32Max, kUint32Max, kUint32Max, + kUint32Max}; TestIntegerClearColor(wgpu::TextureFormat::RGBA32Uint, kClearColor, kExpectedPixelValue); } - constexpr int32_t k2ToThe24Sint = static_cast(k2ToThe24Double); - // RGBA32Sint For +2^24 + constexpr double kSint32MaxDouble = 2147483647.0; + constexpr int32_t kSint32Max = static_cast(kSint32MaxDouble); + + constexpr double kSint32MinDouble = -2147483648.0; + constexpr int32_t kSint32Min = static_cast(kSint32MinDouble); + + // RGBA32Sint for SINT32 upper bound. { - constexpr wgpu::Color kClearColor = {k2ToThe24Double, k2ToThe24Double, k2ToThe24Double, - k2ToThe24Double}; - constexpr std::array kExpectedPixelValue = {k2ToThe24Sint, k2ToThe24Sint, - k2ToThe24Sint, k2ToThe24Sint}; + constexpr wgpu::Color kClearColor = {kSint32MaxDouble, kSint32MaxDouble, kSint32MaxDouble, + kSint32MaxDouble}; + constexpr std::array kExpectedPixelValue = {kSint32Max, kSint32Max, kSint32Max, + kSint32Max}; TestIntegerClearColor(wgpu::TextureFormat::RGBA32Sint, kClearColor, kExpectedPixelValue); } - // RGBA32Sint For -2^24 + // RGBA32Sint for SINT32 lower bound. { - constexpr wgpu::Color kClearColor = {-k2ToThe24Double, -k2ToThe24Double, -k2ToThe24Double, - -k2ToThe24Double}; - constexpr std::array kExpectedPixelValue = {-k2ToThe24Sint, -k2ToThe24Sint, - -k2ToThe24Sint, -k2ToThe24Sint}; + constexpr wgpu::Color kClearColor = {kSint32MinDouble, kSint32MinDouble, kSint32MinDouble, + kSint32MinDouble}; + constexpr std::array kExpectedPixelValue = {kSint32Min, kSint32Min, kSint32Min, + kSint32Min}; TestIntegerClearColor(wgpu::TextureFormat::RGBA32Sint, kClearColor, kExpectedPixelValue); } diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp index 73e53c1406..277c12e32f 100644 --- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp @@ -762,94 +762,6 @@ namespace { } } - // Tests that values that require more than 24 bits to express are not allowed for integer - // formats. - TEST_F(RenderPassDescriptorValidationTest, ExceedValidColorClearRange) { - std::array formats = {wgpu::TextureFormat::RGBA32Sint, - wgpu::TextureFormat::RGBA32Uint}; - - constexpr double k2toThe24 = 16777216.0; - double kLargerThan2toPower24 = nextafter(k2toThe24, k2toThe24 + 1); - - for (wgpu::TextureFormat format : formats) { - wgpu::TextureView color = Create2DAttachment(device, 1, 1, format); - - // Tests that 16777216.0 is a valid clear color. - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.r = k2toThe24; - renderPass.cColorAttachments[0].clearColor.g = k2toThe24; - renderPass.cColorAttachments[0].clearColor.b = k2toThe24; - renderPass.cColorAttachments[0].clearColor.a = k2toThe24; - AssertBeginRenderPassSuccess(&renderPass); - } - - // Tests that 16777216.01 cannot be used as a clear color. - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.r = kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.g = kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.b = kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.a = kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - // Tests that -16777216.0 is a valid clear color for Sint, but not for Uint - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.r = -k2toThe24; - renderPass.cColorAttachments[0].clearColor.g = -k2toThe24; - renderPass.cColorAttachments[0].clearColor.b = -k2toThe24; - renderPass.cColorAttachments[0].clearColor.a = -k2toThe24; - if (format == wgpu::TextureFormat::RGBA32Sint) { - AssertBeginRenderPassSuccess(&renderPass); - } else if (format == wgpu::TextureFormat::RGBA32Uint) { - AssertBeginRenderPassError(&renderPass); - } - } - - // Tests that -16777216.01 cannot be used as a clear color. - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.r = -kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.g = -kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.b = -kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - - { - utils::ComboRenderPassDescriptor renderPass({color}, nullptr); - renderPass.cColorAttachments[0].clearColor.a = -kLargerThan2toPower24; - AssertBeginRenderPassError(&renderPass); - } - } - } - TEST_F(RenderPassDescriptorValidationTest, ValidateDepthStencilReadOnly) { wgpu::TextureView colorView = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);