Add wgpu::TextureFormat::RGB9E5Ufloat

Also update RG11B10Float to be name RG11B10Ufloat

Bug: dawn:22

Change-Id: I0ea76dc25c37ebaeb4c2c2c2a119d00940acc145
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/25760
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez
2020-08-19 21:51:20 +00:00
committed by Commit Bot service account
parent b54c82ed39
commit 2f6e4ec6c0
16 changed files with 173 additions and 76 deletions

View File

@@ -282,7 +282,8 @@ namespace dawn_native {
AddColorFormat(wgpu::TextureFormat::BGRA8UnormSrgb, true, false, 4, Type::Float);
AddColorFormat(wgpu::TextureFormat::RGB10A2Unorm, true, false, 4, Type::Float);
AddColorFormat(wgpu::TextureFormat::RG11B10Float, false, false, 4, Type::Float);
AddColorFormat(wgpu::TextureFormat::RG11B10Ufloat, false, false, 4, Type::Float);
AddColorFormat(wgpu::TextureFormat::RGB9E5Ufloat, false, false, 4, Type::Float);
// 8 bytes color formats
AddColorFormat(wgpu::TextureFormat::RG32Uint, true, true, 8, Type::Uint);

View File

@@ -37,7 +37,7 @@ namespace dawn_native {
// The number of formats Dawn knows about. Asserts in BuildFormatTable ensure that this is the
// exact number of known format.
static constexpr size_t kKnownFormatCount = 52;
static constexpr size_t kKnownFormatCount = 53;
// A wgpu::TextureFormat along with all the information about it necessary for validation.
struct Format : TexelBlockInfo {

View File

@@ -194,7 +194,7 @@ namespace dawn_native {
case spv::ImageFormatRgb10A2:
return wgpu::TextureFormat::RGB10A2Unorm;
case spv::ImageFormatR11fG11fB10f:
return wgpu::TextureFormat::RG11B10Float;
return wgpu::TextureFormat::RG11B10Ufloat;
case spv::ImageFormatRg32f:
return wgpu::TextureFormat::RG32Float;
case spv::ImageFormatRg32ui:
@@ -265,7 +265,7 @@ namespace dawn_native {
case shaderc_spvc_storage_texture_format_rgb10a2unorm:
return wgpu::TextureFormat::RGB10A2Unorm;
case shaderc_spvc_storage_texture_format_rg11b10float:
return wgpu::TextureFormat::RG11B10Float;
return wgpu::TextureFormat::RG11B10Ufloat;
case shaderc_spvc_storage_texture_format_rg32float:
return wgpu::TextureFormat::RG32Float;
case shaderc_spvc_storage_texture_format_rg32uint:

View File

@@ -144,8 +144,10 @@ namespace dawn_native { namespace d3d12 {
case wgpu::TextureFormat::RGB10A2Unorm:
return DXGI_FORMAT_R10G10B10A2_TYPELESS;
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
return DXGI_FORMAT_R11G11B10_FLOAT;
case wgpu::TextureFormat::RGB9E5Ufloat:
return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
case wgpu::TextureFormat::RG32Uint:
case wgpu::TextureFormat::RG32Sint:
@@ -258,8 +260,10 @@ namespace dawn_native { namespace d3d12 {
return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
case wgpu::TextureFormat::RGB10A2Unorm:
return DXGI_FORMAT_R10G10B10A2_UNORM;
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
return DXGI_FORMAT_R11G11B10_FLOAT;
case wgpu::TextureFormat::RGB9E5Ufloat:
return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
case wgpu::TextureFormat::RG32Uint:
return DXGI_FORMAT_R32G32_UINT;

View File

@@ -172,8 +172,10 @@ namespace dawn_native { namespace metal {
return MTLPixelFormatBGRA8Unorm_sRGB;
case wgpu::TextureFormat::RGB10A2Unorm:
return MTLPixelFormatRGB10A2Unorm;
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
return MTLPixelFormatRG11B10Float;
case wgpu::TextureFormat::RGB9E5Ufloat:
return MTLPixelFormatRGB9E5Float;
case wgpu::TextureFormat::RG32Uint:
return MTLPixelFormatRG32Uint;

View File

@@ -74,7 +74,8 @@ namespace dawn_native { namespace opengl {
// This doesn't have an enum for the internal format in OpenGL, so use RGBA8.
AddFormat(wgpu::TextureFormat::BGRA8Unorm, GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, Type::Float);
AddFormat(wgpu::TextureFormat::RGB10A2Unorm, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, Type::Float);
AddFormat(wgpu::TextureFormat::RG11B10Float, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, Type::Float);
AddFormat(wgpu::TextureFormat::RG11B10Ufloat, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, Type::Float);
AddFormat(wgpu::TextureFormat::RGB9E5Ufloat, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, Type::Float);
// 8 bytes color formats
AddFormat(wgpu::TextureFormat::RG32Uint, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, Type::Uint);

View File

@@ -295,8 +295,10 @@ namespace dawn_native { namespace vulkan {
return VK_FORMAT_B8G8R8A8_SRGB;
case wgpu::TextureFormat::RGB10A2Unorm:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
case wgpu::TextureFormat::RGB9E5Ufloat:
return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
case wgpu::TextureFormat::RG32Uint:
return VK_FORMAT_R32G32_UINT;

View File

@@ -20,6 +20,7 @@
#include "utils/TextureFormatUtils.h"
#include "utils/WGPUHelpers.h"
#include <cmath>
#include <type_traits>
// An expectation for float buffer content that can correctly compare different NaN values and
@@ -685,8 +686,8 @@ TEST_P(TextureFormatTest, RGB10A2Unorm) {
uncompressedData, textureData);
}
// Test the RG11B10Float format
TEST_P(TextureFormatTest, RG11B10Float) {
// Test the RG11B10Ufloat format
TEST_P(TextureFormatTest, RG11B10Ufloat) {
constexpr uint32_t kFloat11Zero = 0;
constexpr uint32_t kFloat11Infinity = 0x7C0;
constexpr uint32_t kFloat11Nan = 0x7C1;
@@ -714,7 +715,7 @@ TEST_P(TextureFormatTest, RG11B10Float) {
};
// 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
// should always be sampled as 1
// clang-format off
std::vector<float> uncompressedData = {
0.0f, INFINITY, NAN, 1.0f,
@@ -725,7 +726,54 @@ TEST_P(TextureFormatTest, RG11B10Float) {
// clang-format on
DoFloatFormatSamplingTest(
{wgpu::TextureFormat::RG11B10Float, 4, wgpu::TextureComponentType::Float, 4}, textureData,
{wgpu::TextureFormat::RG11B10Ufloat, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData);
// This format is not renderable.
}
// Test the RGB9E5Ufloat format
TEST_P(TextureFormatTest, RGB9E5Ufloat) {
// RGB9E5 is different from other floating point formats because the mantissa doesn't index in
// the window defined by the exponent but is instead treated as a pure multiplier. There is
// also no Infinity or NaN. The OpenGL 4.6 spec has the best explanation I've found in section
// 8.25 "Shared Exponent Texture Color Conversion":
//
// red = reduint * 2^(expuint - B - N) = reduint * 2^(expuint - 24)
//
// Where reduint and expuint are the integer values when considering the E5 as a 5bit uint, and
// the r9 as a 9bit uint. B the number of bits of the mantissa (9), and N the offset for the
// exponent (15).
float smallestExponent = std::pow(2.0f, -24.0f);
float largestExponent = std::pow(2.0f, float(31 - 24));
auto MakeRGB9E5 = [](uint32_t r, uint32_t g, uint32_t b, uint32_t e) {
ASSERT((r & 0x1FF) == r);
ASSERT((g & 0x1FF) == g);
ASSERT((b & 0x1FF) == b);
ASSERT((e & 0x1F) == e);
return r | g << 9 | b << 18 | e << 27;
};
// Test the smallest largest, and "1" exponents
std::vector<uint32_t> textureData = {
MakeRGB9E5(0, 1, 2, 0b00000),
MakeRGB9E5(2, 1, 0, 0b11111),
MakeRGB9E5(0, 1, 2, 0b11000),
};
// This is one of the only 3-channel formats, so we don't have specific testing for them. Alpha
// should always be sampled as 1
// clang-format off
std::vector<float> uncompressedData = {
0.0f, smallestExponent, 2.0f * smallestExponent, 1.0f,
2.0f * largestExponent, largestExponent, 0.0f, 1.0f,
0.0f, 1.0f, 2.0f, 1.0f,
};
// clang-format on
DoFloatFormatSamplingTest(
{wgpu::TextureFormat::RGB9E5Ufloat, 4, wgpu::TextureComponentType::Float, 4}, textureData,
uncompressedData);
// This format is not renderable.
}

View File

@@ -152,11 +152,11 @@ TEST_F(RenderPipelineValidationTest, NonRenderableFormat) {
}
{
// Fails because RG11B10Float is non-renderable
// Fails because RG11B10Ufloat is non-renderable
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule;
descriptor.cColorStates[0].format = wgpu::TextureFormat::RG11B10Float;
descriptor.cColorStates[0].format = wgpu::TextureFormat::RG11B10Ufloat;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}

View File

@@ -344,7 +344,7 @@ TEST_F(StorageTextureValidationTests, StorageTextureFormatInShaders) {
wgpu::TextureFormat::RG8Snorm, wgpu::TextureFormat::RG8Uint,
wgpu::TextureFormat::RG8Sint, wgpu::TextureFormat::RG16Uint,
wgpu::TextureFormat::RG16Sint, wgpu::TextureFormat::RG16Float,
wgpu::TextureFormat::RGB10A2Unorm, wgpu::TextureFormat::RG11B10Float};
wgpu::TextureFormat::RGB10A2Unorm, wgpu::TextureFormat::RG11B10Ufloat};
for (wgpu::BindingType storageTextureBindingType : kSupportedStorageTextureBindingTypes) {
for (wgpu::TextureFormat format : kWGPUTextureFormatSupportedAsSPIRVImageFormats) {

View File

@@ -330,7 +330,7 @@ namespace {
device.CreateTexture(&descriptor);
wgpu::TextureFormat nonRenderableFormats[] = {
wgpu::TextureFormat::RG11B10Float,
wgpu::TextureFormat::RG11B10Ufloat,
wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::RG8Snorm,
wgpu::TextureFormat::RGBA8Snorm,

View File

@@ -27,7 +27,8 @@ namespace utils {
case wgpu::TextureFormat::RGBA8Unorm:
case wgpu::TextureFormat::RGBA8Snorm:
case wgpu::TextureFormat::RGB10A2Unorm:
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
case wgpu::TextureFormat::RGB9E5Ufloat:
case wgpu::TextureFormat::RG32Float:
case wgpu::TextureFormat::RGBA16Float:
case wgpu::TextureFormat::RGBA32Float:
@@ -118,7 +119,8 @@ namespace utils {
case wgpu::TextureFormat::BGRA8Unorm:
case wgpu::TextureFormat::BGRA8UnormSrgb:
case wgpu::TextureFormat::RGB10A2Unorm:
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
case wgpu::TextureFormat::RGB9E5Ufloat:
case wgpu::TextureFormat::Depth32Float:
return 4u;
@@ -189,7 +191,8 @@ namespace utils {
case wgpu::TextureFormat::BGRA8Unorm:
case wgpu::TextureFormat::BGRA8UnormSrgb:
case wgpu::TextureFormat::RGB10A2Unorm:
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
case wgpu::TextureFormat::RGB9E5Ufloat:
case wgpu::TextureFormat::RG32Float:
case wgpu::TextureFormat::RG32Uint:
case wgpu::TextureFormat::RG32Sint:
@@ -254,7 +257,8 @@ namespace utils {
case wgpu::TextureFormat::BGRA8Unorm:
case wgpu::TextureFormat::BGRA8UnormSrgb:
case wgpu::TextureFormat::RGB10A2Unorm:
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
case wgpu::TextureFormat::RGB9E5Ufloat:
case wgpu::TextureFormat::RG32Float:
case wgpu::TextureFormat::RG32Uint:
case wgpu::TextureFormat::RG32Sint:
@@ -338,7 +342,7 @@ namespace utils {
return "rgba8i";
case wgpu::TextureFormat::RGB10A2Unorm:
return "rgb10_a2";
case wgpu::TextureFormat::RG11B10Float:
case wgpu::TextureFormat::RG11B10Ufloat:
return "r11f_g11f_b10f";
case wgpu::TextureFormat::RG32Float:
return "rg32f";
@@ -359,6 +363,7 @@ namespace utils {
case wgpu::TextureFormat::RGBA32Sint:
return "rgba32i";
case wgpu::TextureFormat::RGB9E5Ufloat:
case wgpu::TextureFormat::RGBA8UnormSrgb:
case wgpu::TextureFormat::BGRA8Unorm:
case wgpu::TextureFormat::BGRA8UnormSrgb:

View File

@@ -22,33 +22,60 @@
#include "common/Assert.h"
namespace utils {
static constexpr std::array<wgpu::TextureFormat, 52> kAllTextureFormats = {
wgpu::TextureFormat::R8Unorm, wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::R8Uint, wgpu::TextureFormat::R8Sint,
wgpu::TextureFormat::R16Uint, wgpu::TextureFormat::R16Sint,
wgpu::TextureFormat::R16Float, wgpu::TextureFormat::RG8Unorm,
wgpu::TextureFormat::RG8Snorm, wgpu::TextureFormat::RG8Uint,
wgpu::TextureFormat::RG8Sint, wgpu::TextureFormat::R32Float,
wgpu::TextureFormat::R32Uint, wgpu::TextureFormat::R32Sint,
wgpu::TextureFormat::RG16Uint, wgpu::TextureFormat::RG16Sint,
wgpu::TextureFormat::RG16Float, wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureFormat::RGBA8UnormSrgb, wgpu::TextureFormat::RGBA8Snorm,
wgpu::TextureFormat::RGBA8Uint, wgpu::TextureFormat::RGBA8Sint,
wgpu::TextureFormat::BGRA8Unorm, wgpu::TextureFormat::BGRA8UnormSrgb,
wgpu::TextureFormat::RGB10A2Unorm, wgpu::TextureFormat::RG11B10Float,
wgpu::TextureFormat::RG32Float, wgpu::TextureFormat::RG32Uint,
wgpu::TextureFormat::RG32Sint, wgpu::TextureFormat::RGBA16Uint,
wgpu::TextureFormat::RGBA16Sint, wgpu::TextureFormat::RGBA16Float,
wgpu::TextureFormat::RGBA32Float, wgpu::TextureFormat::RGBA32Uint,
wgpu::TextureFormat::RGBA32Sint, wgpu::TextureFormat::Depth32Float,
wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm,
wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm,
wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat,
wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb,
static constexpr std::array<wgpu::TextureFormat, 53> kAllTextureFormats = {
wgpu::TextureFormat::R8Unorm,
wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::R8Uint,
wgpu::TextureFormat::R8Sint,
wgpu::TextureFormat::R16Uint,
wgpu::TextureFormat::R16Sint,
wgpu::TextureFormat::R16Float,
wgpu::TextureFormat::RG8Unorm,
wgpu::TextureFormat::RG8Snorm,
wgpu::TextureFormat::RG8Uint,
wgpu::TextureFormat::RG8Sint,
wgpu::TextureFormat::R32Float,
wgpu::TextureFormat::R32Uint,
wgpu::TextureFormat::R32Sint,
wgpu::TextureFormat::RG16Uint,
wgpu::TextureFormat::RG16Sint,
wgpu::TextureFormat::RG16Float,
wgpu::TextureFormat::RGBA8Unorm,
wgpu::TextureFormat::RGBA8UnormSrgb,
wgpu::TextureFormat::RGBA8Snorm,
wgpu::TextureFormat::RGBA8Uint,
wgpu::TextureFormat::RGBA8Sint,
wgpu::TextureFormat::BGRA8Unorm,
wgpu::TextureFormat::BGRA8UnormSrgb,
wgpu::TextureFormat::RGB10A2Unorm,
wgpu::TextureFormat::RG11B10Ufloat,
wgpu::TextureFormat::RGB9E5Ufloat,
wgpu::TextureFormat::RG32Float,
wgpu::TextureFormat::RG32Uint,
wgpu::TextureFormat::RG32Sint,
wgpu::TextureFormat::RGBA16Uint,
wgpu::TextureFormat::RGBA16Sint,
wgpu::TextureFormat::RGBA16Float,
wgpu::TextureFormat::RGBA32Float,
wgpu::TextureFormat::RGBA32Uint,
wgpu::TextureFormat::RGBA32Sint,
wgpu::TextureFormat::Depth32Float,
wgpu::TextureFormat::Depth24Plus,
wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureFormat::BC1RGBAUnorm,
wgpu::TextureFormat::BC1RGBAUnormSrgb,
wgpu::TextureFormat::BC2RGBAUnorm,
wgpu::TextureFormat::BC2RGBAUnormSrgb,
wgpu::TextureFormat::BC3RGBAUnorm,
wgpu::TextureFormat::BC3RGBAUnormSrgb,
wgpu::TextureFormat::BC4RUnorm,
wgpu::TextureFormat::BC4RSnorm,
wgpu::TextureFormat::BC5RGUnorm,
wgpu::TextureFormat::BC5RGSnorm,
wgpu::TextureFormat::BC6HRGBUfloat,
wgpu::TextureFormat::BC6HRGBSfloat,
wgpu::TextureFormat::BC7RGBAUnorm,
wgpu::TextureFormat::BC7RGBAUnormSrgb,
};
const char* GetColorTextureComponentTypePrefix(wgpu::TextureFormat textureFormat);