P4 to Git Change 1133818 by gandryey@gera-w8 on 2015/03/24 11:30:12

ECR #304775 - Mipmaps support in OCL
	- Add support for clEnqueueMapImage/Unmap functionality

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_memobj.cpp#76 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#175 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#241 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#503 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#140 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.cpp#120 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#212 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#356 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa/hsadevice.cpp#89 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa/hsadevice.hpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.hpp#13 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.hpp#14 edit
Este commit está contenido en:
foreman
2015-03-24 11:45:49 -04:00
padre 58b20f1bc4
commit 20974393b1
Se han modificado 10 ficheros con 81 adiciones y 99 borrados
+23 -4
Ver fichero
@@ -269,9 +269,6 @@ Device::isAncestor(const Device* sub) const
return false;
}
bool Device::IsHsaCapableDevice() {
static bool init = false;
typedef std::vector<std::string> ListType;
@@ -506,6 +503,26 @@ Device::getExtensionString()
return result;
}
void*
Device::allocMapTarget(
amd::Memory& mem,
const amd::Coord3D& origin,
const amd::Coord3D& region,
uint mapFlags,
size_t* rowPitch,
size_t* slicePitch)
{
// Translate memory references
device::Memory* devMem = mem.getDeviceMemory(*this);
if (devMem == NULL) {
LogError("allocMapTarget failed. Can't allocate video memory");
return NULL;
}
// Pass request over to memory
return devMem->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
}
} // namespace amd
namespace device {
@@ -577,11 +594,13 @@ Memory::saveMapInfo(
const amd::Coord3D origin,
const amd::Coord3D region,
uint mapFlags,
bool entire)
bool entire,
amd::Image* baseMip)
{
if (mapFlags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)) {
writeMapInfo_.origin_ = origin;
writeMapInfo_.region_ = region;
writeMapInfo_.baseMip_ = baseMip;
writeMapInfo_.entire_ = entire;
flags_ |= UnmapWrite;
}
+14 -3
Ver fichero
@@ -648,8 +648,9 @@ public:
{
amd::Coord3D origin_; //!< Origin of the map location
amd::Coord3D region_; //!< Mapped region
amd::Image* baseMip_; //!< The base mip level for images
bool entire_; //!< True if the enitre memory was mapped
WriteMapInfo(): origin_(0, 0, 0), region_(0, 0, 0), entire_(false) {}
WriteMapInfo(): origin_(0, 0, 0), region_(0, 0, 0), baseMip_(NULL), entire_(false) {}
};
//! Constructor (from an amd::Memory object).
@@ -698,6 +699,15 @@ public:
SyncFlags syncFlags = SyncFlags()
) {}
//! Allocate memory for API-level maps
virtual void* allocMapTarget(
const amd::Coord3D& origin, //!< The map location in memory
const amd::Coord3D& region, //!< The map region in memory
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
) { return NULL; }
virtual bool pinSystemMemory(
void* hostPtr, //!< System memory address
size_t size //!< Size of allocated system memory
@@ -741,7 +751,8 @@ public:
const amd::Coord3D origin, //!< Origin of the map location
const amd::Coord3D region, //!< Mapped region
uint mapFlags, //< Map flags
bool entire //!< True if the enitre memory was mapped
bool entire, //!< True if the enitre memory was mapped
amd::Image* baseMip = NULL //!< The base mip level for map
);
const WriteMapInfo* writeMapInfo() const { return &writeMapInfo_; }
@@ -1605,7 +1616,7 @@ public:
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
) = 0;
);
//! Gets free memory on a GPU device
virtual bool globalFreeMemory(
+1 -20
Ver fichero
@@ -1669,6 +1669,7 @@ Device::createBuffer(
!internalAlloc) {
Resource::CreateParams params;
params.owner_ = &owner;
params.gpu_ = static_cast<VirtualGPU*>(owner.getVirtualDevice());
// Create memory object
result = gpuMemory->create(type, &params);
@@ -2145,26 +2146,6 @@ Device::unbindExternalDevice(intptr_t type, void* pDevice, void* pContext, bool
return true;
}
void*
Device::allocMapTarget(
amd::Memory& mem,
const amd::Coord3D& origin,
const amd::Coord3D& region,
uint mapFlags,
size_t* rowPitch,
size_t* slicePitch)
{
// Translate memory references
gpu::Memory* memory = getGpuMemory(&mem);
if (memory == NULL) {
LogError("allocMapTarget failed. Can't allocate video memory");
return NULL;
}
// Pass request over to memory
return memory->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
}
bool
Device::globalFreeMemory(size_t* freeMemory) const
{
-22
Ver fichero
@@ -105,17 +105,6 @@ public:
virtual bool unbindExternalDevice(
intptr_t type, void* pDevice, void* pContext, bool validateOnly) { return true; }
//! Gets a pointer to a region of host-visible memory for use as the target
//! of a non-blocking map for a given memory object
virtual void* allocMapTarget(
amd::Memory& mem, //!< Abstraction layer memory object
const amd::Coord3D& origin, //!< The map location in memory
const amd::Coord3D& region, //!< The map region in memory
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
) { return NULL; }
//! Releases non-blocking map target memory
virtual void freeMapTarget(amd::Memory& mem, void* target) {}
@@ -432,17 +421,6 @@ public:
const device::VirtualDevice* vdev
);
//! Gets a pointer to a region of host-visible memory for use as the target
//! of a non-blocking map for a given memory object
virtual void* allocMapTarget(
amd::Memory& mem, //!< Abstraction layer memory object
const amd::Coord3D& origin, //!< The map location in memory
const amd::Coord3D& region, //!< The map region in memory
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
);
//! Retrieves information about free memory on a GPU device
virtual bool globalFreeMemory(size_t* freeMemory) const;
+2 -1
Ver fichero
@@ -1324,8 +1324,9 @@ Image::allocMapTarget(
memory = new (owner()->getContext())
amd::Buffer(owner()->getContext(), 0,
cal()->width_ * height * depth * elementSize());
Memory* gpuMemory;
memory->setVirtualDevice(owner()->getVirtualDevice());
Memory* gpuMemory;
do {
if ((memory == NULL) || !memory->create(NULL, SysMem)) {
failed = true;
+5 -2
Ver fichero
@@ -664,6 +664,9 @@ Resource::create(MemoryType memType, CreateParams* params, bool heap)
viewLevel = imageView->level_;
gslResource = imageView->resource_->gslResource();
viewOwner_ = imageView->resource_;
if (viewLevel != 0) {
viewFlags |= CAL_RESALLOCSLICEVIEW_LEVEL;
}
if (viewLayer != 0) {
viewFlags |= CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER;
}
@@ -1662,7 +1665,7 @@ Resource::mapLayers(VirtualGPU* gpu, CALuint flags)
sliceResource = dev().resAllocView(
gslResource(), gslSize,
calOffset, cal()->format_, cal()->channelOrder_, gslDim,
0, i, CAL_RESALLOCSLICEVIEW_LAYER);
0, i, CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER);
if (0 == sliceResource) {
LogError("Map layer. resAllocSliceView failed!");
return NULL;
@@ -1772,7 +1775,7 @@ Resource::unmapLayers(VirtualGPU* gpu)
sliceResource = dev().resAllocView(
gslResource(), gslSize,
calOffset, cal()->format_, cal()->channelOrder_, gslDim,
0, i, CAL_RESALLOCSLICEVIEW_LAYER);
0, i, CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER);
if (0 == sliceResource) {
LogError("Unmap layer. resAllocSliceView failed!");
return;
+34
Ver fichero
@@ -1150,6 +1150,17 @@ VirtualGPU::submitMapMemory(amd::MapMemoryCommand& vcmd)
}
}
else {
// Validate if it's a view for a map of mip level
if (memory->isUnmapWrite() && (vcmd.memory().parent() != NULL)) {
amd::Image* amdImage = vcmd.memory().parent()->asImage();
if ((amdImage != NULL) && (amdImage->getMipLevels() > 1)) {
// Save map write info in the parent object
dev().getGpuMemory(amdImage)->saveMapInfo(
vcmd.origin(), vcmd.size(),
vcmd.mapFlags(), vcmd.isEntireMemory(),
vcmd.memory().asImage());
}
}
if (!blitMgr().copyImageToBuffer(*memory,
*memory->mapMemory(), vcmd.origin(), dstOrigin,
vcmd.size(), vcmd.isEntireMemory())) {
@@ -1175,6 +1186,20 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
profilingBegin(vcmd, true);
gpu::Memory* memory = dev().getGpuMemory(&vcmd.memory());
amd::Memory* owner = memory->owner();
bool unmapMip = false;
// Check if image is a mipmap and assign a saved view
amd::Image* amdImage = owner->asImage();
if ((amdImage != NULL) && (amdImage->getMipLevels() > 1) &&
memory->isUnmapWrite() &&
(memory->writeMapInfo()->baseMip_ != NULL)) {
// Clear unmap flags from the parent image
memory->clearUnmapFlags();
// Assign mip level view
amdImage = memory->writeMapInfo()->baseMip_;
memory = dev().getGpuMemory(amdImage);
unmapMip = true;
}
// We used host memory
if ((owner->getHostMem() != NULL) && memory->isDirectMap()) {
@@ -1249,6 +1274,11 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
}
}
}
else if ((amdImage != NULL) && (amdImage->getMipLevels() > 1) &&
(!memory->isUnmapWrite())) {
// Release a view for a mipmap map
amdImage->release();
}
else {
LogError("Unhandled unmap!");
vcmd.setStatus(CL_INVALID_VALUE);
@@ -1257,6 +1287,10 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
// Clear unmap flags
memory->clearUnmapFlags();
// Release a view for a mipmap map
if (unmapMip) {
amdImage->release();
}
profilingEnd(vcmd);
}
-20
Ver fichero
@@ -680,26 +680,6 @@ Device::globalFreeMemory(size_t *freeMemory) const
return false;
}
void*
Device::allocMapTarget(
amd::Memory& mem,
const amd::Coord3D& origin,
const amd::Coord3D& region,
uint mapFlags,
size_t* rowPitch,
size_t* slicePitch)
{
// Translate memory references
oclhsa::Memory* memory = getOclHsaMemory(&mem);
if (memory == NULL) {
LogError("allocMapTarget failed. Can't allocate video memory");
return NULL;
}
// Pass request over to memory
return memory->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
}
bool
Device::bindExternalDevice(
intptr_t type,
-25
Ver fichero
@@ -185,20 +185,6 @@ public:
return false;
}
//! Gets a pointer to a region of host-visible memory for use as the target
//! of a non-blocking map for a given memory object
virtual void* allocMapTarget(
amd::Memory& mem, //!< Abstraction layer memory object
const amd::Coord3D& origin, //!< The map location in memory
const amd::Coord3D& region, //!< The map region in memory
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
) {
ShouldNotReachHere();
return NULL;
}
//! Releases non-blocking map target memory
virtual void freeMapTarget(amd::Memory& mem, void* target) { ShouldNotReachHere();}
@@ -318,17 +304,6 @@ public:
//!< pDevice/pContext, do not bind.
);
//! Gets a pointer to a region of host-visible memory for use as the target
//! of a non-blocking map for a given memory object
virtual void *allocMapTarget(
amd::Memory &mem, //!< Abstraction layer memory object
const amd::Coord3D &origin, //!< The map location in memory
const amd::Coord3D &region, //!< The map region in memory
uint mapFlags, //!< Map flags
size_t *rowPitch = NULL, //!< Row pitch for the mapped memory
size_t *slicePitch = NULL //!< Slice for the mapped memory
);
//! Gets free memory on a GPU device
virtual bool globalFreeMemory(size_t *freeMemory) const;
+2 -2
Ver fichero
@@ -156,7 +156,7 @@ class HostQueue : public CommandQueue
}
//! Get virtual device for the current thread
const device::VirtualDevice* vdev() const { return virtualDevice_; }
device::VirtualDevice* vdev() const { return virtualDevice_; }
private:
device::VirtualDevice* virtualDevice_; //!< Virtual device for this thread
@@ -207,7 +207,7 @@ public:
void finish();
//! Get virtual device for the current command queue
const device::VirtualDevice* vdev() const { return thread_.vdev(); }
device::VirtualDevice* vdev() const { return thread_.vdev(); }
//! Return the current queue as the HostQueue
virtual HostQueue* asHostQueue() { return this; }