Skip to content

Commit 42fc255

Browse files
committed
Prefer updating buffer data in the host.
1 parent da458d8 commit 42fc255

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

impl/vulkan/Frame.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,12 @@ void vk_gltf_viewer::vulkan::Frame::recordScenePrepassCommands(vk::CommandBuffer
12261226
const bool makeMousePickingResultBufferAvailableToHost = renderingNodes && visit(multilambda {
12271227
[&](const vk::Offset2D &offset) {
12281228
if (sharedData.gpu.supportShaderBufferInt64Atomics) {
1229-
cb.updateBuffer<std::uint64_t>(gltfAsset->mousePickingResultBuffer, 0, NO_INDEX);
1229+
constexpr std::uint64_t initialValue = NO_INDEX;
1230+
sharedData.gpu.allocator.copyMemoryToAllocation(&initialValue, gltfAsset->mousePickingResultBuffer.allocation, 0, sizeof(initialValue));
12301231
}
12311232
else {
1232-
cb.updateBuffer<std::uint32_t>(gltfAsset->mousePickingResultBuffer, 0, NO_INDEX);
1233+
constexpr std::uint32_t initialValue = NO_INDEX;
1234+
sharedData.gpu.allocator.copyMemoryToAllocation(&initialValue, gltfAsset->mousePickingResultBuffer.allocation, 0, sizeof(initialValue));
12331235
}
12341236

12351237
if (renderingNodes->startMousePickingRenderPass) {
@@ -1303,7 +1305,13 @@ void vk_gltf_viewer::vulkan::Frame::recordScenePrepassCommands(vk::CommandBuffer
13031305
},
13041306
[&](const vk::Rect2D &rect) {
13051307
// Clear mousePickingResultBuffer as zeros.
1308+
#if __APPLE__
1309+
// Filling buffer with a value needs MTLBlitCommandEncoder in Metal, and it breaks the render pass.
1310+
// It is better to use host memset for this purpose.
1311+
std::memset(gltfAsset->mousePickingResultBuffer.data, 0, gltfAsset->mousePickingResultBuffer.size);
1312+
#else
13061313
cb.fillBuffer(gltfAsset->mousePickingResultBuffer, 0, gltfAsset->mousePickingResultBuffer.size, 0U);
1314+
#endif
13071315

13081316
if (rect.extent.width == 0 || rect.extent.height == 0) {
13091317
// Do nothing.

0 commit comments

Comments
 (0)