Skip to content

Commit

Permalink
Fixes for Vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Sep 6, 2022
1 parent 2cd7967 commit 3abbafa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void GPUBufferViewVulkan::Init(GPUDeviceVulkan* device, GPUBufferVulkan* owner,
viewInfo.format = RenderToolsVulkan::ToVulkanFormat(format);
viewInfo.offset = 0;
viewInfo.range = Size;
ASSERT_LOW_LAYER(viewInfo.format != VK_FORMAT_UNDEFINED);
if (viewInfo.format == VK_FORMAT_UNDEFINED)
return; // Skip for structured buffers that use custom structure type and have unknown format
VALIDATE_VULKAN_RESULT(vkCreateBufferView(device->Device, &viewInfo, nullptr, &View));
}
}
Expand Down
10 changes: 10 additions & 0 deletions Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,11 @@ void GPUContextVulkan::UpdateBuffer(GPUBuffer* buffer, const void* data, uint32

const auto bufferVulkan = static_cast<GPUBufferVulkan*>(buffer);

// Memory transfer barrier
// TODO: batch pipeline barriers
const VkMemoryBarrier barrierBefore = { VK_STRUCTURE_TYPE_MEMORY_BARRIER, nullptr, VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT };
vkCmdPipelineBarrier(cmdBuffer->GetHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &barrierBefore, 0, nullptr, 0, nullptr);

// Use direct update for small buffers
if (size <= 16 * 1024)
{
Expand All @@ -1331,6 +1336,11 @@ void GPUContextVulkan::UpdateBuffer(GPUBuffer* buffer, const void* data, uint32

_device->StagingManager.ReleaseBuffer(cmdBuffer, staging);
}

// Memory transfer barrier
// TODO: batch pipeline barriers
const VkMemoryBarrier barrierAfter = { VK_STRUCTURE_TYPE_MEMORY_BARRIER, nullptr, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT };
vkCmdPipelineBarrier(cmdBuffer->GetHandle(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &barrierAfter, 0, nullptr, 0, nullptr);
}

void GPUContextVulkan::CopyBuffer(GPUBuffer* dstBuffer, GPUBuffer* srcBuffer, uint32 size, uint32 dstOffset, uint32 srcOffset)
Expand Down
1 change: 1 addition & 0 deletions Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
LOG(Warning, "Failed to create Vulkan surface.");
return true;
}
_memoryUsage = 1;

const auto& gpu = _device->Adapter->Gpu;

Expand Down
1 change: 0 additions & 1 deletion Source/Engine/Particles/Particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ void DrawEmitterGPU(RenderContext& renderContext, ParticleBuffer* buffer, DrawCa
// TODO: model LOD picking for particles?
int32 lodIndex = 0;
ModelLOD& lod = model->LODs[lodIndex];
drawCalls += lod.Meshes.Count();
for (int32 meshIndex = 0; meshIndex < lod.Meshes.Count(); meshIndex++)
{
Mesh& mesh = lod.Meshes[meshIndex];
Expand Down

0 comments on commit 3abbafa

Please sign in to comment.