mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-11-17 21:36:12 +00:00
@@ -14,7 +14,7 @@
|
||||
#include <tinystl/vector.h>
|
||||
namespace stl = tinystl;
|
||||
|
||||
#define BGFX_SHADER_BIN_VERSION 13
|
||||
#define BGFX_SHADER_BIN_VERSION 14
|
||||
#define BGFX_CHUNK_MAGIC_CSH BX_MAKEFOURCC('C', 'S', 'H', BGFX_SHADER_BIN_VERSION)
|
||||
#define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', BGFX_SHADER_BIN_VERSION)
|
||||
#define BGFX_CHUNK_MAGIC_VSH BX_MAKEFOURCC('V', 'S', 'H', BGFX_SHADER_BIN_VERSION)
|
||||
@@ -396,6 +396,23 @@ namespace bgfx
|
||||
return UniformType::Count;
|
||||
}
|
||||
|
||||
bool isUniformNumValid(const char* _name, uint32_t _num, bx::WriterI* _messageWriter)
|
||||
{
|
||||
if (UINT16_MAX < _num)
|
||||
{
|
||||
bx::ErrorAssert err;
|
||||
bx::write(_messageWriter, &err
|
||||
, "Error: Uniform '%s' has %u elements, the limit is %u.\n"
|
||||
, _name
|
||||
, _num
|
||||
, UINT16_MAX
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t spirvDimToTextureDimensionId(uint32_t _dim, bool _arrayed, bool _multisampled)
|
||||
{
|
||||
switch (_dim)
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace bgfx
|
||||
|
||||
const char* getUniformTypeName(UniformType::Enum _enum);
|
||||
UniformType::Enum nameToUniformTypeEnum(const char* _name);
|
||||
bool isUniformNumValid(const char* _name, uint32_t _num, bx::WriterI* _messageWriter);
|
||||
|
||||
/// Converts a SPIR-V `spv::Dim` (plus the arrayed and multisampled flags) into the texture
|
||||
/// dimension id stored in `Uniform::texDimension`.
|
||||
@@ -121,7 +122,7 @@ namespace bgfx
|
||||
|
||||
std::string name;
|
||||
UniformType::Enum type;
|
||||
uint8_t num;
|
||||
uint16_t num;
|
||||
uint16_t regIndex;
|
||||
uint16_t regCount;
|
||||
uint8_t texComponent;
|
||||
|
||||
@@ -358,10 +358,15 @@ namespace bgfx { namespace dxil
|
||||
if (UniformType::Count != uniformType
|
||||
&& 0 != (varDesc.uFlags & D3D_SVF_USED) )
|
||||
{
|
||||
if (!isUniformNumValid(varDesc.Name, constDesc.Elements, _messageWriter) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Uniform un;
|
||||
un.name = varDesc.Name;
|
||||
un.type = uniformType;
|
||||
un.num = uint8_t(constDesc.Elements);
|
||||
un.num = uint16_t(constDesc.Elements);
|
||||
un.regIndex = uint16_t(varDesc.StartOffset);
|
||||
un.regCount = uint16_t(bx::alignUp(varDesc.Size, 16) / 16);
|
||||
_uniforms.push_back(un);
|
||||
|
||||
@@ -292,6 +292,7 @@ namespace bgfx { namespace glsl
|
||||
}
|
||||
|
||||
UniformArray uniforms;
|
||||
bool validUniforms = true;
|
||||
|
||||
for (const spirv_cross::Resource& resource : resources.gl_plain_uniforms)
|
||||
{
|
||||
@@ -311,7 +312,15 @@ namespace bgfx { namespace glsl
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint8_t(type.array.empty() ? 1 : type.array[0]);
|
||||
const uint32_t num = type.array.empty() ? 1 : type.array[0];
|
||||
|
||||
if (!isUniformNumValid(un.name.c_str(), num, _messageWriter) )
|
||||
{
|
||||
validUniforms = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint16_t(num);
|
||||
un.regIndex = 0;
|
||||
un.regCount = un.num;
|
||||
|
||||
@@ -384,7 +393,7 @@ namespace bgfx { namespace glsl
|
||||
writeFile(disasmfp.c_str(), source.c_str(), shaderSize);
|
||||
}
|
||||
|
||||
result = true;
|
||||
result = validUniforms;
|
||||
}
|
||||
|
||||
delete program;
|
||||
|
||||
@@ -448,10 +448,16 @@ namespace bgfx { namespace hlsl
|
||||
if (UniformType::Count != uniformType
|
||||
&& 0 != (varDesc.uFlags & D3D_SVF_USED) )
|
||||
{
|
||||
if (!isUniformNumValid(varDesc.Name, constDesc.Elements, _messageWriter) )
|
||||
{
|
||||
reflect->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
Uniform un;
|
||||
un.name = varDesc.Name;
|
||||
un.type = uniformType;
|
||||
un.num = uint8_t(constDesc.Elements);
|
||||
un.num = uint16_t(constDesc.Elements);
|
||||
un.regIndex = uint16_t(varDesc.StartOffset);
|
||||
un.regCount = uint16_t(bx::alignUp(varDesc.Size, 16) / 16);
|
||||
_uniforms.push_back(un);
|
||||
|
||||
@@ -572,7 +572,7 @@ namespace bgfx { namespace metal
|
||||
}
|
||||
|
||||
UniformArray uniforms;
|
||||
bool implicitUniform = false;
|
||||
bool invalidUniform = false;
|
||||
|
||||
{
|
||||
uint16_t count = (uint16_t)program->getNumLiveUniformVariables();
|
||||
@@ -594,11 +594,19 @@ namespace bgfx { namespace metal
|
||||
, "Error: Global '%s' is implicitly a uniform. Declare it 'static const', or make it a local variable.\n"
|
||||
, un.name.c_str()
|
||||
);
|
||||
implicitUniform = true;
|
||||
invalidUniform = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint8_t(program->getUniformArraySize(ii) );
|
||||
const uint32_t arraySize = uint32_t(program->getUniformArraySize(ii) );
|
||||
|
||||
if (!isUniformNumValid(un.name.c_str(), arraySize, _messageWriter) )
|
||||
{
|
||||
invalidUniform = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint16_t(arraySize);
|
||||
const uint32_t offset = program->getUniformBufferOffset(ii);
|
||||
un.regIndex = uint16_t(offset);
|
||||
un.regCount = un.num;
|
||||
@@ -663,7 +671,7 @@ namespace bgfx { namespace metal
|
||||
validatorOptions.SetBeforeHlslLegalization(true);
|
||||
|
||||
const bool optimized = true
|
||||
&& !implicitUniform
|
||||
&& !invalidUniform
|
||||
&& opt.Run(
|
||||
spirv.data()
|
||||
, spirv.size()
|
||||
|
||||
@@ -677,7 +677,7 @@ namespace bgfx { namespace spirv
|
||||
}
|
||||
|
||||
UniformArray uniforms;
|
||||
bool implicitUniform = false;
|
||||
bool invalidUniform = false;
|
||||
|
||||
{
|
||||
uint16_t count = (uint16_t)program->getNumLiveUniformVariables();
|
||||
@@ -701,11 +701,19 @@ namespace bgfx { namespace spirv
|
||||
, "Error: Global '%s' is implicitly a uniform. Declare it 'static const', or make it a local variable.\n"
|
||||
, un.name.c_str()
|
||||
);
|
||||
implicitUniform = true;
|
||||
invalidUniform = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint8_t(program->getUniformArraySize(ii) );
|
||||
const uint32_t arraySize = uint32_t(program->getUniformArraySize(ii) );
|
||||
|
||||
if (!isUniformNumValid(un.name.c_str(), arraySize, _messageWriter) )
|
||||
{
|
||||
invalidUniform = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint16_t(arraySize);
|
||||
const uint32_t offset = program->getUniformBufferOffset(ii);
|
||||
un.regIndex = uint16_t(offset);
|
||||
un.regCount = un.num;
|
||||
@@ -774,7 +782,7 @@ namespace bgfx { namespace spirv
|
||||
validatorOptions.SetBeforeHlslLegalization(true);
|
||||
|
||||
const bool optimized = true
|
||||
&& !implicitUniform
|
||||
&& !invalidUniform
|
||||
&& opt.Run(
|
||||
spirv.data()
|
||||
, spirv.size()
|
||||
|
||||
@@ -680,6 +680,7 @@ namespace bgfx { namespace wgsl
|
||||
}
|
||||
|
||||
UniformArray uniforms;
|
||||
bool invalidUniform = false;
|
||||
const uint16_t blockSize = bx::narrowCast<uint16_t>(bx::max<int32_t>(0, program->getUniformBlockSize(blockIndex) ) );
|
||||
|
||||
{
|
||||
@@ -695,7 +696,15 @@ namespace bgfx { namespace wgsl
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint8_t(program->getUniformArraySize(ii) );
|
||||
const uint32_t arraySize = uint32_t(program->getUniformArraySize(ii) );
|
||||
|
||||
if (!isUniformNumValid(un.name.c_str(), arraySize, _messageWriter) )
|
||||
{
|
||||
invalidUniform = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
un.num = uint16_t(arraySize);
|
||||
const uint32_t offset = program->getUniformBufferOffset(ii);
|
||||
un.regIndex = uint16_t(offset);
|
||||
un.regCount = un.num;
|
||||
@@ -763,7 +772,9 @@ namespace bgfx { namespace wgsl
|
||||
spvtools::ValidatorOptions validatorOptions;
|
||||
validatorOptions.SetBeforeHlslLegalization(true);
|
||||
|
||||
if (!opt.Run(
|
||||
if (false
|
||||
|| invalidUniform
|
||||
|| !opt.Run(
|
||||
spirv.data()
|
||||
, spirv.size()
|
||||
, &spirv
|
||||
|
||||
Reference in New Issue
Block a user