Skip to content

Commit 7ee9d27

Browse files
Set correct allocation after reseting command container
Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
1 parent 484dea0 commit 7ee9d27

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

shared/source/command_container/cmdcontainer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void CommandContainer::reset() {
129129

130130
commandStream->replaceBuffer(cmdBufferAllocations[0]->getUnderlyingBuffer(),
131131
defaultListCmdBufferSize);
132+
commandStream->replaceGraphicsAllocation(cmdBufferAllocations[0]);
132133
addToResidencyContainer(commandStream->getGraphicsAllocation());
133134

134135
for (auto &indirectHeap : indirectHeaps) {

shared/test/unit_test/command_container/command_container_tests.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,43 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenDestructionThenNonHeapAllo
608608
cmdContainer.reset();
609609
EXPECT_EQ(alloc.getUnderlyingBufferSize(), size);
610610
}
611+
612+
TEST_F(CommandContainerTest, givenContainerAllocatesNextCommandBufferWhenResetingContainerThenExpectFirstCommandBufferAllocationIsReused) {
613+
auto cmdContainer = std::make_unique<CommandContainer>();
614+
cmdContainer->initialize(pDevice);
615+
616+
auto stream = cmdContainer->getCommandStream();
617+
ASSERT_NE(nullptr, stream);
618+
auto firstCmdBufferAllocation = stream->getGraphicsAllocation();
619+
ASSERT_NE(nullptr, firstCmdBufferAllocation);
620+
auto firstCmdBufferCpuPointer = stream->getSpace(0);
621+
EXPECT_EQ(firstCmdBufferCpuPointer, firstCmdBufferAllocation->getUnderlyingBuffer());
622+
623+
cmdContainer->allocateNextCommandBuffer();
624+
auto secondCmdBufferAllocation = stream->getGraphicsAllocation();
625+
ASSERT_NE(nullptr, secondCmdBufferAllocation);
626+
EXPECT_NE(firstCmdBufferAllocation, secondCmdBufferAllocation);
627+
auto secondCmdBufferCpuPointer = stream->getSpace(0);
628+
EXPECT_EQ(secondCmdBufferCpuPointer, secondCmdBufferAllocation->getUnderlyingBuffer());
629+
EXPECT_NE(firstCmdBufferCpuPointer, secondCmdBufferCpuPointer);
630+
631+
cmdContainer->reset();
632+
633+
auto aferResetCmdBufferAllocation = stream->getGraphicsAllocation();
634+
ASSERT_NE(nullptr, aferResetCmdBufferAllocation);
635+
auto afterResetCmdBufferCpuPointer = stream->getSpace(0);
636+
EXPECT_EQ(afterResetCmdBufferCpuPointer, aferResetCmdBufferAllocation->getUnderlyingBuffer());
637+
638+
EXPECT_EQ(firstCmdBufferAllocation, aferResetCmdBufferAllocation);
639+
EXPECT_EQ(firstCmdBufferCpuPointer, afterResetCmdBufferCpuPointer);
640+
641+
bool firstAllocationFound = false;
642+
auto &residencyContainer = cmdContainer->getResidencyContainer();
643+
for (auto *allocation : residencyContainer) {
644+
if (allocation == firstCmdBufferAllocation) {
645+
firstAllocationFound = true;
646+
break;
647+
}
648+
}
649+
EXPECT_TRUE(firstAllocationFound);
650+
}

0 commit comments

Comments
 (0)