diff --git a/rocclr/runtime/device/gpu/gpudevice.cpp b/rocclr/runtime/device/gpu/gpudevice.cpp index a11508a67d..8a5274a2af 100644 --- a/rocclr/runtime/device/gpu/gpudevice.cpp +++ b/rocclr/runtime/device/gpu/gpudevice.cpp @@ -2011,7 +2011,7 @@ Device::createView(amd::Memory& owner, const device::Memory& parent) const const gpu::Memory& gpuMem = static_cast(parent); params.owner_ = &owner; - params.level_ = 0; + params.level_ = image.getBaseMipLevel(); params.layer_ = 0; params.resource_ = &gpuMem; params.gpu_ = reinterpret_cast(owner.getVirtualDevice()); diff --git a/rocclr/runtime/platform/memory.cpp b/rocclr/runtime/platform/memory.cpp index b3fc22ed56..d31f820cdd 100644 --- a/rocclr/runtime/platform/memory.cpp +++ b/rocclr/runtime/platform/memory.cpp @@ -548,9 +548,12 @@ Pipe::initDeviceMemory() context_().devices().size() * sizeof(DeviceMemory)); } +#define GETMIPDIM(dim, mip) (((dim >> mip) > 0) ? (dim >> mip) : 1) + Image::Image( const Format& format, - Image& parent) + Image& parent, + uint baseMipLevel) : Memory(parent, 0, 0, parent.getWidth() * parent.getHeight() * parent.getDepth() * format.getElementSize()) , impl_(format, Coord3D(parent.getWidth() * @@ -559,7 +562,22 @@ Image::Image( parent.getDepth()), parent.getRowPitch(), parent.getSlicePitch(), parent.getBytePitch()) , mipLevels_(1) + , baseMipLevel_(baseMipLevel) { + if (baseMipLevel > 0) { + impl_.region_.c[0] = GETMIPDIM(parent.getWidth(), baseMipLevel) * + parent.getImageFormat().getElementSize() / format.getElementSize(); + impl_.region_.c[1] = GETMIPDIM(parent.getHeight(), baseMipLevel); + impl_.region_.c[2] = GETMIPDIM(parent.getDepth(), baseMipLevel); + + if (parent.getType() == CL_MEM_OBJECT_IMAGE1D_ARRAY) { + impl_.region_.c[1] = parent.getHeight(); + } + else if (parent.getType() == CL_MEM_OBJECT_IMAGE2D_ARRAY) { + impl_.region_.c[2] = parent.getDepth(); + } + size_ = getWidth() * getHeight() * parent.getDepth() * format.getElementSize(); + } initDimension(); } @@ -577,6 +595,7 @@ Image::Image( : Memory(context, type, flags, width * height * depth * format.getElementSize()) , impl_(format, Coord3D(width, height, depth), rowPitch, slicePitch) , mipLevels_(mipLevels) + , baseMipLevel_(0) { initDimension(); } @@ -594,6 +613,7 @@ Image::Image( : Memory(buffer, flags, 0, buffer.getSize(), type) , impl_(format, Coord3D(width, height, depth), rowPitch, slicePitch) , mipLevels_(1) + , baseMipLevel_(0) { initDimension(); } @@ -1158,12 +1178,13 @@ Image* Image::createView( const Context& context, const Format& format, - device::VirtualDevice* vDev) + device::VirtualDevice* vDev, + uint baseMipLevel) { Image* view = NULL; // Find the image dimensions and create a corresponding object - view = new (context) Image(format, *this); + view = new (context) Image(format, *this, baseMipLevel); // Set GPU virtual device for this view view->setVirtualDevice(vDev); diff --git a/rocclr/runtime/platform/memory.hpp b/rocclr/runtime/platform/memory.hpp index dab5a2b44f..24bc78b5e3 100644 --- a/rocclr/runtime/platform/memory.hpp +++ b/rocclr/runtime/platform/memory.hpp @@ -490,12 +490,12 @@ public: struct Impl { - const amd::Coord3D region_; //!< Image size - size_t rp_; //!< Image row pitch - size_t sp_; //!< Image slice pitch - const Format format_; //!< Image format - void* reserved_; - size_t bp_; + amd::Coord3D region_; //!< Image size + size_t rp_; //!< Image row pitch + size_t sp_; //!< Image slice pitch + const Format format_; //!< Image format + void* reserved_; + size_t bp_; Impl(const Format& format, Coord3D region, size_t rp, size_t sp = 0, size_t bp = 0) : region_(region), rp_(rp), sp_(sp), format_(format), bp_(bp) @@ -503,14 +503,16 @@ public: }; private: - Impl impl_; //!< Image object description - size_t dim_; //!< Image dimension - uint mipLevels_; //!< The number of mip levels + Impl impl_; //!< Image object description + size_t dim_; //!< Image dimension + uint mipLevels_; //!< The number of mip levels + uint baseMipLevel_; //!< The base mip level for a view protected: Image( const Format& format, - Image& parent); + Image& parent, + uint baseMipLevel = 0); ///! Initializes the device memory array which is nested // after'Image' object in memory layout. @@ -583,9 +585,10 @@ public: //! Creates a view memory object virtual Image* createView( - const Context& context, //!< Context for a view creation - const Format& format, //!< The new format for a view - device::VirtualDevice* vDev //!< Virtual device object + const Context& context, //!< Context for a view creation + const Format& format, //!< The new format for a view + device::VirtualDevice* vDev, //!< Virtual device object + uint baseMipLevel = 0 //!< Base mip level for a view ); //! Returns the impl for this image. @@ -617,6 +620,9 @@ public: //! Returns image's slice pitch in bytes uint getMipLevels() const { return mipLevels_; } + //! Returns image's slice pitch in bytes + uint getBaseMipLevel() const { return baseMipLevel_; } + //! Get the image covered region const Coord3D& getRegion() const { return impl_.region_; }