mirror of https://github.com/bkaradzic/bgfx
Updated sort key.
This commit is contained in:
parent
9720aa8d0a
commit
d8968e1214
27
src/bgfx.cpp
27
src/bgfx.cpp
|
@ -1154,13 +1154,26 @@ namespace bgfx
|
|||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("Sort key masks:");
|
||||
BX_TRACE("\t View %016" PRIx64, SORT_KEY_VIEW_MASK);
|
||||
BX_TRACE("\t Draw bit %016" PRIx64, SORT_KEY_DRAW_BIT);
|
||||
BX_TRACE("\t Seq %016" PRIx64, SORT_KEY_SEQ_MASK);
|
||||
BX_TRACE("\tD Trans %016" PRIx64, SORT_KEY_DRAW_TRANS_MASK);
|
||||
BX_TRACE("\tD Program %016" PRIx64, SORT_KEY_DRAW_PROGRAM_MASK);
|
||||
BX_TRACE("\tC Program %016" PRIx64, SORT_KEY_COMPUTE_PROGRAM_MASK);
|
||||
BX_TRACE("\tD Depth %016" PRIx64, SORT_KEY_DRAW_DEPTH_MASK);
|
||||
BX_TRACE("\t View %016" PRIx64, SORT_KEY_VIEW_MASK);
|
||||
BX_TRACE("\t Draw bit %016" PRIx64, SORT_KEY_DRAW_BIT);
|
||||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("\tD Type %016" PRIx64, SORT_KEY_DRAW_TYPE_BIT);
|
||||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("\tD0 Seq %016" PRIx64, SORT_KEY_DRAW_0_SEQ_MASK);
|
||||
BX_TRACE("\tD0 Trans %016" PRIx64, SORT_KEY_DRAW_0_TRANS_MASK);
|
||||
BX_TRACE("\tD0 Program %016" PRIx64, SORT_KEY_DRAW_0_PROGRAM_MASK);
|
||||
BX_TRACE("\tD0 Depth %016" PRIx64, SORT_KEY_DRAW_0_DEPTH_MASK);
|
||||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("\tD1 Depth %016" PRIx64, SORT_KEY_DRAW_1_DEPTH_MASK);
|
||||
BX_TRACE("\tD1 Trans %016" PRIx64, SORT_KEY_DRAW_1_TRANS_MASK);
|
||||
BX_TRACE("\tD1 Program %016" PRIx64, SORT_KEY_DRAW_1_PROGRAM_MASK);
|
||||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("\t C Seq %016" PRIx64, SORT_KEY_COMPUTE_SEQ_MASK);
|
||||
BX_TRACE("\t C Program %016" PRIx64, SORT_KEY_COMPUTE_PROGRAM_MASK);
|
||||
|
||||
BX_TRACE("");
|
||||
BX_TRACE("Supported capabilities (renderer %s, vendor 0x%04x, device 0x%04x):"
|
||||
|
|
184
src/bgfx_p.h
184
src/bgfx_p.h
|
@ -724,75 +724,143 @@ namespace bgfx
|
|||
|
||||
#define SORT_KEY_NUM_BITS_TRANS 2
|
||||
|
||||
#define SORT_KEY_DRAW_BIT (UINT64_C(1)<<0x36)
|
||||
|
||||
#define SORT_KEY_VIEW_SHIFT 0x37
|
||||
#define SORT_KEY_VIEW_SHIFT 56
|
||||
#define SORT_KEY_VIEW_MASK ( (uint64_t(BGFX_CONFIG_MAX_VIEWS-1) )<<SORT_KEY_VIEW_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_DEPTH_SHIFT 0
|
||||
#define SORT_KEY_DRAW_DEPTH_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<SORT_KEY_DRAW_DEPTH_SHIFT)
|
||||
#define SORT_KEY_DRAW_BIT_SHIFT (SORT_KEY_VIEW_SHIFT - 1)
|
||||
#define SORT_KEY_DRAW_BIT (UINT64_C(1)<<SORT_KEY_DRAW_BIT_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_PROGRAM_SHIFT (SORT_KEY_DRAW_DEPTH_SHIFT+BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)
|
||||
#define SORT_KEY_DRAW_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_PROGRAM_SHIFT)
|
||||
//
|
||||
#define SORT_KEY_DRAW_TYPE_BIT_SHIFT (SORT_KEY_DRAW_BIT_SHIFT - 1)
|
||||
#define SORT_KEY_DRAW_TYPE_BIT (UINT64_C(1)<<SORT_KEY_DRAW_TYPE_BIT_SHIFT)
|
||||
|
||||
#define SORT_KEY_COMPUTE_PROGRAM_SHIFT (SORT_KEY_DRAW_DEPTH_SHIFT+BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH+SORT_KEY_NUM_BITS_TRANS)
|
||||
//
|
||||
#define SORT_KEY_DRAW_0_SEQ_SHIFT (SORT_KEY_DRAW_TYPE_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)
|
||||
#define SORT_KEY_DRAW_0_SEQ_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<SORT_KEY_DRAW_0_SEQ_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_0_TRANS_SHIFT (SORT_KEY_DRAW_0_SEQ_SHIFT - SORT_KEY_NUM_BITS_TRANS)
|
||||
#define SORT_KEY_DRAW_0_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_0_TRANS_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_0_PROGRAM_SHIFT (SORT_KEY_DRAW_0_TRANS_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM)
|
||||
#define SORT_KEY_DRAW_0_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_0_PROGRAM_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_0_DEPTH_SHIFT (SORT_KEY_DRAW_0_PROGRAM_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)
|
||||
#define SORT_KEY_DRAW_0_DEPTH_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<SORT_KEY_DRAW_0_DEPTH_SHIFT)
|
||||
|
||||
//
|
||||
#define SORT_KEY_DRAW_1_DEPTH_SHIFT (SORT_KEY_DRAW_TYPE_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)
|
||||
#define SORT_KEY_DRAW_1_DEPTH_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<SORT_KEY_DRAW_1_DEPTH_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_1_TRANS_SHIFT (SORT_KEY_DRAW_1_DEPTH_SHIFT - SORT_KEY_NUM_BITS_TRANS)
|
||||
#define SORT_KEY_DRAW_1_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_1_TRANS_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_1_PROGRAM_SHIFT (SORT_KEY_DRAW_1_TRANS_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM)
|
||||
#define SORT_KEY_DRAW_1_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_1_PROGRAM_SHIFT)
|
||||
|
||||
//
|
||||
#define SORT_KEY_COMPUTE_SEQ_SHIFT (SORT_KEY_DRAW_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)
|
||||
#define SORT_KEY_COMPUTE_SEQ_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<SORT_KEY_COMPUTE_SEQ_SHIFT)
|
||||
|
||||
#define SORT_KEY_COMPUTE_PROGRAM_SHIFT (SORT_KEY_COMPUTE_SEQ_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM)
|
||||
#define SORT_KEY_COMPUTE_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_COMPUTE_PROGRAM_SHIFT)
|
||||
|
||||
#define SORT_KEY_DRAW_TRANS_SHIFT (SORT_KEY_DRAW_PROGRAM_SHIFT+BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM)
|
||||
#define SORT_KEY_DRAW_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_TRANS_SHIFT)
|
||||
|
||||
#define SORT_KEY_SEQ_SHIFT (SORT_KEY_DRAW_TRANS_SHIFT+SORT_KEY_NUM_BITS_TRANS)
|
||||
#define SORT_KEY_SEQ_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<SORT_KEY_SEQ_SHIFT)
|
||||
|
||||
BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS <= 256);
|
||||
BX_STATIC_ASSERT( (BGFX_CONFIG_MAX_PROGRAMS & (BGFX_CONFIG_MAX_PROGRAMS-1) ) == 0); // Must be power of 2.
|
||||
BX_STATIC_ASSERT( (0 // Render key mask shouldn't overlap.
|
||||
| SORT_KEY_DRAW_BIT
|
||||
| SORT_KEY_SEQ_MASK
|
||||
| SORT_KEY_VIEW_MASK
|
||||
| SORT_KEY_DRAW_TRANS_MASK
|
||||
| SORT_KEY_DRAW_PROGRAM_MASK
|
||||
| SORT_KEY_DRAW_DEPTH_MASK
|
||||
| SORT_KEY_DRAW_BIT
|
||||
| SORT_KEY_DRAW_TYPE_BIT
|
||||
| SORT_KEY_DRAW_0_SEQ_MASK
|
||||
| SORT_KEY_DRAW_0_TRANS_MASK
|
||||
| SORT_KEY_DRAW_0_PROGRAM_MASK
|
||||
| SORT_KEY_DRAW_0_DEPTH_MASK
|
||||
) == (0
|
||||
^ SORT_KEY_DRAW_BIT
|
||||
^ SORT_KEY_SEQ_MASK
|
||||
^ SORT_KEY_VIEW_MASK
|
||||
^ SORT_KEY_DRAW_TRANS_MASK
|
||||
^ SORT_KEY_DRAW_PROGRAM_MASK
|
||||
^ SORT_KEY_DRAW_DEPTH_MASK
|
||||
^ SORT_KEY_DRAW_BIT
|
||||
^ SORT_KEY_DRAW_TYPE_BIT
|
||||
^ SORT_KEY_DRAW_0_SEQ_MASK
|
||||
^ SORT_KEY_DRAW_0_TRANS_MASK
|
||||
^ SORT_KEY_DRAW_0_PROGRAM_MASK
|
||||
^ SORT_KEY_DRAW_0_DEPTH_MASK
|
||||
) );
|
||||
BX_STATIC_ASSERT( (0 // Render key mask shouldn't overlap.
|
||||
| SORT_KEY_VIEW_MASK
|
||||
| SORT_KEY_DRAW_BIT
|
||||
| SORT_KEY_DRAW_TYPE_BIT
|
||||
| SORT_KEY_DRAW_1_DEPTH_MASK
|
||||
| SORT_KEY_DRAW_1_TRANS_MASK
|
||||
| SORT_KEY_DRAW_1_PROGRAM_MASK
|
||||
) == (0
|
||||
^ SORT_KEY_VIEW_MASK
|
||||
^ SORT_KEY_DRAW_BIT
|
||||
^ SORT_KEY_DRAW_TYPE_BIT
|
||||
^ SORT_KEY_DRAW_1_DEPTH_MASK
|
||||
^ SORT_KEY_DRAW_1_TRANS_MASK
|
||||
^ SORT_KEY_DRAW_1_PROGRAM_MASK
|
||||
) );
|
||||
BX_STATIC_ASSERT( (0 // Compute key mask shouldn't overlap.
|
||||
| SORT_KEY_DRAW_BIT
|
||||
| SORT_KEY_SEQ_MASK
|
||||
| SORT_KEY_VIEW_MASK
|
||||
| SORT_KEY_DRAW_BIT
|
||||
| SORT_KEY_COMPUTE_SEQ_SHIFT
|
||||
| SORT_KEY_COMPUTE_PROGRAM_MASK
|
||||
) == (0
|
||||
^ SORT_KEY_DRAW_BIT
|
||||
^ SORT_KEY_SEQ_MASK
|
||||
^ SORT_KEY_VIEW_MASK
|
||||
^ SORT_KEY_DRAW_BIT
|
||||
^ SORT_KEY_COMPUTE_SEQ_SHIFT
|
||||
^ SORT_KEY_COMPUTE_PROGRAM_MASK
|
||||
) );
|
||||
|
||||
// | 3 2 1 0|
|
||||
// |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210| Common
|
||||
// |vvvvvvvvd |
|
||||
// | ^^ |
|
||||
// | || |
|
||||
// | view-+| |
|
||||
// | +-draw |
|
||||
// |----------------------------------------------------------------| Draw Key 0
|
||||
// | |ksssssssssssttpppppppppdddddddddddddddddddddddddddddddd|
|
||||
// | | ^ ^ ^ ^|
|
||||
// | | | | | ||
|
||||
// | | seq-+ +-trans +-program depth-+|
|
||||
// | | |
|
||||
// |----------------------------------------------------------------| Draw Key 1
|
||||
// | |kddddddddddddddddddddddddddddddddttppppppppp |
|
||||
// | | ^^ ^ ^ |
|
||||
// | | || +-trans | |
|
||||
// | | depth-+ program-+ |
|
||||
// | | |
|
||||
// |----------------------------------------------------------------| Compute Key
|
||||
// | |sssssssssssppppppppp |
|
||||
// | | ^ ^ |
|
||||
// | | | | |
|
||||
// | | seq-+ +-program |
|
||||
// | | |
|
||||
// |--------+-------------------------------------------------------|
|
||||
//
|
||||
struct SortKey
|
||||
{
|
||||
uint64_t encodeDraw()
|
||||
uint64_t encodeDraw(bool _key1 = false)
|
||||
{
|
||||
// | 3 2 1 0|
|
||||
// |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210|
|
||||
// | vvvvvvvvdsssssssssssttpppppppppdddddddddddddddddddddddddddddddd|
|
||||
// | ^^ ^ ^ ^ ^|
|
||||
// | || | | | ||
|
||||
// | view-+| seq-+ +-trans +-program depth-+|
|
||||
// | +-draw |
|
||||
if (_key1)
|
||||
{
|
||||
const uint64_t depth = (uint64_t(m_depth ) << SORT_KEY_DRAW_1_DEPTH_SHIFT ) & SORT_KEY_DRAW_1_DEPTH_MASK;
|
||||
const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_1_PROGRAM_SHIFT) & SORT_KEY_DRAW_1_PROGRAM_MASK;
|
||||
const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_1_TRANS_SHIFT ) & SORT_KEY_DRAW_1_TRANS_MASK;
|
||||
const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK;
|
||||
const uint64_t key = view|SORT_KEY_DRAW_BIT|SORT_KEY_DRAW_TYPE_BIT|depth|trans|program;
|
||||
|
||||
const uint64_t depth = (uint64_t(m_depth ) << SORT_KEY_DRAW_DEPTH_SHIFT ) & SORT_KEY_DRAW_DEPTH_MASK;
|
||||
const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_PROGRAM_SHIFT) & SORT_KEY_DRAW_PROGRAM_MASK;
|
||||
const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_TRANS_SHIFT ) & SORT_KEY_DRAW_TRANS_MASK;
|
||||
const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_SEQ_SHIFT ) & SORT_KEY_SEQ_MASK;
|
||||
const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK;
|
||||
const uint64_t key = depth|program|trans|SORT_KEY_DRAW_BIT|seq|view;
|
||||
return key;
|
||||
}
|
||||
|
||||
BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_SEQ_SHIFT), "SortKey error, sequence is truncated (m_seq: %d)."
|
||||
const uint64_t depth = (uint64_t(m_depth ) << SORT_KEY_DRAW_0_DEPTH_SHIFT ) & SORT_KEY_DRAW_0_DEPTH_MASK;
|
||||
const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_0_PROGRAM_SHIFT) & SORT_KEY_DRAW_0_PROGRAM_MASK;
|
||||
const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_0_TRANS_SHIFT ) & SORT_KEY_DRAW_0_TRANS_MASK;
|
||||
const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_DRAW_0_SEQ_SHIFT ) & SORT_KEY_DRAW_0_SEQ_MASK;
|
||||
const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK;
|
||||
const uint64_t key = view|SORT_KEY_DRAW_BIT|seq|trans|program|depth;
|
||||
|
||||
BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_DRAW_0_SEQ_SHIFT)
|
||||
, "SortKey error, sequence is truncated (m_seq: %d)."
|
||||
, m_seq
|
||||
);
|
||||
|
||||
|
@ -801,20 +869,13 @@ namespace bgfx
|
|||
|
||||
uint64_t encodeCompute()
|
||||
{
|
||||
// | 3 2 1 0|
|
||||
// |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210|
|
||||
// | vvvvvvvvdsssssssssssppppppppp |
|
||||
// | ^^ ^ ^ |
|
||||
// | || | | |
|
||||
// | view-+| seq-+ +-program |
|
||||
// | +-draw |
|
||||
|
||||
const uint64_t program = (uint64_t(m_program) << SORT_KEY_COMPUTE_PROGRAM_SHIFT) & SORT_KEY_COMPUTE_PROGRAM_MASK;
|
||||
const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_SEQ_SHIFT ) & SORT_KEY_SEQ_MASK;
|
||||
const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_COMPUTE_SEQ_SHIFT ) & SORT_KEY_COMPUTE_SEQ_MASK;
|
||||
const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK;
|
||||
const uint64_t key = program|seq|view;
|
||||
|
||||
BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_SEQ_SHIFT), "SortKey error, sequence is truncated (m_seq: %d)."
|
||||
BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_COMPUTE_SEQ_SHIFT)
|
||||
, "SortKey error, sequence is truncated (m_seq: %d)."
|
||||
, m_seq
|
||||
);
|
||||
|
||||
|
@ -824,13 +885,16 @@ namespace bgfx
|
|||
/// Returns true if item is compute command.
|
||||
bool decode(uint64_t _key, uint8_t _viewRemap[BGFX_CONFIG_MAX_VIEWS])
|
||||
{
|
||||
m_seq = uint32_t( (_key & SORT_KEY_SEQ_MASK ) >> SORT_KEY_SEQ_SHIFT);
|
||||
m_view = _viewRemap[(_key & SORT_KEY_VIEW_MASK) >> SORT_KEY_VIEW_SHIFT];
|
||||
if (_key & SORT_KEY_DRAW_BIT)
|
||||
{
|
||||
m_depth = uint32_t( (_key & SORT_KEY_DRAW_DEPTH_MASK ) >> SORT_KEY_DRAW_DEPTH_SHIFT);
|
||||
m_program = uint16_t( (_key & SORT_KEY_DRAW_PROGRAM_MASK) >> SORT_KEY_DRAW_PROGRAM_SHIFT);
|
||||
m_trans = uint8_t( (_key & SORT_KEY_DRAW_TRANS_MASK ) >> SORT_KEY_DRAW_TRANS_SHIFT);
|
||||
if (_key & SORT_KEY_DRAW_TYPE_BIT)
|
||||
{
|
||||
m_program = uint16_t( (_key & SORT_KEY_DRAW_1_PROGRAM_MASK) >> SORT_KEY_DRAW_1_PROGRAM_SHIFT);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_program = uint16_t( (_key & SORT_KEY_DRAW_0_PROGRAM_MASK) >> SORT_KEY_DRAW_0_PROGRAM_SHIFT);
|
||||
return false; // draw
|
||||
}
|
||||
|
||||
|
@ -845,9 +909,9 @@ namespace bgfx
|
|||
|
||||
static uint64_t remapView(uint64_t _key, uint8_t _viewRemap[BGFX_CONFIG_MAX_VIEWS])
|
||||
{
|
||||
const uint8_t oldView = uint8_t( (_key & SORT_KEY_VIEW_MASK) >> SORT_KEY_VIEW_SHIFT);
|
||||
const uint64_t view = uint64_t(_viewRemap[oldView]) << SORT_KEY_VIEW_SHIFT;
|
||||
const uint64_t key = (_key & ~SORT_KEY_VIEW_MASK) | view;
|
||||
const uint8_t oldView = uint8_t( (_key & SORT_KEY_VIEW_MASK) >> SORT_KEY_VIEW_SHIFT);
|
||||
const uint64_t view = uint64_t(_viewRemap[oldView]) << SORT_KEY_VIEW_SHIFT;
|
||||
const uint64_t key = (_key & ~SORT_KEY_VIEW_MASK) | view;
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue