@@ -146,30 +146,29 @@ Buffer *Buffer::create(Context *context,
146
146
zeroCopyAllowed = false ;
147
147
}
148
148
149
+ if (allocateMemory && context->isProvidingPerformanceHints ()) {
150
+ context->providePerformanceHint (CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_BUFFER_NEEDS_ALLOCATE_MEMORY);
151
+ }
152
+
149
153
if (!memory) {
150
- AllocationFlags allocFlags = MemObjHelper::getAllocationFlags (flags);
154
+ AllocationFlags allocFlags = MemObjHelper::getAllocationFlags (flags, allocateMemory );
151
155
DevicesBitfield devices = MemObjHelper::getDevicesBitfield (flags);
152
- allocFlags.flags .allocateMemory = allocateMemory;
153
156
memory = memoryManager->allocateGraphicsMemoryInPreferredPool (allocFlags, devices, hostPtr, static_cast <size_t >(size), allocationType);
154
157
}
155
158
156
- if (allocateMemory) {
157
- if (memory) {
158
- memoryManager->addAllocationToHostPtrManager (memory);
159
- }
160
- if (context->isProvidingPerformanceHints ()) {
161
- context->providePerformanceHint (CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL, CL_BUFFER_NEEDS_ALLOCATE_MEMORY);
162
- }
163
- } else {
164
- if (!memory && Buffer::isReadOnlyMemoryPermittedByFlags (flags)) {
165
- allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
166
- zeroCopyAllowed = false ;
167
- copyMemoryFromHostPtr = true ;
168
- AllocationFlags allocFlags = MemObjHelper::getAllocationFlags (flags);
169
- DevicesBitfield devices = MemObjHelper::getDevicesBitfield (flags);
170
- allocFlags.flags .allocateMemory = true ;
171
- memory = memoryManager->allocateGraphicsMemoryInPreferredPool (allocFlags, devices, nullptr , static_cast <size_t >(size), allocationType);
172
- }
159
+ if (allocateMemory && memory && MemoryPool::isSystemMemoryPool (memory->getMemoryPool ())) {
160
+ memoryManager->addAllocationToHostPtrManager (memory);
161
+ }
162
+
163
+ // if memory pointer should not be allcoated and graphics allocation is nullptr
164
+ // and cl_mem flags allow, create non-zerocopy buffer
165
+ if (!allocateMemory && !memory && Buffer::isReadOnlyMemoryPermittedByFlags (flags)) {
166
+ allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
167
+ zeroCopyAllowed = false ;
168
+ copyMemoryFromHostPtr = true ;
169
+ AllocationFlags allocFlags = MemObjHelper::getAllocationFlags (flags, true );
170
+ DevicesBitfield devices = MemObjHelper::getDevicesBitfield (flags);
171
+ memory = memoryManager->allocateGraphicsMemoryInPreferredPool (allocFlags, devices, nullptr , static_cast <size_t >(size), allocationType);
173
172
}
174
173
175
174
if (!memory) {
0 commit comments