- add VkRenderPassManager::GetVertexFormat so that all VkRenderState access is done through functions that can then be made thread safe

This commit is contained in:
Magnus Norddahl 2019-07-28 17:20:49 +02:00
parent 76675a4d61
commit ad8c5bb96e
3 changed files with 12 additions and 6 deletions

View file

@ -93,6 +93,11 @@ int VkRenderPassManager::GetVertexFormat(int numBindingPoints, int numAttributes
return (int)VertexFormats.size() - 1;
}
VkVertexFormat *VkRenderPassManager::GetVertexFormat(int index)
{
return &VertexFormats[index];
}
void VkRenderPassManager::CreateDynamicSetLayout()
{
DescriptorSetLayoutBuilder builder;
@ -289,7 +294,7 @@ std::unique_ptr<VulkanPipeline> VkRenderPassSetup::CreatePipeline(const VkPipeli
builder.addVertexShader(program->vert.get());
builder.addFragmentShader(program->frag.get());
const VkVertexFormat &vfmt = fb->GetRenderPassManager()->VertexFormats[key.VertexFormat];
const VkVertexFormat &vfmt = *fb->GetRenderPassManager()->GetVertexFormat(key.VertexFormat);
for (int i = 0; i < vfmt.NumBindingPoints; i++)
builder.addVertexBufferBinding(i, vfmt.Stride);

View file

@ -88,6 +88,8 @@ public:
VkRenderPassSetup *GetRenderPass(const VkRenderPassKey &key);
int GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs);
VkVertexFormat *GetVertexFormat(int index);
std::unique_ptr<VulkanDescriptorSet> AllocateTextureDescriptorSet(int numLayers);
VulkanPipelineLayout* GetPipelineLayout(int numLayers);
@ -96,8 +98,6 @@ public:
std::unique_ptr<VulkanDescriptorSet> DynamicSet;
std::vector<VkVertexFormat> VertexFormats;
private:
void CreateDynamicSetLayout();
void CreateDescriptorPool();
@ -111,4 +111,5 @@ private:
std::unique_ptr<VulkanDescriptorPool> DynamicDescriptorPool;
std::vector<std::unique_ptr<VulkanDescriptorSetLayout>> TextureSetLayouts;
std::vector<std::unique_ptr<VulkanPipelineLayout>> PipelineLayouts;
std::vector<VkVertexFormat> VertexFormats;
};

View file

@ -314,7 +314,7 @@ void VkRenderState::ApplyStreamData()
auto fb = GetVulkanFrameBuffer();
auto passManager = fb->GetRenderPassManager();
mStreamData.useVertexData = passManager->VertexFormats[static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat].UseVertexData;
mStreamData.useVertexData = passManager->GetVertexFormat(static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat)->UseVertexData;
if (mMaterial.mMaterial && mMaterial.mMaterial->tex)
mStreamData.timer = static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->tex->shaderspeed / 1000.);
@ -385,9 +385,9 @@ void VkRenderState::ApplyVertexBuffers()
if ((mVertexBuffer != mLastVertexBuffer || mVertexOffsets[0] != mLastVertexOffsets[0] || mVertexOffsets[1] != mLastVertexOffsets[1]) && mVertexBuffer)
{
auto vkbuf = static_cast<VKVertexBuffer*>(mVertexBuffer);
const auto &format = GetVulkanFrameBuffer()->GetRenderPassManager()->VertexFormats[vkbuf->VertexFormat];
const VkVertexFormat *format = GetVulkanFrameBuffer()->GetRenderPassManager()->GetVertexFormat(vkbuf->VertexFormat);
VkBuffer vertexBuffers[2] = { vkbuf->mBuffer->buffer, vkbuf->mBuffer->buffer };
VkDeviceSize offsets[] = { mVertexOffsets[0] * format.Stride, mVertexOffsets[1] * format.Stride };
VkDeviceSize offsets[] = { mVertexOffsets[0] * format->Stride, mVertexOffsets[1] * format->Stride };
mCommandBuffer->bindVertexBuffers(0, 2, vertexBuffers, offsets);
mLastVertexBuffer = mVertexBuffer;
mLastVertexOffsets[0] = mVertexOffsets[0];