diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index 458e180e3..70b4f0032 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -1,5 +1,5 @@ /* - * Copyright 2011-2019 Branimir Karadzic. All rights reserved. + * Copyright 2011-2020 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ @@ -201,6 +201,38 @@ public static partial class bgfx CullCcw = 0x0000002000000000, CullShift = 36, CullMask = 0x0000003000000000, + + /// + /// Discard only Index Buffer + /// + DiscardIndexBuffer = 0x0000000000000001, + + /// + /// Discard only Vertex Streams + /// + DiscardVertexStreams = 0x0000000000000002, + + /// + /// Discard only texture samplers + /// + DiscardTextureSamplers = 0x0000000000000003, + + /// + /// Discard only Compute shader related state + /// + DiscardCompute = 0x0000000000000004, + + /// + /// Discard only state + /// + DiscardState = 0x0000000000000005, + + /// + /// Discard every rendering states + /// + DiscardAll = 0xffffffffffffffff, + DiscardShift = 0, + DiscardMask = 0x0000000000000007, AlphaRefShift = 40, AlphaRefMask = 0x0000ff0000000000, @@ -3787,11 +3819,13 @@ public static partial class bgfx public static extern unsafe void encoder_dispatch_indirect(Encoder* _this, ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num); /// - /// Discard all previously set state for draw or compute call. + /// Discard previously set state for draw or compute call. /// /// + /// rendering states to discard + /// [DllImport(DllName, EntryPoint="bgfx_encoder_discard", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void encoder_discard(Encoder* _this); + public static extern unsafe void encoder_discard(Encoder* _this, ulong _flags); /// /// Blit 2D texture region between two 2D textures. @@ -4300,11 +4334,13 @@ public static partial class bgfx public static extern unsafe void dispatch_indirect(ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num); /// - /// Discard all previously set state for draw or compute call. + /// Discard previously set state for draw or compute call. /// /// + /// rendering states to discard + /// [DllImport(DllName, EntryPoint="bgfx_discard", CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void discard(); + public static extern unsafe void discard(ulong _flags); /// /// Blit 2D texture region between two 2D textures. diff --git a/bindings/d/funcs.d b/bindings/d/funcs.d index 71f9e51be..027dc8c79 100644 --- a/bindings/d/funcs.d +++ b/bindings/d/funcs.d @@ -1571,9 +1571,11 @@ version(BindBgfx_Static) void bgfx_encoder_dispatch_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, ushort _start, ushort _num); /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * Params: + * _flags = rendering states to discard */ - void bgfx_encoder_discard(bgfx_encoder_t* _this); + void bgfx_encoder_discard(bgfx_encoder_t* _this, ulong _flags); /** * Blit 2D texture region between two 2D textures. @@ -2028,9 +2030,11 @@ version(BindBgfx_Static) void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, ushort _start, ushort _num); /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * Params: + * _flags = rendering states to discard */ - void bgfx_discard(); + void bgfx_discard(ulong _flags); /** * Blit 2D texture region between two 2D textures. @@ -3763,9 +3767,11 @@ else da_bgfx_encoder_dispatch_indirect bgfx_encoder_dispatch_indirect; /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * Params: + * _flags = rendering states to discard */ - alias da_bgfx_encoder_discard = void function(bgfx_encoder_t* _this); + alias da_bgfx_encoder_discard = void function(bgfx_encoder_t* _this, ulong _flags); da_bgfx_encoder_discard bgfx_encoder_discard; /** @@ -4262,9 +4268,11 @@ else da_bgfx_dispatch_indirect bgfx_dispatch_indirect; /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * Params: + * _flags = rendering states to discard */ - alias da_bgfx_discard = void function(); + alias da_bgfx_discard = void function(ulong _flags); da_bgfx_discard bgfx_discard; /** diff --git a/bindings/d/types.d b/bindings/d/types.d index 52a4cfda8..2c41cc7a9 100644 --- a/bindings/d/types.d +++ b/bindings/d/types.d @@ -75,6 +75,16 @@ enum ulong BGFX_STATE_CULL_CCW = 0x0000002000000000; /// Cull counter-clockwise enum ulong BGFX_STATE_CULL_SHIFT = 36; /// Culling mode bit shift enum ulong BGFX_STATE_CULL_MASK = 0x0000003000000000; /// Culling mode bit mask +/// Rendering state discard. When state is preserved in submit, rendering states can be discarded on a finer grain. +enum ulong BGFX_STATE_DISCARD_INDEX_BUFFER = 0x0000000000000001; /// Discard only Index Buffer +enum ulong BGFX_STATE_DISCARD_VERTEX_STREAMS = 0x0000000000000002; /// Discard only Vertex Streams +enum ulong BGFX_STATE_DISCARD_TEXTURE_SAMPLERS = 0x0000000000000003; /// Discard only texture samplers +enum ulong BGFX_STATE_DISCARD_COMPUTE = 0x0000000000000004; /// Discard only Compute shader related state +enum ulong BGFX_STATE_DISCARD_STATE = 0x0000000000000005; /// Discard only state +enum ulong BGFX_STATE_DISCARD_ALL = 0xffffffffffffffff; /// Discard every rendering states +enum ulong BGFX_STATE_DISCARD_SHIFT = 0; /// Discard flags bit shift +enum ulong BGFX_STATE_DISCARD_MASK = 0x0000000000000007; /// Discard flags bit mask + /// Alpha reference value. enum ulong BGFX_STATE_ALPHA_REF_SHIFT = 40; /// Alpha reference bit shift enum ulong BGFX_STATE_ALPHA_REF_MASK = 0x0000ff0000000000; /// Alpha reference bit mask diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index 7bface50c..5f58efabf 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -272,7 +272,7 @@ void VectorDisplay::endFrame() } } - bgfx::discard(); + bgfx::discard(BGFX_STATE_DISCARD_ALL); //now do last pass, combination of blur and normal buffer to screen bgfx::setViewTransform(viewCounter, NULL, proj); diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 29784a0f9..bf4325a65 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -1590,7 +1590,7 @@ namespace bgfx /// /// @attention C99 equivalent is `bgfx_encoder_discard`. /// - void discard(); + void discard(uint64_t flags); /// Blit texture 2D region between two 2D textures. /// @@ -3985,7 +3985,7 @@ namespace bgfx /// /// @attention C99 equivalent is `bgfx_discard`. /// - void discard(); + void discard(uint64_t flags); /// Blit 2D texture region between two 2D textures. /// diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 972740e66..f2e41fc64 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -2670,10 +2670,12 @@ BGFX_C_API void bgfx_encoder_dispatch(bgfx_encoder_t* _this, bgfx_view_id_t _id, BGFX_C_API void bgfx_encoder_dispatch_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num); /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * + * @param[in] _flags rendering states to discard * */ -BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this); +BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this, uint64_t _flags); /** * Blit 2D texture region between two 2D textures. @@ -3186,10 +3188,12 @@ BGFX_C_API void bgfx_dispatch(bgfx_view_id_t _id, bgfx_program_handle_t _program BGFX_C_API void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num); /** - * Discard all previously set state for draw or compute call. + * Discard previously set state for draw or compute call. + * + * @param[in] _flags rendering states to discard * */ -BGFX_C_API void bgfx_discard(void); +BGFX_C_API void bgfx_discard(uint64_t _flags); /** * Blit 2D texture region between two 2D textures. @@ -3554,7 +3558,7 @@ struct bgfx_interface_vtbl void (*encoder_set_image)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); void (*encoder_dispatch)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ); void (*encoder_dispatch_indirect)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num); - void (*encoder_discard)(bgfx_encoder_t* _this); + void (*encoder_discard)(bgfx_encoder_t* _this, uint64_t _flags); void (*encoder_blit)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); void (*request_screen_shot)(bgfx_frame_buffer_handle_t _handle, const char* _filePath); bgfx_render_frame_t (*render_frame)(int32_t _msecs); @@ -3596,7 +3600,7 @@ struct bgfx_interface_vtbl void (*set_image)(uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format); void (*dispatch)(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ); void (*dispatch_indirect)(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num); - void (*discard)(void); + void (*discard)(uint64_t _flags); void (*blit)(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth); }; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 4a1261b9d..a7ecc0ef1 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -99,6 +99,19 @@ #define BGFX_STATE_CULL_SHIFT 36 //!< Culling mode bit shift #define BGFX_STATE_CULL_MASK UINT64_C(0x0000003000000000) //!< Culling mode bit mask +/** + * Rendering state discard. When state is preserved in submit, rendering states can be discarded on a finer grain. + * + */ +#define BGFX_STATE_DISCARD_INDEX_BUFFER UINT64_C(0x0000000000000001) //!< Discard only Index Buffer +#define BGFX_STATE_DISCARD_VERTEX_STREAMS UINT64_C(0x0000000000000002) //!< Discard only Vertex Streams +#define BGFX_STATE_DISCARD_TEXTURE_SAMPLERS UINT64_C(0x0000000000000003) //!< Discard only texture samplers +#define BGFX_STATE_DISCARD_COMPUTE UINT64_C(0x0000000000000004) //!< Discard only Compute shader related state +#define BGFX_STATE_DISCARD_STATE UINT64_C(0x0000000000000005) //!< Discard only state +#define BGFX_STATE_DISCARD_ALL UINT64_C(0xffffffffffffffff) //!< Discard every rendering states +#define BGFX_STATE_DISCARD_SHIFT 0 //!< Discard flags bit shift +#define BGFX_STATE_DISCARD_MASK UINT64_C(0x0000000000000007) //!< Discard flags bit mask + /** * Alpha reference value. * diff --git a/scripts/bgfx.idl b/scripts/bgfx.idl index e02d257de..958e026e4 100644 --- a/scripts/bgfx.idl +++ b/scripts/bgfx.idl @@ -83,6 +83,16 @@ flag.StateCull { bits = 64, shift = 36, range = 2, base = 1, desc = "Culling mod .Ccw --- Cull counter-clockwise triangles. () +--- Rendering state discard. When state is preserved in submit, rendering states can be discarded on a finer grain. +flag.StateDiscard { bits = 64, shift = 0, range = 3, base = 1, desc = "Discard flags" } + .IndexBuffer --- Discard only Index Buffer + .VertexStreams --- Discard only Vertex Streams + .TextureSamplers --- Discard only texture samplers + .Compute --- Discard only Compute shader related state + .State --- Discard only state + .All (0xffffffffffffffff) --- Discard every rendering states + () + --- Alpha reference value. flag.StateAlphaRef { bits = 64, shift = 40, range = 8, desc = "Alpha reference", "helper" } @@ -2421,11 +2431,11 @@ func.Encoder.dispatch .id "ViewId" --- View id. .program "ProgramHandle" --- Compute program. .numX "uint32_t" --- Number of groups X. - { deafult = 1 } + { default = 1 } .numY "uint32_t" --- Number of groups Y. - { deafult = 1 } + { default = 1 } .numZ "uint32_t" --- Number of groups Z. - { deafult = 1 } + { default = 1 } --- Dispatch compute indirect. func.Encoder.dispatch { cname = "dispatch_indirect" } @@ -2434,13 +2444,14 @@ func.Encoder.dispatch { cname = "dispatch_indirect" } .program "ProgramHandle" --- Compute program. .indirectHandle "IndirectBufferHandle" --- Indirect buffer. .start "uint16_t" --- First element in indirect buffer. - { deafult = 0 } + { default = 0 } .num "uint16_t" --- Number of dispatches. - { deafult = 1 } + { default = 1 } ---- Discard all previously set state for draw or compute call. +--- Discard previously set state for draw or compute call. func.Encoder.discard "void" + .flags "uint64_t" --- rendering states to discard --- Blit 2D texture region between two 2D textures. --- @@ -2931,11 +2942,11 @@ func.dispatch .id "ViewId" --- View id. .program "ProgramHandle" --- Compute program. .numX "uint32_t" --- Number of groups X. - { deafult = 1 } + { default = 1 } .numY "uint32_t" --- Number of groups Y. - { deafult = 1 } + { default = 1 } .numZ "uint32_t" --- Number of groups Z. - { deafult = 1 } + { default = 1 } --- Dispatch compute indirect. func.dispatch { cname = "dispatch_indirect" } @@ -2944,13 +2955,14 @@ func.dispatch { cname = "dispatch_indirect" } .program "ProgramHandle" --- Compute program. .indirectHandle "IndirectBufferHandle" --- Indirect buffer. .start "uint16_t" --- First element in indirect buffer. - { deafult = 0 } + { default = 0 } .num "uint16_t" --- Number of dispatches. - { deafult = 1 } + { default = 1 } ---- Discard all previously set state for draw or compute call. +--- Discard previously set state for draw or compute call. func.discard "void" + .flags "uint64_t" --- rendering states to discard --- Blit 2D texture region between two 2D textures. --- diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 983d83bac..c0a9a5c7b 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1184,14 +1184,14 @@ namespace bgfx if (m_discard) { - discard(); + discard(BGFX_STATE_DISCARD_ALL); return; } if (0 == m_draw.m_numVertices && 0 == m_draw.m_numIndices) { - discard(); + discard(BGFX_STATE_DISCARD_ALL); ++m_numDropped; return; } @@ -1199,7 +1199,7 @@ namespace bgfx const uint32_t renderItemIdx = bx::atomicFetchAndAddsat(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) { - discard(); + discard(BGFX_STATE_DISCARD_ALL); ++m_numDropped; return; } @@ -1266,8 +1266,8 @@ namespace bgfx if (!_preserveState) { - m_draw.clear(); - m_bind.clear(); + m_draw.clear(BGFX_STATE_DISCARD_ALL); + m_bind.clear(BGFX_STATE_DISCARD_ALL); m_uniformBegin = m_uniformEnd; } } @@ -1281,14 +1281,14 @@ namespace bgfx if (m_discard) { - discard(); + discard(BGFX_STATE_DISCARD_ALL); return; } const uint32_t renderItemIdx = bx::atomicFetchAndAddsat(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) { - discard(); + discard(BGFX_STATE_DISCARD_ALL); ++m_numDropped; return; } @@ -1319,8 +1319,8 @@ namespace bgfx m_frame->m_renderItem[renderItemIdx].compute = m_compute; m_frame->m_renderItemBind[renderItemIdx] = m_bind; - m_compute.clear(); - m_bind.clear(); + m_compute.clear(BGFX_STATE_DISCARD_ALL); + m_bind.clear(BGFX_STATE_DISCARD_ALL); m_uniformBegin = m_uniformEnd; } @@ -3780,9 +3780,9 @@ namespace bgfx BGFX_ENCODER(dispatch(_id, _program, _indirectHandle, _start, _num) ); } - void Encoder::discard() + void Encoder::discard(uint64_t flags) { - BGFX_ENCODER(discard() ); + BGFX_ENCODER(discard(flags) ); } void Encoder::blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) @@ -4992,10 +4992,10 @@ namespace bgfx s_ctx->m_encoder0->dispatch(_id, _handle, _indirectHandle, _start, _num); } - void discard() + void discard(uint64_t flags) { BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->discard(); + s_ctx->m_encoder0->discard(flags); } void blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) diff --git a/src/bgfx.idl.inl b/src/bgfx.idl.inl index e5b01380e..fd245cacc 100644 --- a/src/bgfx.idl.inl +++ b/src/bgfx.idl.inl @@ -912,10 +912,10 @@ BGFX_C_API void bgfx_encoder_dispatch_indirect(bgfx_encoder_t* _this, bgfx_view_ This->dispatch((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num); } -BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this) +BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this, uint64_t _flags) { bgfx::Encoder* This = (bgfx::Encoder*)_this; - This->discard(); + This->discard(_flags); } BGFX_C_API void bgfx_encoder_blit(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) @@ -1154,9 +1154,9 @@ BGFX_C_API void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t bgfx::dispatch((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num); } -BGFX_C_API void bgfx_discard(void) +BGFX_C_API void bgfx_discard(uint64_t _flags) { - bgfx::discard(); + bgfx::discard(_flags); } BGFX_C_API void bgfx_blit(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 44c2b463d..7407de821 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1543,14 +1543,17 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA BX_ALIGN_DECL_CACHE_LINE(struct) RenderBind { - void clear() + void clear(uint64_t flags) { - for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) + if (flags & BGFX_STATE_DISCARD_TEXTURE_SAMPLERS) { - Binding& bind = m_bind[ii]; - bind.m_idx = kInvalidHandle; - bind.m_type = 0; - bind.m_samplerFlags = 0; + for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) + { + Binding& bind = m_bind[ii]; + bind.m_idx = kInvalidHandle; + bind.m_type = 0; + bind.m_samplerFlags = 0; + } } }; @@ -1559,32 +1562,42 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA BX_ALIGN_DECL_CACHE_LINE(struct) RenderDraw { - void clear() + void clear(uint64_t flags) { - m_uniformBegin = 0; - m_uniformEnd = 0; - m_stateFlags = BGFX_STATE_DEFAULT; - m_stencil = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT); - m_rgba = 0; - m_startMatrix = 0; - m_startIndex = 0; - m_numIndices = UINT32_MAX; - m_numVertices = UINT32_MAX; - m_instanceDataOffset = 0; - m_instanceDataStride = 0; - m_numInstances = 1; - m_startIndirect = 0; - m_numIndirect = UINT16_MAX; - m_numMatrices = 1; - m_submitFlags = 0; - m_scissor = UINT16_MAX; - m_streamMask = 0; - m_stream[0].clear(); - m_indexBuffer.idx = kInvalidHandle; - m_instanceDataBuffer.idx = kInvalidHandle; - m_indirectBuffer.idx = kInvalidHandle; - m_occlusionQuery.idx = kInvalidHandle; - m_uniformIdx = UINT8_MAX; + if (flags & BGFX_STATE_DISCARD_STATE) + { + m_uniformBegin = 0; + m_uniformEnd = 0; + m_stateFlags = BGFX_STATE_DEFAULT; + m_stencil = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT); + m_rgba = 0; + m_startMatrix = 0; + m_startIndex = 0; + m_numIndices = UINT32_MAX; + m_numVertices = UINT32_MAX; + m_instanceDataOffset = 0; + m_instanceDataStride = 0; + m_numInstances = 1; + m_startIndirect = 0; + m_numIndirect = UINT16_MAX; + m_numMatrices = 1; + m_submitFlags = 0; + m_scissor = UINT16_MAX; + + m_instanceDataBuffer.idx = kInvalidHandle; + m_indirectBuffer.idx = kInvalidHandle; + m_occlusionQuery.idx = kInvalidHandle; + m_uniformIdx = UINT8_MAX; + } + if (flags & BGFX_STATE_DISCARD_VERTEX_STREAMS) + { + m_streamMask = 0; + m_stream[0].clear(); + } + if (flags & BGFX_STATE_DISCARD_INDEX_BUFFER) + { + m_indexBuffer.idx = kInvalidHandle; + } } bool setStreamBit(uint8_t _stream, VertexBufferHandle _handle) @@ -1625,21 +1638,24 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA BX_ALIGN_DECL_CACHE_LINE(struct) RenderCompute { - void clear() + void clear(uint64_t flags) { - m_uniformBegin = 0; - m_uniformEnd = 0; - m_startMatrix = 0; - m_numX = 0; - m_numY = 0; - m_numZ = 0; - m_numMatrices = 0; - m_submitFlags = 0; - m_uniformIdx = UINT8_MAX; + if (flags & BGFX_STATE_DISCARD_COMPUTE) + { + m_uniformBegin = 0; + m_uniformEnd = 0; + m_startMatrix = 0; + m_numX = 0; + m_numY = 0; + m_numZ = 0; + m_numMatrices = 0; + m_submitFlags = 0; + m_uniformIdx = UINT8_MAX; - m_indirectBuffer.idx = kInvalidHandle; - m_startIndirect = 0; - m_numIndirect = UINT16_MAX; + m_indirectBuffer.idx = kInvalidHandle; + m_startIndirect = 0; + m_numIndirect = UINT16_MAX; + } } uint32_t m_uniformBegin; @@ -2183,7 +2199,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA { EncoderImpl() { - discard(); + discard(BGFX_STATE_DISCARD_ALL); } void begin(Frame* _frame, uint8_t _idx) @@ -2478,7 +2494,7 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA bind.m_mip = _mip; } - void discard() + void discard(uint64_t flags) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) { @@ -2486,9 +2502,9 @@ constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRA } m_discard = false; - m_draw.clear(); - m_compute.clear(); - m_bind.clear(); + m_draw.clear(flags); + m_compute.clear(flags); + m_bind.clear(flags); } void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, bool _preserveState); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index e851cec86..066e4a15e 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -5309,12 +5309,12 @@ namespace bgfx { namespace d3d11 _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); RenderBind currentBind; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); static ViewState viewState; viewState.reset(_render); @@ -5617,9 +5617,9 @@ namespace bgfx { namespace d3d11 { if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); } continue; @@ -5640,14 +5640,14 @@ namespace bgfx { namespace d3d11 { wasCompute = false; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); currentState.m_stateFlags = newFlags; currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); setBlendState(newFlags); setDepthStencilState(newFlags, packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) ); diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 6fd962c39..81a05a19c 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5753,12 +5753,12 @@ namespace bgfx { namespace d3d12 _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); RenderBind currentBind; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); static ViewState viewState; viewState.reset(_render); @@ -6174,9 +6174,9 @@ namespace bgfx { namespace d3d12 { if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); commandListChanged = true; } @@ -6196,14 +6196,14 @@ namespace bgfx { namespace d3d12 { wasCompute = false; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); currentState.m_stateFlags = newFlags; currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); commandListChanged = true; } @@ -6223,14 +6223,14 @@ namespace bgfx { namespace d3d12 currentBindHash = 0; currentSamplerStateIdx = kInvalidHandle; currentProgram = BGFX_INVALID_HANDLE; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); currentState.m_stateFlags = newFlags; currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 34c50d673..67942f39c 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -3746,12 +3746,12 @@ namespace bgfx { namespace d3d9 _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); RenderBind currentBind; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); static ViewState viewState; viewState.reset(_render); @@ -3839,7 +3839,7 @@ namespace bgfx { namespace d3d9 if (key.m_view != view) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index ba6407e1f..dfe58ad95 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -6482,12 +6482,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); RenderBind currentBind; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); static ViewState viewState; viewState.reset(_render); @@ -6769,9 +6769,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); } continue; @@ -6788,14 +6788,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); currentState.m_stateFlags = newFlags; currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); } uint16_t scissor = draw.m_scissor; diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 7d2407c38..d9c1c3781 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -3687,12 +3687,12 @@ namespace bgfx { namespace mtl _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); RenderBind currentBind; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); static ViewState viewState; viewState.reset(_render); @@ -4136,9 +4136,9 @@ namespace bgfx { namespace mtl { if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); } continue; @@ -4155,14 +4155,14 @@ namespace bgfx { namespace mtl if (resetState) { - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); currentState.m_stateFlags = newFlags; currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(BGFX_STATE_DISCARD_ALL); currentProgram = BGFX_INVALID_HANDLE; setDepthStencilState(newFlags, packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) ); diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index 1aff87088..988862966 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -5733,7 +5733,7 @@ VK_DESTROY _render->sort(); RenderDraw currentState; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); @@ -6138,7 +6138,7 @@ VK_DESTROY currentDslHash = 0; currentSamplerStateIdx = kInvalidHandle; currentProgram = BGFX_INVALID_HANDLE; - currentState.clear(); + currentState.clear(BGFX_STATE_DISCARD_ALL); currentState.m_scissor = !draw.m_scissor; changedFlags = BGFX_STATE_MASK; changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK);