Merge pull request #1686 from KhronosGroup/fix-1684

GLSL: Support control flow hints
This commit is contained in:
Hans-Kristian Arntzen 2021-06-03 14:13:18 +02:00 committed by GitHub
commit 2e1b5fb39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 389 additions and 2 deletions

View File

@ -0,0 +1,58 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer bar
{
vec4 _data[];
} bar_1;
layout(binding = 1, std430) buffer foo
{
vec4 _data[];
} foo_1;
void main()
{
bar_1._data[0] = foo_1._data[0];
bar_1._data[1] = foo_1._data[1];
bar_1._data[2] = foo_1._data[2];
bar_1._data[3] = foo_1._data[3];
bar_1._data[4] = foo_1._data[4];
bar_1._data[5] = foo_1._data[5];
bar_1._data[6] = foo_1._data[6];
bar_1._data[7] = foo_1._data[7];
bar_1._data[8] = foo_1._data[8];
bar_1._data[9] = foo_1._data[9];
bar_1._data[10] = foo_1._data[10];
bar_1._data[11] = foo_1._data[11];
bar_1._data[12] = foo_1._data[12];
bar_1._data[13] = foo_1._data[13];
bar_1._data[14] = foo_1._data[14];
bar_1._data[15] = foo_1._data[15];
SPIRV_CROSS_LOOP
for (int _137 = 0; _137 < 16; )
{
bar_1._data[15 - _137] = foo_1._data[_137];
_137++;
continue;
}
SPIRV_CROSS_BRANCH
if (bar_1._data[10].x > 10.0)
{
foo_1._data[20] = vec4(5.0);
}
foo_1._data[20] = vec4(20.0);
}

View File

