[tint] do not emit space for binding group 0

D3D11 only supports HLSL SM5.0 which doesn't support `space`
(binding group in WGSL). So for D3D11, only one binding group will be
used, and tint will not emit `space` for HLSL, so shaders can be used
with D3D11.

Bug: dawn:1705
Change-Id: Ie0e9868137f10762c5243e188d76f5e41879c2bc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125080
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
This commit is contained in:
Peng Huang
2023-03-31 17:55:19 +00:00
committed by Dawn LUCI CQ
parent 70d8711973
commit c00ff7f3c7
1555 changed files with 2097 additions and 2083 deletions

View File

@@ -148,8 +148,14 @@ struct RegisterAndSpace {
};
utils::StringStream& operator<<(utils::StringStream& s, const RegisterAndSpace& rs) {
s << " : register(" << rs.reg << rs.binding_point.binding << ", space" << rs.binding_point.group
<< ")";
s << " : register(" << rs.reg << rs.binding_point.binding;
// Omit the space if it's 0, as it's the default.
// SM 5.0 doesn't support spaces, so we don't emit them if group is 0 for better compatibility.
if (rs.binding_point.group == 0) {
s << ")";
} else {
s << ", space" << rs.binding_point.group << ")";
}
return s;
}
@@ -3123,7 +3129,15 @@ bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable*
if (register_space) {
auto bp = sem->As<sem::GlobalVariable>()->BindingPoint();
out << " : register(" << register_space << bp.binding << ", space" << bp.group << ")";
out << " : register(" << register_space << bp.binding;
// Omit the space if it's 0, as it's the default.
// SM 5.0 doesn't support spaces, so we don't emit them if group is 0 for better
// compatibility.
if (bp.group == 0) {
out << ")";
} else {
out << ", space" << bp.group << ")";
}
}
out << ";";

View File

@@ -864,7 +864,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Multiple_EntryPoint_With_Same_Module
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), R"(RWByteAddressBuffer data : register(u0, space0);
EXPECT_EQ(gen.result(), R"(RWByteAddressBuffer data : register(u0);
[numthreads(1, 1, 1)]
void a() {

View File

@@ -191,7 +191,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl_OmittedIfStorageBuffer) {
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_EQ(gen.result(), "RWByteAddressBuffer g : register(u0, space0);\n");
EXPECT_EQ(gen.result(), "RWByteAddressBuffer g : register(u0);\n");
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {