• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2017 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "utils.h"
17 
get_device_ids(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements,cl_dx9_media_adapter_type_khr adapterType)18 int get_device_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements,
19                    cl_dx9_media_adapter_type_khr adapterType)
20 {
21   CResult result;
22 
23   std::auto_ptr<CDeviceWrapper> deviceWrapper;
24   if (!DeviceCreate(adapterType, deviceWrapper))
25   {
26     result.ResultSub(CResult::TEST_ERROR);
27     return result.Result();
28   }
29 
30   cl_uint devicesExpectedNum = 0;
31   cl_int error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, 0, 0, &devicesExpectedNum);
32   if (error != CL_SUCCESS || devicesExpectedNum < 1)
33   {
34     log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error));
35     result.ResultSub(CResult::TEST_FAIL);
36     return result.Result();
37   }
38 
39   std::vector<cl_device_id> devicesExpected(devicesExpectedNum);
40   error = clGetDeviceIDs(gPlatformIDdetected, CL_DEVICE_TYPE_ALL, devicesExpectedNum, &devicesExpected[0], 0);
41   if (error != CL_SUCCESS)
42   {
43     log_error("clGetDeviceIDs failed: %s\n", IGetErrorString(error));
44     result.ResultSub(CResult::TEST_FAIL);
45     return result.Result();
46   }
47 
48   while (deviceWrapper->AdapterNext())
49   {
50     std::vector<cl_dx9_media_adapter_type_khr> mediaAdapterTypes;
51     mediaAdapterTypes.push_back(adapterType);
52 
53     std::vector<void *> mediaDevices;
54     mediaDevices.push_back(deviceWrapper->Device());
55 
56     //check if the test can be run on the adapter
57     if (CL_SUCCESS != (error = deviceExistForCLTest(gPlatformIDdetected, adapterType, deviceWrapper->Device(), result)))
58     {
59       return result.Result();
60     }
61 
62     cl_uint devicesAllNum = 0;
63     error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0],
64       CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesAllNum);
65     if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND)
66     {
67       log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error));
68       result.ResultSub(CResult::TEST_FAIL);
69       return result.Result();
70     }
71 
72     std::vector<cl_device_id> devicesAll;
73     if (devicesAllNum > 0)
74     {
75       devicesAll.resize(devicesAllNum);
76        error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0],
77         CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, devicesAllNum, &devicesAll[0], 0);
78       if (error != CL_SUCCESS)
79       {
80         log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error));
81         result.ResultSub(CResult::TEST_FAIL);
82         return result.Result();
83       }
84     }
85 
86     cl_uint devicesPreferredNum = 0;
87     error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0],
88       CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, 0, 0, &devicesPreferredNum);
89     if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND)
90     {
91       log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error));
92       result.ResultSub(CResult::TEST_FAIL);
93       return result.Result();
94     }
95 
96     std::vector<cl_device_id> devicesPreferred;
97     if (devicesPreferredNum > 0)
98     {
99       devicesPreferred.resize(devicesPreferredNum);
100       error = clGetDeviceIDsFromDX9MediaAdapterKHR(gPlatformIDdetected, 1, &mediaAdapterTypes[0], &mediaDevices[0],
101         CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR, devicesPreferredNum, &devicesPreferred[0], 0);
102       if (error != CL_SUCCESS)
103       {
104         log_error("clGetDeviceIDsFromDX9MediaAdapterKHR failed: %s\n", IGetErrorString(error));
105         result.ResultSub(CResult::TEST_FAIL);
106         return result.Result();
107       }
108     }
109 
110     if (devicesAllNum < devicesPreferredNum)
111     {
112       log_error("Invalid number of preferred devices. It should be a subset of all devices\n");
113       result.ResultSub(CResult::TEST_FAIL);
114     }
115 
116     for (cl_uint i = 0; i < devicesPreferredNum; ++i)
117     {
118       cl_uint j = 0;
119       for (; j < devicesAllNum; ++j)
120       {
121         if (devicesPreferred[i] == devicesAll[j])
122           break;
123       }
124 
125       if (j == devicesAllNum)
126       {
127         log_error("Preferred device is not a subset of all devices\n");
128         result.ResultSub(CResult::TEST_FAIL);
129       }
130     }
131 
132     for (cl_uint i = 0; i < devicesAllNum; ++i)
133     {
134       cl_uint j = 0;
135       for (; j < devicesExpectedNum; ++j)
136       {
137         if (devicesAll[i] == devicesExpected[j])
138           break;
139       }
140 
141       if (j == devicesExpectedNum)
142       {
143         log_error("CL_ALL_DEVICES_FOR_MEDIA_ADAPTER_KHR should be a subset of all devices for selected platform\n");
144         result.ResultSub(CResult::TEST_FAIL);
145       }
146     }
147   }
148 
149   if (deviceWrapper->Status() != DEVICE_PASS)
150   {
151     std::string adapterName;
152     AdapterToString(adapterType, adapterName);
153     if (deviceWrapper->Status() == DEVICE_FAIL)
154   {
155       log_error("%s init failed\n", adapterName.c_str());
156     result.ResultSub(CResult::TEST_FAIL);
157     }
158     else
159     {
160       log_error("%s init incomplete due to unsupported device\n", adapterName.c_str());
161       result.ResultSub(CResult::TEST_NOTSUPPORTED);
162     }
163   }
164 
165   return result.Result();
166 }
167 
test_get_device_ids(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)168 int test_get_device_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
169 {
170   CResult result;
171 
172 #if defined(_WIN32)
173   if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_D3D9_KHR) != 0)
174   {
175     log_error("\nTest case (D3D9) failed\n\n");
176     result.ResultSub(CResult::TEST_FAIL);
177   }
178 
179   if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_D3D9EX_KHR) != 0)
180   {
181     log_error("\nTest case (D3D9EX) failed\n\n");
182     result.ResultSub(CResult::TEST_FAIL);
183   }
184 
185   if(get_device_ids(deviceID, context, queue, num_elements, CL_ADAPTER_DXVA_KHR) != 0)
186   {
187     log_error("\nTest case (DXVA) failed\n\n");
188     result.ResultSub(CResult::TEST_FAIL);
189   }
190 
191 #else
192   return TEST_NOT_IMPLEMENTED;
193 #endif
194 
195   return result.Result();
196 }
197