SPV: Implement new extensions GL_KHX_device_group and GL_KHX_multiview.

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.
This commit is contained in:
John Kessenich 2017-02-27 01:20:51 -07:00
parent 4a57dced66
commit 6c8aaacd28
18 changed files with 252 additions and 26 deletions

View File

@ -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

View File

@ -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);

View File

@ -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
@ -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";
@ -340,6 +339,7 @@ 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";
@ -347,6 +347,9 @@ const char* BuiltInString(int builtIn)
case 5260: return "PositionPerViewNV";
case 5261: return "ViewportMaskPerViewNV";
#endif
case BuiltInCeiling:
default: return "Bad";
}
}
@ -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";
@ -838,6 +841,8 @@ const char* CapabilityString(int info)
case 5262: return "PerViewAttributesNV";
#endif
case CapabilityCeiling:
default: return "Bad";
}
}
@ -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";
@ -1187,6 +1188,10 @@ const char* OpcodeString(int op)
case 5006: return "OpGroupUMaxNonUniformAMD";
case 5007: return "OpGroupSMaxNonUniformAMD";
#endif
case OpcodeCeiling:
default:
return "Bad";
}
}

View File

@ -428,6 +428,8 @@ enum BuiltIn {
BuiltInBaseVertex = 4424,
BuiltInBaseInstance = 4425,
BuiltInDrawIndex = 4426,
BuiltinDeviceIndex = 4438,
BuiltinViewIndex = 4440,
BuiltInMax = 0x7fffffff,
};
@ -606,6 +608,8 @@ enum Capability {
CapabilitySubgroupBallotKHR = 4423,
CapabilityDrawParameters = 4427,
CapabilitySubgroupVoteKHR = 4431,
CapabilityDeviceGroup = 4437,
CapabilityMultiView = 4439,
CapabilityMax = 0x7fffffff,
};
@ -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,
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"
@ -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

View File

@ -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
Test/spv.drawParams.vert Normal file
View File

@ -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
Test/spv.multiView.frag Normal file
View File

@ -0,0 +1,9 @@
#version 450
#extension GL_KHX_multiview : enable
out vec4 color;
void main() {
color = vec4(gl_ViewIndexKHR, 0, 0, 0);
}

View File

@ -203,6 +203,9 @@ enum TBuiltInVariable {
EbvBaryCoordPullModel,
#endif
EbvViewIndex,
EbvDeviceIndex,
#ifdef NV_EXTENSIONS
EbvViewportMaskNV,
EbvSecondaryPositionNV,
@ -210,6 +213,7 @@ enum TBuiltInVariable {
EbvPositionPerViewNV,
EbvViewportMaskPerViewNV,
#endif
// HLSL built-ins that live only temporarily, until they get remapped
// to one of the above.
EbvFragDepthGreater,

View File

@ -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) {

View File

@ -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"

View File

@ -85,6 +85,8 @@ TBuiltIns::TBuiltIns()
prefixes[EbtFloat] = "";
prefixes[EbtInt] = "i";
prefixes[EbtUint] = "u";
prefixes[EbtInt64] = "i64";
prefixes[EbtUint64] = "u64";
postfixes[2] = "2";
postfixes[3] = "3";
postfixes[4] = "4";
@ -103,6 +105,7 @@ TBuiltIns::~TBuiltIns()
{
}
//
// Add all context-independent built-in functions and variables that are present
// for the given version and profile. Share common ones across stages, otherwise
@ -3698,6 +3701,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"\n");
}
if (profile != EEsProfile) {
commonBuiltins.append("uniform int gl_ViewIndexKHR;");
commonBuiltins.append("uniform int gl_DeviceIndexKHR;"); // GL_KHX_device_group
}
// printf("%s\n", commonBuiltins.c_str());
// printf("%s\n", stageBuiltins[EShLangFragment].c_str());
}
@ -5308,6 +5316,13 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic);
symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic);
}
if (profile != EEsProfile) {
symbolTable.setFunctionExtensions("gl_DeviceIndexKHR", 1, &E_GL_KHX_device_group);
BuiltInVariable("gl_DeviceIndexKHR", EbvDeviceIndex, symbolTable);
symbolTable.setFunctionExtensions("gl_ViewIndexKHR", 1, &E_GL_KHX_multiview);
BuiltInVariable("gl_ViewIndexKHR", EbvViewIndex, symbolTable);
}
break;
case EShLangCompute:

View File

@ -232,6 +232,10 @@ void TParseVersions::initializeExtensionBehavior()
extensionBehavior[E_GL_OES_tessellation_point_size] = EBhDisable;
extensionBehavior[E_GL_OES_texture_buffer] = EBhDisable;
extensionBehavior[E_GL_OES_texture_cube_map_array] = EBhDisable;
// KHX extensions
extensionBehavior[E_GL_KHX_device_group] = EBhDisable;
extensionBehavior[E_GL_KHX_multiview] = EBhDisable;
}
// Get code that is not part of a shared symbol table, is specific to this shader,

View File

@ -132,6 +132,10 @@ const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture
const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
// KHX extensions
const char* const E_GL_KHX_device_group = "GL_KHX_device_group";
const char* const E_GL_KHX_multiview = "GL_KHX_multiview";
// #line and #include
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";

View File

@ -225,7 +225,9 @@ INSTANTIATE_TEST_CASE_P(
"spv.dataOutIndirect.vert",
"spv.deepRvalue.frag",
"spv.depthOut.frag",
"spv.deviceGroup.frag",
"spv.discard-dce.frag",
"spv.drawParams.vert",
"spv.doWhileLoop.frag",
"spv.earlyReturnDiscard.frag",
"spv.flowControl.frag",
@ -234,8 +236,10 @@ INSTANTIATE_TEST_CASE_P(
"spv.functionCall.frag",
"spv.functionNestedOpaque.vert",
"spv.functionSemantics.frag",
"spv.GeometryShaderPassthrough.geom",
"spv.interpOps.frag",
"spv.int64.frag",
"spv.intOps.vert",
"spv.layoutNested.vert",
"spv.length.frag",
"spv.localAggregates.frag",
@ -248,16 +252,17 @@ INSTANTIATE_TEST_CASE_P(
"spv.merge-unreachable.frag",
"spv.multiStruct.comp",
"spv.multiStructFuncall.frag",
"spv.multiView.frag",
"spv.newTexture.frag",
"spv.noDeadDecorations.vert",
"spv.nonSquare.vert",
"spv.noWorkgroup.comp",
"spv.offsets.frag",
"spv.Operations.frag",
"spv.intOps.vert",
"spv.noWorkgroup.comp",
"spv.precision.frag",
"spv.prepost.frag",
"spv.qualifiers.vert",
"spv.sampleMaskOverrideCoverage.frag",
"spv.shaderBallot.comp",
"spv.shaderDrawParams.vert",
"spv.shaderGroupVote.comp",