mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Allow debug allocs to use copyMemoryToAllocation
Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
1e0a2b897f
commit
3281dea1fe
@ -212,6 +212,11 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
type == AllocationType::DEBUG_MODULE_AREA;
|
||||
}
|
||||
|
||||
static bool isDebugSurfaceAllocationType(AllocationType type) {
|
||||
return type == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
|
||||
type == AllocationType::DEBUG_SBA_TRACKING_BUFFER;
|
||||
}
|
||||
|
||||
void *getReservedAddressPtr() const {
|
||||
return this->reservedAddressRangeInfo.addressPtr;
|
||||
}
|
||||
|
@ -426,8 +426,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||
allocationData.flags.multiOsContextCapable = properties.flags.multiOsContextCapable;
|
||||
allocationData.usmInitialPlacement = properties.usmInitialPlacement;
|
||||
|
||||
if (properties.allocationType == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
|
||||
properties.allocationType == AllocationType::DEBUG_SBA_TRACKING_BUFFER) {
|
||||
if (GraphicsAllocation::isDebugSurfaceAllocationType(properties.allocationType)) {
|
||||
allocationData.flags.zeroMemory = 1;
|
||||
}
|
||||
|
||||
@ -696,11 +695,11 @@ bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocatio
|
||||
if (!graphicsAllocation->getUnderlyingBuffer()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < graphicsAllocation->storageInfo.getNumBanks(); ++i) {
|
||||
memcpy_s(ptrOffset(static_cast<uint8_t *>(graphicsAllocation->getUnderlyingBuffer()) + i * graphicsAllocation->getUnderlyingBufferSize(), destinationOffset),
|
||||
(graphicsAllocation->getUnderlyingBufferSize() - destinationOffset), memoryToCopy, sizeToCopy);
|
||||
if (graphicsAllocation->getAllocationType() != AllocationType::DEBUG_CONTEXT_SAVE_AREA &&
|
||||
graphicsAllocation->getAllocationType() != AllocationType::DEBUG_SBA_TRACKING_BUFFER) {
|
||||
if (!GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
|
||||
sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize2Mb);
|
||||
}
|
||||
|
||||
if (allocationData.type == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
|
||||
allocationData.type == AllocationType::DEBUG_SBA_TRACKING_BUFFER) {
|
||||
if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type)) {
|
||||
sizeAligned *= allocationData.storageInfo.getNumBanks();
|
||||
}
|
||||
|
||||
@ -104,8 +103,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
|
||||
memoryAllocation->setCpuPtrAndGpuAddress(ptr, canonizedGpuAddress);
|
||||
}
|
||||
|
||||
if (allocationData.type == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
|
||||
allocationData.type == AllocationType::DEBUG_SBA_TRACKING_BUFFER) {
|
||||
if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type)) {
|
||||
memoryAllocation->storageInfo = allocationData.storageInfo;
|
||||
}
|
||||
|
||||
|
@ -296,8 +296,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
|
||||
if ((allocationData.type == NEO::AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
|
||||
allocationData.type == NEO::AllocationType::DEBUG_SBA_TRACKING_BUFFER) &&
|
||||
if (GraphicsAllocation::isDebugSurfaceAllocationType(allocationData.type) &&
|
||||
allocationData.storageInfo.subDeviceBitfield.count() > 1) {
|
||||
return createMultiHostAllocation(allocationData);
|
||||
}
|
||||
@ -1249,11 +1248,12 @@ uint64_t DrmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
if (graphicsAllocation->getUnderlyingBuffer() && graphicsAllocation->storageInfo.getNumBanks() == 1) {
|
||||
if (graphicsAllocation->getUnderlyingBuffer() && (graphicsAllocation->storageInfo.getNumBanks() == 1 || GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType()))) {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks()));
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) {
|
||||
if (MemoryPoolHelper::isSystemMemoryPool(graphicsAllocation->getMemoryPool())) {
|
||||
return false;
|
||||
|
@ -927,7 +927,7 @@ bool WddmMemoryManager::isCpuCopyRequired(const void *ptr) {
|
||||
}
|
||||
|
||||
bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
if (graphicsAllocation->getUnderlyingBuffer()) {
|
||||
if (graphicsAllocation->getUnderlyingBuffer() && (graphicsAllocation->storageInfo.getNumBanks() == 1 || GraphicsAllocation::isDebugSurfaceAllocationType(graphicsAllocation->getAllocationType()))) {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks()));
|
||||
|
@ -73,6 +73,11 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
|
||||
BaseClass::freeGraphicsMemoryImpl(gfxAllocation);
|
||||
}
|
||||
|
||||
bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) {
|
||||
copyMemoryToAllocationBanksCalled++;
|
||||
return BaseClass::copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, handleMask);
|
||||
}
|
||||
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override {
|
||||
BaseClass::freeGraphicsMemoryImpl(gfxAllocation, isImportedAllocation);
|
||||
}
|
||||
@ -86,7 +91,7 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
|
||||
registerAllocationInOsCalled++;
|
||||
BaseClass::registerAllocationInOs(gfxAllocation);
|
||||
}
|
||||
|
||||
uint32_t copyMemoryToAllocationBanksCalled = 0u;
|
||||
uint32_t freeGraphicsMemoryImplCalled = 0u;
|
||||
uint32_t registerAllocationInOsCalled = 0;
|
||||
bool allocationGraphicsMemory64kbCreated = false;
|
||||
|
@ -1641,6 +1641,27 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
|
||||
drmMemoryManager.freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyDebugSurfaceToMultiTileAllocationThenCallCopyMemoryToAllocation) {
|
||||
size_t sourceAllocationSize = MemoryConstants::pageSize;
|
||||
size_t destinationAllocationSize = sourceAllocationSize;
|
||||
|
||||
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize);
|
||||
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
|
||||
|
||||
AllocationType debugSurfaces[] = {AllocationType::DEBUG_CONTEXT_SAVE_AREA, AllocationType::DEBUG_SBA_TRACKING_BUFFER};
|
||||
|
||||
for (auto type : debugSurfaces) {
|
||||
AllocationProperties debugSurfaceProperties{0, true, sourceAllocationSize, type, false, false, 0b11};
|
||||
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(debugSurfaceProperties);
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
|
||||
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size());
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(0u, drmMemoryManager.copyMemoryToAllocationBanksCalled);
|
||||
drmMemoryManager.freeGraphicsMemory(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationFailsToLockResourceThenItReturnsFalse) {
|
||||
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, 0);
|
||||
std::vector<uint8_t> dataToCopy(MemoryConstants::pageSize, 1u);
|
||||
|
Reference in New Issue
Block a user