mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Add most WebGPU texture formats on Vulkan
This adds the formats to dawn.json, implements support in the Vulkan backend and adds tests performing basic sampling checks for all formats. The R8UnormSrgb and RG8UnormSrgb formats skipped because they are not required in Vulkan (and RG8UnormSrgb is in fact not supported on the machine used for developing this CL). A PR will be sent to the WebGPU repo to remove the from the initial list of formats. The RG11B10Float and RGB10A2Unorm formats of WebGPU are replaced with B10GR11Float and A2RGB10Unorm that are the formats exposed by Vulkan. It is likely that all APIs implement them with components stored in that order. Each format except depth-stencil ones is tested by uploading some interesting texel data and checking that sampling from the texture produces correct results. The goal is to make sure that backends don't make a mistake in the giant switch statements. There was no effort made to check the hardware implementation of the formats. Tests will later be extended to cover rendering and clearing operations as well as multisample resolve. It isn't clear if depth-stencil format will support TRANSFER operations in WebGPU so these are left untested for now. BUG=dawn:128 Change-Id: I78ac5bf77b57398155551e6db3de50b478d69452 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8363 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:
committed by
Commit Bot service account
parent
b6096db4ab
commit
431d618961
@@ -129,19 +129,65 @@ namespace dawn_native {
|
||||
|
||||
switch (format) {
|
||||
case dawn::TextureFormat::R8Unorm:
|
||||
case dawn::TextureFormat::R8Snorm:
|
||||
case dawn::TextureFormat::R8Uint:
|
||||
case dawn::TextureFormat::R8Sint:
|
||||
return MakeColorFormat(format, true, 1);
|
||||
|
||||
case dawn::TextureFormat::R16Unorm:
|
||||
case dawn::TextureFormat::R16Snorm:
|
||||
case dawn::TextureFormat::R16Uint:
|
||||
case dawn::TextureFormat::R16Sint:
|
||||
case dawn::TextureFormat::R16Float:
|
||||
case dawn::TextureFormat::RG8Unorm:
|
||||
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:
|
||||
case dawn::TextureFormat::R32Sint:
|
||||
case dawn::TextureFormat::R32Float:
|
||||
case dawn::TextureFormat::RG16Unorm:
|
||||
case dawn::TextureFormat::RG16Snorm:
|
||||
case dawn::TextureFormat::RG16Uint:
|
||||
case dawn::TextureFormat::RG16Sint:
|
||||
case dawn::TextureFormat::RG16Float:
|
||||
case dawn::TextureFormat::RGBA8Unorm:
|
||||
case dawn::TextureFormat::RGBA8UnormSrgb:
|
||||
case dawn::TextureFormat::RGBA8Snorm:
|
||||
case dawn::TextureFormat::RGBA8Uint:
|
||||
case dawn::TextureFormat::RGBA8Sint:
|
||||
case dawn::TextureFormat::BGRA8Unorm:
|
||||
case dawn::TextureFormat::BGRA8UnormSrgb:
|
||||
case dawn::TextureFormat::A2RGB10Unorm:
|
||||
case dawn::TextureFormat::B10GR11Float:
|
||||
return MakeColorFormat(format, true, 4);
|
||||
|
||||
case dawn::TextureFormat::RG32Uint:
|
||||
case dawn::TextureFormat::RG32Sint:
|
||||
case dawn::TextureFormat::RG32Float:
|
||||
case dawn::TextureFormat::RGBA16Unorm:
|
||||
case dawn::TextureFormat::RGBA16Snorm:
|
||||
case dawn::TextureFormat::RGBA16Uint:
|
||||
case dawn::TextureFormat::RGBA16Sint:
|
||||
case dawn::TextureFormat::RGBA16Float:
|
||||
return MakeColorFormat(format, true, 8);
|
||||
|
||||
case dawn::TextureFormat::RGBA32Uint:
|
||||
case dawn::TextureFormat::RGBA32Sint:
|
||||
case dawn::TextureFormat::RGBA32Float:
|
||||
return MakeColorFormat(format, true, 16);
|
||||
|
||||
case dawn::TextureFormat::Depth32Float:
|
||||
case dawn::TextureFormat::Depth24Plus:
|
||||
return MakeDepthStencilFormat(format, Format::Aspect::Depth, 4);
|
||||
case dawn::TextureFormat::Depth24PlusStencil8:
|
||||
// TODO(cwallez@chromium.org): It isn't clear if this format should be copyable
|
||||
// because its size isn't well defined, is it 4, 5 or 8?
|
||||
return MakeDepthStencilFormat(format, Format::Aspect::DepthStencil, 4);
|
||||
|
||||
case dawn::TextureFormat::BC1RGBAUnorm:
|
||||
case dawn::TextureFormat::BC1RGBAUnormSrgb:
|
||||
case dawn::TextureFormat::BC4RSnorm:
|
||||
|
||||
@@ -211,22 +211,131 @@ namespace dawn_native { namespace vulkan {
|
||||
// Converts Dawn texture format to Vulkan formats.
|
||||
VkFormat VulkanImageFormat(dawn::TextureFormat format) {
|
||||
switch (format) {
|
||||
case dawn::TextureFormat::RGBA8Unorm:
|
||||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case dawn::TextureFormat::RG8Unorm:
|
||||
return VK_FORMAT_R8G8_UNORM;
|
||||
case dawn::TextureFormat::R8Unorm:
|
||||
return VK_FORMAT_R8_UNORM;
|
||||
case dawn::TextureFormat::RGBA8Uint:
|
||||
return VK_FORMAT_R8G8B8A8_UINT;
|
||||
case dawn::TextureFormat::RG8Uint:
|
||||
return VK_FORMAT_R8G8_UINT;
|
||||
case dawn::TextureFormat::R8Snorm:
|
||||
return VK_FORMAT_R8_SNORM;
|
||||
case dawn::TextureFormat::R8Uint:
|
||||
return VK_FORMAT_R8_UINT;
|
||||
case dawn::TextureFormat::R8Sint:
|
||||
return VK_FORMAT_R8_SINT;
|
||||
|
||||
case dawn::TextureFormat::R16Unorm:
|
||||
return VK_FORMAT_R16_UNORM;
|
||||
case dawn::TextureFormat::R16Snorm:
|
||||
return VK_FORMAT_R16_SNORM;
|
||||
case dawn::TextureFormat::R16Uint:
|
||||
return VK_FORMAT_R16_UINT;
|
||||
case dawn::TextureFormat::R16Sint:
|
||||
return VK_FORMAT_R16_SINT;
|
||||
case dawn::TextureFormat::R16Float:
|
||||
return VK_FORMAT_R16_SFLOAT;
|
||||
case dawn::TextureFormat::RG8Unorm:
|
||||
return VK_FORMAT_R8G8_UNORM;
|
||||
case dawn::TextureFormat::RG8Snorm:
|
||||
return VK_FORMAT_R8G8_SNORM;
|
||||
case dawn::TextureFormat::RG8Uint:
|
||||
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;
|
||||
case dawn::TextureFormat::R32Sint:
|
||||
return VK_FORMAT_R32_SINT;
|
||||
case dawn::TextureFormat::R32Float:
|
||||
return VK_FORMAT_R32_SFLOAT;
|
||||
case dawn::TextureFormat::RG16Unorm:
|
||||
return VK_FORMAT_R16G16_UNORM;
|
||||
case dawn::TextureFormat::RG16Snorm:
|
||||
return VK_FORMAT_R16G16_SNORM;
|
||||
case dawn::TextureFormat::RG16Uint:
|
||||
return VK_FORMAT_R16G16_UINT;
|
||||
case dawn::TextureFormat::RG16Sint:
|
||||
return VK_FORMAT_R16G16_SINT;
|
||||
case dawn::TextureFormat::RG16Float:
|
||||
return VK_FORMAT_R16G16_SFLOAT;
|
||||
case dawn::TextureFormat::RGBA8Unorm:
|
||||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case dawn::TextureFormat::RGBA8UnormSrgb:
|
||||
return VK_FORMAT_R8G8B8A8_SRGB;
|
||||
case dawn::TextureFormat::RGBA8Snorm:
|
||||
return VK_FORMAT_R8G8B8A8_SNORM;
|
||||
case dawn::TextureFormat::RGBA8Uint:
|
||||
return VK_FORMAT_R8G8B8A8_UINT;
|
||||
case dawn::TextureFormat::RGBA8Sint:
|
||||
return VK_FORMAT_R8G8B8A8_SINT;
|
||||
case dawn::TextureFormat::BGRA8Unorm:
|
||||
return VK_FORMAT_B8G8R8A8_UNORM;
|
||||
case dawn::TextureFormat::BGRA8UnormSrgb:
|
||||
return VK_FORMAT_B8G8R8A8_SRGB;
|
||||
case dawn::TextureFormat::A2RGB10Unorm:
|
||||
return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
|
||||
case dawn::TextureFormat::B10GR11Float:
|
||||
return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
|
||||
|
||||
case dawn::TextureFormat::RG32Uint:
|
||||
return VK_FORMAT_R32G32_UINT;
|
||||
case dawn::TextureFormat::RG32Sint:
|
||||
return VK_FORMAT_R32G32_SINT;
|
||||
case dawn::TextureFormat::RG32Float:
|
||||
return VK_FORMAT_R32G32_SFLOAT;
|
||||
case dawn::TextureFormat::RGBA16Unorm:
|
||||
return VK_FORMAT_R16G16B16A16_UNORM;
|
||||
case dawn::TextureFormat::RGBA16Snorm:
|
||||
return VK_FORMAT_R16G16B16A16_SNORM;
|
||||
case dawn::TextureFormat::RGBA16Uint:
|
||||
return VK_FORMAT_R16G16B16A16_UINT;
|
||||
case dawn::TextureFormat::RGBA16Sint:
|
||||
return VK_FORMAT_R16G16B16A16_SINT;
|
||||
case dawn::TextureFormat::RGBA16Float:
|
||||
return VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
|
||||
case dawn::TextureFormat::RGBA32Uint:
|
||||
return VK_FORMAT_R32G32B32A32_UINT;
|
||||
case dawn::TextureFormat::RGBA32Sint:
|
||||
return VK_FORMAT_R32G32B32A32_SINT;
|
||||
case dawn::TextureFormat::RGBA32Float:
|
||||
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
|
||||
case dawn::TextureFormat::Depth32Float:
|
||||
return VK_FORMAT_D32_SFLOAT;
|
||||
case dawn::TextureFormat::Depth24Plus:
|
||||
return VK_FORMAT_D32_SFLOAT;
|
||||
case dawn::TextureFormat::Depth24PlusStencil8:
|
||||
return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
|
||||
case dawn::TextureFormat::BC1RGBAUnorm:
|
||||
return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC1RGBAUnormSrgb:
|
||||
return VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
|
||||
case dawn::TextureFormat::BC2RGBAUnorm:
|
||||
return VK_FORMAT_BC2_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC2RGBAUnormSrgb:
|
||||
return VK_FORMAT_BC2_SRGB_BLOCK;
|
||||
case dawn::TextureFormat::BC3RGBAUnorm:
|
||||
return VK_FORMAT_BC3_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC3RGBAUnormSrgb:
|
||||
return VK_FORMAT_BC3_SRGB_BLOCK;
|
||||
case dawn::TextureFormat::BC4RSnorm:
|
||||
return VK_FORMAT_BC4_SNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC4RUnorm:
|
||||
return VK_FORMAT_BC4_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC5RGSnorm:
|
||||
return VK_FORMAT_BC5_SNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC5RGUnorm:
|
||||
return VK_FORMAT_BC5_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC6HRGBSfloat:
|
||||
return VK_FORMAT_BC6H_SFLOAT_BLOCK;
|
||||
case dawn::TextureFormat::BC6HRGBUfloat:
|
||||
return VK_FORMAT_BC6H_UFLOAT_BLOCK;
|
||||
case dawn::TextureFormat::BC7RGBAUnorm:
|
||||
return VK_FORMAT_BC7_UNORM_BLOCK;
|
||||
case dawn::TextureFormat::BC7RGBAUnormSrgb:
|
||||
return VK_FORMAT_BC7_SRGB_BLOCK;
|
||||
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user