Extract more StorageTexture information

BUG=tint:489

Change-Id: I03a15fdd156bf0c85b1afebb6e0e26fd44dff51f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42060
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ryan Harrison 2021-02-18 20:11:49 +00:00 committed by Commit Bot service account
parent 15daded41b
commit 94cfbbeb5f
3 changed files with 320 additions and 87 deletions

View File

@ -38,6 +38,7 @@
#include "src/type/matrix_type.h" #include "src/type/matrix_type.h"
#include "src/type/multisampled_texture_type.h" #include "src/type/multisampled_texture_type.h"
#include "src/type/sampled_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/struct_type.h"
#include "src/type/texture_type.h" #include "src/type/texture_type.h"
#include "src/type/type.h" #include "src/type/type.h"
@ -60,6 +61,131 @@ void AppendResourceBindings(std::vector<ResourceBinding>* dest,
dest->insert(dest->end(), orig.begin(), orig.end()); 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<type::Array>()) {
base_type = at->type();
} else if (auto* mt = base_type->As<type::Matrix>()) {
base_type = mt->type();
} else if (auto* vt = base_type->As<type::Vector>()) {
base_type = vt->type();
}
if (base_type->Is<type::F32>()) {
return ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<type::U32>()) {
return ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<type::I32>()) {
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 } // namespace
Inspector::Inspector(const Program* program) : program_(program) {} Inspector::Inspector(const Program* program) : program_(program) {}
@ -428,32 +554,8 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
entry.binding = binding_info.binding->value(); entry.binding = binding_info.binding->value();
auto* texture_type = decl->type()->UnwrapIfNeeded()->As<type::Texture>(); auto* texture_type = decl->type()->UnwrapIfNeeded()->As<type::Texture>();
switch (texture_type->dim()) { entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
case type::TextureDimension::k1d: texture_type->dim());
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;
}
type::Type* base_type = nullptr; type::Type* base_type = nullptr;
if (multisampled_only) { if (multisampled_only) {
@ -464,24 +566,7 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
base_type = base_type =
texture_type->As<type::SampledTexture>()->type()->UnwrapIfNeeded(); texture_type->As<type::SampledTexture>()->type()->UnwrapIfNeeded();
} }
entry.sampled_kind = BaseTypeToSampledKind(base_type);
if (auto* at = base_type->As<type::Array>()) {
base_type = at->type();
} else if (auto* mt = base_type->As<type::Matrix>()) {
base_type = mt->type();
} else if (auto* vt = base_type->As<type::Vector>()) {
base_type = vt->type();
}
if (base_type->Is<type::F32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<type::U32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<type::I32>()) {
entry.sampled_kind = ResourceBinding::SampledKind::kSInt;
} else {
entry.sampled_kind = ResourceBinding::SampledKind::kUnknown;
}
result.push_back(entry); result.push_back(entry);
} }
@ -520,6 +605,16 @@ std::vector<ResourceBinding> Inspector::GetStorageTextureResourceBindingsImpl(
entry.bind_group = binding_info.group->value(); entry.bind_group = binding_info.group->value();
entry.binding = binding_info.binding->value(); entry.binding = binding_info.binding->value();
auto* texture_type = decl->type()->UnwrapIfNeeded()->As<type::Texture>();
entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
texture_type->dim());
type::Type* base_type =
texture_type->As<type::StorageTexture>()->type()->UnwrapIfNeeded();
entry.sampled_kind = BaseTypeToSampledKind(base_type);
entry.image_format = TypeImageFormatToResourceBindingImageFormat(
texture_type->As<type::StorageTexture>()->image_format());
result.push_back(entry); result.push_back(entry);
} }

View File

@ -55,6 +55,45 @@ struct ResourceBinding {
/// in SPIR-V OpTypeImage. /// in SPIR-V OpTypeImage.
enum class SampledKind { kUnknown = -1, kFloat, kUInt, kSInt }; 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. /// kXXX maps to entries returned by GetXXXResourceBindings call.
enum class ResourceType { enum class ResourceType {
kUniformBuffer, kUniformBuffer,
@ -80,6 +119,8 @@ struct ResourceBinding {
TextureDimension dim; TextureDimension dim;
/// Kind of data being sampled, if defined. /// Kind of data being sampled, if defined.
SampledKind sampled_kind; SampledKind sampled_kind;
/// Format of data, if defined.
ImageFormat image_format;
}; };
/// Extracts information from a program /// Extracts information from a program

View File

@ -760,7 +760,14 @@ class InspectorGetMultisampledTextureResourceBindingsTestWithParam
public testing::TestWithParam<GetMultisampledTextureTestParams> {}; public testing::TestWithParam<GetMultisampledTextureTestParams> {};
class InspectorGetStorageTextureResourceBindingsTest : public InspectorHelper, class InspectorGetStorageTextureResourceBindingsTest : public InspectorHelper,
public testing::Test {}; public testing::Test {};
typedef std::tuple<bool, type::TextureDimension, type::ImageFormat>
typedef std::tuple<type::TextureDimension, ResourceBinding::TextureDimension>
DimensionParams;
typedef std::tuple<type::ImageFormat,
ResourceBinding::ImageFormat,
ResourceBinding::SampledKind>
ImageFormatParams;
typedef std::tuple<bool, DimensionParams, ImageFormatParams>
GetStorageTextureTestParams; GetStorageTextureTestParams;
class InspectorGetStorageTextureResourceBindingsTestWithParam class InspectorGetStorageTextureResourceBindingsTestWithParam
: public InspectorHelper, : public InspectorHelper,
@ -2507,9 +2514,18 @@ TEST_F(InspectorGetStorageTextureResourceBindingsTest, Empty) {
TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {
bool read_only; bool read_only;
DimensionParams dim_params;
ImageFormatParams format_params;
std::tie(read_only, dim_params, format_params) = GetParam();
type::TextureDimension dim; type::TextureDimension dim;
ResourceBinding::TextureDimension expected_dim;
std::tie(dim, expected_dim) = dim_params;
type::ImageFormat format; 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::StorageTexture* st_type;
type::Type* st_subtype; type::Type* st_subtype;
@ -2555,6 +2571,9 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {
result[0].resource_type); result[0].resource_type);
EXPECT_EQ(0u, result[0].bind_group); EXPECT_EQ(0u, result[0].bind_group);
EXPECT_EQ(0u, result[0].binding); 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 result = read_only
? inspector.GetWriteOnlyStorageTextureResourceBindings("ep") ? inspector.GetWriteOnlyStorageTextureResourceBindings("ep")
@ -2566,47 +2585,125 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
InspectorGetStorageTextureResourceBindingsTest, InspectorGetStorageTextureResourceBindingsTest,
InspectorGetStorageTextureResourceBindingsTestWithParam, InspectorGetStorageTextureResourceBindingsTestWithParam,
testing::Combine(testing::Bool(), testing::Combine(
testing::Values(type::TextureDimension::k1d, testing::Bool(),
type::TextureDimension::k1dArray, testing::Values(
type::TextureDimension::k2d, std::make_tuple(type::TextureDimension::k1d,
type::TextureDimension::k2dArray, ResourceBinding::TextureDimension::k1d),
type::TextureDimension::k3d), std::make_tuple(type::TextureDimension::k1dArray,
testing::Values(type::ImageFormat::kR8Uint, ResourceBinding::TextureDimension::k1dArray),
type::ImageFormat::kR16Uint, std::make_tuple(type::TextureDimension::k2d,
type::ImageFormat::kRg8Uint, ResourceBinding::TextureDimension::k2d),
type::ImageFormat::kR32Uint, std::make_tuple(type::TextureDimension::k2dArray,
type::ImageFormat::kRg16Uint, ResourceBinding::TextureDimension::k2dArray),
type::ImageFormat::kRgba8Uint, std::make_tuple(type::TextureDimension::k3d,
type::ImageFormat::kRg32Uint, ResourceBinding::TextureDimension::k3d)),
type::ImageFormat::kRgba16Uint, testing::Values(
type::ImageFormat::kRgba32Uint, std::make_tuple(type::ImageFormat::kR8Uint,
type::ImageFormat::kR8Sint, ResourceBinding::ImageFormat::kR8Uint,
type::ImageFormat::kR16Sint, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRg8Sint, std::make_tuple(type::ImageFormat::kR16Uint,
type::ImageFormat::kR32Sint, ResourceBinding::ImageFormat::kR16Uint,
type::ImageFormat::kRg16Sint, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRgba8Sint, std::make_tuple(type::ImageFormat::kRg8Uint,
type::ImageFormat::kRg32Sint, ResourceBinding::ImageFormat::kRg8Uint,
type::ImageFormat::kRgba16Sint, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRgba32Sint, std::make_tuple(type::ImageFormat::kR32Uint,
type::ImageFormat::kR8Unorm, ResourceBinding::ImageFormat::kR32Uint,
type::ImageFormat::kRg8Unorm, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRgba8Unorm, std::make_tuple(type::ImageFormat::kRg16Uint,
type::ImageFormat::kRgba8UnormSrgb, ResourceBinding::ImageFormat::kRg16Uint,
type::ImageFormat::kBgra8Unorm, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kBgra8UnormSrgb, std::make_tuple(type::ImageFormat::kRgba8Uint,
type::ImageFormat::kRgb10A2Unorm, ResourceBinding::ImageFormat::kRgba8Uint,
type::ImageFormat::kR8Snorm, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRg8Snorm, std::make_tuple(type::ImageFormat::kRg32Uint,
type::ImageFormat::kRgba8Snorm, ResourceBinding::ImageFormat::kRg32Uint,
type::ImageFormat::kR16Float, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kR32Float, std::make_tuple(type::ImageFormat::kRgba16Uint,
type::ImageFormat::kRg16Float, ResourceBinding::ImageFormat::kRgba16Uint,
type::ImageFormat::kRg11B10Float, ResourceBinding::SampledKind::kUInt),
type::ImageFormat::kRg32Float, std::make_tuple(type::ImageFormat::kRgba32Uint,
type::ImageFormat::kRgba16Float, ResourceBinding::ImageFormat::kRgba32Uint,
type::ImageFormat::kRgba32Float))); 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
} // namespace inspector } // namespace inspector