summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/ShaderGenCommon.cpp
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2021-07-26 11:20:04 -0700
committerPokechu22 <Pokechu022@gmail.com>2021-11-17 20:04:33 -0800
commit555a93057c07f045cc71c4652c54eebb990021b7 (patch)
tree24e68c6480404bf3eeccf10f0d9194419752f1ce /Source/Core/VideoCommon/ShaderGenCommon.cpp
parent735fd60e52b871e8edf95545a4e92de7b7eb8999 (diff)
VideoCommon: Allow BitfieldExtract in specialized shaders
Diffstat (limited to 'Source/Core/VideoCommon/ShaderGenCommon.cpp')
-rw-r--r--Source/Core/VideoCommon/ShaderGenCommon.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/ShaderGenCommon.cpp b/Source/Core/VideoCommon/ShaderGenCommon.cpp
index c5cd3ef30d..cbc17f0772 100644
--- a/Source/Core/VideoCommon/ShaderGenCommon.cpp
+++ b/Source/Core/VideoCommon/ShaderGenCommon.cpp
@@ -105,6 +105,24 @@ void WriteIsNanHeader(ShaderCode& out, APIType api_type)
}
}
+void WriteBitfieldExtractHeader(ShaderCode& out, APIType api_type,
+ const ShaderHostConfig& host_config)
+{
+ // ==============================================
+ // BitfieldExtract for APIs which don't have it
+ // ==============================================
+ if (!host_config.backend_bitfield)
+ {
+ out.Write("uint bitfieldExtract(uint val, int off, int size) {{\n"
+ " // This built-in function is only supported in OpenGL 4.0+ and ES 3.1+\n"
+ " // Microsoft's HLSL compiler automatically optimises this to a bitfield extract "
+ "instruction.\n"
+ " uint mask = uint((1 << size) - 1);\n"
+ " return uint(val >> off) & mask;\n"
+ "}}\n\n");
+ }
+}
+
static void DefineOutputMember(ShaderCode& object, APIType api_type, std::string_view qualifier,
std::string_view type, std::string_view name, int var_index,
std::string_view semantic = {}, int semantic_index = -1)