229 lines
7.0 KiB
C++
229 lines
7.0 KiB
C++
#include "vulkan_state.h"
|
|
#include "commands.h"
|
|
|
|
CVkRenderCommandList::~CVkRenderCommandList()
|
|
{
|
|
m_pCommandBufferManager->FreeCommandBufferWithCommands(m_pCommandBuffer);
|
|
}
|
|
|
|
|
|
void CVkRenderCommandList::ResetRendering()
|
|
{
|
|
m_pCommandBuffer->Reset();
|
|
}
|
|
|
|
void CVkRenderCommandList::Begin( BeginInfo *pBegin )
|
|
{
|
|
CUtlVector<VulkanRenderOutput_t> images = {};
|
|
images.Reserve(pBegin->uRenderImageCount);
|
|
|
|
CVkBeginCommand *pBeginCommand = CREATE_COMMAND(m_pCommandBufferManager, Begin);
|
|
pBeginCommand->nResolutionX = pBegin->uWidth;
|
|
pBeginCommand->nResolutionY = pBegin->uHeight;
|
|
for (uint32_t i = 0; i < pBegin->uRenderImageCount; i++)
|
|
{
|
|
RenderImage *renderImage = &pBegin->pRenderImages[i];
|
|
VulkanRenderOutput_t output = {};
|
|
output.m_stImage.m_pSingle = renderImage->pImage;
|
|
output.m_fClearColor[0] = renderImage->clear_color.r;
|
|
output.m_fClearColor[1] = renderImage->clear_color.g;
|
|
output.m_fClearColor[2] = renderImage->clear_color.b;
|
|
output.m_fClearColor[3] = renderImage->clear_color.a;
|
|
output.m_eLoadMode = renderImage->eLoadMode;
|
|
output.m_eStoreMode = renderImage->eStoreMode;
|
|
images.AppendTail(output);
|
|
}
|
|
pBeginCommand->images = images;
|
|
if ( pBegin->pDepth )
|
|
{
|
|
VulkanRenderOutput_t output = {};
|
|
output.m_stImage.m_pSingle = pBegin->pDepth->pImage;
|
|
output.m_fClearDepth = pBegin->pDepth->clear_color.depth;
|
|
output.m_eLoadMode = pBegin->pDepth->eLoadMode;
|
|
output.m_eStoreMode = pBegin->pDepth->eStoreMode;
|
|
pBeginCommand->stDepthImage = output;
|
|
}
|
|
m_pCurrentBegin = pBeginCommand;
|
|
m_pCommandBuffer->AddCommand(pBeginCommand);
|
|
}
|
|
void CVkRenderCommandList::End()
|
|
{
|
|
CVkEndCommand *pEndCommand = CREATE_COMMAND(m_pCommandBufferManager, End);
|
|
pEndCommand->pBeginCommand = (CVkBeginCommand*)m_pCurrentBegin;
|
|
m_pCommandBuffer->AddCommand(pEndCommand);
|
|
}
|
|
|
|
void CVkRenderCommandList::SetScissors( uint32_t uX, uint32_t uY, uint32_t uWidth, uint32_t uHeight )
|
|
{
|
|
CVkSetScissorsCommand *pScissorsCommand = CREATE_COMMAND(m_pCommandBufferManager, SetScissors);
|
|
pScissorsCommand->uWidth = uWidth;
|
|
pScissorsCommand->uHeight = uHeight;
|
|
pScissorsCommand->iX = uX;
|
|
pScissorsCommand->iY = uY;
|
|
m_pCommandBuffer->AddCommand(pScissorsCommand);
|
|
}
|
|
|
|
void CVkRenderCommandList::SetViewport( uint32_t uX, uint32_t uY, uint32_t uWidth, uint32_t uHeight, float fMinDepth, float fMaxDepth )
|
|
{
|
|
|
|
CVkSetViewportCommand *pViewportCommand = CREATE_COMMAND(m_pCommandBufferManager, SetViewport);
|
|
pViewportCommand->fX = uX;
|
|
pViewportCommand->fY = uY;
|
|
pViewportCommand->fWidth = uWidth;
|
|
pViewportCommand->fHeight = uHeight;
|
|
pViewportCommand->fDepthMin = fMinDepth;
|
|
pViewportCommand->fDepthMax = fMaxDepth;
|
|
m_pCommandBuffer->AddCommand(pViewportCommand);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CVkRenderCommandList::SetMaterial( IMaterial *pMaterial )
|
|
{
|
|
CVkMaterial *pVkMat = (CVkMaterial*)pMaterial;
|
|
|
|
CVkSetShaderCommand *pSetShader = CREATE_COMMAND(m_pCommandBufferManager, SetShader);
|
|
pSetShader->pShader = pVkMat->m_pShader;
|
|
m_pCommandBuffer->AddCommand(pSetShader);
|
|
|
|
CVkSetShaderDataCommand *pSetShaderData = CREATE_COMMAND(m_pCommandBufferManager, SetShaderData);
|
|
pSetShaderData->pShaderData = pMaterial;
|
|
m_pCommandBuffer->AddCommand(pSetShaderData);
|
|
}
|
|
|
|
void CVkRenderCommandList::SetVertexBuffer( uint32_t uBinding, IVertexBuffer *pBuffer )
|
|
{
|
|
CVkSetVertexBufferCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, SetVertexBuffer);
|
|
pCmd->uBinding = uBinding;
|
|
pCmd->pBuffer = pBuffer;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
}
|
|
|
|
void CVkRenderCommandList::SetIndexBuffer( IVertexBuffer *pBuffer )
|
|
{
|
|
}
|
|
|
|
void CVkRenderCommandList::DrawPrimitives( uint32_t nVertexCount, uint32_t nFirstVertex, uint32_t nInstanceCount, uint32_t nFirstInstance )
|
|
{
|
|
CVkDrawPrimitivesCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, DrawPrimitives);
|
|
pCmd->nVertexCount = nVertexCount;
|
|
pCmd->nFirstVertex = nFirstVertex;
|
|
pCmd->nInstanceCount = nInstanceCount;
|
|
pCmd->nFirstInstance = nFirstInstance;
|
|
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
}
|
|
|
|
void CVkRenderCommandList::DrawPrimitivesIndexed( uint32_t nIndexCount, uint32_t nFirstIndex, uint32_t nVertexOffset, uint32_t nInstanceCount, uint32_t nFirstInstance )
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void CVkRenderCommandList::CopyImageToImage( IImage *pSrc, IImage *pDst )
|
|
{
|
|
|
|
}
|
|
void CVkRenderCommandList::BlitImageToImage( IImage *pSrc, ImageSector_t src, IImage *pDst, ImageSector_t dst )
|
|
{
|
|
CVkBlitCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, Blit);
|
|
pCmd->stInputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE;
|
|
pCmd->stInputImage.m_pSingle = pSrc;
|
|
pCmd->stOutputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE;
|
|
pCmd->stOutputImage.m_pSingle = pDst;
|
|
pCmd->iSrcMin[0] = src.m_iX;
|
|
pCmd->iSrcMin[1] = src.m_iY;
|
|
pCmd->iSrcMin[2] = 0;
|
|
pCmd->iDstMin[0] = dst.m_iX;
|
|
pCmd->iDstMin[1] = dst.m_iY;
|
|
pCmd->iDstMin[2] = 0;
|
|
pCmd->iSrcMax[0] = src.m_iWidth;
|
|
pCmd->iSrcMax[1] = src.m_iHeight;
|
|
pCmd->iSrcMax[2] = 1;
|
|
pCmd->iDstMax[0] = dst.m_iWidth;
|
|
pCmd->iDstMax[1] = dst.m_iHeight;
|
|
pCmd->iDstMax[2] = 1;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::ClearImage( IImage *pImage, float fR, float fG, float fB, float fA )
|
|
{
|
|
CVkClearColorCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, ClearColor);
|
|
pCmd->r = fR;
|
|
pCmd->g = fG;
|
|
pCmd->b = fB;
|
|
pCmd->a = fA;
|
|
pCmd->stImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE;
|
|
pCmd->stImage.m_pSingle = pImage;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::ClearDepth( IImage *pImage, float fVal )
|
|
{
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::ResolveImage( IImage *pOriginal, IImage *pResolved )
|
|
{
|
|
CVkResolveImageCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, ResolveImage);
|
|
pCmd->stInputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE;
|
|
pCmd->stInputImage.m_pSingle = pOriginal;
|
|
pCmd->stOutputImage.m_eObjectType = FRAME_OBJECT_TYPE_SINGLE;
|
|
pCmd->stOutputImage.m_pSingle = pResolved;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
}
|
|
|
|
|
|
void CVkRenderCommandList::StartRecording()
|
|
{
|
|
m_pCommandBuffer = m_pCommandBufferManager->CreateCommandBuffer();
|
|
m_pCommandBuffer->Reset();
|
|
}
|
|
|
|
void CVkRenderCommandList::EndRecording()
|
|
{
|
|
m_pCommandBuffer->Render();
|
|
}
|
|
void CVkRenderCommandList::Barrier( EStageHazard eBefore, EStageHazard eAfter, uint32_t hazard )
|
|
{
|
|
CVkBarrierCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, Barrier);
|
|
pCmd->eStageIn = eBefore;
|
|
pCmd->eStageOut = eAfter;
|
|
pCmd->eHazard = hazard;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::BarrierTransition( IImage *pObject, EImageLayoutHazard old_layout, EImageLayoutHazard layout, EStageHazard eBefore, EStageHazard eAfter, uint32_t hazard )
|
|
{
|
|
CVkLayoutBarrierCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, LayoutBarrier);
|
|
pCmd->eStageIn = eBefore;
|
|
pCmd->eStageOut = eAfter;
|
|
pCmd->eHazard = hazard;
|
|
pCmd->pImage = pObject;
|
|
pCmd->eLayoutIn = old_layout;
|
|
pCmd->eLayoutOut = layout;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::DispatchCompute( uint32_t uX, uint32_t uY, uint32_t uZ )
|
|
{
|
|
CVkDispatchCommand *pCmd = CREATE_COMMAND(m_pCommandBufferManager, Dispatch);
|
|
|
|
pCmd->uX = uX;
|
|
pCmd->uY = uY;
|
|
pCmd->uZ = uZ;
|
|
m_pCommandBuffer->AddCommand(pCmd);
|
|
|
|
}
|
|
|
|
void CVkRenderCommandList::Submit()
|
|
{
|
|
m_pCommandBuffer->Submit();
|
|
}
|