Implement WebGPU formats on Metal.
This removes the R5G6B5 format that's only available on iOS on Metal and leaves A2RGB10 unimplemented because it has inverted R and G channels compared to Metal's RGB10A2 format. BUG=dawn:128 Change-Id: I9b960d00f281b4d32318bad3360826b8db5bcb72 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8600 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
5df84cea03
commit
7843076b01
91
dawn.json
91
dawn.json
|
@ -1059,57 +1059,56 @@
|
|||
{"value": 10, "name": "RG8 snorm"},
|
||||
{"value": 11, "name": "RG8 uint"},
|
||||
{"value": 12, "name": "RG8 sint"},
|
||||
{"value": 13, "name": "B5 G6 R5 unorm"},
|
||||
|
||||
{"value": 14, "name": "R32 float"},
|
||||
{"value": 15, "name": "R32 uint"},
|
||||
{"value": 16, "name": "R32 sint"},
|
||||
{"value": 17, "name": "RG16 unorm"},
|
||||
{"value": 18, "name": "RG16 snorm"},
|
||||
{"value": 19, "name": "RG16 uint"},
|
||||
{"value": 20, "name": "RG16 sint"},
|
||||
{"value": 21, "name": "RG16 float"},
|
||||
{"value": 22, "name": "RGBA8 unorm"},
|
||||
{"value": 23, "name": "RGBA8 unorm srgb"},
|
||||
{"value": 24, "name": "RGBA8 snorm"},
|
||||
{"value": 25, "name": "RGBA8 uint"},
|
||||
{"value": 26, "name": "RGBA8 sint"},
|
||||
{"value": 27, "name": "BGRA8 unorm"},
|
||||
{"value": 28, "name": "BGRA8 unorm srgb"},
|
||||
{"value": 29, "name": "A2 RGB10 unorm"},
|
||||
{"value": 30, "name": "B10 GR11 float"},
|
||||
{"value": 13, "name": "R32 float"},
|
||||
{"value": 14, "name": "R32 uint"},
|
||||
{"value": 15, "name": "R32 sint"},
|
||||
{"value": 16, "name": "RG16 unorm"},
|
||||
{"value": 17, "name": "RG16 snorm"},
|
||||
{"value": 18, "name": "RG16 uint"},
|
||||
{"value": 19, "name": "RG16 sint"},
|
||||
{"value": 20, "name": "RG16 float"},
|
||||
{"value": 21, "name": "RGBA8 unorm"},
|
||||
{"value": 22, "name": "RGBA8 unorm srgb"},
|
||||
{"value": 23, "name": "RGBA8 snorm"},
|
||||
{"value": 24, "name": "RGBA8 uint"},
|
||||
{"value": 25, "name": "RGBA8 sint"},
|
||||
{"value": 26, "name": "BGRA8 unorm"},
|
||||
{"value": 27, "name": "BGRA8 unorm srgb"},
|
||||
{"value": 28, "name": "A2 RGB10 unorm"},
|
||||
{"value": 29, "name": "B10 GR11 float"},
|
||||
|
||||
{"value": 31, "name": "RG32 float"},
|
||||
{"value": 32, "name": "RG32 uint"},
|
||||
{"value": 33, "name": "RG32 sint"},
|
||||
{"value": 34, "name": "RGBA16 unorm"},
|
||||
{"value": 35, "name": "RGBA16 snorm"},
|
||||
{"value": 36, "name": "RGBA16 uint"},
|
||||
{"value": 37, "name": "RGBA16 sint"},
|
||||
{"value": 38, "name": "RGBA16 float"},
|
||||
{"value": 30, "name": "RG32 float"},
|
||||
{"value": 31, "name": "RG32 uint"},
|
||||
{"value": 32, "name": "RG32 sint"},
|
||||
{"value": 33, "name": "RGBA16 unorm"},
|
||||
{"value": 34, "name": "RGBA16 snorm"},
|
||||
{"value": 35, "name": "RGBA16 uint"},
|
||||
{"value": 36, "name": "RGBA16 sint"},
|
||||
{"value": 37, "name": "RGBA16 float"},
|
||||
|
||||
{"value": 39, "name": "RGBA32 float"},
|
||||
{"value": 40, "name": "RGBA32 uint"},
|
||||
{"value": 41, "name": "RGBA32 sint"},
|
||||
{"value": 38, "name": "RGBA32 float"},
|
||||
{"value": 39, "name": "RGBA32 uint"},
|
||||
{"value": 40, "name": "RGBA32 sint"},
|
||||
|
||||
{"value": 42, "name": "depth32 float"},
|
||||
{"value": 43, "name": "depth24 plus"},
|
||||
{"value": 44, "name": "depth24 plus stencil8"},
|
||||
{"value": 41, "name": "depth32 float"},
|
||||
{"value": 42, "name": "depth24 plus"},
|
||||
{"value": 43, "name": "depth24 plus stencil8"},
|
||||
|
||||
{"value": 45, "name": "BC1 RGBA unorm"},
|
||||
{"value": 46, "name": "BC1 RGBA unorm srgb"},
|
||||
{"value": 47, "name": "BC2 RGBA unorm"},
|
||||
{"value": 48, "name": "BC2 RGBA unorm srgb"},
|
||||
{"value": 49, "name": "BC3 RGBA unorm"},
|
||||
{"value": 50, "name": "BC3 RGBA unorm srgb"},
|
||||
{"value": 51, "name": "BC4 R unorm"},
|
||||
{"value": 52, "name": "BC4 R snorm"},
|
||||
{"value": 53, "name": "BC5 RG unorm"},
|
||||
{"value": 54, "name": "BC5 RG snorm"},
|
||||
{"value": 55, "name": "BC6H RGB ufloat"},
|
||||
{"value": 56, "name": "BC6H RGB sfloat"},
|
||||
{"value": 57, "name": "BC7 RGBA unorm"},
|
||||
{"value": 58, "name": "BC7 RGBA unorm srgb"}
|
||||
{"value": 44, "name": "BC1 RGBA unorm"},
|
||||
{"value": 45, "name": "BC1 RGBA unorm srgb"},
|
||||
{"value": 46, "name": "BC2 RGBA unorm"},
|
||||
{"value": 47, "name": "BC2 RGBA unorm srgb"},
|
||||
{"value": 48, "name": "BC3 RGBA unorm"},
|
||||
{"value": 49, "name": "BC3 RGBA unorm srgb"},
|
||||
{"value": 50, "name": "BC4 R unorm"},
|
||||
{"value": 51, "name": "BC4 R snorm"},
|
||||
{"value": 52, "name": "BC5 RG unorm"},
|
||||
{"value": 53, "name": "BC5 RG snorm"},
|
||||
{"value": 54, "name": "BC6H RGB ufloat"},
|
||||
{"value": 55, "name": "BC6H RGB sfloat"},
|
||||
{"value": 56, "name": "BC7 RGBA unorm"},
|
||||
{"value": 57, "name": "BC7 RGBA unorm srgb"}
|
||||
],
|
||||
"TODO": [
|
||||
"jiawei.shao@intel.com: support BC formats as extension"
|
||||
|
|
|
@ -143,7 +143,6 @@ namespace dawn_native {
|
|||
case dawn::TextureFormat::RG8Snorm:
|
||||
case dawn::TextureFormat::RG8Uint:
|
||||
case dawn::TextureFormat::RG8Sint:
|
||||
case dawn::TextureFormat::B5G6R5Unorm:
|
||||
return MakeColorFormat(format, true, 2);
|
||||
|
||||
case dawn::TextureFormat::R32Uint:
|
||||
|
|
|
@ -121,25 +121,105 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format) {
|
||||
switch (format) {
|
||||
case dawn::TextureFormat::RGBA8Unorm:
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
case dawn::TextureFormat::RG8Unorm:
|
||||
return MTLPixelFormatRG8Unorm;
|
||||
case dawn::TextureFormat::R8Unorm:
|
||||
return MTLPixelFormatR8Unorm;
|
||||
case dawn::TextureFormat::RGBA8Uint:
|
||||
return MTLPixelFormatRGBA8Uint;
|
||||
case dawn::TextureFormat::RG8Uint:
|
||||
return MTLPixelFormatRG8Uint;
|
||||
case dawn::TextureFormat::R8Snorm:
|
||||
return MTLPixelFormatR8Snorm;
|
||||
case dawn::TextureFormat::R8Uint:
|
||||
return MTLPixelFormatR8Uint;
|
||||
case dawn::TextureFormat::R8Sint:
|
||||
return MTLPixelFormatR8Sint;
|
||||
|
||||
case dawn::TextureFormat::R16Unorm:
|
||||
return MTLPixelFormatR16Unorm;
|
||||
case dawn::TextureFormat::R16Snorm:
|
||||
return MTLPixelFormatR16Snorm;
|
||||
case dawn::TextureFormat::R16Uint:
|
||||
return MTLPixelFormatR16Uint;
|
||||
case dawn::TextureFormat::R16Sint:
|
||||
return MTLPixelFormatR16Sint;
|
||||
case dawn::TextureFormat::R16Float:
|
||||
return MTLPixelFormatR16Float;
|
||||
case dawn::TextureFormat::RG8Unorm:
|
||||
return MTLPixelFormatRG8Unorm;
|
||||
case dawn::TextureFormat::RG8Snorm:
|
||||
return MTLPixelFormatRG8Snorm;
|
||||
case dawn::TextureFormat::RG8Uint:
|
||||
return MTLPixelFormatRG8Uint;
|
||||
case dawn::TextureFormat::RG8Sint:
|
||||
return MTLPixelFormatRG8Sint;
|
||||
|
||||
case dawn::TextureFormat::R32Uint:
|
||||
return MTLPixelFormatR32Uint;
|
||||
case dawn::TextureFormat::R32Sint:
|
||||
return MTLPixelFormatR32Sint;
|
||||
case dawn::TextureFormat::R32Float:
|
||||
return MTLPixelFormatR32Float;
|
||||
case dawn::TextureFormat::RG16Unorm:
|
||||
return MTLPixelFormatRG16Unorm;
|
||||
case dawn::TextureFormat::RG16Snorm:
|
||||
return MTLPixelFormatRG16Snorm;
|
||||
case dawn::TextureFormat::RG16Uint:
|
||||
return MTLPixelFormatRG16Uint;
|
||||
case dawn::TextureFormat::RG16Sint:
|
||||
return MTLPixelFormatRG16Sint;
|
||||
case dawn::TextureFormat::RG16Float:
|
||||
return MTLPixelFormatRG16Float;
|
||||
case dawn::TextureFormat::RGBA8Unorm:
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
case dawn::TextureFormat::RGBA8UnormSrgb:
|
||||
return MTLPixelFormatRGBA8Unorm_sRGB;
|
||||
case dawn::TextureFormat::RGBA8Snorm:
|
||||
return MTLPixelFormatRGBA8Snorm;
|
||||
case dawn::TextureFormat::RGBA8Uint:
|
||||
return MTLPixelFormatRGBA8Uint;
|
||||
case dawn::TextureFormat::RGBA8Sint:
|
||||
return MTLPixelFormatRGBA8Sint;
|
||||
case dawn::TextureFormat::BGRA8Unorm:
|
||||
return MTLPixelFormatBGRA8Unorm;
|
||||
case dawn::TextureFormat::BGRA8UnormSrgb:
|
||||
return MTLPixelFormatBGRA8Unorm_sRGB;
|
||||
case dawn::TextureFormat::A2RGB10Unorm:
|
||||
// TODO(cwallez@chromium.org): The format expectations are inverted compared to the
|
||||
// implementation of the format in Metal.
|
||||
UNREACHABLE();
|
||||
return MTLPixelFormatRGB10A2Unorm;
|
||||
case dawn::TextureFormat::B10GR11Float:
|
||||
return MTLPixelFormatRG11B10Float;
|
||||
|
||||
case dawn::TextureFormat::RG32Uint:
|
||||
return MTLPixelFormatRG32Uint;
|
||||
case dawn::TextureFormat::RG32Sint:
|
||||
return MTLPixelFormatRG32Sint;
|
||||
case dawn::TextureFormat::RG32Float:
|
||||
return MTLPixelFormatRG32Float;
|
||||
case dawn::TextureFormat::RGBA16Unorm:
|
||||
return MTLPixelFormatRGBA16Unorm;
|
||||
case dawn::TextureFormat::RGBA16Snorm:
|
||||
return MTLPixelFormatRGBA16Snorm;
|
||||
case dawn::TextureFormat::RGBA16Uint:
|
||||
return MTLPixelFormatRGBA16Uint;
|
||||
case dawn::TextureFormat::RGBA16Sint:
|
||||
return MTLPixelFormatRGBA16Sint;
|
||||
case dawn::TextureFormat::RGBA16Float:
|
||||
return MTLPixelFormatRGBA16Float;
|
||||
|
||||
case dawn::TextureFormat::RGBA32Uint:
|
||||
return MTLPixelFormatRGBA32Uint;
|
||||
case dawn::TextureFormat::RGBA32Sint:
|
||||
return MTLPixelFormatRGBA32Sint;
|
||||
case dawn::TextureFormat::RGBA32Float:
|
||||
return MTLPixelFormatRGBA32Float;
|
||||
|
||||
case dawn::TextureFormat::Depth32Float:
|
||||
return MTLPixelFormatDepth32Float;
|
||||
case dawn::TextureFormat::Depth24Plus:
|
||||
return MTLPixelFormatDepth32Float;
|
||||
case dawn::TextureFormat::Depth24PlusStencil8:
|
||||
return MTLPixelFormatDepth32Float_Stencil8;
|
||||
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,8 +238,6 @@ namespace dawn_native { namespace vulkan {
|
|||
return VK_FORMAT_R8G8_UINT;
|
||||
case dawn::TextureFormat::RG8Sint:
|
||||
return VK_FORMAT_R8G8_SINT;
|
||||
case dawn::TextureFormat::B5G6R5Unorm:
|
||||
return VK_FORMAT_B5G6R5_UNORM_PACK16;
|
||||
|
||||
case dawn::TextureFormat::R32Uint:
|
||||
return VK_FORMAT_R32_UINT;
|
||||
|
|
|
@ -616,36 +616,13 @@ TEST_P(TextureFormatTest, BGRA8UnormSrgb) {
|
|||
1.0e-3);
|
||||
}
|
||||
|
||||
// Test the B5G6R5Unorm format
|
||||
TEST_P(TextureFormatTest, B5G6R5Unorm) {
|
||||
auto MakeBGR565 = [](uint32_t r, uint32_t g, uint32_t b) -> uint16_t {
|
||||
ASSERT((r & 0x1F) == r);
|
||||
ASSERT((g & 0x3F) == g);
|
||||
ASSERT((b & 0x1F) == b);
|
||||
return b << 11 | g << 5 | r;
|
||||
};
|
||||
|
||||
std::vector<uint16_t> textureData = {MakeBGR565(0, 0, 0), MakeBGR565(31, 63, 31),
|
||||
MakeBGR565(9, 18, 27), MakeBGR565(0, 0, 0)};
|
||||
// This is one of the only 3-channel formats, so we don't have specific testing for them. Alpha
|
||||
// should slways be sampled as 1
|
||||
// clang-format off
|
||||
std::vector<float> expectedData = {
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f,
|
||||
9 / 31.0f, 18 / 63.0f, 27 / 31.0f, 1.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
DoSampleTest({dawn::TextureFormat::B5G6R5Unorm, 2, Float, 4}, textureData, expectedData,
|
||||
1.0e-3);
|
||||
}
|
||||
|
||||
// Test the A2RGB10Unorm format
|
||||
// TODO(cwallez@chromium.org): This is actually RGB10A2 in WebGPU but Vulkan doesn't support that
|
||||
// format. Do all platforms have A in the high bits?
|
||||
TEST_P(TextureFormatTest, A2RGB10Unorm) {
|
||||
// TODO(cwallez@chromium.org): The format R and B channel are inverted compared to what Metal
|
||||
// does.
|
||||
DAWN_SKIP_TEST_IF(IsMetal());
|
||||
auto MakeA2RGB10 = [](uint32_t r, uint32_t g, uint32_t b, uint32_t a) -> uint32_t {
|
||||
ASSERT((r & 0x3FF) == r);
|
||||
ASSERT((g & 0x3FF) == g);
|
||||
|
@ -716,4 +693,4 @@ TEST_P(TextureFormatTest, B10GR11Float) {
|
|||
// TODO(cwallez@chromium.org): Add tests for depth-stencil formats when we know if they are copyable
|
||||
// in WebGPU.
|
||||
|
||||
DAWN_INSTANTIATE_TEST(TextureFormatTest, VulkanBackend);
|
||||
DAWN_INSTANTIATE_TEST(TextureFormatTest, MetalBackend, VulkanBackend);
|
||||
|
|
Loading…
Reference in New Issue