mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Refactor GetSupportedFormats calls
Related-To: NEO-612 Change-Id: I2d6b4eeed06cfb3e3afededbfc5e4a1d1355ded7 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
c093f27888
commit
14d8165887
@@ -695,8 +695,10 @@ cl_int CL_API_CALL clEnqueueReleaseD3D11ObjectsKHR(cl_command_queue commandQueue
|
||||
return retVal;
|
||||
}
|
||||
|
||||
cl_int CL_API_CALL clGetSupportedDX9MediaSurfaceFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType,
|
||||
cl_uint numEntries, D3DFORMAT *dx9Formats, cl_uint *numImageFormats) {
|
||||
cl_int CL_API_CALL clGetSupportedDX9MediaSurfaceFormatsINTEL(cl_context context, cl_mem_flags flags,
|
||||
cl_mem_object_type imageType, cl_uint plane,
|
||||
cl_uint numEntries, D3DFORMAT *dx9Formats,
|
||||
cl_uint *numImageFormats) {
|
||||
|
||||
if (validateObject(context) != CL_SUCCESS) {
|
||||
return CL_INVALID_CONTEXT;
|
||||
@@ -711,24 +713,49 @@ cl_int CL_API_CALL clGetSupportedDX9MediaSurfaceFormatsINTEL(cl_context context,
|
||||
}
|
||||
|
||||
cl_uint i = 0;
|
||||
for (auto format : D3DSurface::D3DtoClFormatConversions) {
|
||||
if (i >= numEntries) {
|
||||
break;
|
||||
switch (plane) {
|
||||
case 0:
|
||||
for (auto format : D3DSurface::D3DtoClFormatConversions) {
|
||||
if (i >= numEntries) {
|
||||
break;
|
||||
}
|
||||
dx9Formats[i++] = format.first;
|
||||
}
|
||||
dx9Formats[i++] = format.first;
|
||||
*numImageFormats = static_cast<cl_uint>(D3DSurface::D3DtoClFormatConversions.size());
|
||||
break;
|
||||
case 1:
|
||||
for (auto format : D3DSurface::D3DPlane1Formats) {
|
||||
if (i >= numEntries) {
|
||||
break;
|
||||
}
|
||||
dx9Formats[i++] = format;
|
||||
}
|
||||
*numImageFormats = static_cast<cl_uint>(D3DSurface::D3DPlane1Formats.size());
|
||||
break;
|
||||
case 2:
|
||||
for (auto format : D3DSurface::D3DPlane2Formats) {
|
||||
if (i >= numEntries) {
|
||||
break;
|
||||
}
|
||||
dx9Formats[i++] = format;
|
||||
}
|
||||
*numImageFormats = static_cast<cl_uint>(D3DSurface::D3DPlane2Formats.size());
|
||||
break;
|
||||
default:
|
||||
*numImageFormats = 0;
|
||||
}
|
||||
|
||||
*numImageFormats = static_cast<cl_uint>(D3DSurface::D3DtoClFormatConversions.size());
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
cl_int CL_API_CALL clGetSupportedD3D10TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType,
|
||||
cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) {
|
||||
return getSupportedDXTextureFormats<D3DTypesHelper::D3D10>(context, imageType, numEntries, formats, numImageFormats);
|
||||
cl_int CL_API_CALL clGetSupportedD3D10TextureFormatsINTEL(cl_context context, cl_mem_flags flags,
|
||||
cl_mem_object_type imageType,
|
||||
cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numTextureFormats) {
|
||||
return getSupportedDXTextureFormats<D3DTypesHelper::D3D10>(context, imageType, 0, numEntries, formats, numTextureFormats);
|
||||
}
|
||||
|
||||
cl_int CL_API_CALL clGetSupportedD3D11TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType,
|
||||
cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) {
|
||||
return getSupportedDXTextureFormats<D3DTypesHelper::D3D11>(context, imageType, numEntries, formats, numImageFormats);
|
||||
cl_int CL_API_CALL clGetSupportedD3D11TextureFormatsINTEL(cl_context context, cl_mem_flags flags,
|
||||
cl_mem_object_type imageType, cl_uint plane,
|
||||
cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numTextureFormats) {
|
||||
return getSupportedDXTextureFormats<D3DTypesHelper::D3D11>(context, imageType, plane, numEntries, formats, numTextureFormats);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "runtime/context/context.inl"
|
||||
#include "runtime/os_interface/windows/d3d_sharing_functions.h"
|
||||
#include "runtime/sharings/d3d/d3d_sharing.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
|
||||
using namespace NEO;
|
||||
@@ -215,7 +216,7 @@ void D3DSharingFunctions<D3D>::checkFormatSupport(DXGI_FORMAT format, UINT *pFor
|
||||
}
|
||||
|
||||
template <typename D3D>
|
||||
std::vector<DXGI_FORMAT> &D3DSharingFunctions<D3D>::retrieveTextureFormats(cl_mem_object_type imageType) {
|
||||
std::vector<DXGI_FORMAT> &D3DSharingFunctions<D3D>::retrieveTextureFormats(cl_mem_object_type imageType, cl_uint plane) {
|
||||
auto cached = textureFormatCache.find(imageType);
|
||||
if (cached == textureFormatCache.end()) {
|
||||
bool success;
|
||||
@@ -224,15 +225,25 @@ std::vector<DXGI_FORMAT> &D3DSharingFunctions<D3D>::retrieveTextureFormats(cl_me
|
||||
return DXGINoFormats;
|
||||
}
|
||||
std::vector<DXGI_FORMAT> &cached_formats = cached->second;
|
||||
std::vector<DXGI_FORMAT> planarFormats(0);
|
||||
|
||||
cached_formats.reserve(arrayCount(DXGIFormats));
|
||||
for (auto DXGIFormat : DXGIFormats) {
|
||||
UINT format = 0;
|
||||
checkFormatSupport(DXGIFormat, &format);
|
||||
if (memObjectFormatSupport(imageType, format)) {
|
||||
cached_formats.push_back(DXGIFormat);
|
||||
if (D3DSharing<D3D>::isFormatWithPlane1(DXGIFormat)) {
|
||||
planarFormats.push_back(DXGIFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
cached_formats.shrink_to_fit();
|
||||
textureFormatPlane1Cache.emplace(imageType, planarFormats);
|
||||
}
|
||||
|
||||
if (plane == 1) {
|
||||
return textureFormatPlane1Cache.find(imageType)->second;
|
||||
}
|
||||
return cached->second;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ void D3DSharingFunctions<D3DTypesHelper::D3D9>::fillCreateBufferDesc(D3DBufferDe
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<DXGI_FORMAT> &D3DSharingFunctions<D3DTypesHelper::D3D9>::retrieveTextureFormats(cl_mem_object_type imageType) {
|
||||
std::vector<DXGI_FORMAT> &D3DSharingFunctions<D3DTypesHelper::D3D9>::retrieveTextureFormats(cl_mem_object_type imageType, cl_uint plane) {
|
||||
return DXGINoFormats;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ class D3DSharingFunctions : public SharingFunctions {
|
||||
void fillCreateTexture2dDesc(D3DTexture2dDesc &desc, D3DTexture2dDesc *srcDesc, cl_uint subresource);
|
||||
void fillCreateTexture3dDesc(D3DTexture3dDesc &desc, D3DTexture3dDesc *srcDesc, cl_uint subresource);
|
||||
|
||||
std::vector<DXGI_FORMAT> &retrieveTextureFormats(cl_mem_object_type imageType);
|
||||
std::vector<DXGI_FORMAT> &retrieveTextureFormats(cl_mem_object_type imageType, cl_uint plane);
|
||||
|
||||
protected:
|
||||
D3DDevice *d3dDevice = nullptr;
|
||||
@@ -151,11 +151,12 @@ class D3DSharingFunctions : public SharingFunctions {
|
||||
std::vector<DXGI_FORMAT> DXGINoFormats;
|
||||
std::vector<std::pair<D3DResource *, cl_uint>> trackedResources;
|
||||
std::map<cl_mem_object_type, std::vector<DXGI_FORMAT>> textureFormatCache;
|
||||
std::map<cl_mem_object_type, std::vector<DXGI_FORMAT>> textureFormatPlane1Cache;
|
||||
static void getDxgiDesc(DXGI_ADAPTER_DESC *dxgiDesc, IDXGIAdapter *adapter, D3DDevice *device);
|
||||
};
|
||||
|
||||
template <typename D3DSharing>
|
||||
static inline cl_int getSupportedDXTextureFormats(cl_context context, cl_mem_object_type imageType,
|
||||
static inline cl_int getSupportedDXTextureFormats(cl_context context, cl_mem_object_type imageType, cl_uint plane,
|
||||
cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) {
|
||||
Context *pContext = castToObject<Context>(context);
|
||||
if (!pContext) {
|
||||
@@ -167,10 +168,10 @@ static inline cl_int getSupportedDXTextureFormats(cl_context context, cl_mem_obj
|
||||
return CL_INVALID_CONTEXT;
|
||||
}
|
||||
|
||||
auto supported_formats = pSharing->retrieveTextureFormats(imageType);
|
||||
auto supported_formats = pSharing->retrieveTextureFormats(imageType, plane);
|
||||
|
||||
if (formats != nullptr) {
|
||||
memcpy_s(formats, sizeof(DXGI_FORMAT) * numEntries, supported_formats.data(), std::min(static_cast<size_t>(numEntries), supported_formats.size()));
|
||||
memcpy_s(formats, sizeof(DXGI_FORMAT) * numEntries, supported_formats.data(), sizeof(DXGI_FORMAT) * std::min(static_cast<size_t>(numEntries), supported_formats.size()));
|
||||
}
|
||||
|
||||
if (numImageFormats) {
|
||||
|
||||
Reference in New Issue
Block a user