From ac8d2437d0523c7fb607e6b2f3bf8e1b98067c2c Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 7 Mar 2018 17:35:30 -0500 Subject: [PATCH] P4 to Git Change 1524071 by gandryey@gera-w8 on 2018/03/07 17:26:30 SWDEV-147487 - DX9/DX11 texture and OpenCL interop for YUY2 - Enable YUY2 support for DX11 and DX9. YUY2 contains just one plane of interleaved Y0UY1V components and can be mapped to (CL_RGBA, CL_UNSIGNED_INT8) with image width reduced by 2. YUY2 provides better quality due to 16bit data per pixel Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#23 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#33 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#241 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#49 edit --- opencl/api/opencl/amdocl/cl_d3d11.cpp | 10 ++++++++++ opencl/api/opencl/amdocl/cl_d3d9.cpp | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/opencl/api/opencl/amdocl/cl_d3d11.cpp b/opencl/api/opencl/amdocl/cl_d3d11.cpp index 8f9d4516e3..eed8ebac51 100644 --- a/opencl/api/opencl/amdocl/cl_d3d11.cpp +++ b/opencl/api/opencl/amdocl/cl_d3d11.cpp @@ -600,6 +600,9 @@ cl_uint D3D11Object::getMiscFlag() { if (objDesc_.dxgiFormat_ == DXGI_FORMAT_NV12) { return 1; } + else if (objDesc_.dxgiFormat_ == DXGI_FORMAT_YUY2) { + return 3; + } return 0; } @@ -815,6 +818,10 @@ int D3D11Object::initD3D11Object(const Context& amdContext, ID3D11Resource* pRes obj.objDesc_.objSize_.Height /= 2; } } + // RGBA8 covers 2 pixels, thus divide width by 2 + if (desc.Format == DXGI_FORMAT_YUY2) { + obj.objDesc_.objSize_.Width /= 2; + } } break; case D3D11_RESOURCE_DIMENSION_TEXTURE3D: // = 4 @@ -1450,6 +1457,8 @@ size_t D3D11Object::getElementBytes(DXGI_FORMAT dxgiFmt, cl_uint plane) { case DXGI_FORMAT_B8G8R8A8_UNORM: case DXGI_FORMAT_B8G8R8X8_UNORM: + + case DXGI_FORMAT_YUY2: bytesPerPixel = 4; break; @@ -1651,6 +1660,7 @@ cl_image_format D3D11Object::getCLFormatFromDXGI(DXGI_FORMAT dxgiFmt, cl_uint pl break; case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_YUY2: fmt.image_channel_order = CL_RGBA; fmt.image_channel_data_type = CL_UNSIGNED_INT8; break; diff --git a/opencl/api/opencl/amdocl/cl_d3d9.cpp b/opencl/api/opencl/amdocl/cl_d3d9.cpp index f6d2577e92..06b33f909e 100644 --- a/opencl/api/opencl/amdocl/cl_d3d9.cpp +++ b/opencl/api/opencl/amdocl/cl_d3d9.cpp @@ -16,6 +16,7 @@ #define D3DFMT_NV_12 static_cast(MAKEFOURCC('N', 'V', '1', '2')) #define D3DFMT_YV_12 static_cast(MAKEFOURCC('Y', 'V', '1', '2')) +#define D3DFMT_YUY2 static_cast(MAKEFOURCC('Y', 'U', 'Y', '2')) RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, @@ -306,7 +307,6 @@ size_t D3D9Object::getElementBytes(D3DFORMAT d3d9Format, cl_uint plane) { switch (d3d9Format) { case D3DFMT_UNKNOWN: case D3DFMT_UYVY: - case D3DFMT_YUY2: case D3DFMT_DXT1: case D3DFMT_DXT2: case D3DFMT_DXT3: @@ -372,6 +372,7 @@ size_t D3D9Object::getElementBytes(D3DFORMAT d3d9Format, cl_uint plane) { case D3DFMT_R8G8_B8G8: case D3DFMT_G8R8_G8B8: case D3DFMT_G16R16F: + case D3DFMT_YUY2: bytesPerPixel = 4; break; @@ -459,6 +460,9 @@ void setObjDesc(amd::D3D9ObjDesc_t& objDesc, D3DSURFACE_DESC& resDesc, cl_uint p objDesc.surfRect_.top = 0; objDesc.surfRect_.right = resDesc.Width - 1; objDesc.surfRect_.bottom = resDesc.Height - 1; + if (resDesc.Format == D3DFMT_YUY2) { + objDesc.objSize_.Width >>= 1; + } break; } } @@ -576,6 +580,9 @@ cl_uint D3D9Object::getMiscFlag() { case D3DFMT_YV_12: return 2; break; + case D3DFMT_YUY2: + return 3; + break; default: return 0; break; @@ -684,7 +691,10 @@ cl_image_format D3D9Object::getCLFormatFromD3D9(D3DFORMAT d3d9Fmt, cl_uint plane fmt.image_channel_order = CL_R; fmt.image_channel_data_type = CL_UNORM_INT8; break; - + case D3DFMT_YUY2: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNSIGNED_INT8; + break; case D3DFMT_UNKNOWN: case D3DFMT_R8G8B8: case D3DFMT_R5G6B5: @@ -707,7 +717,6 @@ cl_image_format D3D9Object::getCLFormatFromD3D9(D3DFORMAT d3d9Fmt, cl_uint plane case D3DFMT_A2W10V10U10: case D3DFMT_UYVY: case D3DFMT_R8G8_B8G8: - case D3DFMT_YUY2: case D3DFMT_G8R8_G8B8: case D3DFMT_DXT1: case D3DFMT_DXT2: