Fix HLSL emission of RWTextures
These must have a element type in a declaration statement for the object. See: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwtexture2d Change-Id: Ia13fb37351a7cf3f043e152d5f7a216e3c2bf88e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35380 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
8df62847f4
commit
e075102931
|
@ -112,6 +112,33 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* image_format_to_rwtexture_type(
|
||||||
|
ast::type::ImageFormat image_format) {
|
||||||
|
switch (image_format) {
|
||||||
|
case ast::type::ImageFormat::kRgba8Unorm:
|
||||||
|
case ast::type::ImageFormat::kRgba8Snorm:
|
||||||
|
case ast::type::ImageFormat::kRgba16Float:
|
||||||
|
case ast::type::ImageFormat::kR32Float:
|
||||||
|
case ast::type::ImageFormat::kRg32Float:
|
||||||
|
case ast::type::ImageFormat::kRgba32Float:
|
||||||
|
return "float4";
|
||||||
|
case ast::type::ImageFormat::kRgba8Uint:
|
||||||
|
case ast::type::ImageFormat::kRgba16Uint:
|
||||||
|
case ast::type::ImageFormat::kR32Uint:
|
||||||
|
case ast::type::ImageFormat::kRg32Uint:
|
||||||
|
case ast::type::ImageFormat::kRgba32Uint:
|
||||||
|
return "uint4";
|
||||||
|
case ast::type::ImageFormat::kRgba8Sint:
|
||||||
|
case ast::type::ImageFormat::kRgba16Sint:
|
||||||
|
case ast::type::ImageFormat::kR32Sint:
|
||||||
|
case ast::type::ImageFormat::kRg32Sint:
|
||||||
|
case ast::type::ImageFormat::kRgba32Sint:
|
||||||
|
return "int4";
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
|
GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
|
||||||
|
@ -2157,6 +2184,15 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto* st = tex->As<ast::type::StorageTexture>()) {
|
||||||
|
auto* component = image_format_to_rwtexture_type(st->image_format());
|
||||||
|
if (component == nullptr) {
|
||||||
|
error_ = "Unsupported StorageTexture ImageFormat: " +
|
||||||
|
std::to_string(static_cast<int>(st->image_format()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
out << "<" << component << ">";
|
||||||
|
}
|
||||||
} else if (type->Is<ast::type::U32>()) {
|
} else if (type->Is<ast::type::U32>()) {
|
||||||
out << "uint";
|
out << "uint";
|
||||||
} else if (auto* vec = type->As<ast::type::Vector>()) {
|
} else if (auto* vec = type->As<ast::type::Vector>()) {
|
||||||
|
|
|
@ -405,6 +405,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) {
|
||||||
|
|
||||||
struct HlslStorageTextureData {
|
struct HlslStorageTextureData {
|
||||||
ast::type::TextureDimension dim;
|
ast::type::TextureDimension dim;
|
||||||
|
ast::type::ImageFormat imgfmt;
|
||||||
bool ro;
|
bool ro;
|
||||||
std::string result;
|
std::string result;
|
||||||
};
|
};
|
||||||
|
@ -420,7 +421,7 @@ TEST_P(HlslStoragetexturesTest, Emit) {
|
||||||
ast::type::StorageTexture s(params.dim,
|
ast::type::StorageTexture s(params.dim,
|
||||||
params.ro ? ast::AccessControl::kReadOnly
|
params.ro ? ast::AccessControl::kReadOnly
|
||||||
: ast::AccessControl::kWriteOnly,
|
: ast::AccessControl::kWriteOnly,
|
||||||
ast::type::ImageFormat::kR16Float);
|
params.imgfmt);
|
||||||
|
|
||||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||||
EXPECT_EQ(result(), params.result);
|
EXPECT_EQ(result(), params.result);
|
||||||
|
@ -429,26 +430,54 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
HlslGeneratorImplTest_Type,
|
HlslGeneratorImplTest_Type,
|
||||||
HlslStoragetexturesTest,
|
HlslStoragetexturesTest,
|
||||||
testing::Values(
|
testing::Values(
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k1d, true,
|
HlslStorageTextureData{ast::type::TextureDimension::k1d,
|
||||||
"RWTexture1D"},
|
ast::type::ImageFormat::kRgba8Unorm, true,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k1dArray, true,
|
"RWTexture1D<float4>"},
|
||||||
"RWTexture1DArray"},
|
HlslStorageTextureData{ast::type::TextureDimension::k1dArray,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k2d, true,
|
ast::type::ImageFormat::kRgba8Snorm, true,
|
||||||
"RWTexture2D"},
|
"RWTexture1DArray<float4>"},
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k2dArray, true,
|
HlslStorageTextureData{ast::type::TextureDimension::k2d,
|
||||||
"RWTexture2DArray"},
|
ast::type::ImageFormat::kRgba16Float, true,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k3d, true,
|
"RWTexture2D<float4>"},
|
||||||
"RWTexture3D"},
|
HlslStorageTextureData{ast::type::TextureDimension::k2dArray,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k1d, false,
|
ast::type::ImageFormat::kR32Float, true,
|
||||||
"RWTexture1D"},
|
"RWTexture2DArray<float4>"},
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k1dArray, false,
|
HlslStorageTextureData{ast::type::TextureDimension::k3d,
|
||||||
"RWTexture1DArray"},
|
ast::type::ImageFormat::kRg32Float, true,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k2d, false,
|
"RWTexture3D<float4>"},
|
||||||
"RWTexture2D"},
|
HlslStorageTextureData{ast::type::TextureDimension::k1d,
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k2dArray, false,
|
ast::type::ImageFormat::kRgba32Float, false,
|
||||||
"RWTexture2DArray"},
|
"RWTexture1D<float4>"},
|
||||||
HlslStorageTextureData{ast::type::TextureDimension::k3d, false,
|
HlslStorageTextureData{ast::type::TextureDimension::k1dArray,
|
||||||
"RWTexture3D"}));
|
ast::type::ImageFormat::kRgba8Uint, false,
|
||||||
|
"RWTexture1DArray<uint4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k2d,
|
||||||
|
ast::type::ImageFormat::kRgba16Uint, false,
|
||||||
|
"RWTexture2D<uint4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k2dArray,
|
||||||
|
ast::type::ImageFormat::kR32Uint, false,
|
||||||
|
"RWTexture2DArray<uint4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k3d,
|
||||||
|
ast::type::ImageFormat::kRg32Uint, false,
|
||||||
|
"RWTexture3D<uint4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k1d,
|
||||||
|
ast::type::ImageFormat::kRgba32Uint, true,
|
||||||
|
"RWTexture1D<uint4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k1dArray,
|
||||||
|
ast::type::ImageFormat::kRgba8Sint, true,
|
||||||
|
"RWTexture1DArray<int4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k2d,
|
||||||
|
ast::type::ImageFormat::kRgba16Sint, true,
|
||||||
|
"RWTexture2D<int4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k2dArray,
|
||||||
|
ast::type::ImageFormat::kR32Sint, true,
|
||||||
|
"RWTexture2DArray<int4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k3d,
|
||||||
|
ast::type::ImageFormat::kRg32Sint, true,
|
||||||
|
"RWTexture3D<int4>"},
|
||||||
|
HlslStorageTextureData{ast::type::TextureDimension::k1d,
|
||||||
|
ast::type::ImageFormat::kRgba32Sint, false,
|
||||||
|
"RWTexture1D<int4>"}));
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace hlsl
|
} // namespace hlsl
|
||||||
|
|
Loading…
Reference in New Issue