Merge pull request #360 from KhronosGroup/vulkan-glsl-desktop-mediump
Support mediump in desktop Vulkan GLSL.
This commit is contained in:
commit
3630d7ef75
12
reference/opt/shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
12
reference/opt/shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
layout(location = 0) in vec4 F;
|
||||||
|
layout(location = 1) flat in ivec4 I;
|
||||||
|
layout(location = 2) flat in uvec4 U;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = (F + vec4(I)) + vec4(U);
|
||||||
|
}
|
||||||
|
|
12
reference/opt/shaders/vulkan/frag/desktop-mediump.vk.frag.vk
Normal file
12
reference/opt/shaders/vulkan/frag/desktop-mediump.vk.frag.vk
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) out mediump vec4 FragColor;
|
||||||
|
layout(location = 0) in mediump vec4 F;
|
||||||
|
layout(location = 1) flat in mediump ivec4 I;
|
||||||
|
layout(location = 2) flat in mediump uvec4 U;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = (F + vec4(I)) + vec4(U);
|
||||||
|
}
|
||||||
|
|
12
reference/shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
12
reference/shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
layout(location = 0) in vec4 F;
|
||||||
|
layout(location = 1) flat in ivec4 I;
|
||||||
|
layout(location = 2) flat in uvec4 U;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = (F + vec4(I)) + vec4(U);
|
||||||
|
}
|
||||||
|
|
12
reference/shaders/vulkan/frag/desktop-mediump.vk.frag.vk
Normal file
12
reference/shaders/vulkan/frag/desktop-mediump.vk.frag.vk
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) out mediump vec4 FragColor;
|
||||||
|
layout(location = 0) in mediump vec4 F;
|
||||||
|
layout(location = 1) flat in mediump ivec4 I;
|
||||||
|
layout(location = 2) flat in mediump uvec4 U;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = (F + vec4(I)) + vec4(U);
|
||||||
|
}
|
||||||
|
|
11
shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
11
shaders/vulkan/frag/desktop-mediump.vk.frag
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in mediump vec4 F;
|
||||||
|
layout(location = 1) flat in mediump ivec4 I;
|
||||||
|
layout(location = 2) flat in mediump uvec4 U;
|
||||||
|
layout(location = 0) out mediump vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = F + vec4(I) + vec4(U);
|
||||||
|
}
|
@ -368,6 +368,9 @@ string CompilerGLSL::compile()
|
|||||||
// Force a classic "C" locale, reverts when function returns
|
// Force a classic "C" locale, reverts when function returns
|
||||||
ClassicLocale classic_locale;
|
ClassicLocale classic_locale;
|
||||||
|
|
||||||
|
if (options.vulkan_semantics)
|
||||||
|
backend.allow_precision_qualifiers = true;
|
||||||
|
|
||||||
// Scan the SPIR-V to find trivial uses of extensions.
|
// Scan the SPIR-V to find trivial uses of extensions.
|
||||||
find_static_extensions();
|
find_static_extensions();
|
||||||
fixup_image_load_store_access();
|
fixup_image_load_store_access();
|
||||||
@ -6860,16 +6863,16 @@ void CompilerGLSL::emit_struct_member(const SPIRType &type, uint32_t member_type
|
|||||||
|
|
||||||
const char *CompilerGLSL::flags_to_precision_qualifiers_glsl(const SPIRType &type, uint64_t flags)
|
const char *CompilerGLSL::flags_to_precision_qualifiers_glsl(const SPIRType &type, uint64_t flags)
|
||||||
{
|
{
|
||||||
|
// Structs do not have precision qualifiers, neither do doubles (desktop only anyways, so no mediump/highp).
|
||||||
|
if (type.basetype != SPIRType::Float && type.basetype != SPIRType::Int && type.basetype != SPIRType::UInt &&
|
||||||
|
type.basetype != SPIRType::Image && type.basetype != SPIRType::SampledImage &&
|
||||||
|
type.basetype != SPIRType::Sampler)
|
||||||
|
return "";
|
||||||
|
|
||||||
if (options.es)
|
if (options.es)
|
||||||
{
|
{
|
||||||
auto &execution = get_entry_point();
|
auto &execution = get_entry_point();
|
||||||
|
|
||||||
// Structs do not have precision qualifiers, neither do doubles (desktop only anyways, so no mediump/highp).
|
|
||||||
if (type.basetype != SPIRType::Float && type.basetype != SPIRType::Int && type.basetype != SPIRType::UInt &&
|
|
||||||
type.basetype != SPIRType::Image && type.basetype != SPIRType::SampledImage &&
|
|
||||||
type.basetype != SPIRType::Sampler)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
if (flags & (1ull << DecorationRelaxedPrecision))
|
if (flags & (1ull << DecorationRelaxedPrecision))
|
||||||
{
|
{
|
||||||
bool implied_fmediump = type.basetype == SPIRType::Float &&
|
bool implied_fmediump = type.basetype == SPIRType::Float &&
|
||||||
@ -6897,6 +6900,19 @@ const char *CompilerGLSL::flags_to_precision_qualifiers_glsl(const SPIRType &typ
|
|||||||
return implied_fhighp || implied_ihighp ? "" : "highp ";
|
return implied_fhighp || implied_ihighp ? "" : "highp ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (backend.allow_precision_qualifiers)
|
||||||
|
{
|
||||||
|
// Vulkan GLSL supports precision qualifiers, even in desktop profiles, which is convenient.
|
||||||
|
// The default is highp however, so only emit mediump in the rare case that a shader has these.
|
||||||
|
if (flags & (1ull << DecorationRelaxedPrecision))
|
||||||
|
{
|
||||||
|
bool can_use_mediump =
|
||||||
|
type.basetype == SPIRType::Float || type.basetype == SPIRType::Int || type.basetype == SPIRType::UInt;
|
||||||
|
return can_use_mediump ? "mediump " : "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,7 @@ protected:
|
|||||||
bool native_row_major_matrix = true;
|
bool native_row_major_matrix = true;
|
||||||
bool use_constructor_splatting = true;
|
bool use_constructor_splatting = true;
|
||||||
bool boolean_mix_support = true;
|
bool boolean_mix_support = true;
|
||||||
|
bool allow_precision_qualifiers = false;
|
||||||
} backend;
|
} backend;
|
||||||
|
|
||||||
void emit_struct(SPIRType &type);
|
void emit_struct(SPIRType &type);
|
||||||
|
@ -7,9 +7,10 @@ export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/to
|
|||||||
echo "Using glslangValidation in: $(which glslangValidator)."
|
echo "Using glslangValidation in: $(which glslangValidator)."
|
||||||
echo "Using spirv-opt in: $(which spirv-opt)."
|
echo "Using spirv-opt in: $(which spirv-opt)."
|
||||||
|
|
||||||
./test_shaders.py shaders
|
./test_shaders.py shaders --update || exit 1
|
||||||
./test_shaders.py shaders --opt
|
./test_shaders.py shaders --update --opt || exit 1
|
||||||
./test_shaders.py shaders-msl --msl
|
./test_shaders.py shaders-msl --msl --update || exit 1
|
||||||
./test_shaders.py shaders-msl --msl --opt
|
./test_shaders.py shaders-msl --msl --update --opt || exit 1
|
||||||
./test_shaders.py shaders-hlsl --hlsl
|
./test_shaders.py shaders-hlsl --hlsl --update || exit 1
|
||||||
./test_shaders.py shaders-hlsl --hlsl --opt
|
./test_shaders.py shaders-hlsl --hlsl --update --opt || exit 1
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/to
|
|||||||
echo "Using glslangValidation in: $(which glslangValidator)."
|
echo "Using glslangValidation in: $(which glslangValidator)."
|
||||||
echo "Using spirv-opt in: $(which spirv-opt)."
|
echo "Using spirv-opt in: $(which spirv-opt)."
|
||||||
|
|
||||||
./test_shaders.py shaders --update
|
./test_shaders.py shaders --update || exit 1
|
||||||
./test_shaders.py shaders --update --opt
|
./test_shaders.py shaders --update --opt || exit 1
|
||||||
./test_shaders.py shaders-msl --msl --update
|
./test_shaders.py shaders-msl --msl --update || exit 1
|
||||||
./test_shaders.py shaders-msl --msl --update --opt
|
./test_shaders.py shaders-msl --msl --update --opt || exit 1
|
||||||
./test_shaders.py shaders-hlsl --hlsl --update
|
./test_shaders.py shaders-hlsl --hlsl --update || exit 1
|
||||||
./test_shaders.py shaders-hlsl --hlsl --update --opt
|
./test_shaders.py shaders-hlsl --hlsl --update --opt || exit 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user