diff options
-rw-r--r-- | reference/opt/shaders-msl/frag/16bit-constants.frag | 21 | ||||
-rw-r--r-- | reference/opt/shaders/frag/16bit-constants.frag | 29 | ||||
-rw-r--r-- | reference/shaders-msl/frag/16bit-constants.frag | 21 | ||||
-rw-r--r-- | reference/shaders/frag/16bit-constants.frag | 29 | ||||
-rw-r--r-- | shaders-msl/frag/16bit-constants.frag | 14 | ||||
-rw-r--r-- | shaders/frag/16bit-constants.frag | 14 | ||||
-rw-r--r-- | spirv_glsl.cpp | 66 | ||||
-rw-r--r-- | spirv_glsl.hpp | 2 | ||||
-rw-r--r-- | spirv_hlsl.cpp | 2 | ||||
-rw-r--r-- | spirv_msl.cpp | 2 |
10 files changed, 200 insertions, 0 deletions
diff --git a/reference/opt/shaders-msl/frag/16bit-constants.frag b/reference/opt/shaders-msl/frag/16bit-constants.frag new file mode 100644 index 00000000..2aae1e8a --- /dev/null +++ b/reference/opt/shaders-msl/frag/16bit-constants.frag @@ -0,0 +1,21 @@ +#include <metal_stdlib> +#include <simd/simd.h> + +using namespace metal; + +struct main0_out +{ + half foo [[color(0)]]; + short bar [[color(1)]]; + ushort baz [[color(2)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.foo = 1.0h; + out.bar = 2; + out.baz = 3u; + return out; +} + diff --git a/reference/opt/shaders/frag/16bit-constants.frag b/reference/opt/shaders/frag/16bit-constants.frag new file mode 100644 index 00000000..48fbad97 --- /dev/null +++ b/reference/opt/shaders/frag/16bit-constants.frag @@ -0,0 +1,29 @@ +#version 450 +#if defined(GL_AMD_gpu_shader_half_float) +#extension GL_AMD_gpu_shader_half_float : require +#elif defined(GL_NV_gpu_shader5) +#extension GL_NV_gpu_shader5 : require +#elif defined(GL_EXT_shader_16bit_storage) +#extension GL_EXT_shader_16bit_storage : require +#else +#error No extension available for FP16. +#endif +#if defined(GL_AMD_gpu_shader_int16) +#extension GL_AMD_gpu_shader_int16 : require +#elif defined(GL_EXT_shader_16bit_storage) +#extension GL_EXT_shader_16bit_storage : require +#else +#error No extension available for Int16. +#endif + +layout(location = 0) out float16_t foo; +layout(location = 1) out int16_t bar; +layout(location = 2) out uint16_t baz; + +void main() +{ + foo = 1.0hf; + bar = 2s; + baz = 3us; +} + diff --git a/reference/shaders-msl/frag/16bit-constants.frag b/reference/shaders-msl/frag/16bit-constants.frag new file mode 100644 index 00000000..2aae1e8a --- /dev/null +++ b/reference/shaders-msl/frag/16bit-constants.frag @@ -0,0 +1,21 @@ +#include <metal_stdlib> +#include <simd/simd.h> + +using namespace metal; + +struct main0_out +{ + half foo [[color(0)]]; + short bar [[color(1)]]; + ushort baz [[color(2)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.foo = 1.0h; + out.bar = 2; + out.baz = 3u; + return out; +} + diff --git a/reference/shaders/frag/16bit-constants.frag b/reference/shaders/frag/16bit-constants.frag new file mode 100644 index 00000000..48fbad97 --- /dev/null +++ b/reference/shaders/frag/16bit-constants.frag @@ -0,0 +1,29 @@ +#version 450 +#if defined(GL_AMD_gpu_shader_half_float) +#extension GL_AMD_gpu_shader_half_float : require +#elif defined(GL_NV_gpu_shader5) +#extension GL_NV_gpu_shader5 : require +#elif defined(GL_EXT_shader_16bit_storage) +#extension GL_EXT_shader_16bit_storage : require +#else +#error No extension available for FP16. +#endif +#if defined(GL_AMD_gpu_shader_int16) +#extension GL_AMD_gpu_shader_int16 : require +#elif defined(GL_EXT_shader_16bit_storage) +#extension GL_EXT_shader_16bit_storage : require +#else +#error No extension available for Int16. +#endif + +layout(location = 0) out float16_t foo; +layout(location = 1) out int16_t bar; +layout(location = 2) out uint16_t baz; + +void main() +{ + foo = 1.0hf; + bar = 2s; + baz = 3us; +} + diff --git a/shaders-msl/frag/16bit-constants.frag b/shaders-msl/frag/16bit-constants.frag new file mode 100644 index 00000000..c53091b5 --- /dev/null +++ b/shaders-msl/frag/16bit-constants.frag @@ -0,0 +1,14 @@ +#version 450 core + +#extension GL_AMD_gpu_shader_int16 : require +#extension GL_AMD_gpu_shader_half_float : require + +layout(location = 0) out float16_t foo; +layout(location = 1) out int16_t bar; +layout(location = 2) out uint16_t baz; + +void main() { + foo = 1.0hf; + bar = 2s; + baz = 3us; +} diff --git a/shaders/frag/16bit-constants.frag b/shaders/frag/16bit-constants.frag new file mode 100644 index 00000000..c53091b5 --- /dev/null +++ b/shaders/frag/16bit-constants.frag @@ -0,0 +1,14 @@ +#version 450 core + +#extension GL_AMD_gpu_shader_int16 : require +#extension GL_AMD_gpu_shader_half_float : require + +layout(location = 0) out float16_t foo; +layout(location = 1) out int16_t bar; +layout(location = 2) out uint16_t baz; + +void main() { + foo = 1.0hf; + bar = 2s; + baz = 3us; +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 99a00f5f..f2dd2826 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -3351,6 +3351,72 @@ string CompilerGLSL::constant_expression_vector(const SPIRConstant &c, uint32_t } break; + case SPIRType::UShort: + if (splat) + { + res += convert_to_string(c.scalar(vector, 0)); + if (is_legacy()) + { + // Fake unsigned constant literals with signed ones if possible. + // Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed. + if (c.scalar_i16(vector, 0) < 0) + SPIRV_CROSS_THROW("Tried to convert uint literal into int, but this made the literal negative."); + } + else if (backend.uint16_t_literal_suffix) + res += backend.uint16_t_literal_suffix; + } + else + { + for (uint32_t i = 0; i < c.vector_size(); i++) + { + if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0) + res += to_name(c.specialization_constant_id(vector, i)); + else + { + res += convert_to_string(c.scalar(vector, i)); + if (is_legacy()) + { + // Fake unsigned constant literals with signed ones if possible. + // Things like array sizes, etc, tend to be unsigned even though they could just as easily be signed. + if (c.scalar_i16(vector, i) < 0) + SPIRV_CROSS_THROW( + "Tried to convert uint literal into int, but this made the literal negative."); + } + else if (backend.uint16_t_literal_suffix) + res += backend.uint16_t_literal_suffix; + } + + if (i + 1 < c.vector_size()) + res += ", "; + } + } + break; + + case SPIRType::Short: + if (splat) + { + res += convert_to_string(c.scalar_i16(vector, 0)); + if (backend.int16_t_literal_suffix) + res += backend.int16_t_literal_suffix; + } + else + { + for (uint32_t i = 0; i < c.vector_size(); i++) + { + if (c.vector_size() > 1 && c.specialization_constant_id(vector, i) != 0) + res += to_name(c.specialization_constant_id(vector, i)); + else + { + res += convert_to_string(c.scalar_i16(vector, i)); + if (backend.int16_t_literal_suffix) + res += backend.int16_t_literal_suffix; + } + if (i + 1 < c.vector_size()) + res += ", "; + } + } + break; + case SPIRType::Boolean: if (splat) res += c.scalar(vector, 0) ? "true" : "false"; diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index bad4f47f..33a839ae 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -366,6 +366,8 @@ protected: const char *basic_int16_type = "int16_t"; const char *basic_uint16_type = "uint16_t"; const char *half_literal_suffix = "hf"; + const char *int16_t_literal_suffix = "s"; + const char *uint16_t_literal_suffix = "us"; bool swizzle_is_function = false; bool shared_is_implied = false; bool flexible_member_array_supported = true; diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 6242ac33..cebc0030 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -4616,6 +4616,8 @@ string CompilerHLSL::compile() backend.half_literal_suffix = nullptr; backend.long_long_literal_suffix = true; backend.uint32_t_literal_suffix = true; + backend.int16_t_literal_suffix = nullptr; + backend.uint16_t_literal_suffix = "u"; backend.basic_int_type = "int"; backend.basic_uint_type = "uint"; backend.swizzle_is_function = false; diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 069defb3..001636c7 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -390,6 +390,8 @@ string CompilerMSL::compile() backend.float_literal_suffix = false; backend.half_literal_suffix = "h"; backend.uint32_t_literal_suffix = true; + backend.int16_t_literal_suffix = nullptr; + backend.uint16_t_literal_suffix = "u"; backend.basic_int_type = "int"; backend.basic_uint_type = "uint"; backend.basic_int8_type = "char"; |