diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2020-03-26 13:21:23 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2020-03-26 15:38:27 +0300 |
commit | b8905bbd95b2b25c1765f201d0dc2b137300de88 (patch) | |
tree | 353f7b285d2ce710f482276d4f320b69072ef669 /shaders-hlsl-no-opt | |
parent | 871c85d7f0edc6b613e3959bc51d13bfbc2fe2df (diff) |
Add support for forcefully zero-initialized variables.
Useful to better support certain platforms which require all variables
to be initialized to something.
Diffstat (limited to 'shaders-hlsl-no-opt')
3 files changed, 183 insertions, 0 deletions
diff --git a/shaders-hlsl-no-opt/asm/frag/phi.zero-initialize.asm.frag b/shaders-hlsl-no-opt/asm/frag/phi.zero-initialize.asm.frag new file mode 100644 index 00000000..3696660d --- /dev/null +++ b/shaders-hlsl-no-opt/asm/frag/phi.zero-initialize.asm.frag @@ -0,0 +1,69 @@ +; SPIR-V +; Version: 1.0 +; Generator: Khronos Glslang Reference Front End; 8 +; Bound: 40 +; Schema: 0 + OpCapability Shader + %1 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %vColor %FragColor + OpExecutionMode %main OriginUpperLeft + OpSource GLSL 450 + OpName %main "main" + OpName %vColor "vColor" + OpName %uninit_function_int "uninit_function_int" + OpName %FragColor "FragColor" + OpName %uninit_int "uninit_int" + OpName %uninit_vector "uninit_vector" + OpName %uninit_matrix "uninit_matrix" + OpName %Foo "Foo" + OpMemberName %Foo 0 "a" + OpName %uninit_foo "uninit_foo" + OpDecorate %vColor Location 0 + OpDecorate %FragColor Location 0 + %void = OpTypeVoid + %3 = OpTypeFunction %void + %float = OpTypeFloat 32 + %v4float = OpTypeVector %float 4 +%_ptr_Input_v4float = OpTypePointer Input %v4float + %vColor = OpVariable %_ptr_Input_v4float Input + %uint = OpTypeInt 32 0 + %uint_0 = OpConstant %uint 0 +%_ptr_Input_float = OpTypePointer Input %float + %float_10 = OpConstant %float 10 + %bool = OpTypeBool + %int = OpTypeInt 32 1 +%_ptr_Function_int = OpTypePointer Function %int + %int_10 = OpConstant %int 10 + %int_20 = OpConstant %int 20 +%_ptr_Output_v4float = OpTypePointer Output %v4float + %FragColor = OpVariable %_ptr_Output_v4float Output +%_ptr_Private_int = OpTypePointer Private %int + %uninit_int = OpUndef %int + %v4int = OpTypeVector %int 4 +%_ptr_Private_v4int = OpTypePointer Private %v4int +%uninit_vector = OpUndef %v4int +%mat4v4float = OpTypeMatrix %v4float 4 +%_ptr_Private_mat4v4float = OpTypePointer Private %mat4v4float +%uninit_matrix = OpUndef %mat4v4float + %Foo = OpTypeStruct %int +%_ptr_Private_Foo = OpTypePointer Private %Foo + %uninit_foo = OpUndef %Foo + %main = OpFunction %void None %3 + %5 = OpLabel +%uninit_function_int = OpVariable %_ptr_Function_int Function + %13 = OpAccessChain %_ptr_Input_float %vColor %uint_0 + %14 = OpLoad %float %13 + %17 = OpFOrdGreaterThan %bool %14 %float_10 + OpSelectionMerge %19 None + OpBranchConditional %17 %18 %24 + %18 = OpLabel + OpBranch %19 + %24 = OpLabel + OpBranch %19 + %19 = OpLabel + %27 = OpPhi %int %int_10 %18 %int_20 %24 + %28 = OpLoad %v4float %vColor + OpStore %FragColor %28 + OpReturn + OpFunctionEnd diff --git a/shaders-hlsl-no-opt/asm/temporary.zero-initialize.asm.frag b/shaders-hlsl-no-opt/asm/temporary.zero-initialize.asm.frag new file mode 100644 index 00000000..eccff08b --- /dev/null +++ b/shaders-hlsl-no-opt/asm/temporary.zero-initialize.asm.frag @@ -0,0 +1,93 @@ +; SPIR-V +; Version: 1.0 +; Generator: Khronos Glslang Reference Front End; 8 +; Bound: 65 +; Schema: 0 + OpCapability Shader + %1 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Fragment %main "main" %FragColor %vA %vB + OpExecutionMode %main OriginUpperLeft + OpSource ESSL 310 + OpName %main "main" + OpName %FragColor "FragColor" + OpName %vA "vA" + OpName %vB "vB" + OpDecorate %FragColor RelaxedPrecision + OpDecorate %FragColor Location 0 + OpDecorate %vA RelaxedPrecision + OpDecorate %vA Flat + OpDecorate %vA Location 0 + OpDecorate %25 RelaxedPrecision + OpDecorate %30 RelaxedPrecision + OpDecorate %vB RelaxedPrecision + OpDecorate %vB Flat + OpDecorate %vB Location 1 + OpDecorate %38 RelaxedPrecision + OpDecorate %40 RelaxedPrecision + OpDecorate %49 RelaxedPrecision + OpDecorate %51 RelaxedPrecision + OpDecorate %53 RelaxedPrecision + OpDecorate %56 RelaxedPrecision + OpDecorate %64 RelaxedPrecision + OpDecorate %58 RelaxedPrecision + OpDecorate %57 RelaxedPrecision + OpDecorate %60 RelaxedPrecision + %void = OpTypeVoid + %3 = OpTypeFunction %void + %float = OpTypeFloat 32 + %v4float = OpTypeVector %float 4 +%_ptr_Output_v4float = OpTypePointer Output %v4float + %FragColor = OpVariable %_ptr_Output_v4float Output + %float_0 = OpConstant %float 0 + %11 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 + %int = OpTypeInt 32 1 + %int_0 = OpConstant %int 0 +%_ptr_Input_int = OpTypePointer Input %int + %vA = OpVariable %_ptr_Input_int Input + %bool = OpTypeBool + %int_20 = OpConstant %int 20 + %int_50 = OpConstant %int 50 + %vB = OpVariable %_ptr_Input_int Input + %int_40 = OpConstant %int 40 + %int_60 = OpConstant %int 60 + %int_10 = OpConstant %int 10 + %float_1 = OpConstant %float 1 + %63 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1 + %main = OpFunction %void None %3 + %5 = OpLabel + OpStore %FragColor %11 + OpBranch %17 + %17 = OpLabel + %60 = OpPhi %int %int_0 %5 %58 %20 + %57 = OpPhi %int %int_0 %5 %56 %20 + %25 = OpLoad %int %vA + %27 = OpSLessThan %bool %57 %25 + OpLoopMerge %19 %20 None + OpBranchConditional %27 %18 %19 + %18 = OpLabel + %30 = OpIAdd %int %25 %57 + %32 = OpIEqual %bool %30 %int_20 + OpSelectionMerge %34 None + OpBranchConditional %32 %33 %36 + %33 = OpLabel + OpBranch %34 + %36 = OpLabel + %38 = OpLoad %int %vB + %40 = OpIAdd %int %38 %57 + %42 = OpIEqual %bool %40 %int_40 + %64 = OpSelect %int %42 %int_60 %60 + OpBranch %34 + %34 = OpLabel + %58 = OpPhi %int %int_50 %33 %64 %36 + %49 = OpIAdd %int %58 %int_10 + %51 = OpLoad %v4float %FragColor + %53 = OpFAdd %v4float %51 %63 + OpStore %FragColor %53 + OpBranch %20 + %20 = OpLabel + %56 = OpIAdd %int %57 %49 + OpBranch %17 + %19 = OpLabel + OpReturn + OpFunctionEnd diff --git a/shaders-hlsl-no-opt/frag/variables.zero-initialize.frag b/shaders-hlsl-no-opt/frag/variables.zero-initialize.frag new file mode 100644 index 00000000..41da8001 --- /dev/null +++ b/shaders-hlsl-no-opt/frag/variables.zero-initialize.frag @@ -0,0 +1,21 @@ +#version 450 + +layout(location = 0) in vec4 vColor; +layout(location = 0) out vec4 FragColor; + +int uninit_int; +ivec4 uninit_vector; +mat4 uninit_matrix; + +struct Foo { int a; }; +Foo uninit_foo; + +void main() +{ + int uninit_function_int; + if (vColor.x > 10.0) + uninit_function_int = 10; + else + uninit_function_int = 20; + FragColor = vColor; +} |