@@ -16426,6 +16426,17 @@ bool CompilerGLSL::for_loop_initializers_are_same_type(const SPIRBlock &block)
16426
16426
return true;
16427
16427
}
16428
16428
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
+
16429
16440
bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method)
16430
16441
{
16431
16442
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
16436
16447
// If we're trying to create a true for loop,
16437
16448
// we need to make sure that all opcodes before branch statement do not actually emit any code.
16438
16449
// 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);
16440
16451
16441
16452
bool condition_is_temporary = forced_temporaries.find(block.condition) == end(forced_temporaries);
16442
16453
@@ -16516,7 +16527,7 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method
16516
16527
// If we're trying to create a true for loop,
16517
16528
// we need to make sure that all opcodes before branch statement do not actually emit any code.
16518
16529
// 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);
16520
16531
16521
16532
bool condition_is_temporary = forced_temporaries.find(child.condition) == end(forced_temporaries);
16522
16533
@@ -17895,6 +17906,11 @@ void CompilerGLSL::emit_line_directive(uint32_t file_id, uint32_t line_literal)
17895
17906
if (redirect_statement)
17896
17907
return;
17897
17908
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
+
17898
17914
if (options.emit_line_directives)
17899
17915
{
17900
17916
require_extension_internal("GL_GOOGLE_cpp_style_line_directive");
0 commit comments