diff --git a/neo/renderer/NVRHI/Framebuffer_NVRHI.cpp b/neo/renderer/NVRHI/Framebuffer_NVRHI.cpp index c57c8e48..4738b59a 100644 --- a/neo/renderer/NVRHI/Framebuffer_NVRHI.cpp +++ b/neo/renderer/NVRHI/Framebuffer_NVRHI.cpp @@ -162,8 +162,8 @@ void Framebuffer::ResizeFramebuffers() globalFramebuffers.ldrFBO = new Framebuffer( "_ldr", nvrhi::FramebufferDesc() - .addColorAttachment( globalImages->ldrImage->texture ) ); - //.setDepthAttachment( globalImages->currentDepthImage->texture ) ); + .addColorAttachment( globalImages->ldrImage->texture ) + .setDepthAttachment( globalImages->currentDepthImage->texture ) ); globalFramebuffers.hdrFBO = new Framebuffer( "_hdr", nvrhi::FramebufferDesc() diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index a4e56232..73a35c32 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -271,13 +271,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf ) uint64_t stateBits = glStateBits; - if( currentFrameBuffer == globalFramebuffers.ldrFBO ) - { - // make sure that FBO doesn't require a depth buffer - stateBits |= GLS_DEPTHFUNC_ALWAYS | GLS_DEPTHMASK; - stateBits &= ~( GLS_STENCIL_FUNC_BITS | GLS_STENCIL_OP_BITS ); - } - int program = renderProgManager.CurrentProgram(); PipelineKey key{ stateBits, program, depthBias, slopeScaleBias, currentFrameBuffer }; auto pipeline = pipelineCache.GetOrCreatePipeline( key ); diff --git a/neo/renderer/PipelineCache.cpp b/neo/renderer/PipelineCache.cpp index 41037975..67105552 100644 --- a/neo/renderer/PipelineCache.cpp +++ b/neo/renderer/PipelineCache.cpp @@ -355,14 +355,12 @@ void PipelineCache::GetRenderState( uint64 stateBits, PipelineKey key, nvrhi::Re } } - nvrhi::DepthStencilState::StencilOpDesc stencilOp; - // // stencil // //if( diff & ( GLS_STENCIL_FUNC_BITS | GLS_STENCIL_OP_BITS ) ) { - if( ( stateBits & ( GLS_STENCIL_FUNC_BITS | GLS_STENCIL_OP_BITS ) ) != 0 ) + if( ( stateBits & ( GLS_STENCIL_FUNC_BITS | GLS_STENCIL_OP_BITS | GLS_SEPARATE_STENCIL ) ) != 0 ) { depthStencilState.enableStencil(); } @@ -372,14 +370,40 @@ void PipelineCache::GetRenderState( uint64 stateBits, PipelineKey key, nvrhi::Re } } - // TODO implement Carmack's Reverse with GLS_SEPARATE_STENCIL - if( stateBits & ( GLS_STENCIL_FUNC_BITS | GLS_STENCIL_FUNC_REF_BITS | GLS_STENCIL_FUNC_MASK_BITS ) ) { - depthStencilState.setStencilRefValue( ( stateBits & GLS_STENCIL_FUNC_REF_BITS ) >> GLS_STENCIL_FUNC_REF_SHIFT ); - depthStencilState.setStencilReadMask( ( stateBits & GLS_STENCIL_FUNC_MASK_BITS ) >> GLS_STENCIL_FUNC_MASK_SHIFT ); - depthStencilState.setStencilWriteMask( ( stateBits & GLS_STENCIL_FUNC_MASK_BITS ) >> GLS_STENCIL_FUNC_MASK_SHIFT ); + uint32 ref = uint32( ( stateBits & GLS_STENCIL_FUNC_REF_BITS ) >> GLS_STENCIL_FUNC_REF_SHIFT ); + uint32 mask = uint32( ( stateBits & GLS_STENCIL_FUNC_MASK_BITS ) >> GLS_STENCIL_FUNC_MASK_SHIFT ); + depthStencilState.setStencilRefValue( ref ); + depthStencilState.setStencilReadMask( mask ); + depthStencilState.setStencilWriteMask( 0xFF ); + } + + // Carmack's Reverse with GLS_SEPARATE_STENCIL + if( stateBits & GLS_SEPARATE_STENCIL ) + { + nvrhi::DepthStencilState::StencilOpDesc frontStencilOp = GetStencilOpState( stateBits & GLS_STENCIL_FRONT_OPS ); + nvrhi::DepthStencilState::StencilOpDesc backStencilOp = GetStencilOpState( ( stateBits & GLS_STENCIL_BACK_OPS ) >> 12 ); + + depthStencilState.setFrontFaceStencil( frontStencilOp ); + depthStencilState.setFrontFaceStencil( backStencilOp ); + } + else + { + nvrhi::DepthStencilState::StencilOpDesc stencilOp = GetStencilOpState( stateBits ); + + depthStencilState.setFrontFaceStencil( stencilOp ); + depthStencilState.setBackFaceStencil( stencilOp ); + } +} + +nvrhi::DepthStencilState::StencilOpDesc PipelineCache::GetStencilOpState( uint64 stateBits ) +{ + nvrhi::DepthStencilState::StencilOpDesc stencilOp; + + //if( stateBits & ( GLS_STENCIL_OP_FAIL_BITS | GLS_STENCIL_OP_ZFAIL_BITS | GLS_STENCIL_OP_PASS_BITS ) ) + { switch( stateBits & GLS_STENCIL_FUNC_BITS ) { case GLS_STENCIL_FUNC_NEVER: @@ -407,10 +431,7 @@ void PipelineCache::GetRenderState( uint64 stateBits, PipelineKey key, nvrhi::Re stencilOp.setStencilFunc( nvrhi::ComparisonFunc::Always ); break; } - } - if( stateBits & ( GLS_STENCIL_OP_FAIL_BITS | GLS_STENCIL_OP_ZFAIL_BITS | GLS_STENCIL_OP_PASS_BITS ) ) - { switch( stateBits & GLS_STENCIL_OP_FAIL_BITS ) { case GLS_STENCIL_OP_FAIL_KEEP: @@ -496,5 +517,5 @@ void PipelineCache::GetRenderState( uint64 stateBits, PipelineKey key, nvrhi::Re } } - depthStencilState.setFrontFaceStencil( stencilOp ); + return stencilOp; } \ No newline at end of file diff --git a/neo/renderer/PipelineCache.h b/neo/renderer/PipelineCache.h index 2524f74c..33f20580 100644 --- a/neo/renderer/PipelineCache.h +++ b/neo/renderer/PipelineCache.h @@ -77,6 +77,7 @@ public: private: void GetRenderState( uint64 stateBits, PipelineKey key, nvrhi::RenderState& renderState ); + nvrhi::DepthStencilState::StencilOpDesc GetStencilOpState( uint64 stateBits ); nvrhi::DeviceHandle device; idHashIndex pipelineHash;