summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp')
-rw-r--r--3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp88
1 files changed, 74 insertions, 14 deletions
diff --git a/3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp b/3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp
index 86fad580a2a..dd6dabce0da 100644
--- a/3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp
+++ b/3rdparty/bgfx/3rdparty/glslang/SPIRV/SpvPostProcess.cpp
@@ -44,10 +44,8 @@
#include <algorithm>
#include "SpvBuilder.h"
-
#include "spirv.hpp"
-#include "GlslangToSpv.h"
-#include "SpvBuilder.h"
+
namespace spv {
#include "GLSL.std.450.h"
#include "GLSL.ext.KHR.h"
@@ -58,6 +56,7 @@ namespace spv {
namespace spv {
+#ifndef GLSLANG_WEB
// Hook to visit each operand type and result type of an instruction.
// Will be called multiple times for one instruction, once for each typed
// operand and the result.
@@ -112,8 +111,6 @@ void Builder::postProcessType(const Instruction& inst, Id typeId)
}
}
break;
- case OpAccessChain:
- case OpPtrAccessChain:
case OpCopyObject:
break;
case OpFConvert:
@@ -160,26 +157,43 @@ void Builder::postProcessType(const Instruction& inst, Id typeId)
switch (inst.getImmediateOperand(1)) {
case GLSLstd450Frexp:
case GLSLstd450FrexpStruct:
- if (getSpvVersion() < glslang::EShTargetSpv_1_3 && containsType(typeId, OpTypeInt, 16))
+ if (getSpvVersion() < spv::Spv_1_3 && containsType(typeId, OpTypeInt, 16))
addExtension(spv::E_SPV_AMD_gpu_shader_int16);
break;
case GLSLstd450InterpolateAtCentroid:
case GLSLstd450InterpolateAtSample:
case GLSLstd450InterpolateAtOffset:
- if (getSpvVersion() < glslang::EShTargetSpv_1_3 && containsType(typeId, OpTypeFloat, 16))
+ if (getSpvVersion() < spv::Spv_1_3 && containsType(typeId, OpTypeFloat, 16))
addExtension(spv::E_SPV_AMD_gpu_shader_half_float);
break;
default:
break;
}
break;
+ case OpAccessChain:
+ case OpPtrAccessChain:
+ if (isPointerType(typeId))
+ break;
+ if (basicTypeOp == OpTypeInt) {
+ if (width == 16)
+ addCapability(CapabilityInt16);
+ else if (width == 8)
+ addCapability(CapabilityInt8);
+ }
default:
- if (basicTypeOp == OpTypeFloat && width == 16)
- addCapability(CapabilityFloat16);
- if (basicTypeOp == OpTypeInt && width == 16)
- addCapability(CapabilityInt16);
- if (basicTypeOp == OpTypeInt && width == 8)
- addCapability(CapabilityInt8);
+ if (basicTypeOp == OpTypeInt) {
+ if (width == 16)
+ addCapability(CapabilityInt16);
+ else if (width == 8)
+ addCapability(CapabilityInt8);
+ else if (width == 64)
+ addCapability(CapabilityInt64);
+ } else if (basicTypeOp == OpTypeFloat) {
+ if (width == 16)
+ addCapability(CapabilityFloat16);
+ else if (width == 64)
+ addCapability(CapabilityFloat64);
+ }
break;
}
}
@@ -319,9 +333,10 @@ void Builder::postProcess(Instruction& inst)
}
}
}
+#endif
// comment in header
-void Builder::postProcess()
+void Builder::postProcessCFG()
{
// reachableBlocks is the set of blockss reached via control flow, or which are
// unreachable continue targert or unreachable merge.
@@ -377,7 +392,11 @@ void Builder::postProcess()
return unreachableDefinitions.count(decoration_id) != 0;
}),
decorations.end());
+}
+#ifndef GLSLANG_WEB
+// comment in header
+void Builder::postProcessFeatures() {
// Add per-instruction capabilities, extensions, etc.,
// Look for any 8/16 bit type in physical storage buffer class, and set the
@@ -430,6 +449,47 @@ void Builder::postProcess()
}
}
}
+
+ // If any Vulkan memory model-specific functionality is used, update the
+ // OpMemoryModel to match.
+ if (capabilities.find(spv::CapabilityVulkanMemoryModelKHR) != capabilities.end()) {
+ memoryModel = spv::MemoryModelVulkanKHR;
+ addIncorporatedExtension(spv::E_SPV_KHR_vulkan_memory_model, spv::Spv_1_5);
+ }
+
+ // Add Aliased decoration if there's more than one Workgroup Block variable.
+ if (capabilities.find(spv::CapabilityWorkgroupMemoryExplicitLayoutKHR) != capabilities.end()) {
+ assert(entryPoints.size() == 1);
+ auto &ep = entryPoints[0];
+
+ std::vector<Id> workgroup_variables;
+ for (int i = 0; i < (int)ep->getNumOperands(); i++) {
+ if (!ep->isIdOperand(i))
+ continue;
+
+ const Id id = ep->getIdOperand(i);
+ const Instruction *instr = module.getInstruction(id);
+ if (instr->getOpCode() != spv::OpVariable)
+ continue;
+
+ if (instr->getImmediateOperand(0) == spv::StorageClassWorkgroup)
+ workgroup_variables.push_back(id);
+ }
+
+ if (workgroup_variables.size() > 1) {
+ for (size_t i = 0; i < workgroup_variables.size(); i++)
+ addDecoration(workgroup_variables[i], spv::DecorationAliased);
+ }
+ }
+}
+#endif
+
+// comment in header
+void Builder::postProcess() {
+ postProcessCFG();
+#ifndef GLSLANG_WEB
+ postProcessFeatures();
+#endif
}
}; // end spv namespace