D3D11: Add 16 bits Unorm formats' support to B2T shaders. Bug: 348653642 Change-Id: I8b5d5a96b983f64c4b79ba14696735a0ac67efd7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/232114 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Quyen Le <lehoangquyen@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/BlitBufferToTexture.cpp b/src/dawn/native/BlitBufferToTexture.cpp index 805690d..1f40095 100644 --- a/src/dawn/native/BlitBufferToTexture.cpp +++ b/src/dawn/native/BlitBufferToTexture.cpp
@@ -132,12 +132,27 @@ } )"; +constexpr std::string_view kUnpackR16Unorm = R"( +fn unpackData(byteOffset: u32) -> vec4f { + return vec4f(f32(loadU16AsU32(byteOffset)) / f32(0xffff), 0.0, 0.0, 1.0); +} +)"; + constexpr std::string_view kUnpackRG16Float = R"( fn unpackData(byteOffset: u32) -> vec4f { return vec4f(unpack2x16float(loadU32(byteOffset)), 0.0, 1.0); } )"; +constexpr std::string_view kUnpackRG16Unorm = R"( +fn unpackData(byteOffset: u32) -> vec4f { + let word = loadU32(byteOffset); + let x = f32(word & 0xffff); + let y = f32(word >> 16); + return vec4f(vec2f(x, y) / f32(0xffff), 0.0, 1.0); +} +)"; + constexpr std::string_view kUnpackRGBA16Float = R"( fn unpackData(byteOffset: u32) -> vec4f { let data = loadTwoU32s(byteOffset); @@ -145,6 +160,17 @@ } )"; +constexpr std::string_view kUnpackRGBA16Unorm = R"( +fn unpackData(byteOffset: u32) -> vec4f { + let words = loadTwoU32s(byteOffset); + let x = f32(words[0] & 0xffff); + let y = f32(words[0] >> 16); + let z = f32(words[1] & 0xffff); + let w = f32(words[1] >> 16); + return vec4f(x, y, z, w) / f32(0xffff); +} +)"; + constexpr std::string_view kUnpackR32Float = R"( fn unpackData(byteOffset: u32) -> vec4f { return vec4f(bitcast<f32>(loadU32(byteOffset)), 0.0, 0.0, 1.0); @@ -189,14 +215,26 @@ pixelSize = 2; ss << kUnpackR16Float; break; + case wgpu::TextureFormat::R16Unorm: + pixelSize = 2; + ss << kUnpackR16Unorm; + break; case wgpu::TextureFormat::RG16Float: pixelSize = 4; ss << kUnpackRG16Float; break; + case wgpu::TextureFormat::RG16Unorm: + pixelSize = 4; + ss << kUnpackRG16Unorm; + break; case wgpu::TextureFormat::RGBA16Float: pixelSize = 8; ss << kUnpackRGBA16Float; break; + case wgpu::TextureFormat::RGBA16Unorm: + pixelSize = 8; + ss << kUnpackRGBA16Unorm; + break; case wgpu::TextureFormat::R32Float: pixelSize = 4; ss << kUnpackR32Float; @@ -291,8 +329,11 @@ case wgpu::TextureFormat::RGBA8Unorm: case wgpu::TextureFormat::BGRA8Unorm: case wgpu::TextureFormat::R16Float: + case wgpu::TextureFormat::R16Unorm: case wgpu::TextureFormat::RG16Float: + case wgpu::TextureFormat::RG16Unorm: case wgpu::TextureFormat::RGBA16Float: + case wgpu::TextureFormat::RGBA16Unorm: case wgpu::TextureFormat::R32Float: case wgpu::TextureFormat::RG32Float: case wgpu::TextureFormat::RGBA32Float:
diff --git a/src/dawn/tests/end2end/CopyTests.cpp b/src/dawn/tests/end2end/CopyTests.cpp index f0b4a59..3b54665 100644 --- a/src/dawn/tests/end2end/CopyTests.cpp +++ b/src/dawn/tests/end2end/CopyTests.cpp
@@ -383,8 +383,35 @@ TextureSpec() { format = GetParam().mTextureFormat; } }; + void SetUp() override { + DawnTestWithParams<CopyTextureFormatParams>::SetUp(); + switch (GetParam().mTextureFormat) { + case wgpu::TextureFormat::R16Unorm: + case wgpu::TextureFormat::RG16Unorm: + case wgpu::TextureFormat::RGBA16Unorm: + DAWN_TEST_UNSUPPORTED_IF( + !device.HasFeature(wgpu::FeatureName::Unorm16TextureFormats)); + break; + default: + break; + } + } + std::vector<wgpu::FeatureName> GetRequiredFeatures() override { std::vector<wgpu::FeatureName> requiredFeatures = {}; + + switch (GetParam().mTextureFormat) { + case wgpu::TextureFormat::R16Unorm: + case wgpu::TextureFormat::RG16Unorm: + case wgpu::TextureFormat::RGBA16Unorm: + if (SupportsFeatures({wgpu::FeatureName::Unorm16TextureFormats})) { + requiredFeatures.push_back(wgpu::FeatureName::Unorm16TextureFormats); + } + break; + default: + break; + } + if (SupportsFeatures({wgpu::FeatureName::DawnTexelCopyBufferRowAlignment})) { requiredFeatures.push_back(wgpu::FeatureName::DawnTexelCopyBufferRowAlignment); } @@ -632,14 +659,26 @@ DoTestImpl<ColorF16<1>>(textureSpec, bufferSpec, copySize, dimension, /*tolerance=*/ColorF16<1>(0.001f)); break; + case wgpu::TextureFormat::R16Unorm: + DoTestImpl<Color<uint16_t, 1>>(textureSpec, bufferSpec, copySize, dimension, + /*tolerance=*/Color<uint16_t, 1>(1)); + break; case wgpu::TextureFormat::RG16Float: DoTestImpl<ColorF16<2>>(textureSpec, bufferSpec, copySize, dimension, /*tolerance=*/ColorF16<2>(0.001f)); break; + case wgpu::TextureFormat::RG16Unorm: + DoTestImpl<Color<uint16_t, 2>>(textureSpec, bufferSpec, copySize, dimension, + /*tolerance=*/Color<uint16_t, 2>(1)); + break; case wgpu::TextureFormat::RGBA16Float: DoTestImpl<ColorF16<4>>(textureSpec, bufferSpec, copySize, dimension, /*tolerance=*/ColorF16<4>(0.001f)); break; + case wgpu::TextureFormat::RGBA16Unorm: + DoTestImpl<Color<uint16_t, 4>>(textureSpec, bufferSpec, copySize, dimension, + /*tolerance=*/Color<uint16_t, 4>(1)); + break; case wgpu::TextureFormat::R32Float: DoTestImpl<Color<float, 1>>(textureSpec, bufferSpec, copySize, dimension, /*tolerance=*/Color<float, 1>(0.0001f)); @@ -2761,14 +2800,17 @@ wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureFormat::R16Float, + wgpu::TextureFormat::R16Unorm, wgpu::TextureFormat::RG16Float, + wgpu::TextureFormat::RG16Unorm, wgpu::TextureFormat::R32Float, wgpu::TextureFormat::RG32Float, wgpu::TextureFormat::RGBA16Float, + wgpu::TextureFormat::RGBA16Unorm, wgpu::TextureFormat::RGBA32Float,