@@ -43,7 +43,7 @@ CommandStreamReceiver::~CommandStreamReceiver() {
43
43
if (indirectHeap[i] != nullptr ) {
44
44
auto allocation = indirectHeap[i]->getGraphicsAllocation ();
45
45
if (allocation != nullptr ) {
46
- memoryManager ->storeAllocation (std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
46
+ getMemoryManager () ->storeAllocation (std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
47
47
}
48
48
delete indirectHeap[i];
49
49
}
@@ -119,7 +119,7 @@ void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gf
119
119
120
120
void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList (uint32_t requiredTaskCount, uint32_t allocationType) {
121
121
auto address = getTagAddress ();
122
- if (address && requiredTaskCount != ( unsigned int )- 1 ) {
122
+ if (address && requiredTaskCount != ObjectNotUsed ) {
123
123
while (*address < requiredTaskCount)
124
124
;
125
125
}
@@ -131,21 +131,12 @@ void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requ
131
131
getMemoryManager ()->freeAllocationsList (requiredTaskCount, allocationList);
132
132
}
133
133
134
- MemoryManager *CommandStreamReceiver::getMemoryManager () {
135
- return memoryManager;
136
- }
137
-
138
- void CommandStreamReceiver::setMemoryManager (MemoryManager *mm) {
139
- memoryManager = mm;
140
- if (flatBatchBufferHelper) {
141
- flatBatchBufferHelper->setMemoryManager (mm);
142
- }
134
+ MemoryManager *CommandStreamReceiver::getMemoryManager () const {
135
+ DEBUG_BREAK_IF (!executionEnvironment.memoryManager );
136
+ return executionEnvironment.memoryManager .get ();
143
137
}
144
138
145
139
LinearStream &CommandStreamReceiver::getCS (size_t minRequiredSize) {
146
- auto memoryManager = this ->getMemoryManager ();
147
- DEBUG_BREAK_IF (nullptr == memoryManager);
148
-
149
140
if (commandStream.getAvailableSpace () < minRequiredSize) {
150
141
// Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding.
151
142
// Currently reserving 64bytes (cacheline) which should be more than enough.
@@ -156,16 +147,16 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
156
147
157
148
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
158
149
159
- auto allocation = memoryManager ->obtainReusableAllocation (requiredSize, false ).release ();
150
+ auto allocation = getMemoryManager () ->obtainReusableAllocation (requiredSize, false ).release ();
160
151
if (!allocation) {
161
- allocation = memoryManager ->allocateGraphicsMemory (requiredSize);
152
+ allocation = getMemoryManager () ->allocateGraphicsMemory (requiredSize);
162
153
}
163
154
164
155
allocation->setAllocationType (GraphicsAllocation::AllocationType::LINEAR_STREAM);
165
156
166
157
// pass current allocation to reusable list
167
158
if (commandStream.getCpuBase ()) {
168
- memoryManager ->storeAllocation (std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation ()), REUSABLE_ALLOCATION);
159
+ getMemoryManager () ->storeAllocation (std::unique_ptr<GraphicsAllocation>(commandStream.getGraphicsAllocation ()), REUSABLE_ALLOCATION);
169
160
}
170
161
171
162
commandStream.replaceBuffer (allocation->getUnderlyingBuffer (), minRequiredSize - sizeForSubmission);
@@ -176,30 +167,30 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) {
176
167
}
177
168
178
169
void CommandStreamReceiver::cleanupResources () {
179
- if (!memoryManager )
170
+ if (!getMemoryManager () )
180
171
return ;
181
172
182
173
waitForTaskCountAndCleanAllocationList (this ->latestFlushedTaskCount , TEMPORARY_ALLOCATION);
183
174
waitForTaskCountAndCleanAllocationList (this ->latestFlushedTaskCount , REUSABLE_ALLOCATION);
184
175
185
176
if (scratchAllocation) {
186
- memoryManager ->freeGraphicsMemory (scratchAllocation);
177
+ getMemoryManager () ->freeGraphicsMemory (scratchAllocation);
187
178
scratchAllocation = nullptr ;
188
179
}
189
180
190
181
if (debugSurface) {
191
- memoryManager ->freeGraphicsMemory (debugSurface);
182
+ getMemoryManager () ->freeGraphicsMemory (debugSurface);
192
183
debugSurface = nullptr ;
193
184
}
194
185
195
186
if (commandStream.getCpuBase ()) {
196
- memoryManager ->freeGraphicsMemory (commandStream.getGraphicsAllocation ());
187
+ getMemoryManager () ->freeGraphicsMemory (commandStream.getGraphicsAllocation ());
197
188
commandStream.replaceGraphicsAllocation (nullptr );
198
189
commandStream.replaceBuffer (nullptr , 0 );
199
190
}
200
191
201
192
if (tagAllocation) {
202
- memoryManager ->freeGraphicsMemory (tagAllocation);
193
+ getMemoryManager () ->freeGraphicsMemory (tagAllocation);
203
194
tagAllocation = nullptr ;
204
195
tagAddress = nullptr ;
205
196
}
@@ -267,7 +258,7 @@ void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispa
267
258
268
259
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface (size_t size) {
269
260
UNRECOVERABLE_IF (debugSurface != nullptr );
270
- debugSurface = memoryManager ->allocateGraphicsMemory (size);
261
+ debugSurface = getMemoryManager () ->allocateGraphicsMemory (size);
271
262
return debugSurface;
272
263
}
273
264
@@ -281,7 +272,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType
281
272
heapMemory = heap->getGraphicsAllocation ();
282
273
283
274
if (heap && heap->getAvailableSpace () < minRequiredSize && heapMemory) {
284
- memoryManager ->storeAllocation (std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
275
+ getMemoryManager () ->storeAllocation (std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
285
276
heapMemory = nullptr ;
286
277
}
287
278
@@ -309,13 +300,13 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
309
300
310
301
finalHeapSize = alignUp (std::max (finalHeapSize, minRequiredSize), MemoryConstants::pageSize);
311
302
312
- auto heapMemory = memoryManager ->obtainReusableAllocation (finalHeapSize, requireInternalHeap).release ();
303
+ auto heapMemory = getMemoryManager () ->obtainReusableAllocation (finalHeapSize, requireInternalHeap).release ();
313
304
314
305
if (!heapMemory) {
315
306
if (requireInternalHeap) {
316
- heapMemory = memoryManager ->allocate32BitGraphicsMemory (finalHeapSize, nullptr , AllocationOrigin::INTERNAL_ALLOCATION);
307
+ heapMemory = getMemoryManager () ->allocate32BitGraphicsMemory (finalHeapSize, nullptr , AllocationOrigin::INTERNAL_ALLOCATION);
317
308
} else {
318
- heapMemory = memoryManager ->allocateGraphicsMemory (finalHeapSize);
309
+ heapMemory = getMemoryManager () ->allocateGraphicsMemory (finalHeapSize);
319
310
}
320
311
} else {
321
312
finalHeapSize = std::max (heapMemory->getUnderlyingBufferSize (), finalHeapSize);
@@ -344,7 +335,7 @@ void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {
344
335
if (heap) {
345
336
auto heapMemory = heap->getGraphicsAllocation ();
346
337
if (heapMemory != nullptr )
347
- memoryManager ->storeAllocation (std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
338
+ getMemoryManager () ->storeAllocation (std::unique_ptr<GraphicsAllocation>(heapMemory), REUSABLE_ALLOCATION);
348
339
heap->replaceBuffer (nullptr , 0 );
349
340
heap->replaceGraphicsAllocation (nullptr );
350
341
}
@@ -355,7 +346,7 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr<Experimenta
355
346
}
356
347
357
348
bool CommandStreamReceiver::initializeTagAllocation () {
358
- auto tagAllocation = memoryManager ->allocateGraphicsMemory (sizeof (uint32_t ));
349
+ auto tagAllocation = getMemoryManager () ->allocateGraphicsMemory (sizeof (uint32_t ));
359
350
if (!tagAllocation) {
360
351
return false ;
361
352
}
0 commit comments