Skip to content

Commit 004ea39

Browse files
Correct image format reporting for OCL 1.2
Change-Id: Ia2160248d1cda6c13219598f8962aa3372885b9a Signed-off-by: Koska <[email protected]> Related-To: NEO-3981
1 parent 5f4f1eb commit 004ea39

File tree

57 files changed

+260
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+260
-205
lines changed

runtime/api/api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ cl_int CL_API_CALL clGetImageParamsINTEL(cl_context context,
10981098
retVal = Image::validateImageFormat(imageFormat);
10991099
}
11001100
if (CL_SUCCESS == retVal) {
1101-
surfaceFormat = (ClSurfaceFormatInfo *)Image::getSurfaceFormatFromTable(memFlags, imageFormat);
1101+
surfaceFormat = (ClSurfaceFormatInfo *)Image::getSurfaceFormatFromTable(memFlags, imageFormat, pContext->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
11021102
retVal = Image::validate(pContext, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memFlags, 0, 0), surfaceFormat, imageDesc, nullptr);
11031103
}
11041104
if (CL_SUCCESS == retVal) {

runtime/context/context.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ cl_int Context::getSupportedImageFormats(
282282
};
283283

284284
if (flags & CL_MEM_READ_ONLY) {
285-
appendImageFormats(SurfaceFormats::readOnly());
285+
if (this->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport >= 20) {
286+
appendImageFormats(SurfaceFormats::readOnly20());
287+
} else {
288+
appendImageFormats(SurfaceFormats::readOnly12());
289+
}
286290
if (Image::isImage2d(imageType) && nv12ExtensionEnabled) {
287291
appendImageFormats(SurfaceFormats::planarYuv());
288292
}
@@ -298,7 +302,11 @@ cl_int Context::getSupportedImageFormats(
298302
appendImageFormats(SurfaceFormats::readWriteDepth());
299303
}
300304
} else if (nv12ExtensionEnabled && (flags & CL_MEM_NO_ACCESS_INTEL)) {
301-
appendImageFormats(SurfaceFormats::readOnly());
305+
if (this->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport >= 20) {
306+
appendImageFormats(SurfaceFormats::readOnly20());
307+
} else {
308+
appendImageFormats(SurfaceFormats::readOnly12());
309+
}
302310
if (Image::isImage2d(imageType)) {
303311
appendImageFormats(SurfaceFormats::planarYuv());
304312
}

runtime/helpers/surface_formats.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ namespace NEO {
8484

8585
//Initialize this with the required formats first.
8686
//Append the optional one later
87-
const ClSurfaceFormatInfo SurfaceFormats::readOnlySurfaceFormats[] = { COMMONFORMATS, READONLYFORMATS, SRGBFORMATS };
87+
const ClSurfaceFormatInfo SurfaceFormats::readOnlySurfaceFormats12[] = { COMMONFORMATS, READONLYFORMATS };
88+
const ClSurfaceFormatInfo SurfaceFormats::readOnlySurfaceFormats20[] = { COMMONFORMATS, READONLYFORMATS, SRGBFORMATS };
8889

8990
const ClSurfaceFormatInfo SurfaceFormats::writeOnlySurfaceFormats[] = { COMMONFORMATS };
9091

@@ -105,8 +106,12 @@ const ClSurfaceFormatInfo SurfaceFormats::readOnlyDepthSurfaceFormats[] = { DEPT
105106

106107
const ClSurfaceFormatInfo SurfaceFormats::readWriteDepthSurfaceFormats[] = { DEPTHFORMATS };
107108

108-
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::readOnly() noexcept {
109-
return ArrayRef<const ClSurfaceFormatInfo>(readOnlySurfaceFormats);
109+
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::readOnly12() noexcept {
110+
return ArrayRef<const ClSurfaceFormatInfo>(readOnlySurfaceFormats12);
111+
}
112+
113+
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::readOnly20() noexcept {
114+
return ArrayRef<const ClSurfaceFormatInfo>(readOnlySurfaceFormats20);
110115
}
111116

112117
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::writeOnly() noexcept {
@@ -133,9 +138,14 @@ ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::readWriteDepth() noexcept {
133138
return ArrayRef<const ClSurfaceFormatInfo>(readWriteDepthSurfaceFormats);
134139
}
135140

136-
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags) noexcept {
141+
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags, unsigned int clVersionSupport) noexcept {
137142
if (flags & CL_MEM_READ_ONLY) {
138-
return readOnly();
143+
if(clVersionSupport >= 20 ) {
144+
return readOnly20();
145+
}
146+
else {
147+
return readOnly12();
148+
}
139149
}
140150
else if (flags & CL_MEM_WRITE_ONLY) {
141151
return writeOnly();
@@ -145,7 +155,7 @@ ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags
145155
}
146156
}
147157

148-
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat) noexcept {
158+
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat, unsigned int clVersionSupport) noexcept {
149159
if (NEO::IsNV12Image(imageFormat)) {
150160
return planarYuv();
151161
}
@@ -161,7 +171,12 @@ ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags
161171
}
162172
}
163173
else if (flags & CL_MEM_READ_ONLY) {
164-
return readOnly();
174+
if(clVersionSupport >= 20 ) {
175+
return readOnly20();
176+
}
177+
else {
178+
return readOnly12();
179+
}
165180
}
166181
else if (flags & CL_MEM_WRITE_ONLY) {
167182
return writeOnly();

runtime/helpers/surface_formats.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct ClSurfaceFormatInfo {
2121

2222
class SurfaceFormats {
2323
private:
24-
static const ClSurfaceFormatInfo readOnlySurfaceFormats[];
24+
static const ClSurfaceFormatInfo readOnlySurfaceFormats12[];
25+
static const ClSurfaceFormatInfo readOnlySurfaceFormats20[];
2526
static const ClSurfaceFormatInfo writeOnlySurfaceFormats[];
2627
static const ClSurfaceFormatInfo readWriteSurfaceFormats[];
2728
static const ClSurfaceFormatInfo readOnlyDepthSurfaceFormats[];
@@ -31,16 +32,17 @@ class SurfaceFormats {
3132
static const ClSurfaceFormatInfo planarYuvSurfaceFormats[];
3233

3334
public:
34-
static ArrayRef<const ClSurfaceFormatInfo> readOnly() noexcept;
35+
static ArrayRef<const ClSurfaceFormatInfo> readOnly12() noexcept;
36+
static ArrayRef<const ClSurfaceFormatInfo> readOnly20() noexcept;
3537
static ArrayRef<const ClSurfaceFormatInfo> writeOnly() noexcept;
3638
static ArrayRef<const ClSurfaceFormatInfo> readWrite() noexcept;
3739
static ArrayRef<const ClSurfaceFormatInfo> packedYuv() noexcept;
3840
static ArrayRef<const ClSurfaceFormatInfo> planarYuv() noexcept;
3941
static ArrayRef<const ClSurfaceFormatInfo> readOnlyDepth() noexcept;
4042
static ArrayRef<const ClSurfaceFormatInfo> readWriteDepth() noexcept;
4143

42-
static ArrayRef<const ClSurfaceFormatInfo> surfaceFormats(cl_mem_flags flags) noexcept;
43-
static ArrayRef<const ClSurfaceFormatInfo> surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat) noexcept;
44+
static ArrayRef<const ClSurfaceFormatInfo> surfaceFormats(cl_mem_flags flags, unsigned int clVersionSupport) noexcept;
45+
static ArrayRef<const ClSurfaceFormatInfo> surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat, unsigned int clVersionSupport) noexcept;
4446
};
4547

4648
} // namespace NEO

runtime/mem_obj/image.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ cl_int Image::writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch) {
995995
imageDesc.mem_object = this;
996996
// get access to the Y plane (CL_R)
997997
imageDesc.image_depth = 0;
998-
const ClSurfaceFormatInfo *surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
998+
const ClSurfaceFormatInfo *surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
999999

10001000
// Create NV12 UV Plane image
10011001
std::unique_ptr<Image> imageYPlane(Image::create(
@@ -1020,7 +1020,7 @@ cl_int Image::writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch) {
10201020
imageFormat.image_channel_order = CL_RG;
10211021

10221022
hostPtr = static_cast<const void *>(static_cast<const char *>(hostPtr) + (hostPtrRowPitch * this->imageDesc.image_height));
1023-
surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
1023+
surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
10241024
// Create NV12 UV Plane image
10251025
std::unique_ptr<Image> imageUVPlane(Image::create(
10261026
context,
@@ -1037,13 +1037,13 @@ cl_int Image::writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch) {
10371037
return retVal;
10381038
}
10391039

1040-
const ClSurfaceFormatInfo *Image::getSurfaceFormatFromTable(cl_mem_flags flags, const cl_image_format *imageFormat) {
1040+
const ClSurfaceFormatInfo *Image::getSurfaceFormatFromTable(cl_mem_flags flags, const cl_image_format *imageFormat, unsigned int clVersionSupport) {
10411041
if (!imageFormat) {
10421042
DEBUG_BREAK_IF("Invalid format");
10431043
return nullptr;
10441044
}
10451045

1046-
ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::surfaceFormats(flags, imageFormat);
1046+
ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::surfaceFormats(flags, imageFormat, clVersionSupport);
10471047

10481048
for (auto &format : formats) {
10491049
if (format.OCLImageFormat.image_channel_data_type == imageFormat->image_channel_data_type &&
@@ -1101,7 +1101,7 @@ Image *Image::validateAndCreateImage(Context *context,
11011101
return nullptr;
11021102
}
11031103

1104-
const auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat);
1104+
const auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
11051105

11061106
errcodeRet = Image::validate(context, memoryProperties, surfaceFormat, imageDesc, hostPtr);
11071107
if (errcodeRet != CL_SUCCESS) {

runtime/mem_obj/image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class Image : public MemObj {
172172
uint32_t peekMipCount() { return mipCount; }
173173
void setMipCount(uint32_t mipCountNew) { this->mipCount = mipCountNew; }
174174

175-
static const ClSurfaceFormatInfo *getSurfaceFormatFromTable(cl_mem_flags flags, const cl_image_format *imageFormat);
175+
static const ClSurfaceFormatInfo *getSurfaceFormatFromTable(cl_mem_flags flags, const cl_image_format *imageFormat, unsigned int clVersionSupport);
176176
static cl_int validateRegionAndOrigin(const size_t *origin, const size_t *region, const cl_image_desc &imgDesc);
177177

178178
cl_int writeNV12Planes(const void *hostPtr, size_t hostPtrRowPitch);

runtime/sharings/d3d/d3d_sharing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void D3DSharing<D3D>::updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, ImagePl
8181
}
8282

8383
template <typename D3D>
84-
const ClSurfaceFormatInfo *D3DSharing<D3D>::findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags) {
85-
ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::surfaceFormats(flags);
84+
const ClSurfaceFormatInfo *D3DSharing<D3D>::findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags, unsigned int clVersionSupport) {
85+
ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::surfaceFormats(flags, clVersionSupport);
8686
for (auto &format : formats) {
8787
if (gmmFormat == format.surfaceFormat.GMMSurfaceFormat) {
8888
return &format;

runtime/sharings/d3d/d3d_sharing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class D3DSharing : public SharingHandler {
3636
unsigned int &getSubresource() { return subresource; }
3737
typename D3DQuery *getQuery() { return d3dQuery; }
3838
bool isSharedResource() { return sharedResource; }
39-
static const ClSurfaceFormatInfo *findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags);
39+
static const ClSurfaceFormatInfo *findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags, unsigned int clVersionSupport);
4040
static bool isFormatWithPlane1(DXGI_FORMAT format);
4141

4242
protected:

runtime/sharings/d3d/d3d_surface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo
7070
}
7171

7272
imgInfo.plane = GmmTypesConverter::convertPlane(imagePlane);
73-
auto *clSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat);
73+
auto *clSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
7474
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
7575

7676
bool isSharedResource = false;

runtime/sharings/d3d/d3d_texture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
8484
clSurfaceFormat = findYuvSurfaceFormatInfo(textureDesc.Format, imagePlane, flags);
8585
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
8686
} else {
87-
clSurfaceFormat = findSurfaceFormatInfo(alloc->getDefaultGmm()->gmmResourceInfo->getResourceFormat(), flags);
87+
clSurfaceFormat = findSurfaceFormatInfo(alloc->getDefaultGmm()->gmmResourceInfo->getResourceFormat(), flags, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
8888
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
8989
}
9090

@@ -143,7 +143,7 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
143143
updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, ImagePlane::NO_PLANE, 0u);
144144

145145
auto d3dTextureObj = new D3DTexture<D3D>(context, d3dTexture, subresource, textureStaging, sharedResource);
146-
auto *clSurfaceFormat = findSurfaceFormatInfo(alloc->getDefaultGmm()->gmmResourceInfo->getResourceFormat(), flags);
146+
auto *clSurfaceFormat = findSurfaceFormatInfo(alloc->getDefaultGmm()->gmmResourceInfo->getResourceFormat(), flags, context->getDevice(0)->getHardwareInfo().capabilityTable.clVersionSupport);
147147
imgInfo.qPitch = alloc->getDefaultGmm()->queryQPitch(GMM_RESOURCE_TYPE::RESOURCE_3D);
148148

149149
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat;
@@ -172,5 +172,5 @@ const ClSurfaceFormatInfo *D3DTexture<D3D>::findYuvSurfaceFormatInfo(DXGI_FORMAT
172172
imgFormat.image_channel_data_type = CL_UNORM_INT8;
173173
}
174174

175-
return Image::getSurfaceFormatFromTable(flags, &imgFormat);
175+
return Image::getSurfaceFormatFromTable(flags, &imgFormat, 12);
176176
}

0 commit comments

Comments
 (0)