2020-05-31 08:53:11 +00:00
/*
* * Vulkan backend
* * Copyright ( c ) 2016 - 2020 Magnus Norddahl
* *
* * This software is provided ' as - is ' , without any express or implied
* * warranty . In no event will the authors be held liable for any damages
* * arising from the use of this software .
* *
* * Permission is granted to anyone to use this software for any purpose ,
* * including commercial applications , and to alter it and redistribute it
* * freely , subject to the following restrictions :
* *
* * 1. The origin of this software must not be misrepresented ; you must not
* * claim that you wrote the original software . If you use this software
* * in a product , an acknowledgment in the product documentation would be
* * appreciated but is not required .
* * 2. Altered source versions must be plainly marked as such , and must not be
* * misrepresented as being the original software .
* * 3. This notice may not be removed or altered from any source distribution .
* *
*/
# include "vk_renderstate.h"
2022-12-11 17:30:01 +00:00
# include "vulkan/system/vk_renderdevice.h"
# include "zvulkan/vulkanbuilders.h"
2022-07-02 08:09:59 +00:00
# include "vulkan/system/vk_commandbuffer.h"
# include "vulkan/system/vk_buffer.h"
2020-05-31 08:53:11 +00:00
# include "vulkan/renderer/vk_renderpass.h"
2022-07-02 08:09:59 +00:00
# include "vulkan/renderer/vk_descriptorset.h"
# include "vulkan/textures/vk_renderbuffers.h"
2020-05-31 08:53:11 +00:00
# include "vulkan/textures/vk_hwtexture.h"
2021-10-30 08:51:03 +00:00
2020-05-31 08:53:11 +00:00
# include "hw_skydome.h"
# include "hw_viewpointuniforms.h"
# include "hw_lightbuffer.h"
# include "hw_cvars.h"
# include "hw_clock.h"
# include "flatvertices.h"
# include "hwrenderer/data/hw_viewpointbuffer.h"
# include "hwrenderer/data/shaderuniforms.h"
CVAR ( Int , vk_submit_size , 1000 , 0 ) ;
2021-10-30 07:34:38 +00:00
EXTERN_CVAR ( Bool , r_skipmats )
2020-05-31 08:53:11 +00:00
2022-12-11 17:30:01 +00:00
VkRenderState : : VkRenderState ( VulkanRenderDevice * fb ) : fb ( fb ) , mStreamBufferWriter ( fb ) , mMatrixBufferWriter ( fb )
2020-05-31 08:53:11 +00:00
{
Reset ( ) ;
}
void VkRenderState : : ClearScreen ( )
{
2023-01-13 23:41:22 +00:00
screen - > mViewpoints - > Set2D ( nullptr , * this , SCREENWIDTH , SCREENHEIGHT ) ;
2020-05-31 08:53:11 +00:00
SetColor ( 0 , 0 , 0 ) ;
Apply ( DT_TriangleStrip ) ;
mCommandBuffer - > draw ( 4 , 1 , FFlatVertexBuffer : : FULLSCREEN_INDEX , 0 ) ;
}
void VkRenderState : : Draw ( int dt , int index , int count , bool apply )
{
if ( apply | | mNeedApply )
Apply ( dt ) ;
mCommandBuffer - > draw ( count , 1 , index , 0 ) ;
}
void VkRenderState : : DrawIndexed ( int dt , int index , int count , bool apply )
{
if ( apply | | mNeedApply )
Apply ( dt ) ;
mCommandBuffer - > drawIndexed ( count , 1 , index , 0 , 0 ) ;
}
bool VkRenderState : : SetDepthClamp ( bool on )
{
bool lastValue = mDepthClamp ;
mDepthClamp = on ;
mNeedApply = true ;
return lastValue ;
}
void VkRenderState : : SetDepthMask ( bool on )
{
mDepthWrite = on ;
mNeedApply = true ;
}
void VkRenderState : : SetDepthFunc ( int func )
{
mDepthFunc = func ;
mNeedApply = true ;
}
void VkRenderState : : SetDepthRange ( float min , float max )
{
mViewportDepthMin = min ;
mViewportDepthMax = max ;
mViewportChanged = true ;
mNeedApply = true ;
}
void VkRenderState : : SetColorMask ( bool r , bool g , bool b , bool a )
{
int rr = r , gg = g , bb = b , aa = a ;
mColorMask = ( aa < < 3 ) | ( bb < < 2 ) | ( gg < < 1 ) | rr ;
mNeedApply = true ;
}
void VkRenderState : : SetStencil ( int offs , int op , int flags )
{
mStencilRef = screen - > stencilValue + offs ;
mStencilRefChanged = true ;
mStencilOp = op ;
if ( flags ! = - 1 )
{
bool cmon = ! ( flags & SF_ColorMaskOff ) ;
SetColorMask ( cmon , cmon , cmon , cmon ) ; // don't write to the graphics buffer
mDepthWrite = ! ( flags & SF_DepthMaskOff ) ;
}
mNeedApply = true ;
}
void VkRenderState : : SetCulling ( int mode )
{
mCullMode = mode ;
mNeedApply = true ;
}
void VkRenderState : : EnableClipDistance ( int num , bool state )
{
}
void VkRenderState : : Clear ( int targets )
{
mClearTargets = targets ;
EndRenderPass ( ) ;
}
void VkRenderState : : EnableStencil ( bool on )
{
mStencilTest = on ;
mNeedApply = true ;
}
void VkRenderState : : SetScissor ( int x , int y , int w , int h )
{
mScissorX = x ;
mScissorY = y ;
mScissorWidth = w ;
mScissorHeight = h ;
mScissorChanged = true ;
mNeedApply = true ;
}
void VkRenderState : : SetViewport ( int x , int y , int w , int h )
{
mViewportX = x ;
mViewportY = y ;
mViewportWidth = w ;
mViewportHeight = h ;
mViewportChanged = true ;
mNeedApply = true ;
}
void VkRenderState : : EnableDepthTest ( bool on )
{
mDepthTest = on ;
mNeedApply = true ;
}
void VkRenderState : : EnableMultisampling ( bool on )
{
}
void VkRenderState : : EnableLineSmooth ( bool on )
{
}
void VkRenderState : : Apply ( int dt )
{
drawcalls . Clock ( ) ;
mApplyCount + + ;
if ( mApplyCount > = vk_submit_size )
{
2022-07-02 08:09:59 +00:00
fb - > GetCommands ( ) - > FlushCommands ( false ) ;
2020-05-31 08:53:11 +00:00
mApplyCount = 0 ;
}
ApplyStreamData ( ) ;
ApplyMatrices ( ) ;
ApplyRenderPass ( dt ) ;
ApplyScissor ( ) ;
ApplyViewport ( ) ;
ApplyStencilRef ( ) ;
ApplyDepthBias ( ) ;
ApplyPushConstants ( ) ;
ApplyVertexBuffers ( ) ;
2022-07-02 08:09:59 +00:00
ApplyHWBufferSet ( ) ;
2020-05-31 08:53:11 +00:00
ApplyMaterial ( ) ;
mNeedApply = false ;
drawcalls . Unclock ( ) ;
}
void VkRenderState : : ApplyDepthBias ( )
{
if ( mBias . mChanged )
{
mCommandBuffer - > setDepthBias ( mBias . mUnits , 0.0f , mBias . mFactor ) ;
mBias . mChanged = false ;
}
}
void VkRenderState : : ApplyRenderPass ( int dt )
{
// Find a pipeline that matches our state
VkPipelineKey pipelineKey ;
pipelineKey . DrawType = dt ;
2022-07-02 08:09:59 +00:00
pipelineKey . VertexFormat = static_cast < VkHardwareVertexBuffer * > ( mVertexBuffer ) - > VertexFormat ;
2020-05-31 08:53:11 +00:00
pipelineKey . RenderStyle = mRenderStyle ;
pipelineKey . DepthTest = mDepthTest ;
pipelineKey . DepthWrite = mDepthTest & & mDepthWrite ;
pipelineKey . DepthFunc = mDepthFunc ;
pipelineKey . DepthClamp = mDepthClamp ;
pipelineKey . DepthBias = ! ( mBias . mFactor = = 0 & & mBias . mUnits = = 0 ) ;
pipelineKey . StencilTest = mStencilTest ;
pipelineKey . StencilPassOp = mStencilOp ;
pipelineKey . ColorMask = mColorMask ;
pipelineKey . CullMode = mCullMode ;
pipelineKey . NumTextureLayers = mMaterial . mMaterial ? mMaterial . mMaterial - > NumLayers ( ) : 0 ;
2021-10-30 08:15:01 +00:00
pipelineKey . NumTextureLayers = max ( pipelineKey . NumTextureLayers , SHADER_MIN_REQUIRED_TEXTURE_LAYERS ) ; // Always force minimum 8 textures as the shader requires it
2020-05-31 08:53:11 +00:00
if ( mSpecialEffect > EFF_NONE )
{
pipelineKey . SpecialEffect = mSpecialEffect ;
pipelineKey . EffectState = 0 ;
pipelineKey . AlphaTest = false ;
}
else
{
int effectState = mMaterial . mOverrideShader > = 0 ? mMaterial . mOverrideShader : ( mMaterial . mMaterial ? mMaterial . mMaterial - > GetShaderIndex ( ) : 0 ) ;
pipelineKey . SpecialEffect = EFF_NONE ;
pipelineKey . EffectState = mTextureEnabled ? effectState : SHADER_NoTexture ;
2021-10-30 07:34:38 +00:00
if ( r_skipmats & & pipelineKey . EffectState > = 3 & & pipelineKey . EffectState < = 4 )
pipelineKey . EffectState = 0 ;
2020-05-31 08:53:11 +00:00
pipelineKey . AlphaTest = mAlphaThreshold > = 0.f ;
}
// Is this the one we already have?
bool inRenderPass = mCommandBuffer ;
bool changingPipeline = ( ! inRenderPass ) | | ( pipelineKey ! = mPipelineKey ) ;
if ( ! inRenderPass )
{
2022-07-02 08:09:59 +00:00
mCommandBuffer = fb - > GetCommands ( ) - > GetDrawCommands ( ) ;
2020-05-31 08:53:11 +00:00
mScissorChanged = true ;
mViewportChanged = true ;
mStencilRefChanged = true ;
mBias . mChanged = true ;
BeginRenderPass ( mCommandBuffer ) ;
}
if ( changingPipeline )
{
mCommandBuffer - > bindPipeline ( VK_PIPELINE_BIND_POINT_GRAPHICS , mPassSetup - > GetPipeline ( pipelineKey ) ) ;
mPipelineKey = pipelineKey ;
}
}
void VkRenderState : : ApplyStencilRef ( )
{
if ( mStencilRefChanged )
{
mCommandBuffer - > setStencilReference ( VK_STENCIL_FRONT_AND_BACK , mStencilRef ) ;
mStencilRefChanged = false ;
}
}
void VkRenderState : : ApplyScissor ( )
{
if ( mScissorChanged )
{
VkRect2D scissor ;
if ( mScissorWidth > = 0 )
{
int x0 = clamp ( mScissorX , 0 , mRenderTarget . Width ) ;
int y0 = clamp ( mScissorY , 0 , mRenderTarget . Height ) ;
int x1 = clamp ( mScissorX + mScissorWidth , 0 , mRenderTarget . Width ) ;
int y1 = clamp ( mScissorY + mScissorHeight , 0 , mRenderTarget . Height ) ;
scissor . offset . x = x0 ;
scissor . offset . y = y0 ;
scissor . extent . width = x1 - x0 ;
scissor . extent . height = y1 - y0 ;
}
else
{
scissor . offset . x = 0 ;
scissor . offset . y = 0 ;
scissor . extent . width = mRenderTarget . Width ;
scissor . extent . height = mRenderTarget . Height ;
}
mCommandBuffer - > setScissor ( 0 , 1 , & scissor ) ;
mScissorChanged = false ;
}
}
void VkRenderState : : ApplyViewport ( )
{
if ( mViewportChanged )
{
VkViewport viewport ;
if ( mViewportWidth > = 0 )
{
viewport . x = ( float ) mViewportX ;
viewport . y = ( float ) mViewportY ;
viewport . width = ( float ) mViewportWidth ;
viewport . height = ( float ) mViewportHeight ;
}
else
{
viewport . x = 0.0f ;
viewport . y = 0.0f ;
viewport . width = ( float ) mRenderTarget . Width ;
viewport . height = ( float ) mRenderTarget . Height ;
}
viewport . minDepth = mViewportDepthMin ;
viewport . maxDepth = mViewportDepthMax ;
mCommandBuffer - > setViewport ( 0 , 1 , & viewport ) ;
mViewportChanged = false ;
}
}
void VkRenderState : : ApplyStreamData ( )
{
auto passManager = fb - > GetRenderPassManager ( ) ;
2022-07-02 08:09:59 +00:00
mStreamData . useVertexData = passManager - > GetVertexFormat ( static_cast < VkHardwareVertexBuffer * > ( mVertexBuffer ) - > VertexFormat ) - > UseVertexData ;
2020-05-31 08:53:11 +00:00
if ( mMaterial . mMaterial & & mMaterial . mMaterial - > Source ( ) )
mStreamData . timer = static_cast < float > ( ( double ) ( screen - > FrameTime - firstFrame ) * ( double ) mMaterial . mMaterial - > Source ( ) - > GetShaderSpeed ( ) / 1000. ) ;
else
mStreamData . timer = 0.0f ;
if ( ! mStreamBufferWriter . Write ( mStreamData ) )
{
WaitForStreamBuffers ( ) ;
mStreamBufferWriter . Write ( mStreamData ) ;
}
}
void VkRenderState : : ApplyPushConstants ( )
{
int fogset = 0 ;
if ( mFogEnabled )
{
if ( mFogEnabled = = 2 )
{
fogset = - 3 ; // 2D rendering with 'foggy' overlay.
}
else if ( ( GetFogColor ( ) & 0xffffff ) = = 0 )
{
fogset = gl_fogmode ;
}
else
{
fogset = - gl_fogmode ;
}
}
int tempTM = TM_NORMAL ;
if ( mMaterial . mMaterial & & mMaterial . mMaterial - > Source ( ) - > isHardwareCanvas ( ) )
tempTM = TM_OPAQUE ;
mPushConstants . uFogEnabled = fogset ;
2021-09-22 08:20:39 +00:00
mPushConstants . uTextureMode = GetTextureModeAndFlags ( tempTM ) ;
2020-05-31 08:53:11 +00:00
mPushConstants . uLightDist = mLightParms [ 0 ] ;
mPushConstants . uLightFactor = mLightParms [ 1 ] ;
mPushConstants . uFogDensity = mLightParms [ 2 ] ;
mPushConstants . uLightLevel = mLightParms [ 3 ] ;
mPushConstants . uAlphaThreshold = mAlphaThreshold ;
mPushConstants . uClipSplit = { mClipSplit [ 0 ] , mClipSplit [ 1 ] } ;
if ( mMaterial . mMaterial )
{
auto source = mMaterial . mMaterial - > Source ( ) ;
mPushConstants . uSpecularMaterial = { source - > GetGlossiness ( ) , source - > GetSpecularLevel ( ) } ;
}
mPushConstants . uLightIndex = mLightIndex ;
2022-10-20 20:24:25 +00:00
mPushConstants . uBoneIndexBase = mBoneIndexBase ;
2020-05-31 08:53:11 +00:00
mPushConstants . uDataIndex = mStreamBufferWriter . DataIndex ( ) ;
auto passManager = fb - > GetRenderPassManager ( ) ;
mCommandBuffer - > pushConstants ( passManager - > GetPipelineLayout ( mPipelineKey . NumTextureLayers ) , VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT , 0 , ( uint32_t ) sizeof ( PushConstants ) , & mPushConstants ) ;
}
void VkRenderState : : ApplyMatrices ( )
{
if ( ! mMatrixBufferWriter . Write ( mModelMatrix , mModelMatrixEnabled , mTextureMatrix , mTextureMatrixEnabled ) )
{
WaitForStreamBuffers ( ) ;
mMatrixBufferWriter . Write ( mModelMatrix , mModelMatrixEnabled , mTextureMatrix , mTextureMatrixEnabled ) ;
}
}
void VkRenderState : : ApplyVertexBuffers ( )
{
if ( ( mVertexBuffer ! = mLastVertexBuffer | | mVertexOffsets [ 0 ] ! = mLastVertexOffsets [ 0 ] | | mVertexOffsets [ 1 ] ! = mLastVertexOffsets [ 1 ] ) & & mVertexBuffer )
{
2022-07-02 08:09:59 +00:00
auto vkbuf = static_cast < VkHardwareVertexBuffer * > ( mVertexBuffer ) ;
const VkVertexFormat * format = fb - > GetRenderPassManager ( ) - > GetVertexFormat ( vkbuf - > VertexFormat ) ;
2020-05-31 08:53:11 +00:00
VkBuffer vertexBuffers [ 2 ] = { vkbuf - > mBuffer - > buffer , vkbuf - > mBuffer - > buffer } ;
VkDeviceSize offsets [ ] = { mVertexOffsets [ 0 ] * format - > Stride , mVertexOffsets [ 1 ] * format - > Stride } ;
mCommandBuffer - > bindVertexBuffers ( 0 , 2 , vertexBuffers , offsets ) ;
mLastVertexBuffer = mVertexBuffer ;
mLastVertexOffsets [ 0 ] = mVertexOffsets [ 0 ] ;
mLastVertexOffsets [ 1 ] = mVertexOffsets [ 1 ] ;
}
if ( mIndexBuffer ! = mLastIndexBuffer & & mIndexBuffer )
{
2022-07-02 08:09:59 +00:00
mCommandBuffer - > bindIndexBuffer ( static_cast < VkHardwareIndexBuffer * > ( mIndexBuffer ) - > mBuffer - > buffer , 0 , VK_INDEX_TYPE_UINT32 ) ;
2020-05-31 08:53:11 +00:00
mLastIndexBuffer = mIndexBuffer ;
}
}
void VkRenderState : : ApplyMaterial ( )
{
if ( mMaterial . mChanged )
{
auto passManager = fb - > GetRenderPassManager ( ) ;
2022-07-02 08:09:59 +00:00
auto descriptors = fb - > GetDescriptorSetManager ( ) ;
2020-05-31 08:53:11 +00:00
if ( mMaterial . mMaterial & & mMaterial . mMaterial - > Source ( ) - > isHardwareCanvas ( ) ) static_cast < FCanvasTexture * > ( mMaterial . mMaterial - > Source ( ) - > GetTexture ( ) ) - > NeedUpdate ( ) ;
2022-07-02 08:09:59 +00:00
VulkanDescriptorSet * descriptorset = mMaterial . mMaterial ? static_cast < VkMaterial * > ( mMaterial . mMaterial ) - > GetDescriptorSet ( mMaterial ) : descriptors - > GetNullTextureDescriptorSet ( ) ;
2020-05-31 08:53:11 +00:00
2022-07-02 08:09:59 +00:00
mCommandBuffer - > bindDescriptorSet ( VK_PIPELINE_BIND_POINT_GRAPHICS , fb - > GetRenderPassManager ( ) - > GetPipelineLayout ( mPipelineKey . NumTextureLayers ) , 0 , fb - > GetDescriptorSetManager ( ) - > GetFixedDescriptorSet ( ) ) ;
mCommandBuffer - > bindDescriptorSet ( VK_PIPELINE_BIND_POINT_GRAPHICS , passManager - > GetPipelineLayout ( mPipelineKey . NumTextureLayers ) , 2 , descriptorset ) ;
2020-05-31 08:53:11 +00:00
mMaterial . mChanged = false ;
}
}
2022-07-02 08:09:59 +00:00
void VkRenderState : : ApplyHWBufferSet ( )
2020-05-31 08:53:11 +00:00
{
uint32_t matrixOffset = mMatrixBufferWriter . Offset ( ) ;
uint32_t streamDataOffset = mStreamBufferWriter . StreamDataOffset ( ) ;
if ( mViewpointOffset ! = mLastViewpointOffset | | matrixOffset ! = mLastMatricesOffset | | streamDataOffset ! = mLastStreamDataOffset )
{
auto passManager = fb - > GetRenderPassManager ( ) ;
2022-07-02 08:09:59 +00:00
auto descriptors = fb - > GetDescriptorSetManager ( ) ;
2020-05-31 08:53:11 +00:00
uint32_t offsets [ 3 ] = { mViewpointOffset , matrixOffset , streamDataOffset } ;
2022-07-02 08:09:59 +00:00
mCommandBuffer - > bindDescriptorSet ( VK_PIPELINE_BIND_POINT_GRAPHICS , passManager - > GetPipelineLayout ( mPipelineKey . NumTextureLayers ) , 0 , fb - > GetDescriptorSetManager ( ) - > GetFixedDescriptorSet ( ) ) ;
mCommandBuffer - > bindDescriptorSet ( VK_PIPELINE_BIND_POINT_GRAPHICS , passManager - > GetPipelineLayout ( mPipelineKey . NumTextureLayers ) , 1 , descriptors - > GetHWBufferDescriptorSet ( ) , 3 , offsets ) ;
2020-05-31 08:53:11 +00:00
mLastViewpointOffset = mViewpointOffset ;
mLastMatricesOffset = matrixOffset ;
mLastStreamDataOffset = streamDataOffset ;
}
}
void VkRenderState : : WaitForStreamBuffers ( )
{
2022-07-02 08:09:59 +00:00
fb - > WaitForCommands ( false ) ;
2020-05-31 08:53:11 +00:00
mApplyCount = 0 ;
mStreamBufferWriter . Reset ( ) ;
mMatrixBufferWriter . Reset ( ) ;
}
void VkRenderState : : Bind ( int bindingpoint , uint32_t offset )
{
if ( bindingpoint = = VIEWPOINT_BINDINGPOINT )
{
mViewpointOffset = offset ;
mNeedApply = true ;
}
}
void VkRenderState : : BeginFrame ( )
{
mMaterial . Reset ( ) ;
mApplyCount = 0 ;
}
void VkRenderState : : EndRenderPass ( )
{
if ( mCommandBuffer )
{
mCommandBuffer - > endRenderPass ( ) ;
mCommandBuffer = nullptr ;
mPipelineKey = { } ;
mLastViewpointOffset = 0xffffffff ;
mLastVertexBuffer = nullptr ;
mLastIndexBuffer = nullptr ;
mLastModelMatrixEnabled = true ;
mLastTextureMatrixEnabled = true ;
}
}
void VkRenderState : : EndFrame ( )
{
mMatrixBufferWriter . Reset ( ) ;
mStreamBufferWriter . Reset ( ) ;
}
void VkRenderState : : EnableDrawBuffers ( int count , bool apply )
{
if ( mRenderTarget . DrawBuffers ! = count )
{
EndRenderPass ( ) ;
mRenderTarget . DrawBuffers = count ;
}
}
void VkRenderState : : SetRenderTarget ( VkTextureImage * image , VulkanImageView * depthStencilView , int width , int height , VkFormat format , VkSampleCountFlagBits samples )
{
EndRenderPass ( ) ;
mRenderTarget . Image = image ;
mRenderTarget . DepthStencil = depthStencilView ;
mRenderTarget . Width = width ;
mRenderTarget . Height = height ;
mRenderTarget . Format = format ;
mRenderTarget . Samples = samples ;
}
void VkRenderState : : BeginRenderPass ( VulkanCommandBuffer * cmdbuffer )
{
VkRenderPassKey key = { } ;
key . DrawBufferFormat = mRenderTarget . Format ;
key . Samples = mRenderTarget . Samples ;
key . DrawBuffers = mRenderTarget . DrawBuffers ;
key . DepthStencil = ! ! mRenderTarget . DepthStencil ;
mPassSetup = fb - > GetRenderPassManager ( ) - > GetRenderPass ( key ) ;
auto & framebuffer = mRenderTarget . Image - > RSFramebuffers [ key ] ;
if ( ! framebuffer )
{
auto buffers = fb - > GetBuffers ( ) ;
FramebufferBuilder builder ;
2022-07-02 08:09:59 +00:00
builder . RenderPass ( mPassSetup - > GetRenderPass ( 0 ) ) ;
builder . Size ( mRenderTarget . Width , mRenderTarget . Height ) ;
builder . AddAttachment ( mRenderTarget . Image - > View . get ( ) ) ;
2020-05-31 08:53:11 +00:00
if ( key . DrawBuffers > 1 )
2022-07-02 08:09:59 +00:00
builder . AddAttachment ( buffers - > SceneFog . View . get ( ) ) ;
2020-05-31 08:53:11 +00:00
if ( key . DrawBuffers > 2 )
2022-07-02 08:09:59 +00:00
builder . AddAttachment ( buffers - > SceneNormal . View . get ( ) ) ;
2020-05-31 08:53:11 +00:00
if ( key . DepthStencil )
2022-07-02 08:09:59 +00:00
builder . AddAttachment ( mRenderTarget . DepthStencil ) ;
builder . DebugName ( " VkRenderPassSetup.Framebuffer " ) ;
2022-12-11 17:30:01 +00:00
framebuffer = builder . Create ( fb - > device . get ( ) ) ;
2020-05-31 08:53:11 +00:00
}
// Only clear depth+stencil if the render target actually has that
if ( ! mRenderTarget . DepthStencil )
mClearTargets & = ~ ( CT_Depth | CT_Stencil ) ;
RenderPassBegin beginInfo ;
2022-12-11 17:30:01 +00:00
beginInfo . RenderPass ( mPassSetup - > GetRenderPass ( mClearTargets ) ) ;
beginInfo . RenderArea ( 0 , 0 , mRenderTarget . Width , mRenderTarget . Height ) ;
beginInfo . Framebuffer ( framebuffer . get ( ) ) ;
beginInfo . AddClearColor ( screen - > mSceneClearColor [ 0 ] , screen - > mSceneClearColor [ 1 ] , screen - > mSceneClearColor [ 2 ] , screen - > mSceneClearColor [ 3 ] ) ;
2020-05-31 08:53:11 +00:00
if ( key . DrawBuffers > 1 )
2022-12-11 17:30:01 +00:00
beginInfo . AddClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
2020-05-31 08:53:11 +00:00
if ( key . DrawBuffers > 2 )
2022-12-11 17:30:01 +00:00
beginInfo . AddClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
beginInfo . AddClearDepthStencil ( 1.0f , 0 ) ;
beginInfo . Execute ( cmdbuffer ) ;
2020-05-31 08:53:11 +00:00
mMaterial . mChanged = true ;
mClearTargets = 0 ;
}
/////////////////////////////////////////////////////////////////////////////
void VkRenderStateMolten : : Draw ( int dt , int index , int count , bool apply )
{
if ( dt = = DT_TriangleFan )
{
IIndexBuffer * oldIndexBuffer = mIndexBuffer ;
2022-07-02 08:09:59 +00:00
mIndexBuffer = fb - > GetBufferManager ( ) - > FanToTrisIndexBuffer . get ( ) ;
2020-05-31 08:53:11 +00:00
if ( apply | | mNeedApply )
Apply ( DT_Triangles ) ;
else
ApplyVertexBuffers ( ) ;
mCommandBuffer - > drawIndexed ( ( count - 2 ) * 3 , 1 , 0 , index , 0 ) ;
mIndexBuffer = oldIndexBuffer ;
}
else
{
if ( apply | | mNeedApply )
Apply ( dt ) ;
mCommandBuffer - > draw ( count , 1 , index , 0 ) ;
}
}