From 94cfbbeb5fbafc58ad2f8b27eaf77c52363918c7 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 18 Feb 2021 20:11:49 +0000 Subject: [PATCH] Extract more StorageTexture information BUG=tint:489 Change-Id: I03a15fdd156bf0c85b1afebb6e0e26fd44dff51f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42060 Commit-Queue: Ryan Harrison Commit-Queue: dan sinclair Auto-Submit: Ryan Harrison Reviewed-by: dan sinclair --- src/inspector/inspector.cc | 183 ++++++++++++++++++++++++-------- src/inspector/inspector.h | 41 +++++++ src/inspector/inspector_test.cc | 183 ++++++++++++++++++++++++-------- 3 files changed, 320 insertions(+), 87 deletions(-) diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index f699db523e..d53f7a9bd5 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -38,6 +38,7 @@ #include "src/type/matrix_type.h" #include "src/type/multisampled_texture_type.h" #include "src/type/sampled_texture_type.h" +#include "src/type/storage_texture_type.h" #include "src/type/struct_type.h" #include "src/type/texture_type.h" #include "src/type/type.h" @@ -60,6 +61,131 @@ void AppendResourceBindings(std::vector* dest, dest->insert(dest->end(), orig.begin(), orig.end()); } +ResourceBinding::TextureDimension +TypeTextureDimensionToResourceBindingTextureDimension( + const type::TextureDimension& type_dim) { + switch (type_dim) { + case type::TextureDimension::k1d: + return ResourceBinding::TextureDimension::k1d; + case type::TextureDimension::k1dArray: + return ResourceBinding::TextureDimension::k1dArray; + case type::TextureDimension::k2d: + return ResourceBinding::TextureDimension::k2d; + case type::TextureDimension::k2dArray: + return ResourceBinding::TextureDimension::k2dArray; + case type::TextureDimension::k3d: + return ResourceBinding::TextureDimension::k3d; + case type::TextureDimension::kCube: + return ResourceBinding::TextureDimension::kCube; + case type::TextureDimension::kCubeArray: + return ResourceBinding::TextureDimension::kCubeArray; + default: + return ResourceBinding::TextureDimension::kNone; + } +} + +ResourceBinding::SampledKind BaseTypeToSampledKind(type::Type* base_type) { + if (!base_type) { + return ResourceBinding::SampledKind::kUnknown; + } + + if (auto* at = base_type->As()) { + base_type = at->type(); + } else if (auto* mt = base_type->As()) { + base_type = mt->type(); + } else if (auto* vt = base_type->As()) { + base_type = vt->type(); + } + + if (base_type->Is()) { + return ResourceBinding::SampledKind::kFloat; + } else if (base_type->Is()) { + return ResourceBinding::SampledKind::kUInt; + } else if (base_type->Is()) { + return ResourceBinding::SampledKind::kSInt; + } else { + return ResourceBinding::SampledKind::kUnknown; + } +} + +ResourceBinding::ImageFormat TypeImageFormatToResourceBindingImageFormat( + const type::ImageFormat& image_format) { + switch (image_format) { + case type::ImageFormat::kR8Unorm: + return ResourceBinding::ImageFormat::kR8Unorm; + case type::ImageFormat::kR8Snorm: + return ResourceBinding::ImageFormat::kR8Snorm; + case type::ImageFormat::kR8Uint: + return ResourceBinding::ImageFormat::kR8Uint; + case type::ImageFormat::kR8Sint: + return ResourceBinding::ImageFormat::kR8Sint; + case type::ImageFormat::kR16Uint: + return ResourceBinding::ImageFormat::kR16Uint; + case type::ImageFormat::kR16Sint: + return ResourceBinding::ImageFormat::kR16Sint; + case type::ImageFormat::kR16Float: + return ResourceBinding::ImageFormat::kR16Float; + case type::ImageFormat::kRg8Unorm: + return ResourceBinding::ImageFormat::kRg8Unorm; + case type::ImageFormat::kRg8Snorm: + return ResourceBinding::ImageFormat::kRg8Snorm; + case type::ImageFormat::kRg8Uint: + return ResourceBinding::ImageFormat::kRg8Uint; + case type::ImageFormat::kRg8Sint: + return ResourceBinding::ImageFormat::kRg8Sint; + case type::ImageFormat::kR32Uint: + return ResourceBinding::ImageFormat::kR32Uint; + case type::ImageFormat::kR32Sint: + return ResourceBinding::ImageFormat::kR32Sint; + case type::ImageFormat::kR32Float: + return ResourceBinding::ImageFormat::kR32Float; + case type::ImageFormat::kRg16Uint: + return ResourceBinding::ImageFormat::kRg16Uint; + case type::ImageFormat::kRg16Sint: + return ResourceBinding::ImageFormat::kRg16Sint; + case type::ImageFormat::kRg16Float: + return ResourceBinding::ImageFormat::kRg16Float; + case type::ImageFormat::kRgba8Unorm: + return ResourceBinding::ImageFormat::kRgba8Unorm; + case type::ImageFormat::kRgba8UnormSrgb: + return ResourceBinding::ImageFormat::kRgba8UnormSrgb; + case type::ImageFormat::kRgba8Snorm: + return ResourceBinding::ImageFormat::kRgba8Snorm; + case type::ImageFormat::kRgba8Uint: + return ResourceBinding::ImageFormat::kRgba8Uint; + case type::ImageFormat::kRgba8Sint: + return ResourceBinding::ImageFormat::kRgba8Sint; + case type::ImageFormat::kBgra8Unorm: + return ResourceBinding::ImageFormat::kBgra8Unorm; + case type::ImageFormat::kBgra8UnormSrgb: + return ResourceBinding::ImageFormat::kBgra8UnormSrgb; + case type::ImageFormat::kRgb10A2Unorm: + return ResourceBinding::ImageFormat::kRgb10A2Unorm; + case type::ImageFormat::kRg11B10Float: + return ResourceBinding::ImageFormat::kRg11B10Float; + case type::ImageFormat::kRg32Uint: + return ResourceBinding::ImageFormat::kRg32Uint; + case type::ImageFormat::kRg32Sint: + return ResourceBinding::ImageFormat::kRg32Sint; + case type::ImageFormat::kRg32Float: + return ResourceBinding::ImageFormat::kRg32Float; + case type::ImageFormat::kRgba16Uint: + return ResourceBinding::ImageFormat::kRgba16Uint; + case type::ImageFormat::kRgba16Sint: + return ResourceBinding::ImageFormat::kRgba16Sint; + case type::ImageFormat::kRgba16Float: + return ResourceBinding::ImageFormat::kRgba16Float; + case type::ImageFormat::kRgba32Uint: + return ResourceBinding::ImageFormat::kRgba32Uint; + case type::ImageFormat::kRgba32Sint: + return ResourceBinding::ImageFormat::kRgba32Sint; + case type::ImageFormat::kRgba32Float: + return ResourceBinding::ImageFormat::kRgba32Float; + default: + return ResourceBinding::ImageFormat::kNone; + } +} + } // namespace Inspector::Inspector(const Program* program) : program_(program) {} @@ -428,32 +554,8 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( entry.binding = binding_info.binding->value(); auto* texture_type = decl->type()->UnwrapIfNeeded()->As(); - switch (texture_type->dim()) { - case type::TextureDimension::k1d: - entry.dim = ResourceBinding::TextureDimension::k1d; - break; - case type::TextureDimension::k1dArray: - entry.dim = ResourceBinding::TextureDimension::k1dArray; - break; - case type::TextureDimension::k2d: - entry.dim = ResourceBinding::TextureDimension::k2d; - break; - case type::TextureDimension::k2dArray: - entry.dim = ResourceBinding::TextureDimension::k2dArray; - break; - case type::TextureDimension::k3d: - entry.dim = ResourceBinding::TextureDimension::k3d; - break; - case type::TextureDimension::kCube: - entry.dim = ResourceBinding::TextureDimension::kCube; - break; - case type::TextureDimension::kCubeArray: - entry.dim = ResourceBinding::TextureDimension::kCubeArray; - break; - default: - entry.dim = ResourceBinding::TextureDimension::kNone; - break; - } + entry.dim = TypeTextureDimensionToResourceBindingTextureDimension( + texture_type->dim()); type::Type* base_type = nullptr; if (multisampled_only) { @@ -464,24 +566,7 @@ std::vector Inspector::GetSampledTextureResourceBindingsImpl( base_type = texture_type->As()->type()->UnwrapIfNeeded(); } - - if (auto* at = base_type->As()) { - base_type = at->type(); - } else if (auto* mt = base_type->As()) { - base_type = mt->type(); - } else if (auto* vt = base_type->As()) { - base_type = vt->type(); - } - - if (base_type->Is()) { - entry.sampled_kind = ResourceBinding::SampledKind::kFloat; - } else if (base_type->Is()) { - entry.sampled_kind = ResourceBinding::SampledKind::kUInt; - } else if (base_type->Is()) { - entry.sampled_kind = ResourceBinding::SampledKind::kSInt; - } else { - entry.sampled_kind = ResourceBinding::SampledKind::kUnknown; - } + entry.sampled_kind = BaseTypeToSampledKind(base_type); result.push_back(entry); } @@ -520,6 +605,16 @@ std::vector Inspector::GetStorageTextureResourceBindingsImpl( entry.bind_group = binding_info.group->value(); entry.binding = binding_info.binding->value(); + auto* texture_type = decl->type()->UnwrapIfNeeded()->As(); + entry.dim = TypeTextureDimensionToResourceBindingTextureDimension( + texture_type->dim()); + + type::Type* base_type = + texture_type->As()->type()->UnwrapIfNeeded(); + entry.sampled_kind = BaseTypeToSampledKind(base_type); + entry.image_format = TypeImageFormatToResourceBindingImageFormat( + texture_type->As()->image_format()); + result.push_back(entry); } diff --git a/src/inspector/inspector.h b/src/inspector/inspector.h index 38e59a1434..eeab561433 100644 --- a/src/inspector/inspector.h +++ b/src/inspector/inspector.h @@ -55,6 +55,45 @@ struct ResourceBinding { /// in SPIR-V OpTypeImage. enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt }; + enum class ImageFormat { + kNone = -1, + kR8Unorm, + kR8Snorm, + kR8Uint, + kR8Sint, + kR16Uint, + kR16Sint, + kR16Float, + kRg8Unorm, + kRg8Snorm, + kRg8Uint, + kRg8Sint, + kR32Uint, + kR32Sint, + kR32Float, + kRg16Uint, + kRg16Sint, + kRg16Float, + kRgba8Unorm, + kRgba8UnormSrgb, + kRgba8Snorm, + kRgba8Uint, + kRgba8Sint, + kBgra8Unorm, + kBgra8UnormSrgb, + kRgb10A2Unorm, + kRg11B10Float, + kRg32Uint, + kRg32Sint, + kRg32Float, + kRgba16Uint, + kRgba16Sint, + kRgba16Float, + kRgba32Uint, + kRgba32Sint, + kRgba32Float, + }; + /// kXXX maps to entries returned by GetXXXResourceBindings call. enum class ResourceType { kUniformBuffer, @@ -80,6 +119,8 @@ struct ResourceBinding { TextureDimension dim; /// Kind of data being sampled, if defined. SampledKind sampled_kind; + /// Format of data, if defined. + ImageFormat image_format; }; /// Extracts information from a program diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index ca6b110385..001ebe67fb 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -760,7 +760,14 @@ class InspectorGetMultisampledTextureResourceBindingsTestWithParam public testing::TestWithParam {}; class InspectorGetStorageTextureResourceBindingsTest : public InspectorHelper, public testing::Test {}; -typedef std::tuple + +typedef std::tuple + DimensionParams; +typedef std::tuple + ImageFormatParams; +typedef std::tuple GetStorageTextureTestParams; class InspectorGetStorageTextureResourceBindingsTestWithParam : public InspectorHelper, @@ -2507,9 +2514,18 @@ TEST_F(InspectorGetStorageTextureResourceBindingsTest, Empty) { TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { bool read_only; + DimensionParams dim_params; + ImageFormatParams format_params; + std::tie(read_only, dim_params, format_params) = GetParam(); + type::TextureDimension dim; + ResourceBinding::TextureDimension expected_dim; + std::tie(dim, expected_dim) = dim_params; + type::ImageFormat format; - std::tie(read_only, dim, format) = GetParam(); + ResourceBinding::ImageFormat expected_format; + ResourceBinding::SampledKind expected_kind; + std::tie(format, expected_format, expected_kind) = format_params; type::StorageTexture* st_type; type::Type* st_subtype; @@ -2555,6 +2571,9 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { result[0].resource_type); EXPECT_EQ(0u, result[0].bind_group); EXPECT_EQ(0u, result[0].binding); + EXPECT_EQ(expected_dim, result[0].dim); + EXPECT_EQ(expected_format, result[0].image_format); + EXPECT_EQ(expected_kind, result[0].sampled_kind); result = read_only ? inspector.GetWriteOnlyStorageTextureResourceBindings("ep") @@ -2566,47 +2585,125 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { INSTANTIATE_TEST_SUITE_P( InspectorGetStorageTextureResourceBindingsTest, InspectorGetStorageTextureResourceBindingsTestWithParam, - testing::Combine(testing::Bool(), - testing::Values(type::TextureDimension::k1d, - type::TextureDimension::k1dArray, - type::TextureDimension::k2d, - type::TextureDimension::k2dArray, - type::TextureDimension::k3d), - testing::Values(type::ImageFormat::kR8Uint, - type::ImageFormat::kR16Uint, - type::ImageFormat::kRg8Uint, - type::ImageFormat::kR32Uint, - type::ImageFormat::kRg16Uint, - type::ImageFormat::kRgba8Uint, - type::ImageFormat::kRg32Uint, - type::ImageFormat::kRgba16Uint, - type::ImageFormat::kRgba32Uint, - type::ImageFormat::kR8Sint, - type::ImageFormat::kR16Sint, - type::ImageFormat::kRg8Sint, - type::ImageFormat::kR32Sint, - type::ImageFormat::kRg16Sint, - type::ImageFormat::kRgba8Sint, - type::ImageFormat::kRg32Sint, - type::ImageFormat::kRgba16Sint, - type::ImageFormat::kRgba32Sint, - type::ImageFormat::kR8Unorm, - type::ImageFormat::kRg8Unorm, - type::ImageFormat::kRgba8Unorm, - type::ImageFormat::kRgba8UnormSrgb, - type::ImageFormat::kBgra8Unorm, - type::ImageFormat::kBgra8UnormSrgb, - type::ImageFormat::kRgb10A2Unorm, - type::ImageFormat::kR8Snorm, - type::ImageFormat::kRg8Snorm, - type::ImageFormat::kRgba8Snorm, - type::ImageFormat::kR16Float, - type::ImageFormat::kR32Float, - type::ImageFormat::kRg16Float, - type::ImageFormat::kRg11B10Float, - type::ImageFormat::kRg32Float, - type::ImageFormat::kRgba16Float, - type::ImageFormat::kRgba32Float))); + testing::Combine( + testing::Bool(), + testing::Values( + std::make_tuple(type::TextureDimension::k1d, + ResourceBinding::TextureDimension::k1d), + std::make_tuple(type::TextureDimension::k1dArray, + ResourceBinding::TextureDimension::k1dArray), + std::make_tuple(type::TextureDimension::k2d, + ResourceBinding::TextureDimension::k2d), + std::make_tuple(type::TextureDimension::k2dArray, + ResourceBinding::TextureDimension::k2dArray), + std::make_tuple(type::TextureDimension::k3d, + ResourceBinding::TextureDimension::k3d)), + testing::Values( + std::make_tuple(type::ImageFormat::kR8Uint, + ResourceBinding::ImageFormat::kR8Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kR16Uint, + ResourceBinding::ImageFormat::kR16Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRg8Uint, + ResourceBinding::ImageFormat::kRg8Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kR32Uint, + ResourceBinding::ImageFormat::kR32Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRg16Uint, + ResourceBinding::ImageFormat::kRg16Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRgba8Uint, + ResourceBinding::ImageFormat::kRgba8Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRg32Uint, + ResourceBinding::ImageFormat::kRg32Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRgba16Uint, + ResourceBinding::ImageFormat::kRgba16Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kRgba32Uint, + ResourceBinding::ImageFormat::kRgba32Uint, + ResourceBinding::SampledKind::kUInt), + std::make_tuple(type::ImageFormat::kR8Sint, + ResourceBinding::ImageFormat::kR8Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kR16Sint, + ResourceBinding::ImageFormat::kR16Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRg8Sint, + ResourceBinding::ImageFormat::kRg8Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kR32Sint, + ResourceBinding::ImageFormat::kR32Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRg16Sint, + ResourceBinding::ImageFormat::kRg16Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRgba8Sint, + ResourceBinding::ImageFormat::kRgba8Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRg32Sint, + ResourceBinding::ImageFormat::kRg32Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRgba16Sint, + ResourceBinding::ImageFormat::kRgba16Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kRgba32Sint, + ResourceBinding::ImageFormat::kRgba32Sint, + ResourceBinding::SampledKind::kSInt), + std::make_tuple(type::ImageFormat::kR8Unorm, + ResourceBinding::ImageFormat::kR8Unorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRg8Unorm, + ResourceBinding::ImageFormat::kRg8Unorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgba8Unorm, + ResourceBinding::ImageFormat::kRgba8Unorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgba8UnormSrgb, + ResourceBinding::ImageFormat::kRgba8UnormSrgb, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kBgra8Unorm, + ResourceBinding::ImageFormat::kBgra8Unorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kBgra8UnormSrgb, + ResourceBinding::ImageFormat::kBgra8UnormSrgb, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgb10A2Unorm, + ResourceBinding::ImageFormat::kRgb10A2Unorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kR8Snorm, + ResourceBinding::ImageFormat::kR8Snorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRg8Snorm, + ResourceBinding::ImageFormat::kRg8Snorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgba8Snorm, + ResourceBinding::ImageFormat::kRgba8Snorm, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kR16Float, + ResourceBinding::ImageFormat::kR16Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kR32Float, + ResourceBinding::ImageFormat::kR32Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRg16Float, + ResourceBinding::ImageFormat::kRg16Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRg11B10Float, + ResourceBinding::ImageFormat::kRg11B10Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRg32Float, + ResourceBinding::ImageFormat::kRg32Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgba16Float, + ResourceBinding::ImageFormat::kRgba16Float, + ResourceBinding::SampledKind::kFloat), + std::make_tuple(type::ImageFormat::kRgba32Float, + ResourceBinding::ImageFormat::kRgba32Float, + ResourceBinding::SampledKind::kFloat)))); } // namespace } // namespace inspector