mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Fix UniformBuffer UB regarding UniformType::Enum with extra bits. (#3398)
This commit is contained in:
committed by
GitHub
parent
de56398919
commit
abe193a407
@@ -1522,7 +1522,7 @@ namespace bgfx
|
||||
write(_value, g_uniformTypeSize[_type]*_num);
|
||||
}
|
||||
|
||||
void UniformBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num)
|
||||
void UniformBuffer::writeUniformHandle(uint8_t _type, uint16_t _loc, UniformHandle _handle, uint16_t _num)
|
||||
{
|
||||
const uint32_t opcode = encodeOpcode(_type, _loc, _num, false);
|
||||
write(opcode);
|
||||
@@ -2520,7 +2520,7 @@ namespace bgfx
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
|
||||
@@ -1508,7 +1508,7 @@ namespace bgfx
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t encodeOpcode(UniformType::Enum _type, uint16_t _loc, uint16_t _num, uint16_t _copy)
|
||||
static uint32_t encodeOpcode(uint8_t _type, uint16_t _loc, uint16_t _num, uint16_t _copy)
|
||||
{
|
||||
const uint32_t type = _type << kConstantOpcodeTypeShift;
|
||||
const uint32_t loc = _loc << kConstantOpcodeLocShift;
|
||||
@@ -1517,14 +1517,14 @@ namespace bgfx
|
||||
return type|loc|num|copy;
|
||||
}
|
||||
|
||||
static void decodeOpcode(uint32_t _opcode, UniformType::Enum& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy)
|
||||
static void decodeOpcode(uint32_t _opcode, uint8_t& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy)
|
||||
{
|
||||
const uint32_t type = (_opcode&kConstantOpcodeTypeMask) >> kConstantOpcodeTypeShift;
|
||||
const uint32_t loc = (_opcode&kConstantOpcodeLocMask ) >> kConstantOpcodeLocShift;
|
||||
const uint32_t num = (_opcode&kConstantOpcodeNumMask ) >> kConstantOpcodeNumShift;
|
||||
const uint32_t copy = (_opcode&kConstantOpcodeCopyMask); // >> kConstantOpcodeCopyShift;
|
||||
|
||||
_type = (UniformType::Enum)(type);
|
||||
_type = (uint8_t )type;
|
||||
_copy = (uint16_t)copy;
|
||||
_num = (uint16_t)num;
|
||||
_loc = (uint16_t)loc;
|
||||
@@ -1583,7 +1583,7 @@ namespace bgfx
|
||||
}
|
||||
|
||||
void writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num = 1);
|
||||
void writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num = 1);
|
||||
void writeUniformHandle(uint8_t _type, uint16_t _loc, UniformHandle _handle, uint16_t _num = 1);
|
||||
void writeMarker(const bx::StringView& _name);
|
||||
|
||||
private:
|
||||
|
||||
@@ -3377,7 +3377,7 @@ namespace bgfx { namespace d3d11
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
@@ -3395,7 +3395,7 @@ namespace bgfx { namespace d3d11
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
switch ( (uint32_t)type)
|
||||
switch (type)
|
||||
{
|
||||
case UniformType::Mat3:
|
||||
case UniformType::Mat3|kUniformFragmentBit:
|
||||
@@ -4190,7 +4190,7 @@ namespace bgfx { namespace d3d11
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount);
|
||||
m_constantBuffer->writeUniformHandle(type|fragmentBit, regIndex, info->m_handle, regCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -3384,7 +3384,7 @@ namespace bgfx { namespace d3d12
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
@@ -3402,7 +3402,7 @@ namespace bgfx { namespace d3d12
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
switch ( (uint32_t)type)
|
||||
switch (type)
|
||||
{
|
||||
case UniformType::Mat3:
|
||||
case UniformType::Mat3|kUniformFragmentBit:
|
||||
@@ -4834,7 +4834,7 @@ namespace bgfx { namespace d3d12
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount);
|
||||
m_constantBuffer->writeUniformHandle(type|fragmentBit, regIndex, info->m_handle, regCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -4420,7 +4420,7 @@ namespace bgfx { namespace gl
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t ignore;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
|
||||
@@ -1751,7 +1751,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
@@ -1769,7 +1769,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
switch ( (uint32_t)type)
|
||||
switch (type)
|
||||
{
|
||||
case UniformType::Mat3:
|
||||
case UniformType::Mat3|kUniformFragmentBit:
|
||||
@@ -2229,7 +2229,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
|
||||
}
|
||||
|
||||
UniformType::Enum type = convertMtlType(dataType);
|
||||
constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), uint32_t(uniform.offset), info->m_handle, uint16_t(num) );
|
||||
constantBuffer->writeUniformHandle(type|fragmentBit, uint32_t(uniform.offset), info->m_handle, uint16_t(num) );
|
||||
BX_TRACE("store %s %d offset:%d", name, info->m_handle, uint32_t(uniform.offset) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4150,7 +4150,7 @@ VK_IMPORT_DEVICE
|
||||
break;
|
||||
}
|
||||
|
||||
UniformType::Enum type;
|
||||
uint8_t type;
|
||||
uint16_t loc;
|
||||
uint16_t num;
|
||||
uint16_t copy;
|
||||
@@ -4168,7 +4168,7 @@ VK_IMPORT_DEVICE
|
||||
data = (const char*)m_uniforms[handle.idx];
|
||||
}
|
||||
|
||||
switch ( (uint32_t)type)
|
||||
switch (type)
|
||||
{
|
||||
case UniformType::Mat3:
|
||||
case UniformType::Mat3|kUniformFragmentBit:
|
||||
@@ -5090,7 +5090,7 @@ VK_DESTROY
|
||||
}
|
||||
|
||||
kind = "user";
|
||||
m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount);
|
||||
m_constantBuffer->writeUniformHandle(type|fragmentBit, regIndex, info->m_handle, regCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user