mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-12 15:10:30 +00:00
Support Component decoration in GLSL.
This commit is contained in:
parent
7a32167d63
commit
63f6466065
23
reference/opt/shaders/asm/frag/locations-components.asm.frag
Normal file
23
reference/opt/shaders/asm/frag/locations-components.asm.frag
Normal file
@ -0,0 +1,23 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 1) in vec2 _2;
|
||||
layout(location = 1, component = 2) in float _3;
|
||||
layout(location = 2) flat in float _4;
|
||||
layout(location = 2, component = 1) flat in uint _5;
|
||||
layout(location = 2, component = 2) flat in uint _6;
|
||||
layout(location = 0) out vec4 o0;
|
||||
vec4 v1;
|
||||
vec4 v2;
|
||||
|
||||
void main()
|
||||
{
|
||||
v1 = vec4(_2.x, _2.y, v1.z, v1.w);
|
||||
v1.z = _3;
|
||||
v2.x = _4;
|
||||
v2.y = uintBitsToFloat(_5);
|
||||
v2.z = uintBitsToFloat(_6);
|
||||
o0.y = float(floatBitsToUint(intBitsToFloat(floatBitsToInt(v2.y) + floatBitsToInt(v2.z))));
|
||||
o0.x = v1.y + v2.x;
|
||||
o0 = vec4(o0.x, o0.y, v1.z, v1.x);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 FragColor;
|
||||
layout(location = 0, component = 0) in vec2 v0;
|
||||
layout(location = 0, component = 2) in float v1;
|
||||
in Vertex
|
||||
{
|
||||
layout(location = 1, component = 2) float v3;
|
||||
} _20;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = (v0 + vec2(v1)) + vec2(_20.v3);
|
||||
}
|
||||
|
25
reference/shaders/asm/frag/locations-components.asm.frag
Normal file
25
reference/shaders/asm/frag/locations-components.asm.frag
Normal file
@ -0,0 +1,25 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 1) in vec2 _2;
|
||||
layout(location = 1, component = 2) in float _3;
|
||||
layout(location = 2) flat in float _4;
|
||||
layout(location = 2, component = 1) flat in uint _5;
|
||||
layout(location = 2, component = 2) flat in uint _6;
|
||||
layout(location = 0) out vec4 o0;
|
||||
vec4 v1;
|
||||
vec4 v2;
|
||||
|
||||
void main()
|
||||
{
|
||||
v1 = vec4(_2.x, _2.y, v1.z, v1.w);
|
||||
v1.z = _3;
|
||||
v2.x = _4;
|
||||
v2.y = uintBitsToFloat(_5);
|
||||
v2.z = uintBitsToFloat(_6);
|
||||
vec4 r0;
|
||||
r0.x = intBitsToFloat(floatBitsToInt(v2.y) + floatBitsToInt(v2.z));
|
||||
o0.y = float(floatBitsToUint(r0.x));
|
||||
o0.x = v1.y + v2.x;
|
||||
o0 = vec4(o0.x, o0.y, v1.z, v1.x);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 FragColor;
|
||||
layout(location = 0, component = 0) in vec2 v0;
|
||||
layout(location = 0, component = 2) in float v1;
|
||||
in Vertex
|
||||
{
|
||||
layout(location = 1, component = 2) float v3;
|
||||
} _20;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = (v0 + vec2(v1)) + vec2(_20.v3);
|
||||
}
|
||||
|
102
shaders/asm/frag/locations-components.asm.frag
Normal file
102
shaders/asm/frag/locations-components.asm.frag
Normal file
@ -0,0 +1,102 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: Wine VKD3D Shader Compiler; 0
|
||||
; Bound: 67
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main" %8 %16 %22 %28 %33 %o0
|
||||
OpName %main "main"
|
||||
OpName %v1 "v1"
|
||||
OpName %v2 "v2"
|
||||
OpName %o0 "o0"
|
||||
OpName %r0 "r0"
|
||||
OpDecorate %8 Location 1
|
||||
OpDecorate %16 Location 1
|
||||
OpDecorate %16 Component 2
|
||||
OpDecorate %22 Location 2
|
||||
OpDecorate %22 Flat
|
||||
OpDecorate %28 Location 2
|
||||
OpDecorate %28 Component 1
|
||||
OpDecorate %28 Flat
|
||||
OpDecorate %33 Location 2
|
||||
OpDecorate %33 Component 2
|
||||
OpDecorate %33 Flat
|
||||
OpDecorate %o0 Location 0
|
||||
%void = OpTypeVoid
|
||||
%2 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%v2float = OpTypeVector %float 2
|
||||
%_ptr_Input_v2float = OpTypePointer Input %v2float
|
||||
%8 = OpVariable %_ptr_Input_v2float Input
|
||||
%v4float = OpTypeVector %float 4
|
||||
%_ptr_Private_v4float = OpTypePointer Private %v4float
|
||||
%v1 = OpVariable %_ptr_Private_v4float Private
|
||||
%_ptr_Input_float = OpTypePointer Input %float
|
||||
%16 = OpVariable %_ptr_Input_float Input
|
||||
%_ptr_Private_float = OpTypePointer Private %float
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_2 = OpConstant %uint 2
|
||||
%22 = OpVariable %_ptr_Input_float Input
|
||||
%v2 = OpVariable %_ptr_Private_v4float Private
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Input_uint = OpTypePointer Input %uint
|
||||
%28 = OpVariable %_ptr_Input_uint Input
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%33 = OpVariable %_ptr_Input_uint Input
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
%o0 = OpVariable %_ptr_Output_v4float Output
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%int = OpTypeInt 32 1
|
||||
%_ptr_Function_float = OpTypePointer Function %float
|
||||
%_ptr_Output_float = OpTypePointer Output %float
|
||||
%main = OpFunction %void None %2
|
||||
%4 = OpLabel
|
||||
%r0 = OpVariable %_ptr_Function_v4float Function
|
||||
%12 = OpLoad %v2float %8
|
||||
%13 = OpLoad %v4float %v1
|
||||
%14 = OpVectorShuffle %v4float %13 %12 4 5 2 3
|
||||
OpStore %v1 %14
|
||||
%17 = OpLoad %float %16
|
||||
%21 = OpInBoundsAccessChain %_ptr_Private_float %v1 %uint_2
|
||||
OpStore %21 %17
|
||||
%24 = OpLoad %float %22
|
||||
%26 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_0
|
||||
OpStore %26 %24
|
||||
%29 = OpLoad %uint %28
|
||||
%30 = OpBitcast %float %29
|
||||
%32 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_1
|
||||
OpStore %32 %30
|
||||
%34 = OpLoad %uint %33
|
||||
%35 = OpBitcast %float %34
|
||||
%36 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_2
|
||||
OpStore %36 %35
|
||||
%42 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_1
|
||||
%43 = OpLoad %float %42
|
||||
%44 = OpBitcast %int %43
|
||||
%45 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_2
|
||||
%46 = OpLoad %float %45
|
||||
%47 = OpBitcast %int %46
|
||||
%48 = OpIAdd %int %44 %47
|
||||
%49 = OpBitcast %float %48
|
||||
%51 = OpInBoundsAccessChain %_ptr_Function_float %r0 %uint_0
|
||||
OpStore %51 %49
|
||||
%52 = OpInBoundsAccessChain %_ptr_Function_float %r0 %uint_0
|
||||
%53 = OpLoad %float %52
|
||||
%54 = OpBitcast %uint %53
|
||||
%55 = OpConvertUToF %float %54
|
||||
%57 = OpInBoundsAccessChain %_ptr_Output_float %o0 %uint_1
|
||||
OpStore %57 %55
|
||||
%58 = OpInBoundsAccessChain %_ptr_Private_float %v1 %uint_1
|
||||
%59 = OpLoad %float %58
|
||||
%60 = OpInBoundsAccessChain %_ptr_Private_float %v2 %uint_0
|
||||
%61 = OpLoad %float %60
|
||||
%62 = OpFAdd %float %59 %61
|
||||
%63 = OpInBoundsAccessChain %_ptr_Output_float %o0 %uint_0
|
||||
OpStore %63 %62
|
||||
%64 = OpLoad %v4float %v1
|
||||
%65 = OpLoad %v4float %o0
|
||||
%66 = OpVectorShuffle %v4float %65 %64 0 1 6 4
|
||||
OpStore %o0 %66
|
||||
OpReturn
|
||||
OpFunctionEnd
|
14
shaders/desktop-only/frag/layout-component.desktop.frag
Normal file
14
shaders/desktop-only/frag/layout-component.desktop.frag
Normal file
@ -0,0 +1,14 @@
|
||||
#version 450
|
||||
layout(location = 0, component = 0) in vec2 v0;
|
||||
layout(location = 0, component = 2) in float v1;
|
||||
layout(location = 0) out vec2 FragColor;
|
||||
|
||||
in Vertex
|
||||
{
|
||||
layout(location = 1, component = 2) in float v3;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = v0 + v1 + v3;
|
||||
}
|
@ -775,6 +775,21 @@ string CompilerGLSL::layout_for_member(const SPIRType &type, uint32_t index)
|
||||
if (dec.decoration_flags.get(DecorationLocation) && can_use_io_location(type.storage, true))
|
||||
attr.push_back(join("location = ", dec.location));
|
||||
|
||||
// Can only declare component if we can declare location.
|
||||
if (dec.decoration_flags.get(DecorationComponent) && can_use_io_location(type.storage, true))
|
||||
{
|
||||
if (!options.es)
|
||||
{
|
||||
if (options.version < 440 && options.version >= 140)
|
||||
require_extension_internal("GL_ARB_enhanced_layouts");
|
||||
else if (options.version < 140)
|
||||
SPIRV_CROSS_THROW("Component decoration is not supported in targets below GLSL 1.40.");
|
||||
attr.push_back(join("component = ", dec.component));
|
||||
}
|
||||
else
|
||||
SPIRV_CROSS_THROW("Component decoration is not supported in ES targets.");
|
||||
}
|
||||
|
||||
// DecorationCPacked is set by layout_for_variable earlier to mark that we need to emit offset qualifiers.
|
||||
// This is only done selectively in GLSL as needed.
|
||||
if (has_decoration(type.self, DecorationCPacked) && dec.decoration_flags.get(DecorationOffset))
|
||||
@ -1238,6 +1253,21 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var)
|
||||
attr.push_back(join("location = ", dec.location));
|
||||
}
|
||||
|
||||
// Can only declare Component if we can declare location.
|
||||
if (flags.get(DecorationComponent) && can_use_io_location(var.storage, is_block))
|
||||
{
|
||||
if (!options.es)
|
||||
{
|
||||
if (options.version < 440 && options.version >= 140)
|
||||
require_extension_internal("GL_ARB_enhanced_layouts");
|
||||
else if (options.version < 140)
|
||||
SPIRV_CROSS_THROW("Component decoration is not supported in targets below GLSL 1.40.");
|
||||
attr.push_back(join("component = ", dec.component));
|
||||
}
|
||||
else
|
||||
SPIRV_CROSS_THROW("Component decoration is not supported in ES targets.");
|
||||
}
|
||||
|
||||
if (flags.get(DecorationIndex))
|
||||
attr.push_back(join("index = ", dec.index));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user