Skip to content

Commit 2bcecf3

Browse files
Align command buffers to 64KB
Change-Id: Id1fbd7c6f1aee48c4b69ec305d5332cb0aa86507 Signed-off-by: Jobczyk, Lukasz <[email protected]>
1 parent af2dc20 commit 2bcecf3

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

runtime/command_queue/command_queue.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,14 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
208208

209209
if (commandStream->getAvailableSpace() < minRequiredSize) {
210210
// If not, allocate a new block. allocate full pages
211-
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize);
212-
213-
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
211+
minRequiredSize += CSRequirements::csOverfetchSize;
212+
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k);
214213

215214
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
216-
GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(requiredSize, allocationType).release();
215+
GraphicsAllocation *allocation = storageForAllocation->obtainReusableAllocation(minRequiredSize, allocationType).release();
217216

218217
if (!allocation) {
219-
allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, allocationType});
218+
allocation = memoryManager->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType});
220219
}
221220

222221
// Deallocate the old block, if not null
@@ -225,7 +224,7 @@ LinearStream &CommandQueue::getCS(size_t minRequiredSize) {
225224
if (oldAllocation) {
226225
storageForAllocation->storeAllocation(std::unique_ptr<GraphicsAllocation>(oldAllocation), REUSABLE_ALLOCATION);
227226
}
228-
commandStream->replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - CSRequirements::minCommandQueueCommandStreamSize);
227+
commandStream->replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - CSRequirements::minCommandQueueCommandStreamSize - CSRequirements::csOverfetchSize);
229228
commandStream->replaceGraphicsAllocation(allocation);
230229
}
231230

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,23 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
125125
if (commandStream.getAvailableSpace() < minRequiredSize) {
126126
// Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding.
127127
// Currently reserving 64bytes (cacheline) which should be more than enough.
128-
static const size_t sizeForSubmission = MemoryConstants::cacheLineSize;
129-
minRequiredSize += sizeForSubmission;
128+
minRequiredSize += MemoryConstants::cacheLineSize;
129+
minRequiredSize += CSRequirements::csOverfetchSize;
130130
// If not, allocate a new block. allocate full pages
131-
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize);
131+
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize64k);
132132

133-
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
134133
auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM;
135-
auto allocation = internalAllocationStorage->obtainReusableAllocation(requiredSize, allocationType).release();
134+
auto allocation = internalAllocationStorage->obtainReusableAllocation(minRequiredSize, allocationType).release();
136135
if (!allocation) {
137-
allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({requiredSize, allocationType});
136+
allocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({minRequiredSize, allocationType});
138137
}
139138

140139
//pass current allocation to reusable list
141140
if (commandStream.getCpuBase()) {
142141
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION);
143142
}
144143

145-
commandStream.replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - sizeForSubmission);
144+
commandStream.replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - MemoryConstants::cacheLineSize - CSRequirements::csOverfetchSize);
146145
commandStream.replaceGraphicsAllocation(allocation);
147146
}
148147

unit_tests/command_queue/command_queue_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ TEST_F(CommandQueueCommandStreamTest, GetCommandStreamReturnsCsWithCsOverfetchSi
297297

298298
auto *allocation = cs.getGraphicsAllocation();
299299
ASSERT_NE(nullptr, &allocation);
300-
size_t expectedCsSize = alignUp(minSizeRequested + CSRequirements::minCommandQueueCommandStreamSize, MemoryConstants::pageSize) - CSRequirements::minCommandQueueCommandStreamSize;
300+
size_t expectedCsSize = alignUp(minSizeRequested + CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k) - CSRequirements::minCommandQueueCommandStreamSize - CSRequirements::csOverfetchSize;
301301
EXPECT_EQ(expectedCsSize, cs.getMaxAvailableSpace());
302302

303-
size_t expectedTotalSize = alignUp(minSizeRequested + CSRequirements::minCommandQueueCommandStreamSize, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize;
303+
size_t expectedTotalSize = alignUp(minSizeRequested + CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k);
304304
EXPECT_EQ(expectedTotalSize, allocation->getUnderlyingBufferSize());
305305
}
306306

@@ -331,7 +331,7 @@ TEST_F(CommandQueueCommandStreamTest, givenCommandStreamReceiverWithReusableAllo
331331
CommandQueue cmdQ(context.get(), pDevice, props);
332332

333333
auto memoryManager = pDevice->getMemoryManager();
334-
size_t requiredSize = alignUp(100, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize;
334+
size_t requiredSize = alignUp(100 + CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k);
335335
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
336336
auto &commandStreamReceiver = cmdQ.getCommandStreamReceiver();
337337
commandStreamReceiver.getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
@@ -369,7 +369,7 @@ TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamSt
369369

370370
auto graphicsAllocation = indirectHeap.getGraphicsAllocation();
371371

372-
cmdQ.getCS(10000);
372+
cmdQ.getCS(indirectHeap.getAvailableSpace() + 100);
373373

374374
EXPECT_FALSE(pDevice->getDefaultEngine().commandStreamReceiver->getAllocationsForReuse().peekIsEmpty());
375375

unit_tests/command_stream/command_stream_receiver_flush_task_1_tests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,15 @@ HWTEST_F(CommandStreamReceiverCQFlushTaskTests, getCSShouldReturnACSWithEnoughSi
795795
// work.
796796
size_t sizeCQReserves = CSRequirements::minCommandQueueCommandStreamSize;
797797

798-
size_t sizeRequested = 0x1000 - sizeCQReserves;
798+
size_t sizeRequested = MemoryConstants::pageSize64k - sizeCQReserves;
799799
auto &commandStream = commandQueue.getCS(sizeRequested);
800-
ASSERT_GE(0x1000u, commandStream.getMaxAvailableSpace());
800+
auto expect = alignUp(sizeRequested + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k);
801+
ASSERT_GE(expect, commandStream.getMaxAvailableSpace());
801802

802803
EXPECT_GE(commandStream.getAvailableSpace(), sizeRequested);
803804
commandStream.getSpace(sizeRequested - sizeCQReserves);
804805

805-
MockGraphicsAllocation allocation((void *)MemoryConstants::pageSize, 1);
806+
MockGraphicsAllocation allocation((void *)MemoryConstants::pageSize64k, 1);
806807
IndirectHeap linear(&allocation);
807808

808809
auto blocking = true;
@@ -820,7 +821,7 @@ HWTEST_F(CommandStreamReceiverCQFlushTaskTests, getCSShouldReturnACSWithEnoughSi
820821
dispatchFlags,
821822
*pDevice);
822823

823-
auto expectedSize = 0x1000u - sizeCQReserves;
824+
auto expectedSize = MemoryConstants::pageSize64k - sizeCQReserves;
824825

825826
if (::renderCoreFamily == IGFX_GEN8_CORE) {
826827
expectedSize -= sizeof(typename FamilyType::PIPE_CONTROL);

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ TEST_F(CommandStreamReceiverTest, getCsReturnsCsWithCsOverfetchSizeIncludedInGra
114114
auto *allocation = commandStream.getGraphicsAllocation();
115115
ASSERT_NE(nullptr, allocation);
116116

117-
size_t expectedTotalSize = alignUp(sizeRequested + MemoryConstants::cacheLineSize, MemoryConstants::pageSize) + CSRequirements::csOverfetchSize;
117+
size_t expectedTotalSize = alignUp(sizeRequested + MemoryConstants::cacheLineSize + CSRequirements::csOverfetchSize, MemoryConstants::pageSize64k);
118118

119119
EXPECT_LT(commandStream.getAvailableSpace(), expectedTotalSize);
120120
EXPECT_LE(commandStream.getAvailableSpace(), expectedTotalSize - CSRequirements::csOverfetchSize);

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::pageSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
250+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM});
251251
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
252-
allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
252+
allocation = memoryManager->allocateGraphicsMemoryWithProperties({3 * MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::LINEAR_STREAM});
253253
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
254254

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

0 commit comments

Comments
 (0)