From c4d4b90e328ee793a6498bfedb10ec7626003ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 27 Oct 2022 19:43:17 -0700 Subject: [PATCH] shaderc: Fixed SPIR-V uniform array size reflection. Issue #2964. --- src/bgfx_p.h | 6 ++++-- tools/shaderc/shaderc_spirv.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index a8f7592de..7c0a712b1 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -4868,7 +4868,7 @@ namespace bgfx } } - _num = bx::max(1, _num); + _num = bx::max(1, _num); uint16_t idx = m_uniformHashMap.find(bx::hash(_name) ); if (kInvalidHandle != idx) @@ -4890,6 +4890,8 @@ namespace bgfx uniform.m_type = oldsize < newsize ? _type : uniform.m_type; uniform.m_num = bx::max(uniform.m_num, _num); + BX_TRACE(" Resize uniform (handle %3d) `%s`, num %d", handle.idx, _name, _num); + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateUniform); cmdbuf.write(handle); cmdbuf.write(uniform.m_type); @@ -4911,7 +4913,7 @@ namespace bgfx return BGFX_INVALID_HANDLE; } - BX_TRACE("Creating uniform (handle %3d) %s", handle.idx, _name); + BX_TRACE("Creating uniform (handle %3d) `%s`, num %d", handle.idx, _name, _num); UniformRef& uniform = m_uniformRef[handle.idx]; uniform.m_name.set(_name); diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index 21885171e..657cb1015 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -652,10 +652,10 @@ namespace bgfx { namespace spirv continue; } - un.num = 0; + un.num = uint8_t(program->getUniformArraySize(ii) ); const uint32_t offset = program->getUniformBufferOffset(ii); un.regIndex = uint16_t(offset); - un.regCount = uint16_t(program->getUniformArraySize(ii)); + un.regCount = un.num; switch (program->getUniformType(ii) ) {