Skip to content

Commit

Permalink
SPV: Implement new extensions GL_KHX_device_group and GL_KHX_multiview.
Browse files Browse the repository at this point in the history
These correspond to SPV_KHR_device_group and SPV_KHR_multiview.
Also, bring tests up to date with Khronos internals, and some misc. related changes.
  • Loading branch information
johnkslang committed Feb 27, 2017
1 parent 4a57dce commit 6c8aaac
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 26 deletions.
17 changes: 12 additions & 5 deletions SPIRV/GLSL.ext.KHR.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
#ifndef GLSLextKHR_H
#define GLSLextKHR_H

// SPV_KHR_shader_ballot
static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
enum BuiltIn;
enum Op;
enum Capability;

static const int GLSLextKHRVersion = 100;
static const int GLSLextKHRRevision = 1;

static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group";
static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview";
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";

// SPV_KHR_shader_draw_parameters
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
#endif // #ifndef GLSLextKHR_H
10 changes: 10 additions & 0 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
return spv::BuiltInBaryCoordPullModelAMD;
#endif

case glslang::EbvDeviceIndex:
builder.addExtension(spv::E_SPV_KHR_device_group);
builder.addCapability(spv::CapabilityDeviceGroup);
return spv::BuiltinDeviceIndex;

case glslang::EbvViewIndex:
builder.addExtension(spv::E_SPV_KHR_multiview);
builder.addCapability(spv::CapabilityMultiView);
return spv::BuiltinViewIndex;

#ifdef NV_EXTENSIONS
case glslang::EbvViewportMaskNV:
builder.addExtension(spv::E_SPV_NV_viewport_array2);
Expand Down
27 changes: 16 additions & 11 deletions SPIRV/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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
Expand Down Expand Up @@ -318,15 +319,13 @@ const char* BuiltInString(int builtIn)
case 42: return "VertexIndex"; // TBD: put next to VertexId?
case 43: return "InstanceIndex"; // TBD: put next to InstanceId?

case BuiltInCeiling:
default: return "Bad";

case 4416: return "SubgroupEqMaskKHR";
case 4417: return "SubgroupGeMaskKHR";
case 4418: return "SubgroupGtMaskKHR";
case 4419: return "SubgroupLeMaskKHR";
case 4420: return "SubgroupLtMaskKHR";

case 4438: return "DeviceIndex";
case 4440: return "ViewIndex";
case 4424: return "BaseVertex";
case 4425: return "BaseInstance";
case 4426: return "DrawIndex";
Expand All @@ -340,13 +339,17 @@ const char* BuiltInString(int builtIn)
case 4997: return "BaryCoordSmoothSampleAMD";
case 4998: return "BaryCoordPullModelAMD";
#endif

#ifdef NV_EXTENSIONS
case 5253: return "ViewportMaskNV";
case 5257: return "SecondaryPositionNV";
case 5258: return "SecondaryViewportMaskNV";
case 5260: return "PositionPerViewNV";
case 5261: return "ViewportMaskPerViewNV";
#endif

case BuiltInCeiling:
default: return "Bad";
}
}

Expand Down Expand Up @@ -823,13 +826,13 @@ const char* CapabilityString(int info)
case 56: return "StorageImageWriteWithoutFormat";
case 57: return "MultiViewport";

case CapabilityCeiling:
default: return "Bad";

case 4423: return "SubgroupBallotKHR";
case 4427: return "DrawParameters";
case 4431: return "SubgroupVoteKHR";

case 4437: return "DeviceGroup";
case 4439: return "MultiView";

#ifdef NV_EXTENSIONS
case 5251: return "GeometryShaderPassthroughNV";
case 5254: return "ShaderViewportIndexLayerNV";
Expand All @@ -838,6 +841,8 @@ const char* CapabilityString(int info)
case 5262: return "PerViewAttributesNV";
#endif

case CapabilityCeiling:
default: return "Bad";
}
}

Expand Down Expand Up @@ -1166,10 +1171,6 @@ const char* OpcodeString(int op)
case 319: return "OpAtomicFlagClear";
case 320: return "OpImageSparseRead";

case OpcodeCeiling:
default:
return "Bad";

case 4421: return "OpSubgroupBallotKHR";
case 4422: return "OpSubgroupFirstInvocationKHR";
case 4428: return "OpSubgroupAllKHR";
Expand All @@ -1187,6 +1188,10 @@ const char* OpcodeString(int op)
case 5006: return "OpGroupUMaxNonUniformAMD";
case 5007: return "OpGroupSMaxNonUniformAMD";
#endif

