mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 06:45:16 +00:00
HLSL: force FXC to never unroll loops
Emit the "[loop]" attribute on "for" and "while" so that FXC does not attempt to unroll them. This is to work around an FXC bug where it fails to unroll loops with gradient operations. FXC ostensibly unrolls such loops because gradient operations require uniform control flow, and loops that have varying iterations may possibly not be uniform. Tint will eventually validate that control flow is indeed uniform, so forcing FXC to avoid unrolling in these cases should be fine. Bug: tint:1112 Change-Id: I10077f8b62fbbb230a0003f3864c75a8fe0e1d18 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69880 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
1704fe53f5
commit
11d09f2fe7
@@ -115,6 +115,13 @@ std::ostream& operator<<(std::ostream& s, const RegisterAndSpace& rs) {
|
||||
return s;
|
||||
}
|
||||
|
||||
const char* LoopAttribute() {
|
||||
// Force loops not to be unrolled to work around FXC compilation issues when
|
||||
// it attempts and fails to unroll loops when it contains gradient operations.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-while
|
||||
return "[loop] ";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SanitizedResult Sanitize(const Program* in,
|
||||
@@ -2804,7 +2811,7 @@ bool GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) {
|
||||
};
|
||||
|
||||
TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing);
|
||||
line() << "while (true) {";
|
||||
line() << LoopAttribute() << "while (true) {";
|
||||
{
|
||||
ScopedIndent si(this);
|
||||
if (!EmitStatements(stmt->body->statements)) {
|
||||
@@ -2874,7 +2881,7 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) {
|
||||
};
|
||||
|
||||
TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing);
|
||||
line() << "while (true) {";
|
||||
line() << LoopAttribute() << "while (true) {";
|
||||
increment_indent();
|
||||
TINT_DEFER({
|
||||
decrement_indent();
|
||||
@@ -2897,7 +2904,7 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) {
|
||||
// For-loop can be generated.
|
||||
{
|
||||
auto out = line();
|
||||
out << "for";
|
||||
out << LoopAttribute() << "for";
|
||||
{
|
||||
ScopedParen sp(out);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
EXPECT_EQ(gen.result(), R"( [loop] while (true) {
|
||||
continue;
|
||||
}
|
||||
)");
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
EXPECT_EQ(gen.result(), R"( [loop] while (true) {
|
||||
discard;
|
||||
}
|
||||
)");
|
||||
@@ -54,7 +54,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
EXPECT_EQ(gen.result(), R"( [loop] while (true) {
|
||||
discard;
|
||||
{
|
||||
a_statement();
|
||||
@@ -88,8 +88,8 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
while (true) {
|
||||
EXPECT_EQ(gen.result(), R"( [loop] while (true) {
|
||||
[loop] while (true) {
|
||||
discard;
|
||||
{
|
||||
a_statement();
|
||||
@@ -142,7 +142,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
EXPECT_EQ(gen.result(), R"( [loop] while (true) {
|
||||
float lhs = 2.400000095f;
|
||||
float other = 0.0f;
|
||||
{
|
||||
@@ -169,7 +169,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoop) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
for(; ; ) {
|
||||
[loop] for(; ; ) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInit) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
for(int i = 0; ; ) {
|
||||
[loop] for(int i = 0; ; ) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
bool b = (tint_tmp);
|
||||
for(; ; ) {
|
||||
[loop] for(; ; ) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCond) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
for(; true; ) {
|
||||
[loop] for(; true; ) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
[loop] while (true) {
|
||||
bool tint_tmp = true;
|
||||
if (tint_tmp) {
|
||||
tint_tmp = false;
|
||||
@@ -302,7 +302,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCont) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
for(; ; i = (i + 1)) {
|
||||
[loop] for(; ; i = (i + 1)) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
while (true) {
|
||||
[loop] while (true) {
|
||||
a_statement();
|
||||
bool tint_tmp = true;
|
||||
if (tint_tmp) {
|
||||
@@ -358,7 +358,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInitCondCont) {
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
for(int i = 0; true; i = (i + 1)) {
|
||||
[loop] for(int i = 0; true; i = (i + 1)) {
|
||||
a_statement();
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
tint_tmp = false;
|
||||
}
|
||||
bool i = (tint_tmp);
|
||||
while (true) {
|
||||
[loop] while (true) {
|
||||
bool tint_tmp_1 = true;
|
||||
if (tint_tmp_1) {
|
||||
tint_tmp_1 = false;
|
||||
|
||||
Reference in New Issue
Block a user