diff options
author | Grigory Dzhavadyan <grigoryj@google.com> | 2018-10-30 09:31:32 +0300 |
---|---|---|
committer | nicebyte <nicebyte@mailinator.com> | 2018-11-01 10:39:09 +0300 |
commit | a5d82d1138dd43ab4cd9351bf7d942e55eca0931 (patch) | |
tree | 633a6918dbe19a183b6d5c20634ac09cd9f58485 /reference/opt/shaders/vulkan | |
parent | dfd1bf8c564f51534da2953fcd5b51840e9d7544 (diff) |
Alter the handling of spec consts in non-Vulkan GLSL
Previously, when generating non-Vulkan GLSL, each use of a spec constant
would be subsituted for its default value and the declaration of the constant
itself would be omitted completely.
This change slightly alters this behavior. The uses of the constant are kept,
as well as the declaration, although the latter is stripped of the layout
qualifier. The declaration is also prepended with the following code:
#ifndef <constant name>_value
#define <constant name> <default constant value>
#endif
and the constant itself now looks like
const <constant type> <constant name> = <constant name>_value;
The rationale for this change is that it gives the user a way to provide
custom values for specialization constants even when the target does not
support them.
Diffstat (limited to 'reference/opt/shaders/vulkan')
-rw-r--r-- | reference/opt/shaders/vulkan/frag/spec-constant-block-size.vk.frag | 8 | ||||
-rw-r--r-- | reference/opt/shaders/vulkan/frag/spec-constant-ternary.vk.frag | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/reference/opt/shaders/vulkan/frag/spec-constant-block-size.vk.frag b/reference/opt/shaders/vulkan/frag/spec-constant-block-size.vk.frag index e8c3c4a3..6b0d1ce4 100644 --- a/reference/opt/shaders/vulkan/frag/spec-constant-block-size.vk.frag +++ b/reference/opt/shaders/vulkan/frag/spec-constant-block-size.vk.frag @@ -2,9 +2,15 @@ precision mediump float; precision highp int; +#ifndef SPIRV_CROSS_CONSTANT_ID_10 +#define SPIRV_CROSS_CONSTANT_ID_10 2 +#endif +const int Value = SPIRV_CROSS_CONSTANT_ID_10; + + layout(binding = 0, std140) uniform SpecConstArray { - vec4 samples[2]; + vec4 samples[Value]; } _15; layout(location = 0) out vec4 FragColor; diff --git a/reference/opt/shaders/vulkan/frag/spec-constant-ternary.vk.frag b/reference/opt/shaders/vulkan/frag/spec-constant-ternary.vk.frag index 91b0331b..1ee71fb2 100644 --- a/reference/opt/shaders/vulkan/frag/spec-constant-ternary.vk.frag +++ b/reference/opt/shaders/vulkan/frag/spec-constant-ternary.vk.frag @@ -1,9 +1,17 @@ #version 450 +#ifndef SPIRV_CROSS_CONSTANT_ID_0 +#define SPIRV_CROSS_CONSTANT_ID_0 10u +#endif +const uint s = SPIRV_CROSS_CONSTANT_ID_0; + +const bool _13 = (s > 20u); +const uint _16 = _13 ? 30u : 50u; + layout(location = 0) out float FragColor; void main() { - FragColor = float((10u > 20u) ? 30u : 50u); + FragColor = float(_16); } |