mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Updated glslang.
This commit is contained in:
90
3rdparty/glslang/SPIRV/GlslangToSpv.cpp
vendored
90
3rdparty/glslang/SPIRV/GlslangToSpv.cpp
vendored
@@ -4515,50 +4515,56 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
|
||||
|
||||
std::vector<spv::IdImmediate> operands;
|
||||
for (const auto& typeParam : spirvType.typeParams) {
|
||||
// Constant expression
|
||||
if (typeParam.constant->isLiteral()) {
|
||||
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
||||
float floatValue = static_cast<float>(typeParam.constant->getConstArray()[0].getDConst());
|
||||
unsigned literal;
|
||||
static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)");
|
||||
memcpy(&literal, &floatValue, sizeof(literal));
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtInt) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getIConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtUint) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getUConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtBool) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getBConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtString) {
|
||||
auto str = typeParam.constant->getConstArray()[0].getSConst()->c_str();
|
||||
unsigned literal = 0;
|
||||
char* literalPtr = reinterpret_cast<char*>(&literal);
|
||||
unsigned charCount = 0;
|
||||
char ch = 0;
|
||||
do {
|
||||
ch = *(str++);
|
||||
*(literalPtr++) = ch;
|
||||
++charCount;
|
||||
if (charCount == 4) {
|
||||
operands.push_back({false, literal});
|
||||
literalPtr = reinterpret_cast<char*>(&literal);
|
||||
charCount = 0;
|
||||
}
|
||||
} while (ch != 0);
|
||||
|
||||
// Partial literal is padded with 0
|
||||
if (charCount > 0) {
|
||||
for (; charCount < 4; ++charCount)
|
||||
*(literalPtr++) = 0;
|
||||
if (typeParam.constant != nullptr) {
|
||||
// Constant expression
|
||||
if (typeParam.constant->isLiteral()) {
|
||||
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
||||
float floatValue = static_cast<float>(typeParam.constant->getConstArray()[0].getDConst());
|
||||
unsigned literal;
|
||||
static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)");
|
||||
memcpy(&literal, &floatValue, sizeof(literal));
|
||||
operands.push_back({false, literal});
|
||||
}
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtInt) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getIConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtUint) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getUConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtBool) {
|
||||
unsigned literal = typeParam.constant->getConstArray()[0].getBConst();
|
||||
operands.push_back({false, literal});
|
||||
} else if (typeParam.constant->getBasicType() == glslang::EbtString) {
|
||||
auto str = typeParam.constant->getConstArray()[0].getSConst()->c_str();
|
||||
unsigned literal = 0;
|
||||
char* literalPtr = reinterpret_cast<char*>(&literal);
|
||||
unsigned charCount = 0;
|
||||
char ch = 0;
|
||||
do {
|
||||
ch = *(str++);
|
||||
*(literalPtr++) = ch;
|
||||
++charCount;
|
||||
if (charCount == 4) {
|
||||
operands.push_back({false, literal});
|
||||
literalPtr = reinterpret_cast<char*>(&literal);
|
||||
charCount = 0;
|
||||
}
|
||||
} while (ch != 0);
|
||||
|
||||
// Partial literal is padded with 0
|
||||
if (charCount > 0) {
|
||||
for (; charCount < 4; ++charCount)
|
||||
*(literalPtr++) = 0;
|
||||
operands.push_back({false, literal});
|
||||
}
|
||||
} else
|
||||
assert(0); // Unexpected type
|
||||
} else
|
||||
assert(0); // Unexpected type
|
||||
} else
|
||||
operands.push_back({true, createSpvConstant(*typeParam.constant)});
|
||||
operands.push_back({true, createSpvConstant(*typeParam.constant)});
|
||||
} else {
|
||||
// Type specifier
|
||||
assert(typeParam.type != nullptr);
|
||||
operands.push_back({true, convertGlslangToSpvType(*typeParam.type)});
|
||||
}
|
||||
}
|
||||
|
||||
assert(spirvInst.set == ""); // Currently, couldn't be extended instructions.
|
||||
|
||||
3056
3rdparty/glslang/SPIRV/doc.cpp
vendored
3056
3rdparty/glslang/SPIRV/doc.cpp
vendored
File diff suppressed because it is too large
Load Diff
31
3rdparty/glslang/glslang/HLSL/hlslGrammar.cpp
vendored
31
3rdparty/glslang/glslang/HLSL/hlslGrammar.cpp
vendored
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) 2016-2018 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
// Copyright (C) 2023 Mobica Limited.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
@@ -594,6 +595,7 @@ bool HlslGrammar::acceptControlDeclaration(TIntermNode*& node)
|
||||
// fully_specified_type
|
||||
// : type_specifier
|
||||
// | type_qualifier type_specifier
|
||||
// | type_specifier type_qualifier
|
||||
//
|
||||
bool HlslGrammar::acceptFullySpecifiedType(TType& type, const TAttributes& attributes)
|
||||
{
|
||||
@@ -605,7 +607,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList,
|
||||
// type_qualifier
|
||||
TQualifier qualifier;
|
||||
qualifier.clear();
|
||||
if (! acceptQualifier(qualifier))
|
||||
if (! acceptPreQualifier(qualifier))
|
||||
return false;
|
||||
TSourceLoc loc = token.loc;
|
||||
|
||||
@@ -620,6 +622,10 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList,
|
||||
return false;
|
||||
}
|
||||
|
||||
// type_qualifier
|
||||
if (! acceptPostQualifier(qualifier))
|
||||
return false;
|
||||
|
||||
if (type.getBasicType() == EbtBlock) {
|
||||
// the type was a block, which set some parts of the qualifier
|
||||
parseContext.mergeQualifiers(type.getQualifier(), qualifier);
|
||||
@@ -634,7 +640,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList,
|
||||
parseContext.declareBlock(loc, type);
|
||||
} else {
|
||||
// Some qualifiers are set when parsing the type. Merge those with
|
||||
// whatever comes from acceptQualifier.
|
||||
// whatever comes from acceptPreQualifier and acceptPostQualifier.
|
||||
assert(qualifier.layoutFormat == ElfNone);
|
||||
|
||||
qualifier.layoutFormat = type.getQualifier().layoutFormat;
|
||||
@@ -660,7 +666,7 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type, TIntermNode*& nodeList,
|
||||
//
|
||||
// Zero or more of these, so this can't return false.
|
||||
//
|
||||
bool HlslGrammar::acceptQualifier(TQualifier& qualifier)
|
||||
bool HlslGrammar::acceptPreQualifier(TQualifier& qualifier)
|
||||
{
|
||||
do {
|
||||
switch (peek()) {
|
||||
@@ -766,6 +772,25 @@ bool HlslGrammar::acceptQualifier(TQualifier& qualifier)
|
||||
} while (true);
|
||||
}
|
||||
|
||||
// type_qualifier
|
||||
// : qualifier qualifier ...
|
||||
//
|
||||
// Zero or more of these, so this can't return false.
|
||||
//
|
||||
bool HlslGrammar::acceptPostQualifier(TQualifier& qualifier)
|
||||
{
|
||||
do {
|
||||
switch (peek()) {
|
||||
case EHTokConst:
|
||||
qualifier.storage = EvqConst;
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
advanceToken();
|
||||
} while (true);
|
||||
}
|
||||
|
||||
// layout_qualifier_list
|
||||
// : LAYOUT LEFT_PAREN layout_qualifier COMMA layout_qualifier ... RIGHT_PAREN
|
||||
//
|
||||
|
||||
4
3rdparty/glslang/glslang/HLSL/hlslGrammar.h
vendored
4
3rdparty/glslang/glslang/HLSL/hlslGrammar.h
vendored
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) 2016-2018 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
// Copyright (C) 2023 Mobica Limited.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
@@ -72,7 +73,8 @@ namespace glslang {
|
||||
bool acceptSamplerState();
|
||||
bool acceptFullySpecifiedType(TType&, const TAttributes&);
|
||||
bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false);
|
||||
bool acceptQualifier(TQualifier&);
|
||||
bool acceptPreQualifier(TQualifier&);
|
||||
bool acceptPostQualifier(TQualifier&);
|
||||
bool acceptLayoutQualifierList(TQualifier&);
|
||||
bool acceptType(TType&);
|
||||
bool acceptType(TType&, TIntermNode*& nodeList);
|
||||
|
||||
@@ -98,12 +98,23 @@ struct TSpirvInstruction {
|
||||
struct TSpirvTypeParameter {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TSpirvTypeParameter(const TIntermConstantUnion* arg) { constant = arg; }
|
||||
TSpirvTypeParameter(const TIntermConstantUnion* arg)
|
||||
{
|
||||
constant = arg;
|
||||
type = nullptr;
|
||||
}
|
||||
|
||||
bool operator==(const TSpirvTypeParameter& rhs) const { return constant == rhs.constant; }
|
||||
TSpirvTypeParameter(const TType *arg)
|
||||
{
|
||||
constant = nullptr;
|
||||
type = arg;
|
||||
}
|
||||
|
||||
bool operator==(const TSpirvTypeParameter& rhs) const;
|
||||
bool operator!=(const TSpirvTypeParameter& rhs) const { return !operator==(rhs); }
|
||||
|
||||
const TIntermConstantUnion* constant;
|
||||
const TIntermConstantUnion* constant; // Constant expression
|
||||
const TType* type; // Type specifier
|
||||
};
|
||||
|
||||
typedef TVector<TSpirvTypeParameter> TSpirvTypeParameters;
|
||||
|
||||
@@ -486,6 +486,7 @@ public:
|
||||
TSpirvRequirement* mergeSpirvRequirements(const TSourceLoc& loc, TSpirvRequirement* spirvReq1,
|
||||
TSpirvRequirement* spirvReq2);
|
||||
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TIntermConstantUnion* constant);
|
||||
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TPublicType& type);
|
||||
TSpirvTypeParameters* mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1,
|
||||
TSpirvTypeParameters* spirvTypeParams2);
|
||||
TSpirvInstruction* makeSpirvInstruction(const TSourceLoc& loc, const TString& name, const TString& value);
|
||||
|
||||
@@ -45,6 +45,15 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
bool TSpirvTypeParameter::operator==(const TSpirvTypeParameter& rhs) const
|
||||
{
|
||||
if (constant != nullptr)
|
||||
return constant->getConstArray() == rhs.constant->getConstArray();
|
||||
|
||||
assert(type != nullptr);
|
||||
return *type == *rhs.type;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle SPIR-V requirements
|
||||
//
|
||||
@@ -283,14 +292,19 @@ TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& l
|
||||
constant->getBasicType() != EbtBool &&
|
||||
constant->getBasicType() != EbtString)
|
||||
error(loc, "this type not allowed", constant->getType().getBasicString(), "");
|
||||
else {
|
||||
assert(constant);
|
||||
else
|
||||
spirvTypeParams->push_back(TSpirvTypeParameter(constant));
|
||||
}
|
||||
|
||||
return spirvTypeParams;
|
||||
}
|
||||
|
||||
TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& loc, const TPublicType& type)
|
||||
{
|
||||
TSpirvTypeParameters* spirvTypeParams = new TSpirvTypeParameters;
|
||||
spirvTypeParams->push_back(TSpirvTypeParameter(new TType(type)));
|
||||
return spirvTypeParams;
|
||||
}
|
||||
|
||||
TSpirvTypeParameters* TParseContext::mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1, TSpirvTypeParameters* spirvTypeParams2)
|
||||
{
|
||||
// Merge SPIR-V type parameters of the second one to the first one
|
||||
|
||||
@@ -4439,6 +4439,9 @@ spirv_type_parameter
|
||||
: constant_expression {
|
||||
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
||||
}
|
||||
| type_specifier_nonarray {
|
||||
$$ = parseContext.makeSpirvTypeParameters($1.loc, $1);
|
||||
}
|
||||
|
||||
spirv_instruction_qualifier
|
||||
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
||||
|
||||
@@ -4439,6 +4439,9 @@ spirv_type_parameter
|
||||
: constant_expression {
|
||||
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
||||
}
|
||||
| type_specifier_nonarray {
|
||||
$$ = parseContext.makeSpirvTypeParameters($1.loc, $1);
|
||||
}
|
||||
|
||||
spirv_instruction_qualifier
|
||||
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user