Skip to content

Commit ca9e669

Browse files
authored
Update bx and bgfx. (#22)
1 parent f4dc2cb commit ca9e669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1888
-628
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Minimal is `0.15.1`. But you know try your version and believe.
4141

4242
## Bgfx version
4343

44-
- [BX](https://github.com/bkaradzic/bx//compare/5dc415ee2e9935089b21186518436681c2d03b47...master)
44+
- [BX](https://github.com/bkaradzic/bx//compare/ce31b1445475ecd4b090471144c4c30a1cbdd871...master)
4545
- [BImg](https://github.com/bkaradzic/bimg/compare/bf10ffbb3df1f9f12ad7a9105e5e96e11a9c5a0c...master)
46-
- [BGFX](https://github.com/bkaradzic/bgfx/compare/8a60697cfdfe6181b87ea0c49dff58e43448f712...master)
46+
- [BGFX](https://github.com/bkaradzic/bgfx/compare/56eb016280731451c3b7f18433dc114df035d52a...master)
4747

4848
## Getting started
4949

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .zbgfx,
33
.fingerprint = 0xc48ed871c4086e4a,
4-
.version = "0.6.0",
4+
.version = "0.7.0",
55
.minimum_zig_version = "0.15.2",
66
.paths = .{
77
"includes",

libs/bgfx/3rdparty/glslang/SPIRV/GlslangToSpv.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5167,6 +5167,16 @@ spv::Id TGlslangToSpvTraverser::createSpvVariable(const glslang::TIntermSymbol*
51675167
}
51685168

51695169
spv::Id var = builder.createVariable(spv::NoPrecision, storageClass, spvType, name, initializer, false);
5170+
5171+
if (options.emitNonSemanticShaderDebugInfo && storageClass != spv::StorageClass::Function) {
5172+
// Create variable alias for retargeted symbols if any.
5173+
// Notably, this is only applicable to built-in variables so that it is okay to only use name as the key.
5174+
auto [itBegin, itEnd] = glslangIntermediate->getBuiltinAliasLookup().equal_range(name);
5175+
for (auto it = itBegin; it != itEnd; ++it) {
5176+
builder.createDebugGlobalVariable(builder.getDebugType(spvType), it->second.c_str(), var);
5177+
}
5178+
}
5179+
51705180
std::vector<spv::Decoration> topLevelDecorations;
51715181
glslang::TQualifier typeQualifier = node->getType().getQualifier();
51725182
TranslateMemoryDecoration(typeQualifier, topLevelDecorations, glslangIntermediate->usingVulkanMemoryModel());
@@ -5675,7 +5685,8 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
56755685
if (type.isSizedArray())
56765686
spvType = builder.makeArrayType(spvType, makeArraySizeId(*type.getArraySizes(), 0), stride);
56775687
else {
5678-
if (!lastBufferBlockMember) {
5688+
// If we see an runtime array in a buffer_reference, it is not a descriptor
5689+
if (!lastBufferBlockMember && type.getBasicType() != glslang::EbtReference) {
56795690
builder.addIncorporatedExtension("SPV_EXT_descriptor_indexing", spv::Spv_1_5);
56805691
builder.addCapability(spv::Capability::RuntimeDescriptorArrayEXT);
56815692
}

libs/bgfx/3rdparty/glslang/SPIRV/SpvBuilder.cpp

Lines changed: 114 additions & 103 deletions
Large diffs are not rendered by default.

libs/bgfx/3rdparty/glslang/SPIRV/SpvBuilder.h

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,20 @@ class Builder {
208208

209209
// Maps the given OpType Id to a Non-Semantic DebugType Id.
210210
Id getDebugType(Id type) {
211-
if (emitNonSemanticShaderDebugInfo) {
212-
return debugId[type];
211+
if (auto it = debugTypeIdLookup.find(type); it != debugTypeIdLookup.end()) {
212+
return it->second;
213213
}
214-
return 0;
214+
215+
return NoType;
216+
}
217+
218+
// Maps the given OpFunction Id to a Non-Semantic DebugFunction Id.
219+
Id getDebugFunction(Id func) {
220+
if (auto it = debugFuncIdLookup.find(func); it != debugFuncIdLookup.end()) {
221+
return it->second;
222+
}
223+
224+
return NoResult;
215225
}
216226

217227
// For creating new types (will return old type if the requested one was already made).
@@ -1031,8 +1041,58 @@ class Builder {
10311041

10321042
// not output, internally used for quick & dirty canonical (unique) creation
10331043

1044+
// Key for scalar constants (handles both 32-bit and 64-bit)
1045+
struct ScalarConstantKey {
1046+
unsigned int typeClass; // OpTypeInt, OpTypeFloat, OpTypeBool
1047+
unsigned int opcode; // OpConstant, OpSpecConstant, OpConstantTrue, etc.
1048+
Id typeId; // The specific type
1049+
unsigned value1; // First operand (or only operand)
1050+
unsigned value2; // Second operand (0 for single-operand constants)
1051+
1052+
bool operator==(const ScalarConstantKey& other) const {
1053+
return typeClass == other.typeClass &&
1054+
opcode == other.opcode &&
1055+
typeId == other.typeId &&
1056+
value1 == other.value1 &&
1057+
value2 == other.value2;
1058+
}
1059+
};
1060+
1061+
struct ScalarConstantKeyHash {
1062+
// 64/32 bit mix function from MurmurHash3
1063+
inline std::size_t hash_mix(std::size_t h) const {
1064+
if constexpr (sizeof(std::size_t) == 8) {
1065+
h ^= h >> 33;
1066+
h *= UINT64_C(0xff51afd7ed558ccd);
1067+
h ^= h >> 33;
1068+
h *= UINT64_C(0xc4ceb9fe1a85ec53);
1069+
h ^= h >> 33;
1070+
return h;
1071+
} else {
1072+
h ^= h >> 16;
1073+
h *= UINT32_C(0x85ebca6b);
1074+
h ^= h >> 13;
1075+
h *= UINT32_C(0xc2b2ae35);
1076+
h ^= h >> 16;
1077+
return h;
1078+
}
1079+
}
1080+
1081+
// Hash combine from boost
1082+
inline std::size_t hash_combine(std::size_t seed, std::size_t v) const {
1083+
return hash_mix(seed + 0x9e3779b9 + v);
1084+
}
1085+
1086+
std::size_t operator()(const ScalarConstantKey& k) const {
1087+
size_t hash1 = hash_combine(std::hash<unsigned>{}(k.typeClass), std::hash<unsigned>{}(k.opcode));
1088+
size_t hash2 = hash_combine(std::hash<Id>{}(k.value1), std::hash<unsigned>{}(k.value2));
1089+
size_t hash3 = hash_combine(hash1, hash2);
1090+
return hash_combine(hash3, std::hash<unsigned>{}(k.typeId));
1091+
}
1092+
};
1093+
10341094
// map type opcodes to constant inst.
1035-
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedConstants;
1095+
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedCompositeConstants;
10361096
// map struct-id to constant instructions
10371097
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedStructConstants;
10381098
// map type opcodes to type instructions
@@ -1041,6 +1101,8 @@ class Builder {
10411101
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedDebugTypes;
10421102
// list of OpConstantNull instructions
10431103
std::vector<Instruction*> nullConstants;
1104+
// map scalar constants to result IDs
1105+
std::unordered_map<ScalarConstantKey, Id, ScalarConstantKeyHash> groupedScalarConstantResultIDs;
10441106

10451107
// Track which types have explicit layouts, to avoid reusing in storage classes without layout.
10461108
// Currently only tracks array types.
@@ -1058,8 +1120,11 @@ class Builder {
10581120
// map from include file name ids to their contents
10591121
std::map<spv::Id, const std::string*> includeFiles;
10601122

1061-
// map from core id to debug id
1062-
std::map <spv::Id, spv::Id> debugId;
1123+
// maps from OpTypeXXX id to DebugTypeXXX id
1124+
std::unordered_map<spv::Id, spv::Id> debugTypeIdLookup;
1125+
1126+
// maps from OpFunction id to DebugFunction id
1127+
std::unordered_map<spv::Id, spv::Id> debugFuncIdLookup;
10631128

10641129
// map from file name string id to DebugSource id
10651130
std::unordered_map<spv::Id, spv::Id> debugSourceId;

libs/bgfx/3rdparty/glslang/build_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define GLSLANG_BUILD_INFO
3636

3737
#define GLSLANG_VERSION_MAJOR 16
38-
#define GLSLANG_VERSION_MINOR 0
38+
#define GLSLANG_VERSION_MINOR 1
3939
#define GLSLANG_VERSION_PATCH 0
4040
#define GLSLANG_VERSION_FLAVOR ""
4141

libs/bgfx/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,10 @@ void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& ide
41884188
// "Identifiers starting with "gl_" are reserved for use by OpenGL, and may not be
41894189
// declared in a shader; this results in a compile-time error."
41904190
if (! symbolTable.atBuiltInLevel()) {
4191+
// The extension GL_EXT_conservative_depth allows us to declare "gl_FragDepth".
4192+
if (identifier == "gl_FragDepth" && extensionTurnedOn(E_GL_EXT_conservative_depth))
4193+
return;
4194+
41914195
if (builtInName(identifier) && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
41924196
// The extension GL_EXT_spirv_intrinsics allows us to declare identifiers starting with "gl_".
41934197
error(loc, "identifiers starting with \"gl_\" are reserved", identifier.c_str(), "");
@@ -5830,7 +5834,8 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS
58305834

58315835
bool nonEsRedecls = (!isEsProfile() && (version >= 130 || identifier == "gl_TexCoord"));
58325836
bool esRedecls = (isEsProfile() &&
5833-
(version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks)));
5837+
(version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks) ||
5838+
(identifier == "gl_FragDepth" && extensionTurnedOn(E_GL_EXT_conservative_depth))));
58345839
if (! esRedecls && ! nonEsRedecls)
58355840
return nullptr;
58365841

@@ -6535,6 +6540,9 @@ void TParseContext::finish()
65356540
if (parsingBuiltins)
65366541
return;
65376542

6543+
// Forward builtin alias to AST for later use
6544+
intermediate.setBuiltinAliasLookup(symbolTable.collectBuiltinAlias());
6545+
65386546
// Check on array indexes for ES 2.0 (version 100) limitations.
65396547
for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i)
65406548
constantIndexExpressionCheck(needsIndexLimitationChecking[i]);

libs/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "../Include/InfoSink.h"
7171

7272
#include <functional>
73+
#include <unordered_map>
7374

7475
namespace glslang {
7576

@@ -505,6 +506,11 @@ class TSymbolTableLevel {
505506
retargetedSymbols.push_back({from, to});
506507
}
507508

509+
void collectRetargetedSymbols(std::unordered_multimap<std::string, std::string> &out) const {
510+
for (const auto &[fromName, toName] : retargetedSymbols)
511+
out.insert({std::string{toName}, std::string{fromName}});
512+
}
513+
508514
TSymbol* find(const TString& name) const
509515
{
510516
tLevel::const_iterator it = level.find(name);
@@ -662,9 +668,10 @@ class TSymbolTable {
662668
//
663669
protected:
664670
static const uint32_t LevelFlagBitOffset = 56;
665-
static const int globalLevel = 3;
671+
static constexpr int builtinLevel = 2;
672+
static constexpr int globalLevel = 3;
666673
static bool isSharedLevel(int level) { return level <= 1; } // exclude all per-compile levels
667-
static bool isBuiltInLevel(int level) { return level <= 2; } // exclude user globals
674+
static bool isBuiltInLevel(int level) { return level <= builtinLevel; } // exclude user globals
668675
static bool isGlobalLevel(int level) { return level <= globalLevel; } // include user globals
669676
public:
670677
bool isEmpty() { return table.size() == 0; }
@@ -829,6 +836,13 @@ class TSymbolTable {
829836
table[level]->retargetSymbol(from, to);
830837
}
831838

839+
std::unordered_multimap<std::string, std::string> collectBuiltinAlias() {
840+
std::unordered_multimap<std::string, std::string> allRetargets;
841+
for (int level = 0; level <= std::min(currentLevel(), builtinLevel); ++level)
842+
table[level]->collectRetargetedSymbols(allRetargets);
843+
844+
return allRetargets;
845+
}
832846

833847
// Find of a symbol that returns how many layers deep of nested
834848
// structures-with-member-functions ('this' scopes) deep the symbol was

libs/bgfx/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ void TParseVersions::getPreamble(std::string& preamble)
728728
case EShLangClosestHit: preamble += "#define GL_CLOSEST_HIT_SHADER_EXT 1 \n"; break;
729729
case EShLangMiss: preamble += "#define GL_MISS_SHADER_EXT 1 \n"; break;
730730
case EShLangCallable: preamble += "#define GL_CALLABLE_SHADER_EXT 1 \n"; break;
731-
case EShLangTask: preamble += "#define GL_TASK_SHADER_NV 1 \n"; break;
732-
case EShLangMesh: preamble += "#define GL_MESH_SHADER_NV 1 \n"; break;
731+
case EShLangTask: preamble += "#define GL_TASK_SHADER_EXT 1 \n"; break;
732+
case EShLangMesh: preamble += "#define GL_MESH_SHADER_EXT 1 \n"; break;
733733
default: break;
734734
}
735735
}

libs/bgfx/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <functional>
4949
#include <set>
5050
#include <string>
51+
#include <unordered_map>
5152
#include <vector>
5253

5354
class TInfoSink;
@@ -1161,6 +1162,13 @@ class TIntermediate {
11611162
void updateNumericFeature(TNumericFeatures::feature f, bool on)
11621163
{ on ? numericFeatures.insert(f) : numericFeatures.erase(f); }
11631164

1165+
void setBuiltinAliasLookup(std::unordered_multimap<std::string, std::string> symbolMap) {
1166+
builtinAliasLookup = std::move(symbolMap);
1167+
}
1168+
const std::unordered_multimap<std::string, std::string>& getBuiltinAliasLookup() const {
1169+
return builtinAliasLookup;
1170+
}
1171+
11641172
protected:
11651173
TIntermSymbol* addSymbol(long long Id, const TString&, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&);
11661174
void error(TInfoSink& infoSink, const TSourceLoc* loc, EShMessages messages, const char*, EShLanguage unitStage = EShLangCount);
@@ -1335,6 +1343,9 @@ class TIntermediate {
13351343
// Included text. First string is a name, second is the included text
13361344
std::map<std::string, std::string> includeText;
13371345

1346+
// Maps from canonical symbol name to alias symbol names
1347+
std::unordered_multimap<std::string, std::string> builtinAliasLookup;
1348+
13381349
// for OpModuleProcessed, or equivalent
13391350
TProcesses processes;
13401351

0 commit comments

Comments
 (0)