Skip to content

Commit

Permalink
Web: Make switched methods all be non-virtual, more web-dependent code,
Browse files Browse the repository at this point in the history
added a few more HLSL flag tests.  This was mostly focused on the SPV generator.
Saves about 17K.
  • Loading branch information
johnkslang committed Aug 21, 2019
1 parent d8834df commit b9197c8
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 211 deletions.
251 changes: 155 additions & 96 deletions SPIRV/GlslangToSpv.cpp

Large diffs are not rendered by default.

44 changes: 30 additions & 14 deletions SPIRV/SpvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, boo
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);

#ifndef GLSLANG_WEB
// deal with capabilities
switch (dim) {
case DimBuffer:
Expand Down Expand Up @@ -573,6 +574,7 @@ Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, boo
addCapability(CapabilityImageMSArray);
}
}
#endif

return type->getResultId();
}
Expand Down Expand Up @@ -1018,21 +1020,28 @@ Id Builder::makeFloat16Constant(float f16, bool specConstant)

Id Builder::makeFpConstant(Id type, double d, bool specConstant)
{
assert(isFloatType(type));
#ifdef GLSLANG_WEB
const int width = 32;
assert(width == getScalarTypeWidth(type));
#else
const int width = getScalarTypeWidth(type);
#endif

switch (getScalarTypeWidth(type)) {
case 16:
return makeFloat16Constant((float)d, specConstant);
case 32:
return makeFloatConstant((float)d, specConstant);
case 64:
return makeDoubleConstant(d, specConstant);
default:
break;
}
assert(isFloatType(type));

assert(false);
return NoResult;
switch (width) {
case 16:
return makeFloat16Constant((float)d, specConstant);
case 32:
return makeFloatConstant((float)d, specConstant);
case 64:
return makeDoubleConstant(d, specConstant);
default:
break;
}

assert(false);
return NoResult;
}

Id Builder::findCompositeConstant(Op typeClass, Id typeId, const std::vector<Id>& comps)
Expand Down Expand Up @@ -1895,6 +1904,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
mask = (ImageOperandsMask)(mask | ImageOperandsConstOffsetsMask);
texArgs[numArgs++] = parameters.offsets;
}
#ifndef GLSLANG_WEB
if (parameters.sample) {
mask = (ImageOperandsMask)(mask | ImageOperandsSampleMask);
texArgs[numArgs++] = parameters.sample;
Expand All @@ -1912,6 +1922,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
if (parameters.volatil) {
mask = mask | ImageOperandsVolatileTexelKHRMask;
}
#endif
mask = mask | signExtensionMask;
if (mask == ImageOperandsMaskNone)
--numArgs; // undo speculative reservation for the mask argument
Expand Down Expand Up @@ -2302,7 +2313,12 @@ Id Builder::createMatrixConstructor(Decoration precision, const std::vector<Id>&
int numRows = getTypeNumRows(resultTypeId);

Instruction* instr = module.getInstruction(componentTypeId);
unsigned bitCount = instr->getImmediateOperand(0);
#ifdef GLSLANG_WEB
const unsigned bitCount = 32;
assert(bitcount == instr->getImmediateOperand(0));
#else
const unsigned bitCount = instr->getImmediateOperand(0);
#endif

// Optimize matrix constructed from a bigger matrix
if (isMatrix(sources[0]) && getNumColumns(sources[0]) >= numCols && getNumRows(sources[0]) >= numRows) {
Expand Down
14 changes: 13 additions & 1 deletion SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ class Builder {
bool isMatrixType(Id typeId) const { return getTypeClass(typeId) == OpTypeMatrix; }
bool isStructType(Id typeId) const { return getTypeClass(typeId) == OpTypeStruct; }
bool isArrayType(Id typeId) const { return getTypeClass(typeId) == OpTypeArray; }
#ifdef GLSLANG_WEB
bool isCooperativeMatrixType(Id typeId)const { return false; }
#else
bool isCooperativeMatrixType(Id typeId)const { return getTypeClass(typeId) == OpTypeCooperativeMatrixNV; }
#endif
bool isAggregateType(Id typeId) const { return isArrayType(typeId) || isStructType(typeId) || isCooperativeMatrixType(typeId); }
bool isImageType(Id typeId) const { return getTypeClass(typeId) == OpTypeImage; }
bool isSamplerType(Id typeId) const { return getTypeClass(typeId) == OpTypeSampler; }
Expand Down Expand Up @@ -557,6 +561,14 @@ class Builder {

// Accumulate whether anything in the chain of structures has coherent decorations.
struct CoherentFlags {
CoherentFlags() { clear(); }
#ifdef GLSLANG_WEB
void clear() { }
bool isVolatile() const { return false; }
CoherentFlags operator |=(const CoherentFlags &other) { return *this; }
#else
bool isVolatile() const { return volatil; }

unsigned coherent : 1;
unsigned devicecoherent : 1;
unsigned queuefamilycoherent : 1;
Expand All @@ -577,7 +589,6 @@ class Builder {
isImage = 0;
}

CoherentFlags() { clear(); }
CoherentFlags operator |=(const CoherentFlags &other) {
coherent |= other.coherent;
devicecoherent |= other.devicecoherent;
Expand All @@ -589,6 +600,7 @@ class Builder {
isImage |= other.isImage;
return *this;
}
#endif
};
CoherentFlags coherentFlags;
};
Expand Down
2 changes: 1 addition & 1 deletion Test/baseResults/hlsl.depthGreater.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ using depth_greater
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 18
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 DepthGreater
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthGreater
Source HLSL 500
Name 4 "PixelShaderFunction"
Name 10 "@PixelShaderFunction(f1;"
Expand Down
2 changes: 1 addition & 1 deletion Test/baseResults/hlsl.depthLess.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ using depth_less
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 14
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 DepthLess
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthLess
Source HLSL 500
Name 4 "PixelShaderFunction"
Name 8 "@PixelShaderFunction("
Expand Down
2 changes: 1 addition & 1 deletion Test/baseResults/hlsl.structIoFourWay.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ using depth_greater
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 22 27 31 36 45 48 51 55
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 DepthGreater
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthGreater
Source HLSL 500
Name 4 "main"
Name 8 "T"
Expand Down
2 changes: 1 addition & 1 deletion Test/baseResults/size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
598528 ../build/install/bin/glslangValidator.exe
409600 ../build/install/bin/glslangValidator.exe
2 changes: 1 addition & 1 deletion Test/baseResults/spv.depthOut.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ spv.depthOut.frag
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 10 14
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 DepthGreater
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthGreater
Source GLSL 450
Name 4 "main"
Name 8 "gl_FragDepth"
Expand Down
3 changes: 2 additions & 1 deletion glslang/Include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ __inline bool isTypeFloat(TBasicType type)
}
}

__inline int getTypeRank(TBasicType type) {
__inline int getTypeRank(TBasicType type)
{
int res = -1;
switch(type) {
case EbtInt8:
Expand Down
Loading

0 comments on commit b9197c8

Please sign in to comment.