Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Minimal is `0.15.1`. But you know try your version and believe.

## Bgfx version

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

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.name = .zbgfx,
.fingerprint = 0xc48ed871c4086e4a,
.version = "0.6.0",
.version = "0.7.0",
.minimum_zig_version = "0.15.2",
.paths = .{
"includes",
Expand Down
13 changes: 12 additions & 1 deletion libs/bgfx/3rdparty/glslang/SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5167,6 +5167,16 @@ spv::Id TGlslangToSpvTraverser::createSpvVariable(const glslang::TIntermSymbol*
}

spv::Id var = builder.createVariable(spv::NoPrecision, storageClass, spvType, name, initializer, false);

if (options.emitNonSemanticShaderDebugInfo && storageClass != spv::StorageClass::Function) {
// Create variable alias for retargeted symbols if any.
// Notably, this is only applicable to built-in variables so that it is okay to only use name as the key.
auto [itBegin, itEnd] = glslangIntermediate->getBuiltinAliasLookup().equal_range(name);
for (auto it = itBegin; it != itEnd; ++it) {
builder.createDebugGlobalVariable(builder.getDebugType(spvType), it->second.c_str(), var);
}
}

std::vector<spv::Decoration> topLevelDecorations;
glslang::TQualifier typeQualifier = node->getType().getQualifier();
TranslateMemoryDecoration(typeQualifier, topLevelDecorations, glslangIntermediate->usingVulkanMemoryModel());
Expand Down Expand Up @@ -5675,7 +5685,8 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
if (type.isSizedArray())
spvType = builder.makeArrayType(spvType, makeArraySizeId(*type.getArraySizes(), 0), stride);
else {
if (!lastBufferBlockMember) {
// If we see an runtime array in a buffer_reference, it is not a descriptor
if (!lastBufferBlockMember && type.getBasicType() != glslang::EbtReference) {
builder.addIncorporatedExtension("SPV_EXT_descriptor_indexing", spv::Spv_1_5);
builder.addCapability(spv::Capability::RuntimeDescriptorArrayEXT);
}
Expand Down
217 changes: 114 additions & 103 deletions libs/bgfx/3rdparty/glslang/SPIRV/SpvBuilder.cpp

Large diffs are not rendered by default.

77 changes: 71 additions & 6 deletions libs/bgfx/3rdparty/glslang/SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,20 @@ class Builder {

// Maps the given OpType Id to a Non-Semantic DebugType Id.
Id getDebugType(Id type) {
if (emitNonSemanticShaderDebugInfo) {
return debugId[type];
if (auto it = debugTypeIdLookup.find(type); it != debugTypeIdLookup.end()) {
return it->second;
}
return 0;

return NoType;
}

// Maps the given OpFunction Id to a Non-Semantic DebugFunction Id.
Id getDebugFunction(Id func) {
if (auto it = debugFuncIdLookup.find(func); it != debugFuncIdLookup.end()) {
return it->second;
}

return NoResult;
}

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

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

// Key for scalar constants (handles both 32-bit and 64-bit)
struct ScalarConstantKey {
unsigned int typeClass; // OpTypeInt, OpTypeFloat, OpTypeBool
unsigned int opcode; // OpConstant, OpSpecConstant, OpConstantTrue, etc.
Id typeId; // The specific type
unsigned value1; // First operand (or only operand)
unsigned value2; // Second operand (0 for single-operand constants)

bool operator==(const ScalarConstantKey& other) const {
return typeClass == other.typeClass &&
opcode == other.opcode &&
typeId == other.typeId &&
value1 == other.value1 &&
value2 == other.value2;
}
};

struct ScalarConstantKeyHash {
// 64/32 bit mix function from MurmurHash3
inline std::size_t hash_mix(std::size_t h) const {
if constexpr (sizeof(std::size_t) == 8) {
h ^= h >> 33;
h *= UINT64_C(0xff51afd7ed558ccd);
h ^= h >> 33;
h *= UINT64_C(0xc4ceb9fe1a85ec53);
h ^= h >> 33;
return h;
} else {
h ^= h >> 16;
h *= UINT32_C(0x85ebca6b);
h ^= h >> 13;
h *= UINT32_C(0xc2b2ae35);
h ^= h >> 16;
return h;
}
}

// Hash combine from boost
inline std::size_t hash_combine(std::size_t seed, std::size_t v) const {
return hash_mix(seed + 0x9e3779b9 + v);
}

std::size_t operator()(const ScalarConstantKey& k) const {
size_t hash1 = hash_combine(std::hash<unsigned>{}(k.typeClass), std::hash<unsigned>{}(k.opcode));
size_t hash2 = hash_combine(std::hash<Id>{}(k.value1), std::hash<unsigned>{}(k.value2));
size_t hash3 = hash_combine(hash1, hash2);
return hash_combine(hash3, std::hash<unsigned>{}(k.typeId));
}
};

// map type opcodes to constant inst.
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedConstants;
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedCompositeConstants;
// map struct-id to constant instructions
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedStructConstants;
// map type opcodes to type instructions
Expand All @@ -1041,6 +1101,8 @@ class Builder {
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedDebugTypes;
// list of OpConstantNull instructions
std::vector<Instruction*> nullConstants;
// map scalar constants to result IDs
std::unordered_map<ScalarConstantKey, Id, ScalarConstantKeyHash> groupedScalarConstantResultIDs;

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

// map from core id to debug id
std::map <spv::Id, spv::Id> debugId;
// maps from OpTypeXXX id to DebugTypeXXX id
std::unordered_map<spv::Id, spv::Id> debugTypeIdLookup;

// maps from OpFunction id to DebugFunction id
std::unordered_map<spv::Id, spv::Id> debugFuncIdLookup;

// map from file name string id to DebugSource id
std::unordered_map<spv::Id, spv::Id> debugSourceId;
Expand Down
2 changes: 1 addition & 1 deletion libs/bgfx/3rdparty/glslang/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define GLSLANG_BUILD_INFO

#define GLSLANG_VERSION_MAJOR 16
#define GLSLANG_VERSION_MINOR 0
#define GLSLANG_VERSION_MINOR 1
#define GLSLANG_VERSION_PATCH 0
#define GLSLANG_VERSION_FLAVOR ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,10 @@ void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& ide
// "Identifiers starting with "gl_" are reserved for use by OpenGL, and may not be
// declared in a shader; this results in a compile-time error."
if (! symbolTable.atBuiltInLevel()) {
// The extension GL_EXT_conservative_depth allows us to declare "gl_FragDepth".
if (identifier == "gl_FragDepth" && extensionTurnedOn(E_GL_EXT_conservative_depth))
return;

if (builtInName(identifier) && !extensionTurnedOn(E_GL_EXT_spirv_intrinsics))
// The extension GL_EXT_spirv_intrinsics allows us to declare identifiers starting with "gl_".
error(loc, "identifiers starting with \"gl_\" are reserved", identifier.c_str(), "");
Expand Down Expand Up @@ -5830,7 +5834,8 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS

bool nonEsRedecls = (!isEsProfile() && (version >= 130 || identifier == "gl_TexCoord"));
bool esRedecls = (isEsProfile() &&
(version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks)));
(version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks) ||
(identifier == "gl_FragDepth" && extensionTurnedOn(E_GL_EXT_conservative_depth))));
if (! esRedecls && ! nonEsRedecls)
return nullptr;

Expand Down Expand Up @@ -6535,6 +6540,9 @@ void TParseContext::finish()
if (parsingBuiltins)
return;

// Forward builtin alias to AST for later use
intermediate.setBuiltinAliasLookup(symbolTable.collectBuiltinAlias());

// Check on array indexes for ES 2.0 (version 100) limitations.
for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i)
constantIndexExpressionCheck(needsIndexLimitationChecking[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "../Include/InfoSink.h"

#include <functional>
#include <unordered_map>

namespace glslang {

Expand Down Expand Up @@ -505,6 +506,11 @@ class TSymbolTableLevel {
retargetedSymbols.push_back({from, to});
}

void collectRetargetedSymbols(std::unordered_multimap<std::string, std::string> &out) const {
for (const auto &[fromName, toName] : retargetedSymbols)
out.insert({std::string{toName}, std::string{fromName}});
}

TSymbol* find(const TString& name) const
{
tLevel::const_iterator it = level.find(name);
Expand Down Expand Up @@ -662,9 +668,10 @@ class TSymbolTable {
//
protected:
static const uint32_t LevelFlagBitOffset = 56;
static const int globalLevel = 3;
static constexpr int builtinLevel = 2;
static constexpr int globalLevel = 3;
static bool isSharedLevel(int level) { return level <= 1; } // exclude all per-compile levels
static bool isBuiltInLevel(int level) { return level <= 2; } // exclude user globals
static bool isBuiltInLevel(int level) { return level <= builtinLevel; } // exclude user globals
static bool isGlobalLevel(int level) { return level <= globalLevel; } // include user globals
public:
bool isEmpty() { return table.size() == 0; }
Expand Down Expand Up @@ -829,6 +836,13 @@ class TSymbolTable {
table[level]->retargetSymbol(from, to);
}

std::unordered_multimap<std::string, std::string> collectBuiltinAlias() {
std::unordered_multimap<std::string, std::string> allRetargets;
for (int level = 0; level <= std::min(currentLevel(), builtinLevel); ++level)
table[level]->collectRetargetedSymbols(allRetargets);

return allRetargets;
}

// Find of a symbol that returns how many layers deep of nested
// structures-with-member-functions ('this' scopes) deep the symbol was
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ void TParseVersions::getPreamble(std::string& preamble)
case EShLangClosestHit: preamble += "#define GL_CLOSEST_HIT_SHADER_EXT 1 \n"; break;
case EShLangMiss: preamble += "#define GL_MISS_SHADER_EXT 1 \n"; break;
case EShLangCallable: preamble += "#define GL_CALLABLE_SHADER_EXT 1 \n"; break;
case EShLangTask: preamble += "#define GL_TASK_SHADER_NV 1 \n"; break;
case EShLangMesh: preamble += "#define GL_MESH_SHADER_NV 1 \n"; break;
case EShLangTask: preamble += "#define GL_TASK_SHADER_EXT 1 \n"; break;
case EShLangMesh: preamble += "#define GL_MESH_SHADER_EXT 1 \n"; break;
default: break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <functional>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

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

void setBuiltinAliasLookup(std::unordered_multimap<std::string, std::string> symbolMap) {
builtinAliasLookup = std::move(symbolMap);
}
const std::unordered_multimap<std::string, std::string>& getBuiltinAliasLookup() const {
return builtinAliasLookup;
}

protected:
TIntermSymbol* addSymbol(long long Id, const TString&, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&);
void error(TInfoSink& infoSink, const TSourceLoc* loc, EShMessages messages, const char*, EShLanguage unitStage = EShLangCount);
Expand Down Expand Up @@ -1335,6 +1343,9 @@ class TIntermediate {
// Included text. First string is a name, second is the included text
std::map<std::string, std::string> includeText;

// Maps from canonical symbol name to alias symbol names
std::unordered_multimap<std::string, std::string> builtinAliasLookup;

// for OpModuleProcessed, or equivalent
TProcesses processes;

Expand Down
Loading