@ -1,4 +1,16 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
layout(binding = 0, std140) uniform Foo
{
@ -22,6 +34,7 @@ void main()
bool _225;
int _229;
uint _222 = 0u;
SPIRV_CROSS_UNROLL
for (;;)
{
if (_222 < _11.shadowCascadesNum)

View File

@ -1,4 +1,16 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
struct _28
{
@ -103,6 +115,7 @@ void main()
vec4 _113 = textureLod(SPIRV_Cross_Combined_1, _97, 0.0);
float _114 = _113.y;
vec3 _129;
SPIRV_CROSS_BRANCH
if (_114 > 0.0)
{
_129 = _109 + (textureLod(SPIRV_Cross_Combined_2, _97, 0.0).xyz * clamp(_114 * _113.z, 0.0, 1.0));
@ -116,6 +129,7 @@ void main()
vec4 _160 = textureLod(SPIRV_Cross_Combined_1, _144, 0.0);
float _161 = _160.y;
vec3 _176;
SPIRV_CROSS_BRANCH
if (_161 > 0.0)
{
_176 = _156 + (textureLod(SPIRV_Cross_Combined_2, _144, 0.0).xyz * clamp(_161 * _160.z, 0.0, 1.0));
@ -129,6 +143,7 @@ void main()
vec4 _207 = textureLod(SPIRV_Cross_Combined_1, _191, 0.0);
float _208 = _207.y;
vec3 _223;
SPIRV_CROSS_BRANCH
if (_208 > 0.0)
{
_223 = _203 + (textureLod(SPIRV_Cross_Combined_2, _191, 0.0).xyz * clamp(_208 * _207.z, 0.0, 1.0));
@ -142,6 +157,7 @@ void main()
vec4 _254 = textureLod(SPIRV_Cross_Combined_1, _238, 0.0);
float _255 = _254.y;
vec3 _270;
SPIRV_CROSS_BRANCH
if (_255 > 0.0)
{
_270 = _250 + (textureLod(SPIRV_Cross_Combined_2, _238, 0.0).xyz * clamp(_255 * _254.z, 0.0, 1.0));
@ -155,6 +171,7 @@ void main()
vec4 _301 = textureLod(SPIRV_Cross_Combined_1, _285, 0.0);
float _302 = _301.y;
vec3 _317;
SPIRV_CROSS_BRANCH
if (_302 > 0.0)
{
_317 = _297 + (textureLod(SPIRV_Cross_Combined_2, _285, 0.0).xyz * clamp(_302 * _301.z, 0.0, 1.0));
@ -168,6 +185,7 @@ void main()
vec4 _348 = textureLod(SPIRV_Cross_Combined_1, _332, 0.0);
float _349 = _348.y;
vec3 _364;
SPIRV_CROSS_BRANCH
if (_349 > 0.0)
{
_364 = _344 + (textureLod(SPIRV_Cross_Combined_2, _332, 0.0).xyz * clamp(_349 * _348.z, 0.0, 1.0));
@ -181,6 +199,7 @@ void main()
vec4 _395 = textureLod(SPIRV_Cross_Combined_1, _379, 0.0);
float _396 = _395.y;
vec3 _411;
SPIRV_CROSS_BRANCH
if (_396 > 0.0)
{
_411 = _391 + (textureLod(SPIRV_Cross_Combined_2, _379, 0.0).xyz * clamp(_396 * _395.z, 0.0, 1.0));
@ -194,6 +213,7 @@ void main()
vec4 _442 = textureLod(SPIRV_Cross_Combined_1, _426, 0.0);
float _443 = _442.y;
vec3 _458;
SPIRV_CROSS_BRANCH
if (_443 > 0.0)
{
_458 = _438 + (textureLod(SPIRV_Cross_Combined_2, _426, 0.0).xyz * clamp(_443 * _442.z, 0.0, 1.0));
@ -207,6 +227,7 @@ void main()
vec4 _489 = textureLod(SPIRV_Cross_Combined_1, _473, 0.0);
float _490 = _489.y;
vec3 _505;
SPIRV_CROSS_BRANCH
if (_490 > 0.0)
{
_505 = _485 + (textureLod(SPIRV_Cross_Combined_2, _473, 0.0).xyz * clamp(_490 * _489.z, 0.0, 1.0));
@ -220,6 +241,7 @@ void main()
vec4 _536 = textureLod(SPIRV_Cross_Combined_1, _520, 0.0);
float _537 = _536.y;
vec3 _552;
SPIRV_CROSS_BRANCH
if (_537 > 0.0)
{
_552 = _532 + (textureLod(SPIRV_Cross_Combined_2, _520, 0.0).xyz * clamp(_537 * _536.z, 0.0, 1.0));
@ -233,6 +255,7 @@ void main()
vec4 _583 = textureLod(SPIRV_Cross_Combined_1, _567, 0.0);
float _584 = _583.y;
vec3 _599;
SPIRV_CROSS_BRANCH
if (_584 > 0.0)
{
_599 = _579 + (textureLod(SPIRV_Cross_Combined_2, _567, 0.0).xyz * clamp(_584 * _583.z, 0.0, 1.0));
@ -246,6 +269,7 @@ void main()
vec4 _630 = textureLod(SPIRV_Cross_Combined_1, _614, 0.0);
float _631 = _630.y;
vec3 _646;
SPIRV_CROSS_BRANCH
if (_631 > 0.0)
{
_646 = _626 + (textureLod(SPIRV_Cross_Combined_2, _614, 0.0).xyz * clamp(_631 * _630.z, 0.0, 1.0));
@ -259,6 +283,7 @@ void main()
vec4 _677 = textureLod(SPIRV_Cross_Combined_1, _661, 0.0);
float _678 = _677.y;
vec3 _693;
SPIRV_CROSS_BRANCH
if (_678 > 0.0)
{
_693 = _673 + (textureLod(SPIRV_Cross_Combined_2, _661, 0.0).xyz * clamp(_678 * _677.z, 0.0, 1.0));

View File

@ -0,0 +1,58 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer bar
{
vec4 _data[];
} bar_1;
layout(binding = 1, std430) buffer foo
{
vec4 _data[];
} foo_1;
void _main()
{
SPIRV_CROSS_UNROLL
for (int i = 0; i < 16; i++)
{
bar_1._data[i] = foo_1._data[i];
}
SPIRV_CROSS_LOOP
for (int i_1 = 0; i_1 < 16; i_1++)
{
bar_1._data[15 - i_1] = foo_1._data[i_1];
}
float v = bar_1._data[10].x;
float w = foo_1._data[10].x;
SPIRV_CROSS_BRANCH
if (v > 10.0)
{
foo_1._data[20] = vec4(5.0);
}
float value = 20.0;
SPIRV_CROSS_FLATTEN
if (w > 40.0)
{
value = 20.0;
}
foo_1._data[20] = vec4(value);
}
void main()
{
_main();
}

View File

@ -1,4 +1,16 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
layout(binding = 0, std140) uniform Foo
{
@ -23,6 +35,7 @@ mat4 GetClip2TexMatrix()
int GetCascade(vec3 fragWorldPosition)
{
SPIRV_CROSS_UNROLL
for (uint cascadeIndex = 0u; cascadeIndex < _11.shadowCascadesNum; cascadeIndex++)
{
mat4 worldToShadowMap = GetClip2TexMatrix() * spvWorkaroundRowMajor(_11.lightVP[cascadeIndex]);

View File

@ -1,4 +1,16 @@
#version 450
#if defined(GL_EXT_control_flow_attributes)
#extension GL_EXT_control_flow_attributes : require
#define SPIRV_CROSS_FLATTEN [[flatten]]
#define SPIRV_CROSS_BRANCH [[dont_flatten]]
#define SPIRV_CROSS_UNROLL [[unroll]]
#define SPIRV_CROSS_LOOP [[dont_unroll]]
#else
#define SPIRV_CROSS_FLATTEN
#define SPIRV_CROSS_BRANCH
#define SPIRV_CROSS_UNROLL
#define SPIRV_CROSS_LOOP
#endif
struct _28
{
@ -102,6 +114,7 @@ void main()
vec3 _109 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _97, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _113 = textureLod(SPIRV_Cross_Combined_1, _97, 0.0);
vec3 _129;
SPIRV_CROSS_BRANCH
if (_113.y > 0.0)
{
_129 = _109 + (textureLod(SPIRV_Cross_Combined_2, _97, 0.0).xyz * clamp(_113.y * _113.z, 0.0, 1.0));
@ -118,6 +131,7 @@ void main()
vec3 _156 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _144, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _160 = textureLod(SPIRV_Cross_Combined_1, _144, 0.0);
vec3 _176;
SPIRV_CROSS_BRANCH
if (_160.y > 0.0)
{
_176 = _156 + (textureLod(SPIRV_Cross_Combined_2, _144, 0.0).xyz * clamp(_160.y * _160.z, 0.0, 1.0));
@ -134,6 +148,7 @@ void main()
vec3 _203 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _191, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _207 = textureLod(SPIRV_Cross_Combined_1, _191, 0.0);
vec3 _223;
SPIRV_CROSS_BRANCH
if (_207.y > 0.0)
{
_223 = _203 + (textureLod(SPIRV_Cross_Combined_2, _191, 0.0).xyz * clamp(_207.y * _207.z, 0.0, 1.0));
@ -150,6 +165,7 @@ void main()
vec3 _250 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _238, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _254 = textureLod(SPIRV_Cross_Combined_1, _238, 0.0);
vec3 _270;
SPIRV_CROSS_BRANCH
if (_254.y > 0.0)
{
_270 = _250 + (textureLod(SPIRV_Cross_Combined_2, _238, 0.0).xyz * clamp(_254.y * _254.z, 0.0, 1.0));
@ -166,6 +182,7 @@ void main()
vec3 _297 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _285, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _301 = textureLod(SPIRV_Cross_Combined_1, _285, 0.0);
vec3 _317;
SPIRV_CROSS_BRANCH
if (_301.y > 0.0)
{
_317 = _297 + (textureLod(SPIRV_Cross_Combined_2, _285, 0.0).xyz * clamp(_301.y * _301.z, 0.0, 1.0));
@ -182,6 +199,7 @@ void main()
vec3 _344 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _332, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _348 = textureLod(SPIRV_Cross_Combined_1, _332, 0.0);
vec3 _364;
SPIRV_CROSS_BRANCH
if (_348.y > 0.0)
{
_364 = _344 + (textureLod(SPIRV_Cross_Combined_2, _332, 0.0).xyz * clamp(_348.y * _348.z, 0.0, 1.0));
@ -198,6 +216,7 @@ void main()
vec3 _391 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _379, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _395 = textureLod(SPIRV_Cross_Combined_1, _379, 0.0);
vec3 _411;
SPIRV_CROSS_BRANCH
if (_395.y > 0.0)
{
_411 = _391 + (textureLod(SPIRV_Cross_Combined_2, _379, 0.0).xyz * clamp(_395.y * _395.z, 0.0, 1.0));
@ -214,6 +233,7 @@ void main()
vec3 _438 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _426, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _442 = textureLod(SPIRV_Cross_Combined_1, _426, 0.0);
vec3 _458;
SPIRV_CROSS_BRANCH
if (_442.y > 0.0)
{
_458 = _438 + (textureLod(SPIRV_Cross_Combined_2, _426, 0.0).xyz * clamp(_442.y * _442.z, 0.0, 1.0));
@ -230,6 +250,7 @@ void main()
vec3 _485 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _473, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _489 = textureLod(SPIRV_Cross_Combined_1, _473, 0.0);
vec3 _505;
SPIRV_CROSS_BRANCH
if (_489.y > 0.0)
{
_505 = _485 + (textureLod(SPIRV_Cross_Combined_2, _473, 0.0).xyz * clamp(_489.y * _489.z, 0.0, 1.0));
@ -246,6 +267,7 @@ void main()
vec3 _532 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _520, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _536 = textureLod(SPIRV_Cross_Combined_1, _520, 0.0);
vec3 _552;
SPIRV_CROSS_BRANCH
if (_536.y > 0.0)
{
_552 = _532 + (textureLod(SPIRV_Cross_Combined_2, _520, 0.0).xyz * clamp(_536.y * _536.z, 0.0, 1.0));
@ -262,6 +284,7 @@ void main()
vec3 _579 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _567, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _583 = textureLod(SPIRV_Cross_Combined_1, _567, 0.0);
vec3 _599;
SPIRV_CROSS_BRANCH
if (_583.y > 0.0)
{
_599 = _579 + (textureLod(SPIRV_Cross_Combined_2, _567, 0.0).xyz * clamp(_583.y * _583.z, 0.0, 1.0));
@ -278,6 +301,7 @@ void main()
vec3 _626 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _614, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _630 = textureLod(SPIRV_Cross_Combined_1, _614, 0.0);
vec3 _646;
SPIRV_CROSS_BRANCH
if (_630.y > 0.0)
{
_646 = _626 + (textureLod(SPIRV_Cross_Combined_2, _614, 0.0).xyz * clamp(_630.y * _630.z, 0.0, 1.0));
@ -294,6 +318,7 @@ void main()
vec3 _673 = _11._m5 * clamp(textureLod(SPIRV_Cross_Combined, _661, 0.0).w * _7._m1, 0.0, 1.0);
vec4 _677 = textureLod(SPIRV_Cross_Combined_1, _661, 0.0);
vec3 _693;
SPIRV_CROSS_BRANCH
if (_677.y > 0.0)
{
_693 = _673 + (textureLod(SPIRV_Cross_Combined_2, _661, 0.0).xyz * clamp(_677.y * _677.z, 0.0, 1.0));

View File

@ -0,0 +1,146 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 6
; Bound: 85
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpSource HLSL 500
OpName %main "main"
OpName %_main_ "@main("
OpName %i "i"
OpName %bar "bar"
OpMemberName %bar 0 "@data"
OpName %bar_0 "bar"
OpName %foo "foo"
OpName %i_0 "i"
OpName %v "v"
OpName %w "w"
OpName %value "value"
OpDecorate %_runtimearr_v4float ArrayStride 16
OpMemberDecorate %bar 0 Offset 0
OpDecorate %bar BufferBlock
OpDecorate %bar_0 DescriptorSet 0
OpDecorate %bar_0 Binding 0
OpDecorate %foo DescriptorSet 0
OpDecorate %foo Binding 1
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%int_0 = OpConstant %int 0
%int_16 = OpConstant %int 16
%bool = OpTypeBool
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_runtimearr_v4float = OpTypeRuntimeArray %v4float
%bar = OpTypeStruct %_runtimearr_v4float
%_ptr_Uniform_bar = OpTypePointer Uniform %bar
%bar_0 = OpVariable %_ptr_Uniform_bar Uniform
%foo = OpVariable %_ptr_Uniform_bar Uniform
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_1 = OpConstant %int 1
%int_15 = OpConstant %int 15
%_ptr_Function_float = OpTypePointer Function %float
%int_10 = OpConstant %int 10
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%float_10 = OpConstant %float 10
%int_20 = OpConstant %int 20
%float_5 = OpConstant %float 5
%72 = OpConstantComposite %v4float %float_5 %float_5 %float_5 %float_5
%float_20 = OpConstant %float 20
%float_40 = OpConstant %float 40
%main = OpFunction %void None %3
%5 = OpLabel
%84 = OpFunctionCall %void %_main_
OpReturn
OpFunctionEnd
%_main_ = OpFunction %void None %3
%7 = OpLabel
%i = OpVariable %_ptr_Function_int Function
%i_0 = OpVariable %_ptr_Function_int Function
%v = OpVariable %_ptr_Function_float Function
%w = OpVariable %_ptr_Function_float Function
%value = OpVariable %_ptr_Function_float Function
OpStore %i %int_0
OpBranch %12
%12 = OpLabel
OpLoopMerge %14 %15 Unroll
OpBranch %16
%16 = OpLabel
%17 = OpLoad %int %i
%20 = OpSLessThan %bool %17 %int_16
OpBranchConditional %20 %13 %14
%13 = OpLabel
%27 = OpLoad %int %i
%29 = OpLoad %int %i
%31 = OpAccessChain %_ptr_Uniform_v4float %foo %int_0 %29
%32 = OpLoad %v4float %31
%33 = OpAccessChain %_ptr_Uniform_v4float %bar_0 %int_0 %27
OpStore %33 %32
OpBranch %15
%15 = OpLabel
%34 = OpLoad %int %i
%36 = OpIAdd %int %34 %int_1
OpStore %i %36
OpBranch %12
%14 = OpLabel
OpStore %i_0 %int_0
OpBranch %38
%38 = OpLabel
OpLoopMerge %40 %41 DontUnroll
OpBranch %42
%42 = OpLabel
%43 = OpLoad %int %i_0
%44 = OpSLessThan %bool %43 %int_16
OpBranchConditional %44 %39 %40
%39 = OpLabel
%46 = OpLoad %int %i_0
%47 = OpISub %int %int_15 %46
%48 = OpLoad %int %i_0
%49 = OpAccessChain %_ptr_Uniform_v4float %foo %int_0 %48
%50 = OpLoad %v4float %49
%51 = OpAccessChain %_ptr_Uniform_v4float %bar_0 %int_0 %47
OpStore %51 %50
OpBranch %41
%41 = OpLabel
%52 = OpLoad %int %i_0
%53 = OpIAdd %int %52 %int_1
OpStore %i_0 %53
OpBranch %38
%40 = OpLabel
%60 = OpAccessChain %_ptr_Uniform_float %bar_0 %int_0 %int_10 %uint_0
%61 = OpLoad %float %60
OpStore %v %61
%63 = OpAccessChain %_ptr_Uniform_float %foo %int_0 %int_10 %uint_0
%64 = OpLoad %float %63
OpStore %w %64
%65 = OpLoad %float %v
%67 = OpFOrdGreaterThan %bool %65 %float_10
OpSelectionMerge %69 DontFlatten
OpBranchConditional %67 %68 %69
%68 = OpLabel
%73 = OpAccessChain %_ptr_Uniform_v4float %foo %int_0 %int_20
OpStore %73 %72
OpBranch %69
%69 = OpLabel
OpStore %value %float_20
%76 = OpLoad %float %w
%78 = OpFOrdGreaterThan %bool %76 %float_40
OpSelectionMerge %80 Flatten
OpBranchConditional %78 %79 %80
%79 = OpLabel
OpStore %value %float_20
OpBranch %80
%80 = OpLabel
%81 = OpLoad %float %value
%82 = OpCompositeConstruct %v4float %81 %81 %81 %81
%83 = OpAccessChain %_ptr_Uniform_v4float %foo %int_0 %int_20
OpStore %83 %82
OpReturn
OpFunctionEnd

View File

@ -823,6 +823,22 @@ void CompilerGLSL::emit_header()
statement("#extension ", ext, " : enable");
statement("#endif");
}
else if (ext == "GL_EXT_control_flow_attributes")
{
// These are just hints so we can conditionally enable and fallback in the shader.
statement("#if defined(GL_EXT_control_flow_attributes)");
statement("#extension GL_EXT_control_flow_attributes : require");
statement("#define SPIRV_CROSS_FLATTEN [[flatten]]");
statement("#define SPIRV_CROSS_BRANCH [[dont_flatten]]");
statement("#define SPIRV_CROSS_UNROLL [[unroll]]");
statement("#define SPIRV_CROSS_LOOP [[dont_unroll]]");
statement("#else");
statement("#define SPIRV_CROSS_FLATTEN");
statement("#define SPIRV_CROSS_BRANCH");
statement("#define SPIRV_CROSS_UNROLL");
statement("#define SPIRV_CROSS_LOOP");
statement("#endif");
}
else
statement("#extension ", ext, " : require");
}
@ -14004,7 +14020,10 @@ void CompilerGLSL::branch(BlockID from, uint32_t cond, BlockID true_block, Block
if (!true_block_needs_code && !false_block_needs_code)
return;
emit_block_hints(get<SPIRBlock>(from));
// We might have a loop merge here. Only consider selection flattening constructs.
// Loop hints are handled explicitly elsewhere.
if (from_block.hint == SPIRBlock::HintFlatten || from_block.hint == SPIRBlock::HintDontFlatten)
emit_block_hints(from_block);
if (true_block_needs_code)
{
@ -14510,6 +14529,7 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
// for (;;) { create-temporary; break; } consume-temporary;
// so force-declare temporaries here.
emit_hoisted_temporaries(block.potential_declare_temporary);
emit_block_hints(block);
statement("for (;;)");
begin_scope();
@ -15376,8 +15396,32 @@ void CompilerGLSL::convert_non_uniform_expression(string &expr, uint32_t ptr_id)
expr.substr(end_array_index, string::npos));
}
void CompilerGLSL::emit_block_hints(const SPIRBlock &)
void CompilerGLSL::emit_block_hints(const SPIRBlock &block)
{
if ((options.es && options.version < 310) || (!options.es && options.version < 140))
return;
switch (block.hint)
{
case SPIRBlock::HintFlatten:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_FLATTEN");
break;
case SPIRBlock::HintDontFlatten:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_BRANCH");
break;
case SPIRBlock::HintUnroll:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_UNROLL");
break;
case SPIRBlock::HintDontUnroll:
require_extension_internal("GL_EXT_control_flow_attributes");
statement("SPIRV_CROSS_LOOP");
break;
default:
break;
}
}
void CompilerGLSL::preserve_alias_on_reset(uint32_t id)

View File

@ -15936,3 +15936,7 @@ const char *CompilerMSL::get_combined_sampler_suffix() const
{
return sampler_name_suffix.c_str();
}
void CompilerMSL::emit_block_hints(const SPIRBlock &)
{
}

View File

@ -730,6 +730,7 @@ protected:
const std::string &qualifier = "", uint32_t base_offset = 0) override;
void emit_struct_padding_target(const SPIRType &type) override;
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
void emit_block_hints(const SPIRBlock &block) override;
// Allow Metal to use the array<T> template to make arrays a value type
std::string type_to_array_glsl(const SPIRType &type) override;