mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-09 12:00:05 +00:00
SPV: Implement extension SPV_KHR_shader_draw_parameters.
This commit is contained in:
parent
dd2fc1f3d8
commit
f3b27471f8
@ -27,25 +27,10 @@
|
||||
#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 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);
|
||||
// SPV_KHR_shader_draw_parameters
|
||||
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";
|
||||
|
||||
#endif // #ifndef GLSLextKHR_H
|
||||
|
@ -498,13 +498,21 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
|
||||
case glslang::EbvInstanceId: return spv::BuiltInInstanceId;
|
||||
case glslang::EbvVertexIndex: return spv::BuiltInVertexIndex;
|
||||
case glslang::EbvInstanceIndex: return spv::BuiltInInstanceIndex;
|
||||
|
||||
case glslang::EbvBaseVertex:
|
||||
builder.addExtension(spv::E_SPV_KHR_shader_draw_parameters);
|
||||
builder.addCapability(spv::CapabilityDrawParameters);
|
||||
return spv::BuiltInBaseVertex;
|
||||
|
||||
case glslang::EbvBaseInstance:
|
||||
builder.addExtension(spv::E_SPV_KHR_shader_draw_parameters);
|
||||
builder.addCapability(spv::CapabilityDrawParameters);
|
||||
return spv::BuiltInBaseInstance;
|
||||
|
||||
case glslang::EbvDrawId:
|
||||
// TODO: Add SPIR-V builtin ID.
|
||||
logger->missingFunctionality("shader draw parameters");
|
||||
return spv::BuiltInMax;
|
||||
builder.addExtension(spv::E_SPV_KHR_shader_draw_parameters);
|
||||
builder.addCapability(spv::CapabilityDrawParameters);
|
||||
return spv::BuiltInDrawIndex;
|
||||
|
||||
case glslang::EbvPrimitiveId:
|
||||
if (glslangIntermediate->getStage() == EShLangFragment)
|
||||
|
@ -48,7 +48,6 @@
|
||||
namespace spv {
|
||||
extern "C" {
|
||||
// Include C-based headers that don't have a namespace
|
||||
#include "GLSL.ext.KHR.h"
|
||||
#ifdef AMD_EXTENSIONS
|
||||
#include "GLSL.ext.AMD.h"
|
||||
#endif
|
||||
@ -319,6 +318,10 @@ const char* BuiltInString(int builtIn)
|
||||
case 4419: return "SubgroupLeMaskKHR";
|
||||
case 4420: return "SubgroupLtMaskKHR";
|
||||
|
||||
case 4424: return "BaseVertex";
|
||||
case 4425: return "BaseInstance";
|
||||
case 4426: return "DrawIndex";
|
||||
|
||||
#ifdef AMD_EXTENSIONS
|
||||
case 4992: return "BaryCoordNoPerspAMD";
|
||||
case 4993: return "BaryCoordNoPerspCentroidAMD";
|
||||
@ -808,6 +811,7 @@ const char* CapabilityString(int info)
|
||||
default: return "Bad";
|
||||
|
||||
case 4423: return "SubgroupBallotKHR";
|
||||
case 4427: return "DrawParameters";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,11 @@ namespace spv {
|
||||
typedef unsigned int Id;
|
||||
|
||||
#define SPV_VERSION 0x10000
|
||||
#define SPV_REVISION 6
|
||||
#define SPV_REVISION 8
|
||||
|
||||
static const unsigned int MagicNumber = 0x07230203;
|
||||
static const unsigned int Version = 0x00010000;
|
||||
static const unsigned int Revision = 6;
|
||||
static const unsigned int Revision = 8;
|
||||
static const unsigned int OpCodeMask = 0xffff;
|
||||
static const unsigned int WordCountShift = 16;
|
||||
|
||||
@ -420,6 +420,14 @@ enum BuiltIn {
|
||||
BuiltInSubgroupLocalInvocationId = 41,
|
||||
BuiltInVertexIndex = 42,
|
||||
BuiltInInstanceIndex = 43,
|
||||
BuiltInSubgroupEqMaskKHR = 4416,
|
||||
BuiltInSubgroupGeMaskKHR = 4417,
|
||||
BuiltInSubgroupGtMaskKHR = 4418,
|
||||
BuiltInSubgroupLeMaskKHR = 4419,
|
||||
BuiltInSubgroupLtMaskKHR = 4420,
|
||||
BuiltInBaseVertex = 4424,
|
||||
BuiltInBaseInstance = 4425,
|
||||
BuiltInDrawIndex = 4426,
|
||||
BuiltInMax = 0x7fffffff,
|
||||
};
|
||||
|
||||
@ -595,6 +603,8 @@ enum Capability {
|
||||
CapabilityStorageImageReadWithoutFormat = 55,
|
||||
CapabilityStorageImageWriteWithoutFormat = 56,
|
||||
CapabilityMultiViewport = 57,
|
||||
CapabilitySubgroupBallotKHR = 4423,
|
||||
CapabilityDrawParameters = 4427,
|
||||
CapabilityMax = 0x7fffffff,
|
||||
};
|
||||
|
||||
@ -893,6 +903,8 @@ enum Op {
|
||||
OpAtomicFlagTestAndSet = 318,
|
||||
OpAtomicFlagClear = 319,
|
||||
OpImageSparseRead = 320,
|
||||
OpSubgroupBallotKHR = 4421,
|
||||
OpSubgroupFirstInvocationKHR = 4422,
|
||||
OpMax = 0x7fffffff,
|
||||
};
|
||||
|
||||
|
108
Test/baseResults/spv.shaderDrawParams.vert.out
Normal file
108
Test/baseResults/spv.shaderDrawParams.vert.out
Normal file
@ -0,0 +1,108 @@
|
||||
spv.shaderDrawParams.vert
|
||||
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
|
||||
|
||||
|
||||
Linked vertex stage:
|
||||
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 53
|
||||
|
||||
Capability Shader
|
||||
Capability DrawParameters
|
||||
Extension "SPV_KHR_shader_draw_parameters"
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint Vertex 4 "main" 9 16 29 37
|
||||
Source GLSL 450
|
||||
SourceExtension "GL_ARB_shader_draw_parameters"
|
||||
Name 4 "main"
|
||||
Name 9 "gl_BaseVertexARB"
|
||||
Name 16 "gl_BaseInstanceARB"
|
||||
Name 27 "gl_PerVertex"
|
||||
MemberName 27(gl_PerVertex) 0 "gl_Position"
|
||||
MemberName 27(gl_PerVertex) 1 "gl_PointSize"
|
||||
MemberName 27(gl_PerVertex) 2 "gl_ClipDistance"
|
||||
MemberName 27(gl_PerVertex) 3 "gl_CullDistance"
|
||||
Name 29 ""
|
||||
Name 34 "Block"
|
||||
MemberName 34(Block) 0 "pos"
|
||||
Name 36 "block"
|
||||
Name 37 "gl_DrawIDARB"
|
||||
Decorate 9(gl_BaseVertexARB) BuiltIn BaseVertex
|
||||
Decorate 16(gl_BaseInstanceARB) BuiltIn BaseInstance
|
||||
MemberDecorate 27(gl_PerVertex) 0 BuiltIn Position
|
||||
MemberDecorate 27(gl_PerVertex) 1 BuiltIn PointSize
|
||||
MemberDecorate 27(gl_PerVertex) 2 BuiltIn ClipDistance
|
||||
MemberDecorate 27(gl_PerVertex) 3 BuiltIn CullDistance
|
||||
Decorate 27(gl_PerVertex) Block
|
||||
Decorate 31 ArrayStride 16
|
||||
Decorate 33 ArrayStride 64
|
||||
MemberDecorate 34(Block) 0 Offset 0
|
||||
Decorate 34(Block) Block
|
||||
Decorate 36(block) DescriptorSet 0
|
||||
Decorate 36(block) Binding 0
|
||||
Decorate 37(gl_DrawIDARB) BuiltIn DrawIndex
|
||||
2: TypeVoid
|
||||
3: TypeFunction 2
|
||||
6: TypeBool
|
||||
7: TypeInt 32 1
|
||||
8: TypePointer Input 7(int)
|
||||
9(gl_BaseVertexARB): 8(ptr) Variable Input
|
||||
11: 7(int) Constant 0
|
||||
16(gl_BaseInstanceARB): 8(ptr) Variable Input
|
||||
22: TypeFloat 32
|
||||
23: TypeVector 22(float) 4
|
||||
24: TypeInt 32 0
|
||||
25: 24(int) Constant 1
|
||||
26: TypeArray 22(float) 25
|
||||
27(gl_PerVertex): TypeStruct 23(fvec4) 22(float) 26 26
|
||||
28: TypePointer Output 27(gl_PerVertex)
|
||||
29: 28(ptr) Variable Output
|
||||
30: 24(int) Constant 4
|
||||
31: TypeArray 23(fvec4) 30
|
||||
32: 24(int) Constant 2
|
||||
33: TypeArray 31 32
|
||||
34(Block): TypeStruct 33
|
||||
35: TypePointer Uniform 34(Block)
|
||||
36(block): 35(ptr) Variable Uniform
|
||||
37(gl_DrawIDARB): 8(ptr) Variable Input
|
||||
39: 7(int) Constant 4
|
||||
41: TypePointer Uniform 23(fvec4)
|
||||
44: TypePointer Output 23(fvec4)
|
||||
47: 7(int) Constant 1
|
||||
4(main): 2 Function None 3
|
||||
5: Label
|
||||
10: 7(int) Load 9(gl_BaseVertexARB)
|
||||
12: 6(bool) SGreaterThan 10 11
|
||||
13: 6(bool) LogicalNot 12
|
||||
SelectionMerge 15 None
|
||||
BranchConditional 13 14 15
|
||||
14: Label
|
||||
17: 7(int) Load 16(gl_BaseInstanceARB)
|
||||
18: 6(bool) SGreaterThan 17 11
|
||||
Branch 15
|
||||
15: Label
|
||||
19: 6(bool) Phi 12 5 18 14
|
||||
SelectionMerge 21 None
|
||||
BranchConditional 19 20 46
|
||||
20: Label
|
||||
38: 7(int) Load 37(gl_DrawIDARB)
|
||||
40: 7(int) SMod 38 39
|
||||
42: 41(ptr) AccessChain 36(block) 11 11 40
|
||||
43: 23(fvec4) Load 42
|
||||
45: 44(ptr) AccessChain 29 11
|
||||
Store 45 43
|
||||
Branch 21
|
||||
46: Label
|
||||
48: 7(int) Load 37(gl_DrawIDARB)
|
||||
49: 7(int) SMod 48 39
|
||||
50: 41(ptr) AccessChain 36(block) 11 47 49
|
||||
51: 23(fvec4) Load 50
|
||||
52: 44(ptr) AccessChain 29 11
|
||||
Store 52 51
|
||||
Branch 21
|
||||
21: Label
|
||||
Return
|
||||
FunctionEnd
|
16
Test/spv.shaderDrawParams.vert
Normal file
16
Test/spv.shaderDrawParams.vert
Normal file
@ -0,0 +1,16 @@
|
||||
#version 450 core
|
||||
|
||||
#extension GL_ARB_shader_draw_parameters: enable
|
||||
|
||||
layout(binding = 0) uniform Block
|
||||
{
|
||||
vec4 pos[2][4];
|
||||
} block;
|
||||
|
||||
void main()
|
||||
{
|
||||
if ((gl_BaseVertexARB > 0) || (gl_BaseInstanceARB > 0))
|
||||
gl_Position = block.pos[0][gl_DrawIDARB % 4];
|
||||
else
|
||||
gl_Position = block.pos[1][gl_DrawIDARB % 4];
|
||||
}
|
@ -237,6 +237,7 @@ INSTANTIATE_TEST_CASE_P(
|
||||
"spv.prepost.frag",
|
||||
"spv.qualifiers.vert",
|
||||
"spv.shaderBallot.comp",
|
||||
"spv.shaderDrawParams.vert",
|
||||
"spv.shaderGroupVote.comp",
|
||||
"spv.shiftOps.frag",
|
||||
"spv.simpleFunctionCall.frag",
|
||||
|
Loading…
Reference in New Issue
Block a user