mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Increased number of views to 256. Added view remap support.
This commit is contained in:
parent
ca3a6e5c84
commit
2883be5c1a
7 changed files with 75 additions and 12 deletions
|
@ -1098,6 +1098,15 @@ namespace bgfx
|
|||
/// view will use these matrices.
|
||||
void setViewTransform(uint8_t _id, const void* _view, const void* _projL, uint8_t _flags = BGFX_VIEW_STEREO, const void* _projR = NULL);
|
||||
|
||||
/// Post submit view reordering.
|
||||
///
|
||||
/// @param _id First view id.
|
||||
/// @param _num Number of views to remap.
|
||||
/// @param _remap View remap id table. Passing `NULL` will reset view ids
|
||||
/// to default state.
|
||||
///
|
||||
void setViewRemap(uint8_t _id = 0, uint8_t _num = UINT8_MAX, const void* _remap = NULL);
|
||||
|
||||
/// Sets debug marker.
|
||||
void setMarker(const char* _marker);
|
||||
|
||||
|
|
18
src/bgfx.cpp
18
src/bgfx.cpp
|
@ -797,6 +797,10 @@ namespace bgfx
|
|||
|
||||
void Frame::sort()
|
||||
{
|
||||
for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
|
||||
{
|
||||
m_sortKeys[ii] = SortKey::remapView(m_sortKeys[ii], m_viewRemap);
|
||||
}
|
||||
bx::radixSort64(m_sortKeys, s_ctx->m_tempKeys, m_sortValues, s_ctx->m_tempValues, m_num);
|
||||
}
|
||||
|
||||
|
@ -951,6 +955,11 @@ namespace bgfx
|
|||
BX_TRACE("Multithreaded renderer is disabled.");
|
||||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii)
|
||||
{
|
||||
m_viewRemap[ii] = ii;
|
||||
}
|
||||
|
||||
memset(m_fb, 0xff, sizeof(m_fb) );
|
||||
memset(m_clear, 0, sizeof(m_clear) );
|
||||
memset(m_rect, 0, sizeof(m_rect) );
|
||||
|
@ -1156,6 +1165,8 @@ namespace bgfx
|
|||
freeDynamicBuffers();
|
||||
m_submit->m_resolution = m_resolution;
|
||||
m_submit->m_debug = m_debug;
|
||||
|
||||
memcpy(m_submit->m_viewRemap, m_viewRemap, sizeof(m_viewRemap) );
|
||||
memcpy(m_submit->m_fb, m_fb, sizeof(m_fb) );
|
||||
memcpy(m_submit->m_clear, m_clear, sizeof(m_clear) );
|
||||
memcpy(m_submit->m_rect, m_rect, sizeof(m_rect) );
|
||||
|
@ -2673,6 +2684,13 @@ again:
|
|||
s_ctx->setViewTransform(_id, _view, _projL, _flags, _projR);
|
||||
}
|
||||
|
||||
void setViewRemap(uint8_t _id, uint8_t _num, const void* _remap)
|
||||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
BX_CHECK(_id < BGFX_CONFIG_MAX_VIEWS, "Invalid view id: %d", _id);
|
||||
s_ctx->setViewRemap(_id, _num, _remap);
|
||||
}
|
||||
|
||||
void setMarker(const char* _marker)
|
||||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
|
|
48
src/bgfx_p.h
48
src/bgfx_p.h
|
@ -679,8 +679,10 @@ namespace bgfx
|
|||
};
|
||||
|
||||
#define SORT_KEY_RENDER_DRAW (UINT64_C(1)<<0x2b)
|
||||
#define SORT_KEY_VIEW_SHIFT UINT8_C(0x37)
|
||||
#define SORT_KEY_VIEW_MASK ( (uint64_t(BGFX_CONFIG_MAX_VIEWS-1) )<<SORT_KEY_VIEW_SHIFT)
|
||||
|
||||
BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS <= 32);
|
||||
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
|
||||
|
||||
struct SortKey
|
||||
|
@ -689,7 +691,7 @@ namespace bgfx
|
|||
{
|
||||
// | 3 2 1 0|
|
||||
// |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210|
|
||||
// | vvvvvsssssssssssdttpppppppppdddddddddddddddddddddddddddddddd|
|
||||
// | vvvvvvvvsssssssssssdttpppppppppdddddddddddddddddddddddddddddddd|
|
||||
// | ^ ^^ ^ ^ ^|
|
||||
// | | || | | ||
|
||||
// | view-+ seq-+| +-trans +-program depth-+|
|
||||
|
@ -699,7 +701,7 @@ namespace bgfx
|
|||
const uint64_t program = uint64_t(m_program)<<0x20;
|
||||
const uint64_t trans = uint64_t(m_trans )<<0x29;
|
||||
const uint64_t seq = uint64_t(m_seq )<<0x2c;
|
||||
const uint64_t view = uint64_t(m_view )<<0x37;
|
||||
const uint64_t view = uint64_t(m_view )<<SORT_KEY_VIEW_SHIFT;
|
||||
const uint64_t key = depth|program|trans|SORT_KEY_RENDER_DRAW|seq|view;
|
||||
return key;
|
||||
}
|
||||
|
@ -708,7 +710,7 @@ namespace bgfx
|
|||
{
|
||||
// | 3 2 1 0|
|
||||
// |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210|
|
||||
// | vvvvvsssssssssssdppppppppp |
|
||||
// | vvvvvvvvsssssssssssdppppppppp |
|
||||
// | ^ ^^ ^ |
|
||||
// | | || | |
|
||||
// | view-+ seq-+| +-program |
|
||||
|
@ -716,7 +718,7 @@ namespace bgfx
|
|||
|
||||
const uint64_t program = uint64_t(m_program)<<0x22;
|
||||
const uint64_t seq = uint64_t(m_seq )<<0x2c;
|
||||
const uint64_t view = uint64_t(m_view )<<0x37;
|
||||
const uint64_t view = uint64_t(m_view )<<SORT_KEY_VIEW_SHIFT;
|
||||
const uint64_t key = program|seq|view;
|
||||
return key;
|
||||
}
|
||||
|
@ -725,7 +727,7 @@ namespace bgfx
|
|||
bool decode(uint64_t _key)
|
||||
{
|
||||
m_seq = (_key>>0x2c)& 0x7ff;
|
||||
m_view = (_key>>0x37)&(BGFX_CONFIG_MAX_VIEWS-1);
|
||||
m_view = uint8_t( (_key&SORT_KEY_VIEW_MASK)>>SORT_KEY_VIEW_SHIFT);
|
||||
if (_key & SORT_KEY_RENDER_DRAW)
|
||||
{
|
||||
m_depth = _key & 0xffffffff;
|
||||
|
@ -738,6 +740,21 @@ namespace bgfx
|
|||
return true; // compute
|
||||
}
|
||||
|
||||
bool decode(uint64_t _key, uint8_t _viewRemap[BGFX_CONFIG_MAX_VIEWS])
|
||||
{
|
||||
bool compute = decode(_key);
|
||||
m_view = _viewRemap[m_view];
|
||||
return compute;
|
||||
}
|
||||
|
||||
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;
|
||||
return key;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_depth = 0;
|
||||
|
@ -1564,6 +1581,7 @@ namespace bgfx
|
|||
|
||||
SortKey m_key;
|
||||
|
||||
uint8_t m_viewRemap[BGFX_CONFIG_MAX_VIEWS];
|
||||
FrameBufferHandle m_fb[BGFX_CONFIG_MAX_VIEWS];
|
||||
Clear m_clear[BGFX_CONFIG_MAX_VIEWS];
|
||||
float m_clearColor[BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE][4];
|
||||
|
@ -3038,6 +3056,23 @@ namespace bgfx
|
|||
}
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(void setViewRemap(uint8_t _id, uint8_t _num, const void* _remap) )
|
||||
{
|
||||
const uint32_t num = bx::uint32_min( (BGFX_CONFIG_MAX_VIEWS - _id) + _num, BGFX_CONFIG_MAX_VIEWS) - _id;
|
||||
if (NULL == _remap)
|
||||
{
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
uint8_t id = uint8_t(ii+_id);
|
||||
m_viewRemap[id] = id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&m_viewRemap[_id], _remap, num);
|
||||
}
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(void setMarker(const char* _marker) )
|
||||
{
|
||||
m_submit->setMarker(_marker);
|
||||
|
@ -3358,6 +3393,7 @@ namespace bgfx
|
|||
FrameBufferRef m_frameBufferRef[BGFX_CONFIG_MAX_FRAME_BUFFERS];
|
||||
VertexDeclRef m_declRef;
|
||||
|
||||
uint8_t m_viewRemap[BGFX_CONFIG_MAX_VIEWS];
|
||||
FrameBufferHandle m_fb[BGFX_CONFIG_MAX_VIEWS];
|
||||
Clear m_clear[BGFX_CONFIG_MAX_VIEWS];
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@
|
|||
|
||||
#ifndef BGFX_CONFIG_MAX_VIEWS
|
||||
// Do not change. Must be power of 2.
|
||||
# define BGFX_CONFIG_MAX_VIEWS 32
|
||||
# define BGFX_CONFIG_MAX_VIEWS 256
|
||||
#endif // BGFX_CONFIG_MAX_VIEWS
|
||||
|
||||
#define BGFX_CONFIG_MAX_VIEW_NAME_RESERVED 5
|
||||
|
|
|
@ -726,7 +726,7 @@ namespace bgfx
|
|||
}
|
||||
|
||||
// Init reserved part of view name.
|
||||
for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||
{
|
||||
char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1];
|
||||
bx::snprintf(name, sizeof(name), "%3d ", ii);
|
||||
|
@ -3051,7 +3051,7 @@ namespace bgfx
|
|||
int32_t numItems = _render->m_num;
|
||||
for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;)
|
||||
{
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item]);
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item], _render->m_viewRemap);
|
||||
const bool viewChanged = 0
|
||||
|| key.m_view != view
|
||||
|| item == numItems
|
||||
|
|
|
@ -570,7 +570,7 @@ namespace bgfx
|
|||
}
|
||||
|
||||
// Init reserved part of view name.
|
||||
for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||
{
|
||||
char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1];
|
||||
bx::snprintf(name, sizeof(name), "%3d ", ii);
|
||||
|
@ -2864,7 +2864,7 @@ namespace bgfx
|
|||
{
|
||||
for (uint32_t item = 0, numItems = _render->m_num; item < numItems; ++item)
|
||||
{
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item]);
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item], _render->m_viewRemap);
|
||||
|
||||
if (isCompute)
|
||||
{
|
||||
|
|
|
@ -4292,7 +4292,7 @@ namespace bgfx
|
|||
int32_t numItems = _render->m_num;
|
||||
for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;)
|
||||
{
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item]);
|
||||
const bool isCompute = key.decode(_render->m_sortKeys[item], _render->m_viewRemap);
|
||||
const bool viewChanged = 0
|
||||
|| key.m_view != view
|
||||
|| item == numItems
|
||||
|
|
Loading…
Reference in a new issue