Commit 51ed01c8 by John Kessenich

Web: Add compute stage.

parent 61c22e25
......@@ -292,8 +292,8 @@ spv::ExecutionModel TranslateExecutionModel(EShLanguage stage)
switch (stage) {
case EShLangVertex: return spv::ExecutionModelVertex;
case EShLangFragment: return spv::ExecutionModelFragment;
#ifndef GLSLANG_WEB
case EShLangCompute: return spv::ExecutionModelGLCompute;
#ifndef GLSLANG_WEB
case EShLangTessControl: return spv::ExecutionModelTessellationControl;
case EShLangTessEvaluation: return spv::ExecutionModelTessellationEvaluation;
case EShLangGeometry: return spv::ExecutionModelGeometry;
......@@ -1489,12 +1489,12 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, const gl
#endif
break;
#ifndef GLSLANG_WEB
case EShLangCompute:
builder.addCapability(spv::CapabilityShader);
builder.addExecutionMode(shaderEntry, spv::ExecutionModeLocalSize, glslangIntermediate->getLocalSize(0),
glslangIntermediate->getLocalSize(1),
glslangIntermediate->getLocalSize(2));
#ifndef GLSLANG_WEB
if (glslangIntermediate->getLayoutDerivativeModeNone() == glslang::LayoutDerivativeGroupQuads) {
builder.addCapability(spv::CapabilityComputeDerivativeGroupQuadsNV);
builder.addExecutionMode(shaderEntry, spv::ExecutionModeDerivativeGroupQuadsNV);
......@@ -1504,7 +1504,9 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, const gl
builder.addExecutionMode(shaderEntry, spv::ExecutionModeDerivativeGroupLinearNV);
builder.addExtension(spv::E_SPV_NV_compute_shader_derivatives);
}
#endif
break;
#ifndef GLSLANG_WEB
case EShLangTessEvaluation:
case EShLangTessControl:
builder.addCapability(spv::CapabilityTessellation);
......@@ -7826,7 +7828,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
// We now know we have a specialization constant to build
#ifndef GLSLANG_WEB
// gl_WorkGroupSize is a special case until the front-end handles hierarchical specialization constants,
// even then, it's specialization ids are handled by special case syntax in GLSL: layout(local_size_x = ...
if (node.getType().getQualifier().builtIn == glslang::EbvWorkGroupSize) {
......@@ -7841,7 +7842,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n
}
return builder.makeCompositeConstant(builder.makeVectorType(builder.makeUintType(32), 3), dimConstId, true);
}
#endif
// An AST node labelled as specialization constant should be a symbol node.
// Its initializer should either be a sub tree with constant nodes, or a constant union array.
......
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 55
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 2 5 7
OpSource ESSL 310
OpName %main "main"
OpName %s "s"
OpName %arrX "arrX"
OpName %arrY "arrY"
OpName %arrZ "arrZ"
OpDecorate %19 SpecId 18
OpDecorate %21 SpecId 19
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_197645 = OpConstant %uint 197645
%_arr_v4float_uint_197645 = OpTypeArray %v4float %uint_197645
%_ptr_Function__arr_v4float_uint_197645 = OpTypePointer Function %_arr_v4float_uint_197645
%int = OpTypeInt 32 1
%int_3 = OpConstant %int 3
%float_1 = OpConstant %float 1
%16 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Function_v4float = OpTypePointer Function %v4float
%19 = OpSpecConstant %uint 2
%uint_5 = OpConstant %uint 5
%21 = OpSpecConstant %uint 7
%v3uint = OpTypeVector %uint 3
%23 = OpSpecConstantComposite %v3uint %19 %uint_5 %21
%uint_0 = OpConstant %uint 0
%_arr_int_25 = OpTypeArray %int %25
%_ptr_Private__arr_int_25 = OpTypePointer Private %_arr_int_25
%arrX = OpVariable %_ptr_Private__arr_int_25 Private
%int_0 = OpConstant %int 0
%_ptr_Private_int = OpTypePointer Private %int
%uint_1 = OpConstant %uint 1
%_arr_int_34 = OpTypeArray %int %34
%_ptr_Private__arr_int_34 = OpTypePointer Private %_arr_int_34
%arrY = OpVariable %_ptr_Private__arr_int_34 Private
%uint_2 = OpConstant %uint 2
%_arr_int_42 = OpTypeArray %int %42
%_ptr_Private__arr_int_42 = OpTypePointer Private %_arr_int_42
%arrZ = OpVariable %_ptr_Private__arr_int_42 Private
%int_197645 = OpConstant %int 197645
%main = OpFunction %void None %3
%5 = OpLabel
%s = OpVariable %_ptr_Function__arr_v4float_uint_197645 Function
%18 = OpAccessChain %_ptr_Function_v4float %s %int_3
OpStore %18 %16
%25 = OpCompositeExtract %uint %23 0
%31 = OpAccessChain %_ptr_Private_int %arrX %int_0
%32 = OpLoad %int %31
%34 = OpCompositeExtract %uint %23 1
%38 = OpAccessChain %_ptr_Private_int %arrY %int_0
%39 = OpLoad %int %38
%40 = OpIMul %int %32 %39
%42 = OpCompositeExtract %uint %23 2
%46 = OpAccessChain %_ptr_Private_int %arrZ %int_0
%47 = OpLoad %int %46
%48 = OpIMul %int %40 %47
%49 = OpConvertSToF %float %48
%50 = OpAccessChain %_ptr_Function_v4float %s %int_3
%51 = OpLoad %v4float %50
%52 = OpVectorTimesScalar %v4float %51 %49
%53 = OpAccessChain %_ptr_Function_v4float %s %int_3
OpStore %53 %52
OpReturn
OpFunctionEnd
#version 310 es
layout(local_size_x_id = 18, local_size_z_id = 19) in;
layout(local_size_x = 2) in;
layout(local_size_y = 5) in;
layout(local_size_z = 7) in;
const int total = gl_MaxComputeWorkGroupCount.x
+ gl_MaxComputeWorkGroupCount.y
+ gl_MaxComputeWorkGroupCount.z
+ gl_MaxComputeUniformComponents
+ gl_MaxComputeTextureImageUnits;
shared vec4 s[total];
int arrX[gl_WorkGroupSize.x];
int arrY[gl_WorkGroupSize.y];
int arrZ[gl_WorkGroupSize.z];
void main()
{
barrier();
memoryBarrier();
memoryBarrierShared();
groupMemoryBarrier();
s[3] = vec4(1.0);
s[3] *= arrX[0] * arrY[0] * arrZ[0];
}
......@@ -6,3 +6,4 @@ web.operations.frag
web.texture.frag
web.array.frag
web.separate.frag
web.comp
......@@ -3387,11 +3387,11 @@ void TParseContext::globalQualifierTypeCheck(const TSourceLoc& loc, const TQuali
requireProfile(loc, ~EEsProfile, "fragment-shader struct input containing an array");
}
break;
#ifndef GLSLANG_WEB
case EShLangCompute:
if (! symbolTable.atBuiltInLevel())
error(loc, "global storage input qualifier cannot be used in a compute shader", "in", "");
break;
#ifndef GLSLANG_WEB
case EShLangTessControl:
if (qualifier.patch)
error(loc, "can only use on output in tessellation-control shader", "patch", "");
......@@ -3432,10 +3432,10 @@ void TParseContext::globalQualifierTypeCheck(const TSourceLoc& loc, const TQuali
error(loc, "cannot contain a double, int64, or uint64", GetStorageQualifierString(qualifier.storage), "");
break;
#ifndef GLSLANG_WEB
case EShLangCompute:
error(loc, "global storage output qualifier cannot be used in a compute shader", "out", "");
break;
#ifndef GLSLANG_WEB
case EShLangTessEvaluation:
if (qualifier.patch)
error(loc, "can only use on input in tessellation-evaluation shader", "patch", "");
......@@ -5293,11 +5293,10 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
error(loc, "needs a literal integer", "buffer_reference_align", "");
return;
}
#endif
switch (language) {
case EShLangVertex:
break;
#ifndef GLSLANG_WEB
case EShLangTessControl:
if (id == "vertices") {
if (value == 0)
......@@ -5310,9 +5309,6 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
}
break;
case EShLangTessEvaluation:
break;
case EShLangGeometry:
if (id == "invocations") {
profileRequires(loc, ECompatibilityProfile | ECoreProfile, 400, nullptr, "invocations");
......@@ -5385,6 +5381,7 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
case EShLangTaskNV:
// Fall through
#endif
case EShLangCompute:
if (id.compare(0, 11, "local_size_") == 0) {
if (language == EShLangMeshNV || language == EShLangTaskNV) {
......@@ -5432,12 +5429,11 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi
}
}
break;
default:
break;
}
#endif // GLSLANG_WEB
error(loc, "there is no such layout identifier for this stage taking an assigned value", id.c_str(), "");
}
......@@ -8004,6 +8000,7 @@ void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, con
else
error(loc, "can only apply to 'in'", "point_mode", "");
}
#endif
for (int i = 0; i < 3; ++i) {
if (publicType.shaderQualifiers.localSizeNotDefault[i]) {
if (publicType.qualifier.storage == EvqVaryingIn) {
......@@ -8063,6 +8060,7 @@ void TParseContext::updateStandaloneQualifierDefaults(const TSourceLoc& loc, con
}
}
#ifndef GLSLANG_WEB
if (publicType.shaderQualifiers.earlyFragmentTests) {
if (publicType.qualifier.storage == EvqVaryingIn)
intermediate.setEarlyFragmentTests();
......
......@@ -1058,13 +1058,12 @@ int TScanContext::tokenizeIdentifier()
case SUBROUTINE:
return es30ReservedFromGLSL(400);
#endif
case SHARED:
if ((parseContext.isEsProfile() && parseContext.version < 300) ||
(!parseContext.isEsProfile() && parseContext.version < 140))
return identifierOrType();
return keyword;
#endif
case LAYOUT:
{
const int numLayoutExts = 2;
......
......@@ -341,6 +341,7 @@ bool InitializeSymbolTables(TInfoSink& infoSink, TSymbolTable** commonTable, TS
(profile == EEsProfile && version >= 310))
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangGeometry, source,
infoSink, commonTable, symbolTables);
#endif
// check for compute
if ((profile != EEsProfile && version >= 420) ||
......@@ -348,6 +349,7 @@ bool InitializeSymbolTables(TInfoSink& infoSink, TSymbolTable** commonTable, TS
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangCompute, source,
infoSink, commonTable, symbolTables);
#ifndef GLSLANG_WEB
// check for ray tracing stages
if (profile != EEsProfile && version >= 450) {
InitializeStageSymbolTable(*builtInParseables, version, profile, spvVersion, EShLangRayGenNV, source,
......
......@@ -527,11 +527,11 @@ const char* StageName(EShLanguage stage)
switch(stage) {
case EShLangVertex: return "vertex";
case EShLangFragment: return "fragment";
case EShLangCompute: return "compute";
#ifndef GLSLANG_WEB
case EShLangTessControl: return "tessellation control";
case EShLangTessEvaluation: return "tessellation evaluation";
case EShLangGeometry: return "geometry";
case EShLangCompute: return "compute";
case EShLangRayGenNV: return "ray-generation";
case EShLangIntersectNV: return "intersection";
case EShLangAnyHitNV: return "any-hit";
......
......@@ -1360,7 +1360,6 @@ storage_qualifier
$$.init($1.loc);
$$.qualifier.storage = EvqUniform;
}
GLSLANG_WEB_EXCLUDE_ON
| SHARED {
parseContext.globalCheck($1.loc, "shared");
parseContext.profileRequires($1.loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_compute_shader, "shared");
......@@ -1369,6 +1368,7 @@ GLSLANG_WEB_EXCLUDE_ON
$$.init($1.loc);
$$.qualifier.storage = EvqShared;
}
GLSLANG_WEB_EXCLUDE_ON
| BUFFER {
parseContext.globalCheck($1.loc, "buffer");
$$.init($1.loc);
......
......@@ -1156,6 +1156,14 @@ storage_qualifier
$$.init($1.loc);
$$.qualifier.storage = EvqUniform;
}
| SHARED {
parseContext.globalCheck($1.loc, "shared");
parseContext.profileRequires($1.loc, ECoreProfile | ECompatibilityProfile, 430, E_GL_ARB_compute_shader, "shared");
parseContext.profileRequires($1.loc, EEsProfile, 310, 0, "shared");
parseContext.requireStage($1.loc, (EShLanguageMask)(EShLangComputeMask | EShLangMeshNVMask | EShLangTaskNVMask), "shared");
$$.init($1.loc);
$$.qualifier.storage = EvqShared;
}
;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -267,7 +267,6 @@ public:
uniformLocationBase(0)
#endif
{
#ifndef GLSLANG_WEB
localSize[0] = 1;
localSize[1] = 1;
localSize[2] = 1;
......@@ -277,6 +276,7 @@ public:
localSizeSpecId[0] = TQualifier::layoutNotSet;
localSizeSpecId[1] = TQualifier::layoutNotSet;
localSizeSpecId[2] = TQualifier::layoutNotSet;
#ifndef GLSLANG_WEB
xfbBuffers.resize(TQualifier::layoutXfbBufferEnd);
shiftBinding.fill(0);
#endif
......@@ -492,6 +492,23 @@ public:
bool usingVariablePointers() const { return false; }
unsigned getXfbStride(int buffer) const { return 0; }
bool hasLayoutDerivativeModeNone() const { return false; }
bool setLocalSize(int dim, int size)
{
if (localSizeNotDefault[dim])
return size == localSize[dim];
localSizeNotDefault[dim] = true;
localSize[dim] = size;
return true;
}
unsigned int getLocalSize(int dim) const { return localSize[dim]; }
bool setLocalSizeSpecId(int dim, int id)
{
if (localSizeSpecId[dim] != TQualifier::layoutNotSet)
return id == localSizeSpecId[dim];
localSizeSpecId[dim] = id;
return true;
}
int getLocalSizeSpecId(int dim) const { return localSizeSpecId[dim]; }
#else
void output(TInfoSink&, bool tree);
......@@ -655,24 +672,6 @@ public:
}
TInterlockOrdering getInterlockOrdering() const { return interlockOrdering; }
bool setLocalSize(int dim, int size)
{
if (localSizeNotDefault[dim])
return size == localSize[dim];
localSizeNotDefault[dim] = true;
localSize[dim] = size;
return true;
}
unsigned int getLocalSize(int dim) const { return localSize[dim]; }
bool setLocalSizeSpecId(int dim, int id)
{
if (localSizeSpecId[dim] != TQualifier::layoutNotSet)
return id == localSizeSpecId[dim];
localSizeSpecId[dim] = id;
return true;
}
int getLocalSizeSpecId(int dim) const { return localSizeSpecId[dim]; }
void setXfbMode() { xfbMode = true; }
bool getXfbMode() const { return xfbMode; }
void setMultiStream() { multiStream = true; }
......@@ -920,6 +919,9 @@ protected:
bool useStorageBuffer;
bool nanMinMaxClamp; // true if desiring min/max/clamp to favor non-NaN over NaN
bool depthReplacing;
int localSize[3];
bool localSizeNotDefault[3];
int localSizeSpecId[3];
#ifndef GLSLANG_WEB
bool useVulkanMemoryModel;
int invocations;
......@@ -932,9 +934,6 @@ protected:
TVertexOrder vertexOrder;
TInterlockOrdering interlockOrdering;
bool pointMode;
int localSize[3];
bool localSizeNotDefault[3];
int localSizeSpecId[3];
bool earlyFragmentTests;
bool postDepthCoverage;
TLayoutDepth depthLayout;
......
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