Allow Clearing Integer Formats To Large Values

Removes validation preventing integer formats from being cleared to
>2^24. Adds a test that clears to the largest values for UINT32 and
SINT32 formats.

Bug: dawn:537
Change-Id: I8aabd36608138725c8ddbbedd50192c0978da99c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30300
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Brandon Jones <brandon1.jones@intel.com>
This commit is contained in:
Brandon Jones 2020-10-15 22:23:45 +00:00 committed by Commit Bot service account
parent cb055303b5
commit a63a00cd65
3 changed files with 28 additions and 129 deletions

View File

@ -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));

View File

@ -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<uint32_t>(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<uint32_t>(kUint32MaxDouble);
// RGBA32Uint for UINT32_MAX
{
constexpr wgpu::Color kClearColor = {k2ToThe24Double, k2ToThe24Double, k2ToThe24Double,
k2ToThe24Double};
constexpr std::array<uint32_t, 4> kExpectedPixelValue = {k2ToThe24Uint, k2ToThe24Uint,
k2ToThe24Uint, k2ToThe24Uint};
constexpr wgpu::Color kClearColor = {kUint32MaxDouble, kUint32MaxDouble, kUint32MaxDouble,
kUint32MaxDouble};
constexpr std::array<uint32_t, 4> kExpectedPixelValue = {kUint32Max, kUint32Max, kUint32Max,
kUint32Max};
TestIntegerClearColor<uint32_t>(wgpu::TextureFormat::RGBA32Uint, kClearColor,
kExpectedPixelValue);
}
constexpr int32_t k2ToThe24Sint = static_cast<int32_t>(k2ToThe24Double);
// RGBA32Sint For +2^24
constexpr double kSint32MaxDouble = 2147483647.0;
constexpr int32_t kSint32Max = static_cast<int32_t>(kSint32MaxDouble);
constexpr double kSint32MinDouble = -2147483648.0;
constexpr int32_t kSint32Min = static_cast<int32_t>(kSint32MinDouble);
// RGBA32Sint for SINT32 upper bound.
{
constexpr wgpu::Color kClearColor = {k2ToThe24Double, k2ToThe24Double, k2ToThe24Double,
k2ToThe24Double};
constexpr std::array<int32_t, 4> kExpectedPixelValue = {k2ToThe24Sint, k2ToThe24Sint,
k2ToThe24Sint, k2ToThe24Sint};
constexpr wgpu::Color kClearColor = {kSint32MaxDouble, kSint32MaxDouble, kSint32MaxDouble,
kSint32MaxDouble};
constexpr std::array<int32_t, 4> kExpectedPixelValue = {kSint32Max, kSint32Max, kSint32Max,
kSint32Max};
TestIntegerClearColor<int32_t>(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<int32_t, 4> kExpectedPixelValue = {-k2ToThe24Sint, -k2ToThe24Sint,
-k2ToThe24Sint, -k2ToThe24Sint};
constexpr wgpu::Color kClearColor = {kSint32MinDouble, kSint32MinDouble, kSint32MinDouble,
kSint32MinDouble};
constexpr std::array<int32_t, 4> kExpectedPixelValue = {kSint32Min, kSint32Min, kSint32Min,
kSint32Min};
TestIntegerClearColor<int32_t>(wgpu::TextureFormat::RGBA32Sint, kClearColor,
kExpectedPixelValue);
}

View File

@ -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<wgpu::TextureFormat, 2> 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);