Commit 02df206c by John Kessenich Committed by GitHub

Merge pull request #516 from amdrexu/feature3

SPV: Implement the extension SPV_KHR_shader_ballot
parents 4455258a 51596644
...@@ -13,6 +13,7 @@ set(SPVREMAP_SOURCES ...@@ -13,6 +13,7 @@ set(SPVREMAP_SOURCES
set(HEADERS set(HEADERS
spirv.hpp spirv.hpp
GLSL.std.450.h GLSL.std.450.h
GLSL.ext.KHR.h
GlslangToSpv.h GlslangToSpv.h
Logger.h Logger.h
SpvBuilder.h SpvBuilder.h
......
/*
** Copyright (c) 2014-2016 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLextKHR_H
#define GLSLextKHR_H
enum BuiltIn;
enum Op;
enum Capability;
static const int GLSLextKHRVersion = 100;
static const int GLSLextKHRRevision = 1;
// SPV_KHR_shader_ballot
static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
static const BuiltIn BuiltInSubgroupEqMaskKHR = static_cast<BuiltIn>(4416);
static const BuiltIn BuiltInSubgroupGeMaskKHR = static_cast<BuiltIn>(4417);
static const BuiltIn BuiltInSubgroupGtMaskKHR = static_cast<BuiltIn>(4418);
static const BuiltIn BuiltInSubgroupLeMaskKHR = static_cast<BuiltIn>(4419);
static const BuiltIn BuiltInSubgroupLtMaskKHR = static_cast<BuiltIn>(4420);
static const Op OpSubgroupBallotKHR = static_cast<Op>(4421);
static const Op OpSubgroupFirstInvocationKHR = static_cast<Op>(4422);
static const Capability CapabilitySubgroupBallotKHR = static_cast<Capability>(4423);
#endif // #ifndef GLSLextKHR_H
...@@ -2318,9 +2318,9 @@ void Builder::dump(std::vector<unsigned int>& out) const ...@@ -2318,9 +2318,9 @@ void Builder::dump(std::vector<unsigned int>& out) const
capInst.dump(out); capInst.dump(out);
} }
for (int e = 0; e < (int)extensions.size(); ++e) { for (auto it = extensions.cbegin(); it != extensions.cend(); ++it) {
Instruction extInst(0, 0, OpExtension); Instruction extInst(0, 0, OpExtension);
extInst.addStringOperand(extensions[e]); extInst.addStringOperand(*it);
extInst.dump(out); extInst.dump(out);
} }
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
sourceVersion = version; sourceVersion = version;
} }
void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); } void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); }
void addExtensions(const char* ext) { extensions.push_back(ext); } void addExtension(const char* ext) { extensions.insert(ext); }
Id import(const char*); Id import(const char*);
void setMemoryModel(spv::AddressingModel addr, spv::MemoryModel mem) void setMemoryModel(spv::AddressingModel addr, spv::MemoryModel mem)
{ {
...@@ -552,7 +552,7 @@ public: ...@@ -552,7 +552,7 @@ public:
SourceLanguage source; SourceLanguage source;
int sourceVersion; int sourceVersion;
std::vector<const char*> extensions; std::set<const char*> extensions;
std::vector<const char*> sourceExtensions; std::vector<const char*> sourceExtensions;
AddressingModel addressModel; AddressingModel addressModel;
MemoryModel memoryModel; MemoryModel memoryModel;
......
...@@ -45,14 +45,15 @@ ...@@ -45,14 +45,15 @@
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#ifdef AMD_EXTENSIONS
namespace spv { namespace spv {
extern "C" { extern "C" {
// Include C-based headers that don't have a namespace // Include C-based headers that don't have a namespace
#include "GLSL.ext.KHR.h"
#ifdef AMD_EXTENSIONS
#include "GLSL.ext.AMD.h" #include "GLSL.ext.AMD.h"
#endif
} }
} }
#endif
namespace spv { namespace spv {
...@@ -312,6 +313,12 @@ const char* BuiltInString(int builtIn) ...@@ -312,6 +313,12 @@ const char* BuiltInString(int builtIn)
case BuiltInCeiling: case BuiltInCeiling:
default: return "Bad"; default: return "Bad";
case 4416: return "SubgroupEqMaskKHR";
case 4417: return "SubgroupGeMaskKHR";
case 4418: return "SubgroupGtMaskKHR";
case 4419: return "SubgroupLeMaskKHR";
case 4420: return "SubgroupLtMaskKHR";
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
case 4992: return "BaryCoordNoPerspAMD"; case 4992: return "BaryCoordNoPerspAMD";
case 4993: return "BaryCoordNoPerspCentroidAMD"; case 4993: return "BaryCoordNoPerspCentroidAMD";
...@@ -799,6 +806,8 @@ const char* CapabilityString(int info) ...@@ -799,6 +806,8 @@ const char* CapabilityString(int info)
case CapabilityCeiling: case CapabilityCeiling:
default: return "Bad"; default: return "Bad";
case 4423: return "SubgroupBallotKHR";
} }
} }
...@@ -1131,6 +1140,9 @@ const char* OpcodeString(int op) ...@@ -1131,6 +1140,9 @@ const char* OpcodeString(int op)
default: default:
return "Bad"; return "Bad";
case 4421: return "OpSubgroupBallotKHR";
case 4422: return "OpSubgroupFirstInvocationKHR";
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
case 5000: return "OpGroupIAddNonUniformAMD"; case 5000: return "OpGroupIAddNonUniformAMD";
case 5001: return "OpGroupFAddNonUniformAMD"; case 5001: return "OpGroupFAddNonUniformAMD";
...@@ -1146,11 +1158,7 @@ const char* OpcodeString(int op) ...@@ -1146,11 +1158,7 @@ const char* OpcodeString(int op)
// The set of objects that hold all the instruction/operand // The set of objects that hold all the instruction/operand
// parameterization information. // parameterization information.
#ifdef AMD_EXTENSIONS
InstructionParameters InstructionDesc[OpCodeMask + 1]; InstructionParameters InstructionDesc[OpCodeMask + 1];
#else
InstructionParameters InstructionDesc[OpcodeCeiling];
#endif
OperandParameters ExecutionModeOperands[ExecutionModeCeiling]; OperandParameters ExecutionModeOperands[ExecutionModeCeiling];
OperandParameters DecorationOperands[DecorationCeiling]; OperandParameters DecorationOperands[DecorationCeiling];
...@@ -2742,6 +2750,10 @@ void Parameterize() ...@@ -2742,6 +2750,10 @@ void Parameterize()
InstructionDesc[OpEnqueueMarker].operands.push(OperandId, "'Wait Events'"); InstructionDesc[OpEnqueueMarker].operands.push(OperandId, "'Wait Events'");
InstructionDesc[OpEnqueueMarker].operands.push(OperandId, "'Ret Event'"); InstructionDesc[OpEnqueueMarker].operands.push(OperandId, "'Ret Event'");
InstructionDesc[OpSubgroupBallotKHR].operands.push(OperandId, "'Predicate'");
InstructionDesc[OpSubgroupFirstInvocationKHR].operands.push(OperandId, "'Value'");
#ifdef AMD_EXTENSIONS #ifdef AMD_EXTENSIONS
InstructionDesc[OpGroupIAddNonUniformAMD].capabilities.push_back(CapabilityGroups); InstructionDesc[OpGroupIAddNonUniformAMD].capabilities.push_back(CapabilityGroups);
InstructionDesc[OpGroupIAddNonUniformAMD].operands.push(OperandScope, "'Execution'"); InstructionDesc[OpGroupIAddNonUniformAMD].operands.push(OperandScope, "'Execution'");
......
...@@ -3862,7 +3862,6 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion ...@@ -3862,7 +3862,6 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setFunctionExtensions("readInvocationARB", 1, &E_GL_ARB_shader_ballot); symbolTable.setFunctionExtensions("readInvocationARB", 1, &E_GL_ARB_shader_ballot);
symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot); symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot);
BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable);
BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable); BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable);
BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable); BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable);
BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable); BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable);
...@@ -3870,6 +3869,10 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion ...@@ -3870,6 +3869,10 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable); BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable);
BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable); BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable);
if (spvVersion.vulkan >= 100)
// Treat "gl_SubGroupSizeARB" as shader input instead of uniform for Vulkan
SpecialQualifier("gl_SubGroupSizeARB", EvqVaryingIn, EbvSubGroupSize, symbolTable);
symbolTable.setFunctionExtensions("anyInvocationARB", 1, &E_GL_ARB_shader_group_vote); symbolTable.setFunctionExtensions("anyInvocationARB", 1, &E_GL_ARB_shader_group_vote);
symbolTable.setFunctionExtensions("allInvocationsARB", 1, &E_GL_ARB_shader_group_vote); symbolTable.setFunctionExtensions("allInvocationsARB", 1, &E_GL_ARB_shader_group_vote);
symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote); symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment