| 1 |
/* |
| 2 |
* Copyright (C) 2018-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/test/common/helpers/gtest_helpers.h" |
| 9 |
|
| 10 |
#include "opencl/source/os_interface/windows/d3d_sharing_functions.h" |
| 11 |
#include "opencl/source/sharings/d3d/cl_d3d_api.h" |
| 12 |
#include "opencl/test/unit_test/api/cl_api_tests.h" |
| 13 |
#include "opencl/test/unit_test/mocks/mock_context.h" |
| 14 |
|
| 15 |
#include "gtest/gtest.h" |
| 16 |
|
| 17 |
using namespace NEO; |
| 18 |
|
| 19 |
TEST(D3DContextTest, WhenContextIsCreatedThenSharingIsNotPresent) { |
| 20 |
MockContext context; |
| 21 |
|
| 22 |
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>()); |
| 23 |
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D10>>()); |
| 24 |
EXPECT_EQ(nullptr, context.getSharing<D3DSharingFunctions<D3DTypesHelper::D3D11>>()); |
| 25 |
} |
| 26 |
|
| 27 |
TEST(D3DContextTest, givenDispatchTableThenItContainsValidEntries) { |
| 28 |
sharingFactory.fillGlobalDispatchTable(); |
| 29 |
|
| 30 |
MockContext context; |
| 31 |
|
| 32 |
EXPECT_EQ(&clGetDeviceIDsFromDX9INTEL, context.dispatch.crtDispatch->clGetDeviceIDsFromDX9INTEL); |
| 33 |
EXPECT_EQ(&clCreateFromDX9MediaSurfaceINTEL, context.dispatch.crtDispatch->clCreateFromDX9MediaSurfaceINTEL); |
| 34 |
EXPECT_EQ(&clEnqueueAcquireDX9ObjectsINTEL, context.dispatch.crtDispatch->clEnqueueAcquireDX9ObjectsINTEL); |
| 35 |
EXPECT_EQ(&clEnqueueReleaseDX9ObjectsINTEL, context.dispatch.crtDispatch->clEnqueueReleaseDX9ObjectsINTEL); |
| 36 |
} |
| 37 |
|
| 38 |
struct ClIntelSharingFormatQueryDX9 : public ApiTests { |
| 39 |
std::vector<D3DFORMAT> supportedNonPlanarFormats; |
| 40 |
std::vector<D3DFORMAT> supportedPlanarFormats; |
| 41 |
std::vector<D3DFORMAT> supportedPlane1Formats; |
| 42 |
std::vector<D3DFORMAT> supportedPlane2Formats; |
| 43 |
std::vector<D3DFORMAT> retrievedFormats; |
| 44 |
|
| 45 |
cl_uint numImageFormats; |
| 46 |
|
| 47 |
void SetUp() override { |
| 48 |
ApiTests::SetUp(); |
| 49 |
supportedNonPlanarFormats = {D3DFMT_R32F, D3DFMT_R16F, D3DFMT_L16, D3DFMT_A8, |
| 50 |
D3DFMT_L8, D3DFMT_G32R32F, D3DFMT_G16R16F, D3DFMT_G16R16, |
| 51 |
D3DFMT_A8L8, D3DFMT_A32B32G32R32F, D3DFMT_A16B16G16R16F, D3DFMT_A16B16G16R16, |
| 52 |
D3DFMT_A8B8G8R8, D3DFMT_X8B8G8R8, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8}; |
| 53 |
|
| 54 |
supportedPlanarFormats = {D3DFMT_YUY2, D3DFMT_UYVY, |
| 55 |
static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), |
| 56 |
static_cast<D3DFORMAT>(MAKEFOURCC('Y', 'V', '1', '2')), |
| 57 |
static_cast<D3DFORMAT>(MAKEFOURCC('Y', 'V', 'Y', 'U')), |
| 58 |
static_cast<D3DFORMAT>(MAKEFOURCC('V', 'Y', 'U', 'Y'))}; |
| 59 |
|
| 60 |
supportedPlane1Formats = {static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), |
| 61 |
static_cast<D3DFORMAT>(MAKEFOURCC('Y', 'V', '1', '2'))}; |
| 62 |
|
| 63 |
supportedPlane2Formats = {static_cast<D3DFORMAT>(MAKEFOURCC('Y', 'V', '1', '2'))}; |
| 64 |
retrievedFormats.assign(supportedNonPlanarFormats.size() + supportedPlanarFormats.size(), D3DFMT_UNKNOWN); |
| 65 |
} |
| 66 |
|
| 67 |
void TearDown() override { |
| 68 |
ApiTests::TearDown(); |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
namespace ULT { |
| 73 |
|
| 74 |
TEST_F(ClIntelSharingFormatQueryDX9, givenInvalidContextWhenMediaSurfaceFormatsRequestedThenInvalidContextError) { |
| 75 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(nullptr, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, |
| 76 |
static_cast<cl_uint>(retrievedFormats.size()), |
| 77 |
&retrievedFormats[0], |
| 78 |
&numImageFormats); |
| 79 |
EXPECT_EQ(CL_INVALID_CONTEXT, retVal); |
| 80 |
} |
| 81 |
|
| 82 |
TEST_F(ClIntelSharingFormatQueryDX9, givenInvalidFlagsWhenMediaSurfaceFormatsRequestedThenInvalidValueError) { |
| 83 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL( |
| 84 |
pContext, 0, CL_MEM_OBJECT_IMAGE2D, 0, |
| 85 |
static_cast<cl_uint>(retrievedFormats.size()), |
| 86 |
&retrievedFormats[0], &numImageFormats); |
| 87 |
EXPECT_EQ(CL_INVALID_VALUE, retVal); |
| 88 |
} |
| 89 |
|
| 90 |
TEST_F(ClIntelSharingFormatQueryDX9, givenInvalidImageTypeWhenMediaSurfaceFormatsRequestedThenInvalidValueError) { |
| 91 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, 0, 0, static_cast<cl_uint>(retrievedFormats.size()), |
| 92 |
&retrievedFormats[0], &numImageFormats); |
| 93 |
EXPECT_EQ(CL_INVALID_VALUE, retVal); |
| 94 |
} |
| 95 |
|
| 96 |
TEST_F(ClIntelSharingFormatQueryDX9, givenValidParametersWhenRequestedMediaSurfaceFormatsBelowMaximumThenExceedingFormatAreaRemainsUntouched) { |
| 97 |
for (cl_uint i = 0; i <= static_cast<cl_uint>(retrievedFormats.size()); ++i) { |
| 98 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, i, |
| 99 |
&retrievedFormats[0], &numImageFormats); |
| 100 |
EXPECT_EQ(retVal, CL_SUCCESS); |
| 101 |
for (cl_uint j = i; j < retrievedFormats.size(); ++j) { |
| 102 |
EXPECT_EQ(retrievedFormats[j], D3DFMT_UNKNOWN); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
TEST_F(ClIntelSharingFormatQueryDX9, givenValidParametersWhenRequestingMediaSurfaceFormatsForPlane0ThenAllKnownFormatsAreIncludedInTheResult) { |
| 108 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, |
| 109 |
static_cast<cl_uint>(retrievedFormats.size()), |
| 110 |
&retrievedFormats[0], |
| 111 |
&numImageFormats); |
| 112 |
EXPECT_EQ(retVal, CL_SUCCESS); |
| 113 |
|
| 114 |
EXPECT_EQ(supportedNonPlanarFormats.size() + supportedPlanarFormats.size(), numImageFormats); |
| 115 |
|
| 116 |
for (auto format : supportedNonPlanarFormats) { |
| 117 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 118 |
EXPECT_NE(found, retrievedFormats.end()); |
| 119 |
} |
| 120 |
|
| 121 |
for (auto format : supportedPlanarFormats) { |
| 122 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 123 |
EXPECT_NE(found, retrievedFormats.end()); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
TEST_F(ClIntelSharingFormatQueryDX9, givenValidParametersWhenRequestingMediaSurfaceFormatsForPlane1ThenOnlyPlanarFormatsAreIncludedInTheResult) { |
| 128 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 1, |
| 129 |
static_cast<cl_uint>(retrievedFormats.size()), |
| 130 |
&retrievedFormats[0], |
| 131 |
&numImageFormats); |
| 132 |
ASSERT_EQ(retVal, CL_SUCCESS); |
| 133 |
|
| 134 |
EXPECT_EQ(supportedPlane1Formats.size(), numImageFormats); |
| 135 |
|
| 136 |
for (auto format : supportedPlane1Formats) { |
| 137 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 138 |
EXPECT_NE(found, retrievedFormats.end()); |
| 139 |
} |
| 140 |
|
| 141 |
for (auto format : supportedNonPlanarFormats) { |
| 142 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 143 |
EXPECT_EQ(found, retrievedFormats.end()); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
TEST_F(ClIntelSharingFormatQueryDX9, givenValidParametersWhenRequestingMediaSurfaceFormatsForPlane2ThenOnlyYV12FormatIsIncludedInTheResult) { |
| 148 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 2, |
| 149 |
static_cast<cl_uint>(retrievedFormats.size()), |
| 150 |
&retrievedFormats[0], |
| 151 |
&numImageFormats); |
| 152 |
ASSERT_EQ(retVal, CL_SUCCESS); |
| 153 |
EXPECT_EQ(supportedPlane2Formats.size(), numImageFormats); |
| 154 |
|
| 155 |
for (auto format : supportedPlane2Formats) { |
| 156 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 157 |
EXPECT_NE(found, retrievedFormats.end()); |
| 158 |
} |
| 159 |
|
| 160 |
for (auto format : supportedNonPlanarFormats) { |
| 161 |
auto found = std::find(retrievedFormats.begin(), retrievedFormats.end(), format); |
| 162 |
EXPECT_EQ(found, retrievedFormats.end()); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
TEST_F(ClIntelSharingFormatQueryDX9, givenValidParametersWhenRequestingMediaSurfaceFormatsForPlaneGraterThan2ThenZeroNumFormatsIsReturned) { |
| 167 |
retVal = clGetSupportedDX9MediaSurfaceFormatsINTEL(pContext, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 3, |
| 168 |
0, |
| 169 |
nullptr, |
| 170 |
&numImageFormats); |
| 171 |
EXPECT_EQ(retVal, CL_SUCCESS); |
| 172 |
EXPECT_EQ(0u, numImageFormats); |
| 173 |
} |
| 174 |
} // namespace ULT |