Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't encode invalid programs as valid unrelated programs #2231

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,11 +1247,7 @@ namespace bgfx
UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx];
m_uniformEnd = uniformBuffer->getPos();

m_key.m_program = isValid(_program)
? _program
: ProgramHandle{0}
;

m_key.m_program = _program;
m_key.m_view = _id;

SortKey::Enum type = SortKey::SortProgram;
Expand Down
18 changes: 14 additions & 4 deletions src/bgfx_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,23 +1161,33 @@ namespace bgfx
uint64_t type = _key & kSortKeyDrawTypeMask;
if (type == kSortKeyDrawTypeDepth)
{
m_program.idx = uint16_t( (_key & kSortKeyDraw1ProgramMask) >> kSortKeyDraw1ProgramShift);
m_program = decodeProgram( _key, kSortKeyDraw1ProgramMask, kSortKeyDraw1ProgramShift);
return false;
}
else if (type == kSortKeyDrawTypeSequence)
{
m_program.idx = uint16_t( (_key & kSortKeyDraw2ProgramMask) >> kSortKeyDraw2ProgramShift);
m_program = decodeProgram( _key, kSortKeyDraw2ProgramMask, kSortKeyDraw2ProgramShift);
return false;
}

m_program.idx = uint16_t( (_key & kSortKeyDraw0ProgramMask) >> kSortKeyDraw0ProgramShift);
m_program = decodeProgram( _key, kSortKeyDraw0ProgramMask, kSortKeyDraw0ProgramShift);
return false; // draw
}

m_program.idx = uint16_t( (_key & kSortKeyComputeProgramMask) >> kSortKeyComputeProgramShift);
m_program = decodeProgram( _key, kSortKeyComputeProgramMask, kSortKeyComputeProgramShift);
return true; // compute
}

static ProgramHandle decodeProgram(uint64_t _key, uint64_t _mask, uint8_t _shift)
{
uint16_t idx = uint16_t( (_key & _mask) >> _shift);
if (idx == (_mask >> _shift))
{
return ProgramHandle{kInvalidHandle};
}
return ProgramHandle{idx};
}

static ViewId decodeView(uint64_t _key)
{
return ViewId( (_key & kSortKeyViewMask) >> kSortKeyViewBitShift);
Expand Down