Skip to content

Commit

Permalink
tests: Move AMD buffer marker to a separate test
Browse files Browse the repository at this point in the history
Also remove CmdFillBuffer/CmdUpdateBuffer sections from a big buffer
test since we have separate small tests for these functions.
  • Loading branch information
artem-lunarg committed Jan 28, 2025
1 parent abf70b9 commit abf82d0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 52 deletions.
69 changes: 17 additions & 52 deletions tests/unit/sync_val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
class NegativeSyncVal : public VkSyncValTest {};

TEST_F(NegativeSyncVal, BufferCopyHazards) {
AddOptionalExtensions(VK_AMD_BUFFER_MARKER_EXTENSION_NAME);
RETURN_IF_SKIP(InitSyncValFramework());
RETURN_IF_SKIP(InitState());
bool has_amd_buffer_maker = IsExtensionsEnabled(VK_AMD_BUFFER_MARKER_EXTENSION_NAME);
RETURN_IF_SKIP(InitSyncVal());

VkMemoryPropertyFlags mem_prop = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
VkBufferUsageFlags transfer_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Expand Down Expand Up @@ -89,35 +86,6 @@ TEST_F(NegativeSyncVal, BufferCopyHazards) {

m_command_buffer.End();

// CmdFillBuffer
m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdFillBuffer(m_command_buffer.handle(), buffer_a.handle(), 0, 256, 1);
m_command_buffer.End();

m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdCopyBuffer(cb, buffer_b.handle(), buffer_a.handle(), 1, &region);
m_errorMonitor->SetDesiredError("SYNC-HAZARD-WRITE-AFTER-WRITE");
vk::CmdFillBuffer(m_command_buffer.handle(), buffer_a.handle(), 0, 256, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.End();

// CmdUpdateBuffer
int i = 10;
m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdUpdateBuffer(m_command_buffer.handle(), buffer_a.handle(), 0, sizeof(i), &i);
m_command_buffer.End();

m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdCopyBuffer(cb, buffer_b.handle(), buffer_a.handle(), 1, &region);
m_errorMonitor->SetDesiredError("SYNC-HAZARD-WRITE-AFTER-WRITE");
vk::CmdUpdateBuffer(m_command_buffer.handle(), buffer_a.handle(), 0, sizeof(i), &i);
m_errorMonitor->VerifyFound();
m_command_buffer.End();

// Create secondary buffers to use
vkt::CommandBuffer secondary_cb1(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
VkCommandBuffer scb1 = secondary_cb1.handle();
Expand Down Expand Up @@ -184,25 +152,6 @@ TEST_F(NegativeSyncVal, BufferCopyHazards) {
vk::CmdExecuteCommands(cb, 3, three_cbs);
}
m_command_buffer.End();

m_command_buffer.Reset();
// CmdWriteBufferMarkerAMD
if (has_amd_buffer_maker) {
m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdWriteBufferMarkerAMD(m_command_buffer.handle(), VK_PIPELINE_STAGE_TRANSFER_BIT, buffer_a.handle(), 0, 1);
m_command_buffer.End();

m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdCopyBuffer(cb, buffer_b.handle(), buffer_a.handle(), 1, &region);
m_errorMonitor->SetDesiredError("SYNC-HAZARD-WRITE-AFTER-WRITE");
vk::CmdWriteBufferMarkerAMD(m_command_buffer.handle(), VK_PIPELINE_STAGE_TRANSFER_BIT, buffer_a.handle(), 0, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
} else {
printf("Test requires unsupported vkCmdWriteBufferMarkerAMD feature. Skipped.\n");
}
}

TEST_F(NegativeSyncVal, BufferCopyHazardsSync2) {
Expand Down Expand Up @@ -5735,3 +5684,19 @@ TEST_F(NegativeSyncVal, ExpandedMetaStage3) {
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}

TEST_F(NegativeSyncVal, AmdBufferMarker) {
TEST_DESCRIPTION("Hazard with AMD buffer marker accesses");
AddRequiredExtensions(VK_AMD_BUFFER_MARKER_EXTENSION_NAME);
RETURN_IF_SKIP(InitSyncVal());

vkt::Buffer buffer_a(*m_device, 256, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
vkt::Buffer buffer_b(*m_device, 256, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);

m_command_buffer.Begin();
m_command_buffer.Copy(buffer_b, buffer_a);
m_errorMonitor->SetDesiredError("SYNC-HAZARD-WRITE-AFTER-WRITE");
vk::CmdWriteBufferMarkerAMD(m_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, buffer_a, 0, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
31 changes: 31 additions & 0 deletions tests/unit/sync_val_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,3 +2148,34 @@ TEST_F(PositiveSyncVal, DynamicRenderingDSWithOnlyStencilAspect) {
m_command_buffer.EndRendering();
m_command_buffer.End();
}

TEST_F(PositiveSyncVal, AmdBufferMarker) {
TEST_DESCRIPTION("Use barrier to synchronize with AMD buffer marker accesses");
SetTargetApiVersion(VK_API_VERSION_1_3);
AddRequiredFeature(vkt::Feature::synchronization2);
AddRequiredExtensions(VK_AMD_BUFFER_MARKER_EXTENSION_NAME);
RETURN_IF_SKIP(InitSyncVal());

vkt::Buffer buffer_a(*m_device, 256, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
vkt::Buffer buffer_b(*m_device, 256, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);

VkBufferMemoryBarrier2 barrier = vku::InitStructHelper();
// AMD marker access is WRITE on TRANSFER stage
barrier.srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT;
barrier.srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT;
// Buffer copy access
barrier.dstStageMask = VK_PIPELINE_STAGE_2_COPY_BIT;
barrier.dstAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT;
barrier.buffer = buffer_a;
barrier.size = 256;

VkDependencyInfo dep_info = vku::InitStructHelper();
dep_info.bufferMemoryBarrierCount = 1;
dep_info.pBufferMemoryBarriers = &barrier;

m_command_buffer.Begin();
vk::CmdWriteBufferMarkerAMD(m_command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, buffer_a, 0, 1);
vk::CmdPipelineBarrier2(m_command_buffer, &dep_info);
m_command_buffer.Copy(buffer_b, buffer_a);
m_command_buffer.End();
}

0 comments on commit abf82d0

Please sign in to comment.