case OpcodeCeiling:
default:
return "Bad";
}
}

Expand Down
10 changes: 7 additions & 3 deletions SPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ enum BuiltIn {
BuiltInBaseVertex = 4424,
BuiltInBaseInstance = 4425,
BuiltInDrawIndex = 4426,
BuiltinDeviceIndex = 4438,
BuiltinViewIndex = 4440,
BuiltInMax = 0x7fffffff,
};

Expand Down Expand Up @@ -606,6 +608,8 @@ enum Capability {
CapabilitySubgroupBallotKHR = 4423,
CapabilityDrawParameters = 4427,
CapabilitySubgroupVoteKHR = 4431,
CapabilityDeviceGroup = 4437,
CapabilityMultiView = 4439,
CapabilityMax = 0x7fffffff,
};

Expand Down Expand Up @@ -906,10 +910,10 @@ enum Op {
OpImageSparseRead = 320,
OpSubgroupBallotKHR = 4421,
OpSubgroupFirstInvocationKHR = 4422,
OpSubgroupReadInvocationKHR = 4432,
OpSubgroupAllKHR = 4428,
OpSubgroupAnyKHR = 4429,
OpSubgroupAllKHR = 4428,
OpSubgroupAnyKHR = 4429,
OpSubgroupAllEqualKHR = 4430,
OpSubgroupReadInvocationKHR = 4432,
OpMax = 0x7fffffff,
};

Expand Down
38 changes: 38 additions & 0 deletions Test/baseResults/spv.deviceGroup.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
spv.deviceGroup.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.

// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 17

Capability Shader
Capability DeviceGroup
Extension "SPV_KHR_device_group"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
SourceExtension "GL_KHX_device_group"
Name 4 "main"
Name 9 "color"
Name 12 "gl_DeviceIndexKHR"
Decorate 12(gl_DeviceIndexKHR) BuiltIn DeviceIndex
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(color): 8(ptr) Variable Output
10: TypeInt 32 1
11: TypePointer UniformConstant 10(int)
12(gl_DeviceIndexKHR): 11(ptr) Variable UniformConstant
15: 6(float) Constant 0
4(main): 2 Function None 3
5: Label
13: 10(int) Load 12(gl_DeviceIndexKHR)
14: 6(float) ConvertSToF 13
16: 7(fvec4) CompositeConstruct 14 15 15 15
Store 9(color) 16
Return
FunctionEnd
59 changes: 59 additions & 0 deletions Test/baseResults/spv.drawParams.vert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
spv.drawParams.vert
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.

// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 29

Capability Shader
Capability DrawParameters
Extension "SPV_KHR_shader_draw_parameters"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 10 13 16 21
Source GLSL 450
SourceExtension "GL_ARB_shader_draw_parameters"
Name 4 "main"
Name 8 "a"
Name 10 "gl_BaseVertexARB"
Name 12 "b"
Name 13 "gl_BaseInstanceARB"
Name 15 "c"
Name 16 "gl_DrawIDARB"
Name 21 "pos"
Decorate 10(gl_BaseVertexARB) BuiltIn BaseVertex
Decorate 13(gl_BaseInstanceARB) BuiltIn BaseInstance
Decorate 16(gl_DrawIDARB) BuiltIn DrawIndex
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypePointer Function 6(int)
9: TypePointer Input 6(int)
10(gl_BaseVertexARB): 9(ptr) Variable Input
13(gl_BaseInstanceARB): 9(ptr) Variable Input
16(gl_DrawIDARB): 9(ptr) Variable Input
18: TypeFloat 32
19: TypeVector 18(float) 3
20: TypePointer Output 19(fvec3)
21(pos): 20(ptr) Variable Output
4(main): 2 Function None 3
5: Label
8(a): 7(ptr) Variable Function
12(b): 7(ptr) Variable Function
15(c): 7(ptr) Variable Function
11: 6(int) Load 10(gl_BaseVertexARB)
Store 8(a) 11
14: 6(int) Load 13(gl_BaseInstanceARB)
Store 12(b) 14
17: 6(int) Load 16(gl_DrawIDARB)
Store 15(c) 17
22: 6(int) Load 8(a)
23: 18(float) ConvertSToF 22
24: 6(int) Load 12(b)
25: 18(float) ConvertSToF 24
26: 6(int) Load 15(c)
27: 18(float) ConvertSToF 26
28: 19(fvec3) CompositeConstruct 23 25 27
Store 21(pos) 28
Return
FunctionEnd
38 changes: 38 additions & 0 deletions Test/baseResults/spv.multiView.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
spv.multiView.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.

// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 17

Capability Shader
Capability MultiView
Extension "SPV_KHR_multiview"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
SourceExtension "GL_KHX_multiview"
Name 4 "main"
Name 9 "color"
Name 12 "gl_ViewIndexKHR"
Decorate 12(gl_ViewIndexKHR) BuiltIn ViewIndex
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(color): 8(ptr) Variable Output
10: TypeInt 32 1
11: TypePointer UniformConstant 10(int)
12(gl_ViewIndexKHR): 11(ptr) Variable UniformConstant
15: 6(float) Constant 0
4(main): 2 Function None 3
5: Label
13: 10(int) Load 12(gl_ViewIndexKHR)
14: 6(float) ConvertSToF 13
16: 7(fvec4) CompositeConstruct 14 15 15 15
Store 9(color) 16
Return
FunctionEnd
6 changes: 3 additions & 3 deletions Test/baseResults/spv.specConstant.vert.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Warning, version 400 is not yet complete; most version-specific features are pre
Source GLSL 400
Name 4 "main"
Name 9 "arraySize"
Name 14 "foo(vf4[s1516];"
Name 14 "foo(vf4[s1518];"
Name 13 "p"
Name 17 "builtin_spec_constant("
Name 20 "color"
Expand Down Expand Up @@ -104,10 +104,10 @@ Warning, version 400 is not yet complete; most version-specific features are pre
Store 20(color) 46
48: 10 Load 22(ucol)
Store 47(param) 48
49: 2 FunctionCall 14(foo(vf4[s1516];) 47(param)
49: 2 FunctionCall 14(foo(vf4[s1518];) 47(param)
Return
FunctionEnd
14(foo(vf4[s1516];): 2 Function None 12
14(foo(vf4[s1518];): 2 Function None 12
13(p): 11(ptr) FunctionParameter
15: Label
54: 24(ptr) AccessChain 53(dupUcol) 23
Expand Down
9 changes: 9 additions & 0 deletions Test/spv.deviceGroup.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 450

#extension GL_KHX_device_group : enable

out vec4 color;

void main() {
color = vec4(gl_DeviceIndexKHR, 0, 0, 0);
}
13 changes: 13 additions & 0 deletions Test/spv.drawParams.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 450

#extension GL_ARB_shader_draw_parameters : enable

out vec3 pos;

void main()
{
int a = gl_BaseVertexARB;
int b = gl_BaseInstanceARB;
int c = gl_DrawIDARB;
pos = vec3(a, b, c);
}
9 changes: 9 additions & 0 deletions Test/spv.multiView.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 450

#extension GL_KHX_multiview : enable

out vec4 color;

void main() {
color = vec4(gl_ViewIndexKHR, 0, 0, 0);
}
4 changes: 4 additions & 0 deletions glslang/Include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,17 @@ enum TBuiltInVariable {
EbvBaryCoordPullModel,
#endif

EbvViewIndex,
EbvDeviceIndex,

#ifdef NV_EXTENSIONS
EbvViewportMaskNV,
EbvSecondaryPositionNV,
EbvSecondaryViewportMaskNV,
EbvPositionPerViewNV,
EbvViewportMaskPerViewNV,
#endif

// HLSL built-ins that live only temporarily, until they get remapped
// to one of the above.
EbvFragDepthGreater,
Expand Down
2 changes: 2 additions & 0 deletions glslang/Include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ struct TSampler { // misnomer now; includes images, textures without sampler,
case EbtFloat: break;
case EbtInt: s.append("i"); break;
case EbtUint: s.append("u"); break;
case EbtInt64: s.append("i64"); break;
case EbtUint64: s.append("u64"); break;
default: break; // some compilers want this
}
if (image) {
Expand Down
4 changes: 2 additions & 2 deletions glslang/Include/revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).

#define GLSLANG_REVISION "Overload400-PrecQual.1845"
#define GLSLANG_DATE "24-Feb-2017"
#define GLSLANG_REVISION "Overload400-PrecQual.1853"
#define GLSLANG_DATE "27-Feb-2017"
Loading

0 comments on commit 6c8aaac

Please sign in to comment.