2025-04-01 19:52:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2025 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-08-18 15:15:55 +00:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
|
|
|
|
|
2025-04-01 19:52:25 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
|
|
|
|
|
class SharedPoolAllocation {
|
|
|
|
|
public:
|
|
|
|
|
SharedPoolAllocation(GraphicsAllocation *graphicsAllocation, size_t offset, size_t size, std::mutex *mtx)
|
2025-08-18 15:15:55 +00:00
|
|
|
: graphicsAllocation(graphicsAllocation), offset(offset), size(size), mtx(mtx){};
|
|
|
|
|
|
|
|
|
|
explicit SharedPoolAllocation(GraphicsAllocation *graphicsAllocation)
|
|
|
|
|
: graphicsAllocation(graphicsAllocation), offset(0u), size(graphicsAllocation ? graphicsAllocation->getUnderlyingBufferSize() : 0u), mtx(nullptr){};
|
2025-04-01 19:52:25 +00:00
|
|
|
|
|
|
|
|
GraphicsAllocation *getGraphicsAllocation() const {
|
|
|
|
|
return graphicsAllocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t getOffset() const {
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t getSize() const {
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-18 15:15:55 +00:00
|
|
|
uint64_t getGpuAddress() const {
|
|
|
|
|
UNRECOVERABLE_IF(graphicsAllocation == nullptr);
|
|
|
|
|
return graphicsAllocation->getGpuAddress() + offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t getGpuAddressToPatch() const {
|
|
|
|
|
UNRECOVERABLE_IF(graphicsAllocation == nullptr);
|
|
|
|
|
return graphicsAllocation->getGpuAddressToPatch() + offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *getUnderlyingBuffer() const {
|
|
|
|
|
UNRECOVERABLE_IF(graphicsAllocation == nullptr);
|
|
|
|
|
return ptrOffset(graphicsAllocation->getUnderlyingBuffer(), offset);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 19:52:25 +00:00
|
|
|
std::unique_lock<std::mutex> obtainSharedAllocationLock() {
|
2025-08-18 15:15:55 +00:00
|
|
|
if (mtx) {
|
|
|
|
|
return std::unique_lock<std::mutex>(*mtx);
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG_BREAK_IF(true);
|
|
|
|
|
return std::unique_lock<std::mutex>();
|
|
|
|
|
}
|
2025-04-01 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
GraphicsAllocation *graphicsAllocation;
|
|
|
|
|
const size_t offset;
|
|
|
|
|
const size_t size;
|
2025-08-18 15:15:55 +00:00
|
|
|
std::mutex *mtx; // This mutex is shared across all users of this GA
|
2025-04-01 19:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace NEO
|