- move streaming uniform buffers out of VkRenderState
This commit is contained in:
parent
05cae50612
commit
4adac3fe59
8 changed files with 227 additions and 88 deletions
|
|
@ -21,7 +21,6 @@ CVAR(Int, vk_submit_size, 1000, 0);
|
|||
|
||||
VkRenderState::VkRenderState()
|
||||
{
|
||||
mIdentityMatrix.loadIdentity();
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
|
@ -322,17 +321,11 @@ void VkRenderState::ApplyStreamData()
|
|||
else
|
||||
mStreamData.timer = 0.0f;
|
||||
|
||||
mDataIndex++;
|
||||
if (mDataIndex == MAX_STREAM_DATA)
|
||||
if (!mStreamBufferWriter.Write(mStreamData))
|
||||
{
|
||||
mDataIndex = 0;
|
||||
mStreamDataOffset += sizeof(StreamUBO);
|
||||
|
||||
if (mStreamDataOffset + sizeof(StreamUBO) >= fb->StreamUBO->Size())
|
||||
WaitForStreamBuffers();
|
||||
WaitForStreamBuffers();
|
||||
mStreamBufferWriter.Write(mStreamData);
|
||||
}
|
||||
uint8_t *ptr = (uint8_t*)fb->StreamUBO->Memory();
|
||||
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &mStreamData, sizeof(StreamData));
|
||||
}
|
||||
|
||||
void VkRenderState::ApplyPushConstants()
|
||||
|
|
@ -371,63 +364,20 @@ void VkRenderState::ApplyPushConstants()
|
|||
mPushConstants.uSpecularMaterial = { mMaterial.mMaterial->tex->Glossiness, mMaterial.mMaterial->tex->SpecularLevel };
|
||||
|
||||
mPushConstants.uLightIndex = mLightIndex;
|
||||
mPushConstants.uDataIndex = mDataIndex;
|
||||
mPushConstants.uDataIndex = mStreamBufferWriter.DataIndex();
|
||||
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
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);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void BufferedSet(bool &modified, T &dst, const T &src)
|
||||
{
|
||||
if (dst == src)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
static void BufferedSet(bool &modified, VSMatrix &dst, const VSMatrix &src)
|
||||
{
|
||||
if (memcmp(dst.get(), src.get(), sizeof(FLOATTYPE) * 16) == 0)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
void VkRenderState::ApplyMatrices()
|
||||
{
|
||||
bool modified = (mMatricesOffset == 0); // always modified first call
|
||||
if (mTextureMatrixEnabled)
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
if (!fb->MatrixBuffer->Write(mModelMatrix, mModelMatrixEnabled, mTextureMatrix, mTextureMatrixEnabled))
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, mTextureMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (mModelMatrixEnabled)
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, mModelMatrix);
|
||||
if (modified)
|
||||
mMatrices.NormalModelMatrix.computeNormalMatrix(mModelMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, mIdentityMatrix);
|
||||
BufferedSet(modified, mMatrices.NormalModelMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (modified)
|
||||
{
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
|
||||
if (mMatricesOffset + (fb->UniformBufferAlignedSize<MatricesUBO>() << 1) >= fb->MatricesUBO->Size())
|
||||
WaitForStreamBuffers();
|
||||
|
||||
mMatricesOffset += fb->UniformBufferAlignedSize<MatricesUBO>();
|
||||
memcpy(static_cast<uint8_t*>(fb->MatricesUBO->Memory()) + mMatricesOffset, &mMatrices, sizeof(MatricesUBO));
|
||||
WaitForStreamBuffers();
|
||||
fb->MatrixBuffer->Write(mModelMatrix, mModelMatrixEnabled, mTextureMatrix, mTextureMatrixEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -470,17 +420,19 @@ void VkRenderState::ApplyMaterial()
|
|||
|
||||
void VkRenderState::ApplyDynamicSet()
|
||||
{
|
||||
if (mViewpointOffset != mLastViewpointOffset || mMatricesOffset != mLastMatricesOffset || mStreamDataOffset != mLastStreamDataOffset)
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
uint32_t matrixOffset = fb->MatrixBuffer->Offset();
|
||||
uint32_t streamDataOffset = mStreamBufferWriter.StreamDataOffset();
|
||||
if (mViewpointOffset != mLastViewpointOffset || matrixOffset != mLastMatricesOffset || streamDataOffset != mLastStreamDataOffset)
|
||||
{
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
auto passManager = fb->GetRenderPassManager();
|
||||
|
||||
uint32_t offsets[3] = { mViewpointOffset, mMatricesOffset, mStreamDataOffset };
|
||||
uint32_t offsets[3] = { mViewpointOffset, matrixOffset, streamDataOffset };
|
||||
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 0, passManager->DynamicSet.get(), 3, offsets);
|
||||
|
||||
mLastViewpointOffset = mViewpointOffset;
|
||||
mLastMatricesOffset = mMatricesOffset;
|
||||
mLastStreamDataOffset = mStreamDataOffset;
|
||||
mLastMatricesOffset = matrixOffset;
|
||||
mLastStreamDataOffset = streamDataOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -489,9 +441,8 @@ void VkRenderState::WaitForStreamBuffers()
|
|||
EndRenderPass();
|
||||
GetVulkanFrameBuffer()->WaitForCommands(false);
|
||||
mApplyCount = 0;
|
||||
mStreamDataOffset = 0;
|
||||
mDataIndex = 0;
|
||||
mMatricesOffset = 0;
|
||||
mStreamBufferWriter.Reset();
|
||||
GetVulkanFrameBuffer()->MatrixBuffer->Reset();
|
||||
}
|
||||
|
||||
void VkRenderState::Bind(int bindingpoint, uint32_t offset)
|
||||
|
|
@ -527,9 +478,8 @@ void VkRenderState::EndRenderPass()
|
|||
|
||||
void VkRenderState::EndFrame()
|
||||
{
|
||||
mMatricesOffset = 0;
|
||||
mStreamDataOffset = 0;
|
||||
mDataIndex = -1;
|
||||
GetVulkanFrameBuffer()->MatrixBuffer->Reset();
|
||||
mStreamBufferWriter.Reset();
|
||||
}
|
||||
|
||||
void VkRenderState::EnableDrawBuffers(int count)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue