Skip to content

Commit 4139e88

Browse files
committed
Allocate command buffers with proper allocation type.
Change-Id: I912dd41cf68fa16ab481bb003c4f5ae63f1f04c4
1 parent 65625e2 commit 4139e88

File tree

10 files changed

+40
-12
lines changed

10 files changed

+40
-12
lines changed

runtime/command_queue/command_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
211211
minRequiredSize += CSRequirements::csOverfetchSize;
212212
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k);
213213

214-
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
214+
auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
215215
GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(minRequiredSize, allocationType).release();
216216

217217
if (!allocation) {

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
130130
// If not, allocate a new block. allocate full pages
131131
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k);
132132

133-
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
133+
auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
134134
auto allocation = internalAllocationStorage->obtainReusableAllocation(minRequiredSize, allocationType).release();
135135
if (!allocation) {
136136
allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType});

runtime/command_stream/experimental_command_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) {
5959

6060
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
6161
auto storageWithAllocations = commandStreamReceiver->getInternalAllocationStorage();
62-
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
62+
auto allocationType = GraphicsAllocation::AllocationType::COMMAND_BUFFER;
6363
GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, allocationType).release();
6464
if (!allocation) {
6565
allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, allocationType});

runtime/memory_manager/graphics_allocation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
168168
return allocationType == AllocationType::LINEAR_STREAM ||
169169
allocationType == AllocationType::KERNEL_ISA ||
170170
allocationType == AllocationType::INTERNAL_HEAP ||
171-
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
171+
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER ||
172+
allocationType == AllocationType::COMMAND_BUFFER;
172173
}
173174

174175
protected:

runtime/os_interface/windows/wddm_device_command_stream.inl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2018 Intel Corporation
2+
* Copyright (C) 2017-2019 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -193,7 +193,8 @@ template <typename GfxFamily>
193193
void WddmCommandStreamReceiver<GfxFamily>::kmDafLockAllocations(ResidencyContainer &allocationsForResidency) {
194194
for (auto &graphicsAllocation : allocationsForResidency) {
195195
if ((GraphicsAllocation::AllocationType::LINEAR_STREAM == graphicsAllocation->getAllocationType()) ||
196-
(GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType())) {
196+
(GraphicsAllocation::AllocationType::FILL_PATTERN == graphicsAllocation->getAllocationType()) ||
197+
(GraphicsAllocation::AllocationType::COMMAND_BUFFER == graphicsAllocation->getAllocationType())) {
197198
wddm->kmDafLock(static_cast<WddmAllocation *>(graphicsAllocation));
198199
}
199200
}

unit_tests/command_queue/command_queue_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandStreamReceiverWithReusableAllo
332332

333333
auto memoryManager = pDevice->getMemoryManager();
334334
size_t requiredSize = alignUp(100 + CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k);
335-
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
335+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::COMMAND_BUFFER});
336336
auto &commandStreamReceiver = cmdQ.getCommandStreamReceiver();
337337
commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
338338

@@ -376,15 +376,15 @@ TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamSt
376376
EXPECT_TRUE(pDevice->getDefaultEngine().commandStreamReceiver->getAllocationsForReuse().peekContains(*graphicsAllocation));
377377
}
378378

379-
TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToLinearStream) {
379+
TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToCommandBuffer) {
380380
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
381381
CommandQueue cmdQ(context.get(), pDevice, props);
382382

383383
const auto &commandStream = cmdQ.getCS(100);
384384
auto commandStreamAllocation = commandStream.getGraphicsAllocation();
385385
ASSERT_NE(nullptr, commandStreamAllocation);
386386

387-
EXPECT_EQ(GraphicsAllocation::AllocationType::LINEAR_STREAM, commandStreamAllocation->getAllocationType());
387+
EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, commandStreamAllocation->getAllocationType());
388388
}
389389

390390
struct CommandQueueIndirectHeapTest : public CommandQueueMemoryDevice,

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ TEST_F(CommandStreamReceiverTest, givenCommandStreamReceiverWhenGetCSIsCalledThe
135135
auto commandStreamAllocation = commandStream.getGraphicsAllocation();
136136
ASSERT_NE(nullptr, commandStreamAllocation);
137137

138-
EXPECT_EQ(GraphicsAllocation::AllocationType::LINEAR_STREAM, commandStreamAllocation->getAllocationType());
138+
EXPECT_EQ(GraphicsAllocation::AllocationType::COMMAND_BUFFER, commandStreamAllocation->getAllocationType());
139139
}
140140

141141
HWTEST_F(CommandStreamReceiverTest, givenPtrAndSizeThatMeetL3CriteriaWhenMakeResidentHostPtrThenCsrEnableL3) {

unit_tests/command_stream/experimental_command_buffer_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ HWTEST_F(MockExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhe
247247
MemoryManager *memoryManager = commandStreamReceiver.getMemoryManager();
248248

249249
//Make two allocations, since CSR will try to reuse it also
250-
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM});
250+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::COMMAND_BUFFER});
251251
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
252-
allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM});
252+
allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::COMMAND_BUFFER});
253253
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
254254

255255
MockExperimentalCommandBuffer *mockExCmdBuffer = static_cast<MockExperimentalCommandBuffer *>(commandStreamReceiver.experimentalCmdBuffer.get());

unit_tests/memory_manager/graphics_allocation_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,7 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsInternalHeapThenCpuAccessIsRequ
128128
TEST(GraphicsAllocationTest, whenAllocationTypeIsTimestampPacketThenCpuAccessIsRequired) {
129129
EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER));
130130
}
131+
132+
TEST(GraphicsAllocationTest, whenAllocationTypeIsCommandBufferThenCpuAccessIsRequired) {
133+
EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(GraphicsAllocation::AllocationType::COMMAND_BUFFER));
134+
}

unit_tests/os_interface/windows/device_command_stream_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,28 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
469469
memoryManager->freeGraphicsMemory(fillPatternAllocation);
470470
}
471471

472+
TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenCommandBufferAllocationsShouldBeKmDafLocked) {
473+
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
474+
ASSERT_NE(nullptr, commandBuffer);
475+
LinearStream cs(commandBuffer);
476+
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
477+
478+
auto commandBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
479+
ASSERT_NE(nullptr, commandBufferAllocation);
480+
commandBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::COMMAND_BUFFER);
481+
ResidencyContainer allocationsForResidency = {commandBufferAllocation};
482+
483+
wddm->setKmDafEnabled(true);
484+
csr->flush(batchBuffer, allocationsForResidency);
485+
486+
EXPECT_EQ(1u, wddm->kmDafLockResult.called);
487+
EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size());
488+
EXPECT_EQ(commandBufferAllocation, wddm->kmDafLockResult.lockedAllocations[0]);
489+
490+
memoryManager->freeGraphicsMemory(commandBuffer);
491+
memoryManager->freeGraphicsMemory(commandBufferAllocation);
492+
}
493+
472494
TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenNonLinearStreamAllocationShouldNotBeKmDafLocked) {
473495
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
474496
ASSERT_NE(nullptr, commandBuffer);

0 commit comments

Comments
 (0)