mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 17:39:51 +08:00
Reuse command buffers in L0 command list
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
64aec8dc4e
commit
616580637b
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "shared/source/command_container/cmdcontainer.h"
|
||||
#include "shared/source/memory_manager/allocations_list.h"
|
||||
#include "shared/test/common/fixtures/device_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
||||
@@ -87,7 +88,7 @@ TEST_F(CommandContainerHeapStateTests, givenDirtyHeapsWhenSettingStateForSingleH
|
||||
|
||||
TEST_F(CommandContainerTest, givenCmdContainerWhenCreatingCommandBufferThenCorrectAllocationTypeIsSet) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
|
||||
ASSERT_NE(0u, cmdContainer.getCmdBufferAllocations().size());
|
||||
EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, cmdContainer.getCmdBufferAllocations()[0]->getAllocationType());
|
||||
@@ -100,7 +101,7 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenCreatingCommandBufferThenCorre
|
||||
|
||||
TEST_F(CommandContainerTest, givenCmdContainerWhenAllocatingHeapsThenSetCorrectAllocationTypes) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES; i++) {
|
||||
HeapType heapType = static_cast<HeapType>(i);
|
||||
@@ -118,7 +119,7 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenAllocatingHeapsThenSetCorrectA
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeThenEverythingIsInitialized) {
|
||||
CommandContainer cmdContainer;
|
||||
auto status = cmdContainer.initialize(pDevice);
|
||||
auto status = cmdContainer.initialize(pDevice, nullptr);
|
||||
EXPECT_EQ(ErrorCode::SUCCESS, status);
|
||||
|
||||
EXPECT_EQ(pDevice, cmdContainer.getDevice());
|
||||
@@ -158,7 +159,7 @@ TEST_F(CommandContainerTest, givenEnabledLocalMemoryAndIsaInSystemMemoryWhenCmdC
|
||||
auto instructionHeapBaseAddress = device->getMemoryManager()->getInternalHeapBaseAddress(0, false);
|
||||
|
||||
CommandContainer cmdContainer;
|
||||
auto status = cmdContainer.initialize(device.get());
|
||||
auto status = cmdContainer.initialize(device.get(), nullptr);
|
||||
EXPECT_EQ(ErrorCode::SUCCESS, status);
|
||||
|
||||
EXPECT_EQ(instructionHeapBaseAddress, cmdContainer.getInstructionHeapBaseAddress());
|
||||
@@ -167,15 +168,44 @@ TEST_F(CommandContainerTest, givenEnabledLocalMemoryAndIsaInSystemMemoryWhenCmdC
|
||||
TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateGfxMemoryFailsThenErrorIsReturned) {
|
||||
CommandContainer cmdContainer;
|
||||
pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(0, *pDevice->executionEnvironment));
|
||||
auto status = cmdContainer.initialize(pDevice);
|
||||
auto status = cmdContainer.initialize(pDevice, nullptr);
|
||||
EXPECT_EQ(ErrorCode::OUT_OF_DEVICE_MEMORY, status);
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, givenCmdContainerWithAllocsListWhenAllocateAndResetThenCmdBufferAllocIsReused) {
|
||||
AllocationsList allocList;
|
||||
auto cmdContainer = std::make_unique<CommandContainer>();
|
||||
cmdContainer->initialize(pDevice, &allocList);
|
||||
auto &cmdBufferAllocs = cmdContainer->getCmdBufferAllocations();
|
||||
EXPECT_EQ(cmdBufferAllocs.size(), 1u);
|
||||
EXPECT_TRUE(allocList.peekIsEmpty());
|
||||
|
||||
cmdContainer->allocateNextCommandBuffer();
|
||||
EXPECT_EQ(cmdBufferAllocs.size(), 2u);
|
||||
|
||||
auto cmdBuffer0 = cmdBufferAllocs[0];
|
||||
auto cmdBuffer1 = cmdBufferAllocs[1];
|
||||
|
||||
cmdContainer->reset();
|
||||
EXPECT_EQ(cmdBufferAllocs.size(), 1u);
|
||||
EXPECT_EQ(cmdBufferAllocs[0], cmdBuffer0);
|
||||
EXPECT_FALSE(allocList.peekIsEmpty());
|
||||
|
||||
cmdContainer->allocateNextCommandBuffer();
|
||||
EXPECT_EQ(cmdBufferAllocs.size(), 2u);
|
||||
EXPECT_EQ(cmdBufferAllocs[0], cmdBuffer0);
|
||||
EXPECT_EQ(cmdBufferAllocs[1], cmdBuffer1);
|
||||
EXPECT_TRUE(allocList.peekIsEmpty());
|
||||
|
||||
cmdContainer.reset();
|
||||
allocList.freeAllGraphicsAllocations(pDevice);
|
||||
}
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateHeapMemoryFailsThenErrorIsReturned) {
|
||||
CommandContainer cmdContainer;
|
||||
auto temp_memoryManager = pDevice->executionEnvironment->memoryManager.release();
|
||||
pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(1, *pDevice->executionEnvironment));
|
||||
auto status = cmdContainer.initialize(pDevice);
|
||||
auto status = cmdContainer.initialize(pDevice, nullptr);
|
||||
EXPECT_EQ(ErrorCode::OUT_OF_DEVICE_MEMORY, status);
|
||||
delete temp_memoryManager;
|
||||
}
|
||||
@@ -190,10 +220,10 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenSettingIndirectHeapAllocat
|
||||
|
||||
TEST_F(CommandContainerTest, givenHeapAllocationsWhenDestroyCommandContainerThenHeapAllocationsAreReused) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
auto heapAllocationsAddress = cmdContainer->getIndirectHeapAllocation(HeapType::DYNAMIC_STATE)->getUnderlyingBuffer();
|
||||
cmdContainer.reset(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
bool status = false;
|
||||
for (uint32_t i = 0; i < HeapType::NUM_TYPES && !status; i++) {
|
||||
status = cmdContainer->getIndirectHeapAllocation(static_cast<HeapType>(i))->getUnderlyingBuffer() == heapAllocationsAddress;
|
||||
@@ -203,7 +233,7 @@ TEST_F(CommandContainerTest, givenHeapAllocationsWhenDestroyCommandContainerThen
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerWhenResetThenStateIsReset) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
LinearStream stream;
|
||||
uint32_t usedSize = 1;
|
||||
cmdContainer.lastSentNumGrfRequired = 64;
|
||||
@@ -219,7 +249,7 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenResetThenStateIsReset) {
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerWhenWantToAddNullPtrToResidencyContainerThenNothingIsAdded) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
auto size = cmdContainer.getResidencyContainer().size();
|
||||
cmdContainer.addToResidencyContainer(nullptr);
|
||||
EXPECT_EQ(cmdContainer.getResidencyContainer().size(), size);
|
||||
@@ -227,7 +257,7 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenWantToAddNullPtrToResidenc
|
||||
|
||||
TEST_F(CommandContainerTest, givenCommandContainerWhenWantToAddAlreadyAddedAllocationAndDuplicatesRemovedThenExpectedSizeIsReturned) {
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
MockGraphicsAllocation mockAllocation;
|
||||
|
||||
auto sizeBefore = cmdContainer.getResidencyContainer().size();
|
||||
@@ -252,7 +282,7 @@ HWTEST_F(CommandContainerTest, givenCmdContainerWhenInitializeCalledThenSSHHeapH
|
||||
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->setReservedSshSize(4 * MemoryConstants::pageSize);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
|
||||
auto heap = cmdContainer->getIndirectHeap(HeapType::SURFACE_STATE);
|
||||
@@ -265,7 +295,7 @@ HWTEST_F(CommandContainerTest, givenNotEnoughSpaceInSSHWhenGettingHeapWithRequir
|
||||
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->setReservedSshSize(4 * MemoryConstants::pageSize);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
|
||||
auto heap = cmdContainer->getIndirectHeap(HeapType::SURFACE_STATE);
|
||||
@@ -280,7 +310,7 @@ HWTEST_F(CommandContainerTest, givenNotEnoughSpaceInSSHWhenGettingHeapWithRequir
|
||||
|
||||
TEST_F(CommandContainerTest, givenAvailableSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenExistingAllocationIsReturned) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
HeapType types[] = {HeapType::SURFACE_STATE,
|
||||
HeapType::DYNAMIC_STATE};
|
||||
@@ -311,7 +341,7 @@ TEST_F(CommandContainerTest, givenAvailableSpaceWhenGetHeapWithRequiredSizeAndAl
|
||||
|
||||
TEST_F(CommandContainerTest, givenUnalignedAvailableSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenHeapReturnedIsCorrectlyAligned) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
auto heapAllocation = cmdContainer->getIndirectHeapAllocation(HeapType::SURFACE_STATE);
|
||||
auto heap = cmdContainer->getIndirectHeap(HeapType::SURFACE_STATE);
|
||||
@@ -335,7 +365,7 @@ TEST_F(CommandContainerTest, givenUnalignedAvailableSpaceWhenGetHeapWithRequired
|
||||
|
||||
TEST_F(CommandContainerTest, givenNoAlignmentAndAvailableSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenHeapReturnedIsNotAligned) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
auto heapAllocation = cmdContainer->getIndirectHeapAllocation(HeapType::SURFACE_STATE);
|
||||
auto heap = cmdContainer->getIndirectHeap(HeapType::SURFACE_STATE);
|
||||
@@ -359,7 +389,7 @@ TEST_F(CommandContainerTest, givenNoAlignmentAndAvailableSpaceWhenGetHeapWithReq
|
||||
|
||||
TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAlignmentCalledThenNewAllocationIsReturned) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
HeapType types[] = {HeapType::SURFACE_STATE,
|
||||
HeapType::DYNAMIC_STATE};
|
||||
@@ -393,7 +423,7 @@ TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenGetHeapWithRequiredSizeAndAl
|
||||
|
||||
TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenCreatedAlocationHaveDifferentBaseThenHeapIsDirty) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->setDirtyStateForAllHeaps(false);
|
||||
HeapType type = HeapType::INDIRECT_OBJECT;
|
||||
|
||||
@@ -425,7 +455,7 @@ TEST_F(CommandContainerTest, givenNotEnoughSpaceWhenCreatedAlocationHaveDifferen
|
||||
|
||||
TEST_F(CommandContainerTest, whenAllocateNextCmdBufferIsCalledThenNewAllocationIsCreatedAndCommandStreamReplaced) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
auto stream = cmdContainer->getCommandStream();
|
||||
ASSERT_NE(nullptr, stream);
|
||||
|
||||
@@ -452,7 +482,7 @@ TEST_F(CommandContainerTest, whenAllocateNextCmdBufferIsCalledThenNewAllocationI
|
||||
|
||||
TEST_F(CommandContainerTest, whenResettingCommandContainerThenStoredCmdBuffersAreFreedAndStreamIsReplacedWithInitialBuffer) {
|
||||
std::unique_ptr<CommandContainer> cmdContainer(new CommandContainer);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
|
||||
cmdContainer->allocateNextCommandBuffer();
|
||||
cmdContainer->allocateNextCommandBuffer();
|
||||
@@ -497,7 +527,7 @@ TEST_P(CommandContainerHeaps, givenCommandContainerWhenGetAllowHeapGrowCalledThe
|
||||
HeapType heap = GetParam();
|
||||
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
auto usedSpaceBefore = cmdContainer.getIndirectHeap(heap)->getUsed();
|
||||
size_t size = 5000;
|
||||
void *ptr = cmdContainer.getHeapSpaceAllowGrow(heap, size);
|
||||
@@ -511,7 +541,7 @@ TEST_P(CommandContainerHeaps, givenCommandContainerWhenGetingMoreThanAvailableSi
|
||||
HeapType heap = GetParam();
|
||||
|
||||
CommandContainer cmdContainer;
|
||||
cmdContainer.initialize(pDevice);
|
||||
cmdContainer.initialize(pDevice, nullptr);
|
||||
cmdContainer.setDirtyStateForAllHeaps(false);
|
||||
|
||||
auto usedSpaceBefore = cmdContainer.getIndirectHeap(heap)->getUsed();
|
||||
@@ -539,12 +569,12 @@ TEST_P(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenHe
|
||||
auto device1 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 1u));
|
||||
|
||||
CommandContainer cmdContainer0;
|
||||
cmdContainer0.initialize(device0.get());
|
||||
cmdContainer0.initialize(device0.get(), nullptr);
|
||||
uint32_t heapRootDeviceIndex0 = cmdContainer0.getIndirectHeap(heap)->getGraphicsAllocation()->getRootDeviceIndex();
|
||||
EXPECT_EQ(device0->getRootDeviceIndex(), heapRootDeviceIndex0);
|
||||
|
||||
CommandContainer cmdContainer1;
|
||||
cmdContainer1.initialize(device1.get());
|
||||
cmdContainer1.initialize(device1.get(), nullptr);
|
||||
uint32_t heapRootDeviceIndex1 = cmdContainer1.getIndirectHeap(heap)->getGraphicsAllocation()->getRootDeviceIndex();
|
||||
EXPECT_EQ(device1->getRootDeviceIndex(), heapRootDeviceIndex1);
|
||||
}
|
||||
@@ -560,13 +590,13 @@ TEST_F(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenCm
|
||||
auto device1 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 1u));
|
||||
|
||||
CommandContainer cmdContainer0;
|
||||
cmdContainer0.initialize(device0.get());
|
||||
cmdContainer0.initialize(device0.get(), nullptr);
|
||||
EXPECT_EQ(1u, cmdContainer0.getCmdBufferAllocations().size());
|
||||
uint32_t cmdBufferAllocationIndex0 = cmdContainer0.getCmdBufferAllocations().front()->getRootDeviceIndex();
|
||||
EXPECT_EQ(device0->getRootDeviceIndex(), cmdBufferAllocationIndex0);
|
||||
|
||||
CommandContainer cmdContainer1;
|
||||
cmdContainer1.initialize(device1.get());
|
||||
cmdContainer1.initialize(device1.get(), nullptr);
|
||||
EXPECT_EQ(1u, cmdContainer1.getCmdBufferAllocations().size());
|
||||
uint32_t cmdBufferAllocationIndex1 = cmdContainer1.getCmdBufferAllocations().front()->getRootDeviceIndex();
|
||||
EXPECT_EQ(device1->getRootDeviceIndex(), cmdBufferAllocationIndex1);
|
||||
@@ -586,13 +616,13 @@ TEST_F(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenIn
|
||||
auto &hwHelper1 = HwHelper::get(device1->getHardwareInfo().platform.eRenderCoreFamily);
|
||||
|
||||
CommandContainer cmdContainer0;
|
||||
cmdContainer0.initialize(device0.get());
|
||||
cmdContainer0.initialize(device0.get(), nullptr);
|
||||
bool useLocalMemory0 = !hwHelper0.useSystemMemoryPlacementForISA(device0->getHardwareInfo());
|
||||
uint64_t baseAddressHeapDevice0 = device0.get()->getMemoryManager()->getInternalHeapBaseAddress(device0->getRootDeviceIndex(), useLocalMemory0);
|
||||
EXPECT_EQ(cmdContainer0.getInstructionHeapBaseAddress(), baseAddressHeapDevice0);
|
||||
|
||||
CommandContainer cmdContainer1;
|
||||
cmdContainer1.initialize(device1.get());
|
||||
cmdContainer1.initialize(device1.get(), nullptr);
|
||||
bool useLocalMemory1 = !hwHelper1.useSystemMemoryPlacementForISA(device0->getHardwareInfo());
|
||||
uint64_t baseAddressHeapDevice1 = device1.get()->getMemoryManager()->getInternalHeapBaseAddress(device1->getRootDeviceIndex(), useLocalMemory1);
|
||||
EXPECT_EQ(cmdContainer1.getInstructionHeapBaseAddress(), baseAddressHeapDevice1);
|
||||
@@ -603,7 +633,7 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenDestructionThenNonHeapAllo
|
||||
MockGraphicsAllocation alloc;
|
||||
size_t size = 0x1000;
|
||||
alloc.setSize(size);
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
cmdContainer->getDeallocationContainer().push_back(&alloc);
|
||||
cmdContainer.reset();
|
||||
EXPECT_EQ(alloc.getUnderlyingBufferSize(), size);
|
||||
@@ -611,7 +641,7 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenDestructionThenNonHeapAllo
|
||||
|
||||
TEST_F(CommandContainerTest, givenContainerAllocatesNextCommandBufferWhenResetingContainerThenExpectFirstCommandBufferAllocationIsReused) {
|
||||
auto cmdContainer = std::make_unique<CommandContainer>();
|
||||
cmdContainer->initialize(pDevice);
|
||||
cmdContainer->initialize(pDevice, nullptr);
|
||||
|
||||
auto stream = cmdContainer->getCommandStream();
|
||||
ASSERT_NE(nullptr, stream);
|
||||
|
||||
Reference in New Issue
Block a user