Deal with phi copies which happen inside continue blocks.
This commit is contained in:
parent
c8ddf7e7d5
commit
d4926a0405
@ -15,6 +15,7 @@ void main()
|
||||
{
|
||||
bool _34;
|
||||
float _35;
|
||||
float _35_copy;
|
||||
float _36;
|
||||
_34 = true;
|
||||
_35 = _4._m0[gl_GlobalInvocationID.x];
|
||||
@ -24,7 +25,7 @@ void main()
|
||||
if (_34)
|
||||
{
|
||||
_34 = false;
|
||||
float _35_copy = _35;
|
||||
_35_copy = _35;
|
||||
_35 = _36;
|
||||
_36 = _35_copy;
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0, std140) uniform UBO
|
||||
{
|
||||
int uCount;
|
||||
int uJ;
|
||||
int uK;
|
||||
} _5;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
int _23;
|
||||
int _23_copy;
|
||||
int _24;
|
||||
_23 = _5.uK;
|
||||
_24 = _5.uJ;
|
||||
for (int _26 = 0; _26 < _5.uCount; )
|
||||
{
|
||||
_23_copy = _23;
|
||||
_23 = _24;
|
||||
_24 = _23_copy;
|
||||
_26++;
|
||||
continue;
|
||||
}
|
||||
FragColor = float(_24 - _23) * float(_5.uJ * _5.uK);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ void main()
|
||||
float _26 = 8.5;
|
||||
bool _34;
|
||||
float _35;
|
||||
float _35_copy;
|
||||
float _36;
|
||||
_34 = true;
|
||||
_35 = _4._m0[gl_GlobalInvocationID.x];
|
||||
@ -25,7 +26,7 @@ void main()
|
||||
if (_34)
|
||||
{
|
||||
_34 = false;
|
||||
float _35_copy = _35;
|
||||
_35_copy = _35;
|
||||
_35 = _36;
|
||||
_36 = _35_copy;
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0, std140) uniform UBO
|
||||
{
|
||||
int uCount;
|
||||
int uJ;
|
||||
int uK;
|
||||
} _5;
|
||||
|
||||
layout(location = 0) out float FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
int _23;
|
||||
int _23_copy;
|
||||
int _24;
|
||||
_23 = _5.uK;
|
||||
_24 = _5.uJ;
|
||||
for (int _26 = 0; _26 < _5.uCount; _23_copy = _23, _23 = _24, _24 = _23_copy, _26++)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
FragColor = float(_24 - _23) * float(_5.uJ * _5.uK);
|
||||
}
|
||||
|
69
shaders/asm/frag/op-phi-swap-continue-block.asm.frag
Normal file
69
shaders/asm/frag/op-phi-swap-continue-block.asm.frag
Normal file
@ -0,0 +1,69 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Khronos Glslang Reference Front End; 7
|
||||
; Bound: 55
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %FragColor
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpSource GLSL 450
|
||||
OpName %main "main"
|
||||
OpName %UBO "UBO"
|
||||
OpMemberName %UBO 0 "uCount"
|
||||
OpMemberName %UBO 1 "uJ"
|
||||
OpMemberName %UBO 2 "uK"
|
||||
OpName %_ ""
|
||||
OpName %FragColor "FragColor"
|
||||
OpMemberDecorate %UBO 0 Offset 0
|
||||
OpMemberDecorate %UBO 1 Offset 4
|
||||
OpMemberDecorate %UBO 2 Offset 8
|
||||
OpDecorate %UBO Block
|
||||
OpDecorate %_ DescriptorSet 0
|
||||
OpDecorate %_ Binding 0
|
||||
OpDecorate %FragColor Location 0
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%UBO = OpTypeStruct %int %int %int
|
||||
%_ptr_Uniform_UBO = OpTypePointer Uniform %UBO
|
||||
%_ = OpVariable %_ptr_Uniform_UBO Uniform
|
||||
%int_1 = OpConstant %int 1
|
||||
%_ptr_Uniform_int = OpTypePointer Uniform %int
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_0 = OpConstant %int 0
|
||||
%bool = OpTypeBool
|
||||
%float = OpTypeFloat 32
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%FragColor = OpVariable %_ptr_Output_float Output
|
||||
%main = OpFunction %void None %3
|
||||
%5 = OpLabel
|
||||
%14 = OpAccessChain %_ptr_Uniform_int %_ %int_1
|
||||
%15 = OpLoad %int %14
|
||||
%18 = OpAccessChain %_ptr_Uniform_int %_ %int_2
|
||||
%19 = OpLoad %int %18
|
||||
OpBranch %22
|
||||
%22 = OpLabel
|
||||
%54 = OpPhi %int %19 %5 %53 %23
|
||||
%53 = OpPhi %int %15 %5 %54 %23
|
||||
%52 = OpPhi %int %int_0 %5 %37 %23
|
||||
%28 = OpAccessChain %_ptr_Uniform_int %_ %int_0
|
||||
%29 = OpLoad %int %28
|
||||
%31 = OpSLessThan %bool %52 %29
|
||||
OpLoopMerge %24 %23 None
|
||||
OpBranchConditional %31 %inbetween %24
|
||||
%inbetween = OpLabel
|
||||
OpBranch %23
|
||||
%23 = OpLabel
|
||||
%37 = OpIAdd %int %52 %int_1
|
||||
OpBranch %22
|
||||
%24 = OpLabel
|
||||
%43 = OpISub %int %53 %54
|
||||
%44 = OpConvertSToF %float %43
|
||||
%49 = OpIMul %int %15 %19
|
||||
%50 = OpConvertSToF %float %49
|
||||
%51 = OpFMul %float %44 %50
|
||||
OpStore %FragColor %51
|
||||
OpReturn
|
||||
OpFunctionEnd
|
@ -894,6 +894,10 @@ struct SPIRVariable : IVariant
|
||||
|
||||
bool deferred_declaration = false;
|
||||
bool phi_variable = false;
|
||||
|
||||
// Used to deal with Phi variable flushes. See flush_phi().
|
||||
bool allocate_temporary_copy = false;
|
||||
|
||||
bool remapped_variable = false;
|
||||
uint32_t remapped_components = 0;
|
||||
|
||||
|
@ -6219,6 +6219,13 @@ void CompilerGLSL::flush_variable_declaration(uint32_t id)
|
||||
if (var && var->deferred_declaration)
|
||||
{
|
||||
statement(variable_decl_function_local(*var), ";");
|
||||
if (var->allocate_temporary_copy)
|
||||
{
|
||||
auto &type = get<SPIRType>(var->basetype);
|
||||
auto &flags = ir.meta[id].decoration.decoration_flags;
|
||||
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, join("_", id, "_copy")),
|
||||
";");
|
||||
}
|
||||
var->deferred_declaration = false;
|
||||
}
|
||||
}
|
||||
@ -9626,12 +9633,15 @@ void CompilerGLSL::flush_phi(uint32_t from, uint32_t to)
|
||||
|
||||
if (need_saved_temporary)
|
||||
{
|
||||
// Need to make sure we declare the phi variable with a copy at the right scope.
|
||||
// We cannot safely declare a temporary here since we might be inside a continue block.
|
||||
if (!var.allocate_temporary_copy)
|
||||
{
|
||||
var.allocate_temporary_copy = true;
|
||||
force_recompile = true;
|
||||
}
|
||||
statement("_", phi.function_variable, "_copy", " = ", to_name(phi.function_variable), ";");
|
||||
temporary_phi_variables.insert(phi.function_variable);
|
||||
auto &type = expression_type(phi.function_variable);
|
||||
auto &flags = ir.meta[phi.function_variable].decoration.decoration_flags;
|
||||
statement(flags_to_precision_qualifiers_glsl(type, flags),
|
||||
variable_decl(type, join("_", phi.function_variable, "_copy")), " = ",
|
||||
to_name(phi.function_variable), ";");
|
||||
}
|
||||
|
||||
// This might be called in continue block, so make sure we
|
||||
@ -10138,14 +10148,8 @@ void CompilerGLSL::flush_undeclared_variables(SPIRBlock &block)
|
||||
{
|
||||
// Enforce declaration order for regression testing purposes.
|
||||
sort(begin(block.dominated_variables), end(block.dominated_variables));
|
||||
|
||||
for (auto &v : block.dominated_variables)
|
||||
{
|
||||
auto &var = get<SPIRVariable>(v);
|
||||
if (var.deferred_declaration)
|
||||
statement(variable_decl(var), ";");
|
||||
var.deferred_declaration = false;
|
||||
}
|
||||
flush_variable_declaration(v);
|
||||
}
|
||||
|
||||
void CompilerGLSL::emit_hoisted_temporaries(vector<pair<uint32_t, uint32_t>> &temporaries)
|
||||
|
Loading…
Reference in New Issue
Block a user