Skip to content

Commit 2d3a152

Browse files
Merge pull request KhronosGroup#2167 from KhronosGroup/fix-2154
Skip line directives when emitting loop condition blocks.
2 parents 030d0be + 0e1ce21 commit 2d3a152

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

spirv_glsl.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16426,6 +16426,17 @@ bool CompilerGLSL::for_loop_initializers_are_same_type(const SPIRBlock &block)
1642616426
return true;
1642716427
}
1642816428

16429+
void CompilerGLSL::emit_block_instructions_with_masked_debug(SPIRBlock &block)
16430+
{
16431+
// Have to block debug instructions such as OpLine here, since it will be treated as a statement otherwise,
16432+
// which breaks loop optimizations.
16433+
// Any line directive would be declared outside the loop body, which would just be confusing either way.
16434+
bool old_block_debug_directives = block_debug_directives;
16435+
block_debug_directives = true;
16436+
emit_block_instructions(block);
16437+
block_debug_directives = old_block_debug_directives;
16438+
}
16439+
1642916440
bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method)
1643016441
{
1643116442
SPIRBlock::ContinueBlockType continue_type = continue_block_type(get<SPIRBlock>(block.continue_block));
@@ -16436,7 +16447,7 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method
1643616447
// If we're trying to create a true for loop,
1643716448
// we need to make sure that all opcodes before branch statement do not actually emit any code.
1643816449
// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
16439-
emit_block_instructions(block);
16450+
emit_block_instructions_with_masked_debug(block);
1644016451

1644116452
bool condition_is_temporary = forced_temporaries.find(block.condition) == end(forced_temporaries);
1644216453

@@ -16516,7 +16527,7 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method
1651616527
// If we're trying to create a true for loop,
1651716528
// we need to make sure that all opcodes before branch statement do not actually emit any code.
1651816529
// We can then take the condition expression and create a for (; cond ; ) { body; } structure instead.
16519-
emit_block_instructions(child);
16530+
emit_block_instructions_with_masked_debug(child);
1652016531

1652116532
bool condition_is_temporary = forced_temporaries.find(child.condition) == end(forced_temporaries);
1652216533

@@ -17895,6 +17906,11 @@ void CompilerGLSL::emit_line_directive(uint32_t file_id, uint32_t line_literal)
1789517906
if (redirect_statement)
1789617907
return;
1789717908

17909+
// If we're emitting code in a sensitive context such as condition blocks in for loops, don't emit
17910+
// any line directives, because it's not possible.
17911+
if (block_debug_directives)
17912+
return;
17913+
1789817914
if (options.emit_line_directives)
1789917915
{
1790017916
require_extension_internal("GL_GOOGLE_cpp_style_line_directive");

spirv_glsl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class CompilerGLSL : public Compiler
397397
};
398398
TemporaryCopy handle_instruction_precision(const Instruction &instr);
399399
void emit_block_instructions(SPIRBlock &block);
400+
void emit_block_instructions_with_masked_debug(SPIRBlock &block);
400401

401402
// For relax_nan_checks.
402403
GLSLstd450 get_remapped_glsl_op(GLSLstd450 std450_op) const;
@@ -545,6 +546,7 @@ class CompilerGLSL : public Compiler
545546
SmallVector<std::string> *redirect_statement = nullptr;
546547
const SPIRBlock *current_continue_block = nullptr;
547548
bool block_temporary_hoisting = false;
549+
bool block_debug_directives = false;
548550

549551
void begin_scope();
550552
void end_scope();

0 commit comments

Comments
 (0)