Validate Storage Textures and update existing tests
Adds rejecting unsupported image formats and texture dimensions. BUG=tint:718 Change-Id: Ic6375d1e75524336462ea59b159cb4c8601f55fd Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48500 Auto-Submit: Ryan Harrison <rharrison@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
5b3d88b748
commit
de8f1332f6
|
@ -1722,7 +1722,7 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) {
|
|||
sem::Type* st_subtype;
|
||||
sem::AccessControl* st_ac;
|
||||
std::tie(st_type, st_subtype, st_ac) = MakeStorageTextureTypes(
|
||||
sem::TextureDimension::k2d, sem::ImageFormat::kR8Uint, false);
|
||||
sem::TextureDimension::k2d, sem::ImageFormat::kR32Uint, false);
|
||||
AddStorageTexture("st_var", st_ac, 4, 0);
|
||||
MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2<i32>(), {});
|
||||
|
||||
|
@ -1730,7 +1730,7 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) {
|
|||
sem::Type* rost_subtype;
|
||||
sem::AccessControl* rost_ac;
|
||||
std::tie(rost_type, rost_subtype, rost_ac) = MakeStorageTextureTypes(
|
||||
sem::TextureDimension::k2d, sem::ImageFormat::kR8Uint, true);
|
||||
sem::TextureDimension::k2d, sem::ImageFormat::kR32Uint, true);
|
||||
AddStorageTexture("rost_var", rost_ac, 4, 1);
|
||||
MakeStorageTextureBodyFunction("rost_func", "rost_var", ty.vec2<i32>(), {});
|
||||
|
||||
|
@ -2965,110 +2965,53 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
std::make_tuple(sem::TextureDimension::k3d,
|
||||
ResourceBinding::TextureDimension::k3d)),
|
||||
testing::Values(
|
||||
std::make_tuple(sem::ImageFormat::kR8Uint,
|
||||
ResourceBinding::ImageFormat::kR8Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kR16Uint,
|
||||
ResourceBinding::ImageFormat::kR16Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg8Uint,
|
||||
ResourceBinding::ImageFormat::kRg8Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kR32Uint,
|
||||
ResourceBinding::ImageFormat::kR32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg16Uint,
|
||||
ResourceBinding::ImageFormat::kRg16Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Uint,
|
||||
ResourceBinding::ImageFormat::kRgba8Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg32Uint,
|
||||
ResourceBinding::ImageFormat::kRg32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba16Uint,
|
||||
ResourceBinding::ImageFormat::kRgba16Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba32Uint,
|
||||
ResourceBinding::ImageFormat::kRgba32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kR8Sint,
|
||||
ResourceBinding::ImageFormat::kR8Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kR16Sint,
|
||||
ResourceBinding::ImageFormat::kR16Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg8Sint,
|
||||
ResourceBinding::ImageFormat::kRg8Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kR32Sint,
|
||||
ResourceBinding::ImageFormat::kR32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg16Sint,
|
||||
ResourceBinding::ImageFormat::kRg16Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Sint,
|
||||
ResourceBinding::ImageFormat::kRgba8Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg32Sint,
|
||||
ResourceBinding::ImageFormat::kRg32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba16Sint,
|
||||
ResourceBinding::ImageFormat::kRgba16Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba32Sint,
|
||||
ResourceBinding::ImageFormat::kRgba32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kR8Unorm,
|
||||
ResourceBinding::ImageFormat::kR8Unorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRg8Unorm,
|
||||
ResourceBinding::ImageFormat::kRg8Unorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Unorm,
|
||||
ResourceBinding::ImageFormat::kRgba8Unorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8UnormSrgb,
|
||||
ResourceBinding::ImageFormat::kRgba8UnormSrgb,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kBgra8Unorm,
|
||||
ResourceBinding::ImageFormat::kBgra8Unorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kBgra8UnormSrgb,
|
||||
ResourceBinding::ImageFormat::kBgra8UnormSrgb,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgb10A2Unorm,
|
||||
ResourceBinding::ImageFormat::kRgb10A2Unorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kR8Snorm,
|
||||
ResourceBinding::ImageFormat::kR8Snorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRg8Snorm,
|
||||
ResourceBinding::ImageFormat::kRg8Snorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Snorm,
|
||||
ResourceBinding::ImageFormat::kRgba8Snorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kR16Float,
|
||||
ResourceBinding::ImageFormat::kR16Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kR32Float,
|
||||
ResourceBinding::ImageFormat::kR32Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRg16Float,
|
||||
ResourceBinding::ImageFormat::kRg16Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRg11B10Float,
|
||||
ResourceBinding::ImageFormat::kRg11B10Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kR32Sint,
|
||||
ResourceBinding::ImageFormat::kR32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kR32Uint,
|
||||
ResourceBinding::ImageFormat::kR32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg32Float,
|
||||
ResourceBinding::ImageFormat::kRg32Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRg32Sint,
|
||||
ResourceBinding::ImageFormat::kRg32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRg32Uint,
|
||||
ResourceBinding::ImageFormat::kRg32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba16Float,
|
||||
ResourceBinding::ImageFormat::kRgba16Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba16Sint,
|
||||
ResourceBinding::ImageFormat::kRgba16Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba16Uint,
|
||||
ResourceBinding::ImageFormat::kRgba16Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba32Float,
|
||||
ResourceBinding::ImageFormat::kRgba32Float,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba32Sint,
|
||||
ResourceBinding::ImageFormat::kRgba32Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba32Uint,
|
||||
ResourceBinding::ImageFormat::kRgba32Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Sint,
|
||||
ResourceBinding::ImageFormat::kRgba8Sint,
|
||||
ResourceBinding::SampledKind::kSInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Snorm,
|
||||
ResourceBinding::ImageFormat::kRgba8Snorm,
|
||||
ResourceBinding::SampledKind::kFloat),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Uint,
|
||||
ResourceBinding::ImageFormat::kRgba8Uint,
|
||||
ResourceBinding::SampledKind::kUInt),
|
||||
std::make_tuple(sem::ImageFormat::kRgba8Unorm,
|
||||
ResourceBinding::ImageFormat::kRgba8Unorm,
|
||||
ResourceBinding::SampledKind::kFloat))));
|
||||
|
||||
TEST_P(InspectorGetDepthTextureResourceBindingsTestWithParam,
|
||||
|
|
|
@ -302,29 +302,29 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
ResolverIntrinsicTest_StorageTextureOperation,
|
||||
testing::Values(
|
||||
TextureTestParams{sem::TextureDimension::k1d, Texture::kF32,
|
||||
sem::ImageFormat::kR16Float},
|
||||
sem::ImageFormat::kR32Float},
|
||||
TextureTestParams{sem::TextureDimension::k1d, Texture::kI32,
|
||||
sem::ImageFormat::kR16Sint},
|
||||
sem::ImageFormat::kR32Sint},
|
||||
TextureTestParams{sem::TextureDimension::k1d, Texture::kF32,
|
||||
sem::ImageFormat::kR8Unorm},
|
||||
sem::ImageFormat::kRgba8Unorm},
|
||||
TextureTestParams{sem::TextureDimension::k2d, Texture::kF32,
|
||||
sem::ImageFormat::kR16Float},
|
||||
sem::ImageFormat::kR32Float},
|
||||
TextureTestParams{sem::TextureDimension::k2d, Texture::kI32,
|
||||
sem::ImageFormat::kR16Sint},
|
||||
sem::ImageFormat::kR32Sint},
|
||||
TextureTestParams{sem::TextureDimension::k2d, Texture::kF32,
|
||||
sem::ImageFormat::kR8Unorm},
|
||||
sem::ImageFormat::kRgba8Unorm},
|
||||
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kF32,
|
||||
sem::ImageFormat::kR16Float},
|
||||
sem::ImageFormat::kR32Float},
|
||||
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kI32,
|
||||
sem::ImageFormat::kR16Sint},
|
||||
sem::ImageFormat::kR32Sint},
|
||||
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kF32,
|
||||
sem::ImageFormat::kR8Unorm},
|
||||
sem::ImageFormat::kRgba8Unorm},
|
||||
TextureTestParams{sem::TextureDimension::k3d, Texture::kF32,
|
||||
sem::ImageFormat::kR16Float},
|
||||
sem::ImageFormat::kR32Float},
|
||||
TextureTestParams{sem::TextureDimension::k3d, Texture::kI32,
|
||||
sem::ImageFormat::kR16Sint},
|
||||
sem::ImageFormat::kR32Sint},
|
||||
TextureTestParams{sem::TextureDimension::k3d, Texture::kF32,
|
||||
sem::ImageFormat::kR8Unorm}));
|
||||
sem::ImageFormat::kRgba8Unorm}));
|
||||
|
||||
using ResolverIntrinsicTest_SampledTextureOperation =
|
||||
ResolverIntrinsicTest_TextureOperation;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "src/sem/member_accessor_expression.h"
|
||||
#include "src/sem/multisampled_texture_type.h"
|
||||
#include "src/sem/statement.h"
|
||||
#include "src/sem/storage_texture_type.h"
|
||||
#include "src/sem/struct.h"
|
||||
#include "src/sem/variable.h"
|
||||
#include "src/utils/get_or_create.h"
|
||||
|
@ -77,6 +78,42 @@ Source CombineSourceRange(const Source& start, const Source& end) {
|
|||
start.file_path, start.file_content);
|
||||
}
|
||||
|
||||
bool IsValidStorageTextureDimension(sem::TextureDimension dim) {
|
||||
switch (dim) {
|
||||
case sem::TextureDimension::k1d:
|
||||
case sem::TextureDimension::k2d:
|
||||
case sem::TextureDimension::k2dArray:
|
||||
case sem::TextureDimension::k3d:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidStorageTextureImageFormat(sem::ImageFormat format) {
|
||||
switch (format) {
|
||||
case sem::ImageFormat::kR32Uint:
|
||||
case sem::ImageFormat::kR32Sint:
|
||||
case sem::ImageFormat::kR32Float:
|
||||
case sem::ImageFormat::kRg32Uint:
|
||||
case sem::ImageFormat::kRg32Sint:
|
||||
case sem::ImageFormat::kRg32Float:
|
||||
case sem::ImageFormat::kRgba8Unorm:
|
||||
case sem::ImageFormat::kRgba8Snorm:
|
||||
case sem::ImageFormat::kRgba8Uint:
|
||||
case sem::ImageFormat::kRgba8Sint:
|
||||
case sem::ImageFormat::kRgba16Uint:
|
||||
case sem::ImageFormat::kRgba16Sint:
|
||||
case sem::ImageFormat::kRgba16Float:
|
||||
case sem::ImageFormat::kRgba32Uint:
|
||||
case sem::ImageFormat::kRgba32Sint:
|
||||
case sem::ImageFormat::kRgba32Float:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Resolver::Resolver(ProgramBuilder* builder)
|
||||
|
@ -175,6 +212,7 @@ bool Resolver::IsValidAssignment(sem::Type* lhs, sem::Type* rhs) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -372,14 +410,14 @@ bool Resolver::ValidateVariable(const ast::Variable* var) {
|
|||
}
|
||||
}
|
||||
|
||||
if (auto* mst = type->UnwrapAll()->As<sem::MultisampledTexture>()) {
|
||||
if (mst->dim() != sem::TextureDimension::k2d) {
|
||||
if (auto* r = type->UnwrapAll()->As<sem::MultisampledTexture>()) {
|
||||
if (r->dim() != sem::TextureDimension::k2d) {
|
||||
diagnostics_.add_error("Only 2d multisampled textures are supported",
|
||||
var->source());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* data_type = mst->type()->UnwrapAll();
|
||||
auto* data_type = r->type()->UnwrapAll();
|
||||
if (!data_type->is_numeric_scalar()) {
|
||||
diagnostics_.add_error(
|
||||
"texture_multisampled_2d<type>: type must be f32, i32 or u32",
|
||||
|
@ -388,6 +426,24 @@ bool Resolver::ValidateVariable(const ast::Variable* var) {
|
|||
}
|
||||
}
|
||||
|
||||
if (auto* r = type->UnwrapAll()->As<sem::StorageTexture>()) {
|
||||
if (!IsValidStorageTextureDimension(r->dim())) {
|
||||
diagnostics_.add_error(
|
||||
"Cube dimensions for storage textures are not "
|
||||
"supported.",
|
||||
var->source());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsValidStorageTextureImageFormat(r->image_format())) {
|
||||
diagnostics_.add_error(
|
||||
"image format must be one of the texel formats specified for storage "
|
||||
"textues in https://gpuweb.github.io/gpuweb/wgsl/#texel-formats",
|
||||
var->source());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "src/resolver/resolver.h"
|
||||
#include "src/resolver/resolver_test_helper.h"
|
||||
#include "src/sem/multisampled_texture_type.h"
|
||||
#include "src/sem/storage_texture_type.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
|
@ -613,6 +614,146 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
|||
|
||||
} // namespace MultisampledTextureTests
|
||||
|
||||
namespace StorageTextureTests {
|
||||
struct DimensionParams {
|
||||
sem::TextureDimension dim;
|
||||
bool is_valid;
|
||||
};
|
||||
|
||||
static constexpr DimensionParams Dimension_cases[] = {
|
||||
DimensionParams{sem::TextureDimension::k1d, true},
|
||||
DimensionParams{sem::TextureDimension::k2d, true},
|
||||
DimensionParams{sem::TextureDimension::k2dArray, true},
|
||||
DimensionParams{sem::TextureDimension::k3d, true},
|
||||
DimensionParams{sem::TextureDimension::kCube, false},
|
||||
DimensionParams{sem::TextureDimension::kCubeArray, false}};
|
||||
|
||||
using StorageTextureDimensionTest = ResolverTestWithParam<DimensionParams>;
|
||||
TEST_P(StorageTextureDimensionTest, All) {
|
||||
auto& params = GetParam();
|
||||
Global("a",
|
||||
create<sem::StorageTexture>(params.dim, sem::ImageFormat::kR32Uint,
|
||||
sem::StorageTexture::SubtypeFor(
|
||||
sem::ImageFormat::kR32Uint, Types())),
|
||||
ast::StorageClass::kUniformConstant, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BindingDecoration>(0),
|
||||
create<ast::GroupDecoration>(0),
|
||||
});
|
||||
|
||||
if (params.is_valid) {
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
} else {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
}
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||
StorageTextureDimensionTest,
|
||||
testing::ValuesIn(Dimension_cases));
|
||||
|
||||
struct FormatParams {
|
||||
sem::ImageFormat format;
|
||||
bool is_valid;
|
||||
};
|
||||
|
||||
static constexpr FormatParams format_cases[] = {
|
||||
FormatParams{sem::ImageFormat::kBgra8Unorm, false},
|
||||
FormatParams{sem::ImageFormat::kBgra8UnormSrgb, false},
|
||||
FormatParams{sem::ImageFormat::kR16Float, false},
|
||||
FormatParams{sem::ImageFormat::kR16Sint, false},
|
||||
FormatParams{sem::ImageFormat::kR16Uint, false},
|
||||
FormatParams{sem::ImageFormat::kR32Float, true},
|
||||
FormatParams{sem::ImageFormat::kR32Sint, true},
|
||||
FormatParams{sem::ImageFormat::kR32Uint, true},
|
||||
FormatParams{sem::ImageFormat::kR8Sint, false},
|
||||
FormatParams{sem::ImageFormat::kR8Snorm, false},
|
||||
FormatParams{sem::ImageFormat::kR8Uint, false},
|
||||
FormatParams{sem::ImageFormat::kR8Unorm, false},
|
||||
FormatParams{sem::ImageFormat::kRg11B10Float, false},
|
||||
FormatParams{sem::ImageFormat::kRg16Float, false},
|
||||
FormatParams{sem::ImageFormat::kRg16Sint, false},
|
||||
FormatParams{sem::ImageFormat::kRg16Uint, false},
|
||||
FormatParams{sem::ImageFormat::kRg32Float, true},
|
||||
FormatParams{sem::ImageFormat::kRg32Sint, true},
|
||||
FormatParams{sem::ImageFormat::kRg32Uint, true},
|
||||
FormatParams{sem::ImageFormat::kRg8Sint, false},
|
||||
FormatParams{sem::ImageFormat::kRg8Snorm, false},
|
||||
FormatParams{sem::ImageFormat::kRg8Uint, false},
|
||||
FormatParams{sem::ImageFormat::kRg8Unorm, false},
|
||||
FormatParams{sem::ImageFormat::kRgb10A2Unorm, false},
|
||||
FormatParams{sem::ImageFormat::kRgba16Float, true},
|
||||
FormatParams{sem::ImageFormat::kRgba16Sint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba16Uint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba32Float, true},
|
||||
FormatParams{sem::ImageFormat::kRgba32Sint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba32Uint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba8Sint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba8Snorm, true},
|
||||
FormatParams{sem::ImageFormat::kRgba8Uint, true},
|
||||
FormatParams{sem::ImageFormat::kRgba8Unorm, true},
|
||||
FormatParams{sem::ImageFormat::kRgba8UnormSrgb, false}};
|
||||
|
||||
using StorageTextureFormatTest = ResolverTestWithParam<FormatParams>;
|
||||
TEST_P(StorageTextureFormatTest, All) {
|
||||
auto& params = GetParam();
|
||||
// {
|
||||
// var a : texture_storage_1d<*>;
|
||||
// var b : texture_storage_2d<*>;
|
||||
// var c : texture_storage_2d_array<*>;
|
||||
// var d : texture_storage_3<*>;
|
||||
// }
|
||||
|
||||
Global("a",
|
||||
create<sem::StorageTexture>(
|
||||
sem::TextureDimension::k1d, params.format,
|
||||
sem::StorageTexture::SubtypeFor(params.format, Types())),
|
||||
ast::StorageClass::kUniformConstant, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BindingDecoration>(0),
|
||||
create<ast::GroupDecoration>(0),
|
||||
});
|
||||
|
||||
Global("b",
|
||||
create<sem::StorageTexture>(
|
||||
sem::TextureDimension::k2d, params.format,
|
||||
sem::StorageTexture::SubtypeFor(params.format, Types())),
|
||||
ast::StorageClass::kUniformConstant, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BindingDecoration>(1),
|
||||
create<ast::GroupDecoration>(0),
|
||||
});
|
||||
|
||||
Global("c",
|
||||
create<sem::StorageTexture>(
|
||||
sem::TextureDimension::k2dArray, params.format,
|
||||
sem::StorageTexture::SubtypeFor(params.format, Types())),
|
||||
ast::StorageClass::kUniformConstant, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BindingDecoration>(2),
|
||||
create<ast::GroupDecoration>(0),
|
||||
});
|
||||
|
||||
Global("d",
|
||||
create<sem::StorageTexture>(
|
||||
sem::TextureDimension::k3d, params.format,
|
||||
sem::StorageTexture::SubtypeFor(params.format, Types())),
|
||||
ast::StorageClass::kUniformConstant, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BindingDecoration>(3),
|
||||
create<ast::GroupDecoration>(0),
|
||||
});
|
||||
|
||||
if (params.is_valid) {
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
} else {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
}
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||
StorageTextureFormatTest,
|
||||
testing::ValuesIn(format_cases));
|
||||
} // namespace StorageTextureTests
|
||||
|
||||
} // namespace
|
||||
} // namespace resolver
|
||||
} // namespace tint
|
||||
|
|
|
@ -739,8 +739,8 @@ TEST_P(MslStorageTexturesTest, Emit) {
|
|||
auto params = GetParam();
|
||||
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(params.dim, sem::ImageFormat::kR16Float,
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR32Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(params.dim, sem::ImageFormat::kR32Float,
|
||||
subtype);
|
||||
auto* ac =
|
||||
create<sem::AccessControl>(params.ro ? ast::AccessControl::kReadOnly
|
||||
|
|
|
@ -836,11 +836,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) {
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types());
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR32Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k1d,
|
||||
sem::ImageFormat::kR16Float, subtype);
|
||||
sem::ImageFormat::kR32Float, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
|
@ -849,98 +849,15 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R16Float) {
|
|||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R16f
|
||||
)");
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.capabilities()),
|
||||
R"(OpCapability Image1D
|
||||
OpCapability StorageImageExtendedFormats
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8SNorm) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR8Snorm, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k1d,
|
||||
sem::ImageFormat::kR8Snorm, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm
|
||||
)");
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.capabilities()),
|
||||
R"(OpCapability Image1D
|
||||
OpCapability StorageImageExtendedFormats
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8UNorm) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR8Unorm, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k1d,
|
||||
sem::ImageFormat::kR8Unorm, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8
|
||||
)");
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.capabilities()),
|
||||
R"(OpCapability Image1D
|
||||
OpCapability StorageImageExtendedFormats
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Uint) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR8Uint, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k1d,
|
||||
sem::ImageFormat::kR8Uint, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8ui
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_1d_R8Sint) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR8Sint, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k1d,
|
||||
sem::ImageFormat::kR8Sint, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R8i
|
||||
%1 = OpTypeImage %2 1D 0 0 0 2 R32f
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types());
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR32Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k2d,
|
||||
sem::ImageFormat::kR16Float, subtype);
|
||||
sem::ImageFormat::kR32Float, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
|
@ -949,15 +866,15 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
|
|||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 2D 0 0 0 2 R16f
|
||||
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types());
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR32Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k2dArray,
|
||||
sem::ImageFormat::kR16Float, subtype);
|
||||
sem::ImageFormat::kR32Float, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
|
@ -966,15 +883,15 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
|
|||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 2D 0 1 0 2 R16f
|
||||
%1 = OpTypeImage %2 2D 0 1 0 2 R32f
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
|
||||
auto* subtype =
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types());
|
||||
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR32Float, Types());
|
||||
auto* s = create<sem::StorageTexture>(sem::TextureDimension::k3d,
|
||||
sem::ImageFormat::kR16Float, subtype);
|
||||
sem::ImageFormat::kR32Float, subtype);
|
||||
|
||||
Global("test_var", s, ast::StorageClass::kInput);
|
||||
|
||||
|
@ -983,7 +900,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
|
|||
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeImage %2 3D 0 0 0 2 R16f
|
||||
%1 = OpTypeImage %2 3D 0 0 0 2 R32f
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue