diff --git a/test_conformance/CMakeLists.txt b/test_conformance/CMakeLists.txt index d0e4496160..d3f67fa3b0 100644 --- a/test_conformance/CMakeLists.txt +++ b/test_conformance/CMakeLists.txt @@ -56,7 +56,7 @@ if(VULKAN_IS_SUPPORTED) add_subdirectory( common/vulkan_wrapper ) add_subdirectory( vulkan ) endif() -if(D3D12_IS_SUPPORTED) +if(D3D10_IS_SUPPORTED OR D3D11_IS_SUPPORTED OR D3D12_IS_SUPPORTED) add_subdirectory(common/directx_wrapper) endif () diff --git a/test_conformance/common/directx_wrapper/CMakeLists.txt b/test_conformance/common/directx_wrapper/CMakeLists.txt index 58ae19a81a..ff62f45e2d 100644 --- a/test_conformance/common/directx_wrapper/CMakeLists.txt +++ b/test_conformance/common/directx_wrapper/CMakeLists.txt @@ -4,10 +4,17 @@ set(DIRECTX_WRAPPER_SOURCES add_library(directx_wrapper STATIC ${DIRECTX_WRAPPER_SOURCES}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(directx_wrapper + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CLConform_INCLUDE_DIR}) +target_compile_definitions(directx_wrapper + PUBLIC + $<$:D3D10_IS_SUPPORTED> + $<$:D3D11_IS_SUPPORTED> + $<$:D3D12_IS_SUPPORTED>) -if (WIN32) - target_link_libraries(directx_wrapper d3d12) -endif () +target_link_libraries(directx_wrapper + dxgi + $<$:d3d10> + $<$:d3d11> + $<$:d3d12>) diff --git a/test_conformance/common/directx_wrapper/directx_wrapper.cpp b/test_conformance/common/directx_wrapper/directx_wrapper.cpp index 2255a5410a..19039a7aea 100644 --- a/test_conformance/common/directx_wrapper/directx_wrapper.cpp +++ b/test_conformance/common/directx_wrapper/directx_wrapper.cpp @@ -14,9 +14,12 @@ // limitations under the License. // +#include + #include "directx_wrapper.hpp" -DirectXWrapper::DirectXWrapper() +#if D3D12_IS_SUPPORTED +DirectX12Wrapper::DirectX12Wrapper() { HRESULT hr = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0, @@ -44,18 +47,18 @@ DirectXWrapper::DirectXWrapper() } } -ID3D12Device* DirectXWrapper::getDXDevice() const { return dx_device.Get(); } +ID3D12Device* DirectX12Wrapper::getDXDevice() const { return dx_device.Get(); } -ID3D12CommandQueue* DirectXWrapper::getDXCommandQueue() const +ID3D12CommandQueue* DirectX12Wrapper::getDXCommandQueue() const { return dx_command_queue.Get(); } -ID3D12CommandAllocator* DirectXWrapper::getDXCommandAllocator() const +ID3D12CommandAllocator* DirectX12Wrapper::getDXCommandAllocator() const { return dx_command_allocator.Get(); } -DirectXFenceWrapper::DirectXFenceWrapper(ID3D12Device* dx_device) +DirectX12FenceWrapper::DirectX12FenceWrapper(ID3D12Device* dx_device) : dx_device(dx_device) { if (!dx_device) @@ -69,3 +72,66 @@ DirectXFenceWrapper::DirectXFenceWrapper(ID3D12Device* dx_device) throw std::runtime_error("Failed to create the DirectX fence"); } } +#endif + +#if D3D11_IS_SUPPORTED +DirectX11Wrapper::DirectX11Wrapper() +{ + ComPtr factory; + HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(factory.GetAddressOf())); + if (FAILED(hr)) + { + throw std::runtime_error("Failed to create DXGI factory"); + } + + UINT i = 0; + ComPtr adapter; + while (factory->EnumAdapters(i, adapter.GetAddressOf()) + != DXGI_ERROR_NOT_FOUND) + { + ++i; + + ComPtr device; + hr = D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_HARDWARE, nullptr, + 0, nullptr, 0, D3D11_SDK_VERSION, + device.GetAddressOf(), nullptr, nullptr); + if (FAILED(hr)) + { + throw std::runtime_error("Failed to create DirectX 10 device"); + } + + devices.push_back({ adapter, device }); + } +} +#endif + +#if D3D10_IS_SUPPORTED +DirectX10Wrapper::DirectX10Wrapper() +{ + ComPtr factory; + HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(factory.GetAddressOf())); + if (FAILED(hr)) + { + throw std::runtime_error("Failed to create DXGI factory"); + } + + UINT i = 0; + ComPtr adapter; + while (factory->EnumAdapters(i, adapter.GetAddressOf()) + != DXGI_ERROR_NOT_FOUND) + { + ++i; + + ComPtr device; + hr = D3D10CreateDevice(adapter.Get(), D3D10_DRIVER_TYPE_HARDWARE, + nullptr, 0, D3D10_SDK_VERSION, + device.GetAddressOf()); + if (FAILED(hr)) + { + throw std::runtime_error("Failed to create DirectX 10 device"); + } + + devices.push_back({ adapter, device }); + } +} +#endif diff --git a/test_conformance/common/directx_wrapper/directx_wrapper.hpp b/test_conformance/common/directx_wrapper/directx_wrapper.hpp index fb75888045..96cef5e39d 100644 --- a/test_conformance/common/directx_wrapper/directx_wrapper.hpp +++ b/test_conformance/common/directx_wrapper/directx_wrapper.hpp @@ -16,15 +16,25 @@ #pragma once +#if D3D12_IS_SUPPORTED #include +#endif +#if D3D11_IS_SUPPORTED +#include +#endif +#if D3D10_IS_SUPPORTED +#include +#endif + +#include #include -#include using namespace Microsoft::WRL; -class DirectXWrapper { +#if D3D12_IS_SUPPORTED +class DirectX12Wrapper { public: - DirectXWrapper(); + DirectX12Wrapper(); [[nodiscard]] ID3D12Device* getDXDevice() const; [[nodiscard]] ID3D12CommandQueue* getDXCommandQueue() const; @@ -36,12 +46,43 @@ class DirectXWrapper { ComPtr dx_command_allocator = nullptr; }; -class DirectXFenceWrapper { +class DirectX12FenceWrapper { public: - DirectXFenceWrapper(ID3D12Device* dx_device); + DirectX12FenceWrapper(ID3D12Device* dx_device); [[nodiscard]] ID3D12Fence* get() const { return dx_fence.Get(); } private: ComPtr dx_fence = nullptr; ComPtr dx_device = nullptr; -}; \ No newline at end of file +}; +#endif + +#if D3D11_IS_SUPPORTED +struct DirectX11Wrapper +{ + struct DeviceEntry + { + ComPtr dx_adapter; + ComPtr dx_device; + }; + + DirectX11Wrapper(); + + std::vector devices; +}; +#endif + +#if D3D10_IS_SUPPORTED +struct DirectX10Wrapper +{ + struct DeviceEntry + { + ComPtr dx_adapter; + ComPtr dx_device; + }; + + DirectX10Wrapper(); + + std::vector devices; +}; +#endif diff --git a/test_conformance/d3d10/CMakeLists.txt b/test_conformance/d3d10/CMakeLists.txt index 46387f5184..e2581b106f 100644 --- a/test_conformance/d3d10/CMakeLists.txt +++ b/test_conformance/d3d10/CMakeLists.txt @@ -10,7 +10,7 @@ set(${MODULE_NAME}_SOURCES harness.cpp ) -list(APPEND CLConform_LIBRARIES d3d10 dxgi) +list(APPEND CLConform_LIBRARIES directx_wrapper) include(../CMakeCommon.txt) else() diff --git a/test_conformance/d3d10/buffer.cpp b/test_conformance/d3d10/buffer.cpp index ed411db050..17af1d8410 100644 --- a/test_conformance/d3d10/buffer.cpp +++ b/test_conformance/d3d10/buffer.cpp @@ -58,11 +58,9 @@ void SubTestBuffer( cl_mem mem = NULL; cl_int result = CL_SUCCESS; - HarnessD3D10_TestBegin("Buffer: Size=%d, BindFlags=%s, Usage=%s, CPUAccess=%s", - props->ByteWidth, - props->name_BindFlags, - props->name_Usage, - props->name_CPUAccess); + log_info("Buffer: Size=%d, BindFlags=%s, Usage=%s, CPUAccess=%s", + props->ByteWidth, props->name_BindFlags, props->name_Usage, + props->name_CPUAccess); // create the D3D10 resource { @@ -288,8 +286,6 @@ void SubTestBuffer( { clReleaseMemObject(mem); } - - HarnessD3D10_TestEnd(); } diff --git a/test_conformance/d3d10/harness.cpp b/test_conformance/d3d10/harness.cpp index 93f2281d8b..23a13d1462 100644 --- a/test_conformance/d3d10/harness.cpp +++ b/test_conformance/d3d10/harness.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -13,11 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#define INITGUID #include "harness.h" -#include - -#include /* * OpenCL state @@ -33,69 +29,9 @@ clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR = NULL; #define INITPFN(x) \ x = (x ## _fn)clGetExtensionFunctionAddressForPlatform(platform, #x); NonTestRequire(x, "Failed to get function pointer for %s", #x); -void -HarnessD3D10_ExtensionCheck() -{ - bool extensionPresent = false; - cl_int result = CL_SUCCESS; - cl_platform_id platform = NULL; - size_t set_size; - - HarnessD3D10_TestBegin("Extension query"); - - result = clGetPlatformIDs(1, &platform, NULL); - NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms."); - result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, 0, NULL, &set_size); - NonTestRequire(result == CL_SUCCESS, "Failed to get size of extensions string."); - std::vector extensions(set_size); - result = clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, extensions.size(), extensions.data(), NULL); - NonTestRequire(result == CL_SUCCESS, "Failed to list extensions."); - extensionPresent = strstr(extensions.data(), "cl_khr_d3d10_sharing") ? true : false; - - if (!extensionPresent) { - // platform is required to report the extension only if all devices support it - cl_uint devicesCount; - result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &devicesCount); - NonTestRequire(result == CL_SUCCESS, "Failed to get devices count."); - std::vector devices(devicesCount); - result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, devicesCount, &devices[0], NULL); - NonTestRequire(result == CL_SUCCESS, "Failed to get devices count."); - - for (cl_uint i = 0; i < devicesCount; i++) { - if (is_extension_available(devices[i], "cl_khr_d3d10_sharing")) { - extensionPresent = true; - break; - } - } - } - - OSVERSIONINFO osvi; - osvi.dwOSVersionInfoSize = sizeof(osvi); - GetVersionEx(&osvi); - if (osvi.dwMajorVersion <= 5) - { - TestRequire(!extensionPresent, "Extension should not be exported on Windows < 6"); - } - else - { - TestRequire(extensionPresent, "Extension should be exported on Windows >= 6"); - } - -Cleanup: - HarnessD3D10_TestEnd(); - - // early-out of the extension is not present - if (!extensionPresent) - { - HarnessD3D10_TestStats(); - } -} - void HarnessD3D10_Initialize(cl_platform_id platform) { - HarnessD3D10_ExtensionCheck(); - // extract function pointers for exported functions INITPFN(clGetDeviceIDsFromD3D10KHR); INITPFN(clCreateFromD3D10BufferKHR); @@ -105,126 +41,6 @@ HarnessD3D10_Initialize(cl_platform_id platform) INITPFN(clEnqueueReleaseD3D10ObjectsKHR); } -/* - * Window management - */ - -static IDXGISwapChain* HarnessD3D10_pSwapChain = NULL; -static ID3D10Device* HarnessD3D10_pDevice = NULL; -static HWND HarnessD3D10_hWnd = NULL; - -static LRESULT WINAPI HarnessD3D10_Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg) - { - case WM_KEYDOWN: - return 0; - break; - case WM_DESTROY: - HarnessD3D10_hWnd = NULL; - PostQuitMessage(0); - return 0; - case WM_PAINT: - ValidateRect(hWnd, NULL); - return 0; - } - return DefWindowProc(hWnd, msg, wParam, lParam); -} - -static void HarnessD3D10_InteractiveLoop() -{ - MSG msg; - while(PeekMessage(&msg,HarnessD3D10_hWnd,0,0,PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice) -{ - HRESULT hr = S_OK; - unsigned int cuStatus = 1; - - *ppDevice = NULL; - - // create window - static WNDCLASSEX wc = - { - sizeof(WNDCLASSEX), - CS_CLASSDC, - HarnessD3D10_Proc, - 0L, - 0L, - GetModuleHandle(NULL), - NULL, - NULL, - NULL, - NULL, - _T( "cl_khr_d3d10_sharing_conformance" ), - NULL - }; - RegisterClassEx(&wc); - HarnessD3D10_hWnd = CreateWindow( - _T( "cl_khr_d3d10_sharing_conformance" ), - _T( "cl_khr_d3d10_sharing_conformance" ), - WS_OVERLAPPEDWINDOW, - 0, 0, 256, 256, - NULL, - NULL, - wc.hInstance, - NULL); - NonTestRequire(0 != HarnessD3D10_hWnd, "Failed to create window"); - - ShowWindow(HarnessD3D10_hWnd,SW_SHOWDEFAULT); - UpdateWindow(HarnessD3D10_hWnd); - - RECT rc; - GetClientRect(HarnessD3D10_hWnd, &rc); - UINT width = rc.right - rc.left; - UINT height = rc.bottom - rc.top; - - // Create device and swapchain - DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory(&sd, sizeof(sd)); - sd.BufferCount = 1; - sd.BufferDesc.Width = width; - sd.BufferDesc.Height = height; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = 60; - sd.BufferDesc.RefreshRate.Denominator = 1; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = HarnessD3D10_hWnd; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.Windowed = TRUE; - hr = D3D10CreateDeviceAndSwapChain( - pAdapter, - D3D10_DRIVER_TYPE_HARDWARE, - NULL, - 0, - D3D10_SDK_VERSION, - &sd, - &HarnessD3D10_pSwapChain, - &HarnessD3D10_pDevice); - - if (FAILED(hr) ) { - return CL_DEVICE_NOT_FOUND; - } - - *ppDevice = HarnessD3D10_pDevice; - return CL_SUCCESS; -} - -void HarnessD3D10_DestroyDevice() -{ - HarnessD3D10_pSwapChain->Release(); - HarnessD3D10_pDevice->Release(); - - if (HarnessD3D10_hWnd) DestroyWindow(HarnessD3D10_hWnd); - HarnessD3D10_hWnd = 0; -} - /* * * texture formats @@ -275,76 +91,6 @@ TextureFormat formats[] = }; UINT formatCount = sizeof(formats)/sizeof(formats[0]); -/* - * - * Logging and error reporting - * - */ - -static struct -{ - cl_int testCount; - cl_int passCount; - - cl_int nonTestFailures; - cl_int inTest; - cl_int currentTestPass; - - char currentTestName[1024]; -} HarnessD3D10_testStats = {0}; - -void HarnessD3D10_TestBegin(const char* fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsprintf(HarnessD3D10_testStats.currentTestName, fmt, ap); - va_end(ap); - - TestPrint("[%s] ... ", HarnessD3D10_testStats.currentTestName); - - HarnessD3D10_testStats.inTest = 1; - HarnessD3D10_testStats.currentTestPass = 1; -} - -void HarnessD3D10_TestFail() -{ - if (HarnessD3D10_testStats.inTest) - { - HarnessD3D10_testStats.currentTestPass = 0; - } - else - { - ++HarnessD3D10_testStats.nonTestFailures; - } -} - -void HarnessD3D10_TestEnd() -{ - HarnessD3D10_testStats.inTest = 0; - - HarnessD3D10_testStats.testCount += 1; - HarnessD3D10_testStats.passCount += HarnessD3D10_testStats.currentTestPass; - - TestPrint("%s\n", - HarnessD3D10_testStats.currentTestPass ? "PASSED" : "FAILED"); -} - -void HarnessD3D10_TestStats() -{ - TestPrint("PASSED %d of %d tests.\n", HarnessD3D10_testStats.passCount, HarnessD3D10_testStats.testCount); - if (HarnessD3D10_testStats.testCount > HarnessD3D10_testStats.passCount) - { - TestPrint("***FAILED***\n"); - exit(1); - } - else - { - TestPrint("&&&& cl_khr_d3d10_sharing test PASSED\n"); - } - exit(0); -} - /* * * Helper function diff --git a/test_conformance/d3d10/harness.h b/test_conformance/d3d10/harness.h index afeb4966a8..b1d2fd5e4b 100644 --- a/test_conformance/d3d10/harness.h +++ b/test_conformance/d3d10/harness.h @@ -13,27 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#ifndef HARNESS_H_ -#define HARNESS_H_ - -#define _CRT_SECURE_NO_WARNINGS - -#if defined (__MINGW32__) -#include -typedef unsigned char UINT8; -#define __out -#define __in -#define __inout -#define __out_bcount_opt(size) -#define __in_opt -#define __in_ecount(size) -#define __in_ecount_opt(size) -#define __out_opt -#define __out_ecount(size) -#define __out_ecount_opt(size) -#define __in_bcount_opt(size) -#define __inout_opt -#endif +#pragma once + +#include "directx_wrapper.hpp" #include #include @@ -42,9 +24,6 @@ typedef unsigned char UINT8; #include "errorHelpers.h" #include "kernelHelpers.h" -// #define log_info(...) printf(__VA_ARGS__) -// #define log_error(...) printf(__VA_ARGS__) - #define NonTestRequire(x, ...) \ do \ { \ @@ -59,18 +38,18 @@ do \ } \ } while (0) -#define TestRequire(x, ...) \ - do \ - { \ - if (!(x) ) \ - { \ - log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, __LINE__); \ - log_info("ERROR: "); \ - log_error(__VA_ARGS__); \ - log_info("\n"); \ - HarnessD3D10_TestFail(); \ - goto Cleanup; \ - } \ +#define TestRequire(x, ...) \ + do \ + { \ + if (!(x)) \ + { \ + log_info("\n[assertion failed: %s at %s:%d]\n", #x, __FILE__, \ + __LINE__); \ + log_info("ERROR: "); \ + log_error(__VA_ARGS__); \ + log_info("\n"); \ + goto Cleanup; \ + } \ } while (0) #define TestPrint(...) \ @@ -142,14 +121,6 @@ struct Texture3DSize }; void HarnessD3D10_Initialize(cl_platform_id platform); -cl_int HarnessD3D10_CreateDevice(IDXGIAdapter* pAdapter, ID3D10Device **ppDevice); -void HarnessD3D10_DestroyDevice(); - -void HarnessD3D10_TestBegin(const char* fmt, ...); -void HarnessD3D10_TestFail(); -void HarnessD3D10_TestEnd(); -void HarnessD3D10_TestStats(); - void TestAdapterEnumeration( cl_platform_id platform, @@ -209,5 +180,3 @@ extern clCreateFromD3D10Texture2DKHR_fn clCreateFromD3D10Texture2DKHR; extern clCreateFromD3D10Texture3DKHR_fn clCreateFromD3D10Texture3DKHR; extern clEnqueueAcquireD3D10ObjectsKHR_fn clEnqueueAcquireD3D10ObjectsKHR; extern clEnqueueReleaseD3D10ObjectsKHR_fn clEnqueueReleaseD3D10ObjectsKHR; - -#endif diff --git a/test_conformance/d3d10/main.cpp b/test_conformance/d3d10/main.cpp index 9c574cca02..236408e64e 100644 --- a/test_conformance/d3d10/main.cpp +++ b/test_conformance/d3d10/main.cpp @@ -13,78 +13,242 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#if defined( _WIN32 ) - -#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include #include "harness.h" #include "harness/testHarness.h" -#include "harness/parseParameters.h" -int main(int argc, const char* argv[]) +namespace { + +struct D3D10SuiteState { - cl_int result; - cl_platform_id platform = NULL; - cl_uint num_devices_tested = 0; + bool initialized = false; + cl_platform_id platform = nullptr; + std::unique_ptr wrapper; + std::unordered_map device_to_target; +}; - argc = parseCustomParam(argc, argv); +static D3D10SuiteState State; - // get the platform to test - result = clGetPlatformIDs(1, &platform, NULL); NonTestRequire(result == CL_SUCCESS, "Failed to get any platforms."); +test_status InitState(cl_device_id selected_device) +{ + if (State.initialized) + { + return State.device_to_target.count(selected_device) + ? TEST_PASS + : TEST_SKIPPED_ITSELF; + } - HarnessD3D10_Initialize(platform); + cl_int result = + clGetDeviceInfo(selected_device, CL_DEVICE_PLATFORM, + sizeof(State.platform), &State.platform, NULL); + if (result != CL_SUCCESS) + { + log_error("clGetDeviceInfo(CL_DEVICE_PLATFORM) failed during D3D10 " + "suite initialization (%d)\n", + result); + return TEST_FAIL; + } - // for each adapter... - IDXGIFactory* pFactory = NULL; - HRESULT hr = CreateDXGIFactory(IID_IDXGIFactory, (void**)(&pFactory) ); - NonTestRequire(SUCCEEDED(hr), "Failed to create DXGI factory."); - for (UINT adapter = 0;; ++adapter) + try { - IDXGIAdapter* pAdapter = NULL; - ID3D10Device* pDevice = NULL; - HRESULT hr = pFactory->EnumAdapters(adapter, &pAdapter); - if (FAILED(hr)) + HarnessD3D10_Initialize(State.platform); + + State.wrapper.reset(new DirectX10Wrapper()); + for (size_t target_index = 0; + target_index < State.wrapper->devices.size(); ++target_index) { - break; - } + const auto& device_entry = State.wrapper->devices[target_index]; + + cl_uint num_devices = 0; + cl_int query_result = clGetDeviceIDsFromD3D10KHR( + State.platform, CL_D3D10_DEVICE_KHR, + device_entry.dx_device.Get(), CL_ALL_DEVICES_FOR_D3D10_KHR, 0, + NULL, &num_devices); + if (query_result != CL_DEVICE_NOT_FOUND) + { + if (query_result != CL_SUCCESS) + { + log_error("clGetDeviceIDsFromD3D10KHR failed during D3D10 " + "target discovery (%d)\n", + query_result); + return TEST_FAIL; + } - // print data about the adapter - DXGI_ADAPTER_DESC desc; - hr = pAdapter->GetDesc(&desc); - NonTestRequire(SUCCEEDED(hr), "IDXGIAdapter::GetDesc failed."); + std::vector devices(num_devices); + query_result = clGetDeviceIDsFromD3D10KHR( + State.platform, CL_D3D10_DEVICE_KHR, + device_entry.dx_device.Get(), CL_ALL_DEVICES_FOR_D3D10_KHR, + num_devices, devices.data(), NULL); + if (query_result != CL_SUCCESS) + { + log_error("clGetDeviceIDsFromD3D10KHR failed while " + "retrieving discovered D3D10 targets (%d)\n", + query_result); + return TEST_FAIL; + } - TestPrint("=====================================\n"); - TestPrint("Testing DXGI Adapter and D3D10 Device\n"); - TestPrint("Description=%ls, VendorID=%x, DeviceID=%x\n", desc.Description, desc.VendorId, desc.DeviceId); - TestPrint("=====================================\n"); + for (cl_device_id device_id : devices) + { + State.device_to_target[device_id] = target_index; + } + } + } + } catch (const std::exception& e) + { + log_error("D3D10 suite initialization failed: %s\n", e.what()); + return TEST_FAIL; + } catch (...) + { + log_error( + "D3D10 suite initialization failed with an unknown exception\n"); + return TEST_FAIL; + } - // run the test on the adapter - HarnessD3D10_CreateDevice(pAdapter, &pDevice); + State.initialized = true; + return State.device_to_target.count(selected_device) ? TEST_PASS + : TEST_SKIPPED_ITSELF; +} - cl_uint num_devices = 0; +test_status InitD3D10Device(cl_device_id device) +{ + if (!is_extension_available(device, "cl_khr_d3d10_sharing")) + { + return TEST_SKIPPED_ITSELF; + } - // test adapter and device enumeration - TestAdapterEnumeration(platform, pAdapter, pDevice, &num_devices); + return InitState(device); +} - // if there were any devices found in enumeration, run the tests on them - if (num_devices) - { - TestAdapterDevices(platform, pAdapter, pDevice, num_devices); - } - num_devices_tested += num_devices; +} // namespace - // destroy the D3D10 device - if (pDevice) - { - HarnessD3D10_DestroyDevice(); - } +int main(int argc, const char* argv[]) +{ + return runTestHarnessWithCheck( + argc, argv, test_registry::getInstance().num_tests(), + test_registry::getInstance().definitions(), true, 0, InitD3D10Device); +} - pAdapter->Release(); +template +test_status RunD3D10TargetTest(cl_device_id device, TargetFn target_fn) +{ + test_status init_status = InitState(device); + if (init_status != TEST_PASS) + { + return init_status; } - pFactory->Release(); - NonTestRequire(num_devices_tested, "No D3D10 compatible cl_device_ids were found."); + auto iter = State.device_to_target.find(device); + if (iter == State.device_to_target.end()) + { + return TEST_SKIPPED_ITSELF; + } + + const DirectX10Wrapper::DeviceEntry* target = + &State.wrapper->devices[iter->second]; + target_fn(target); + + return TEST_PASS; +} + +template +test_status RunD3D10InteropTest(cl_device_id device, TargetFn target_fn) +{ + return RunD3D10TargetTest( + device, [&](const DirectX10Wrapper::DeviceEntry* target) { + cl_context interop_context = NULL; + cl_command_queue interop_queue = NULL; + + if (!TestDeviceContextCreate(device, target->dx_device.Get(), + &interop_context, &interop_queue)) + { + return TEST_FAIL; + } + + target_fn(target, interop_context, interop_queue); + + if (interop_queue != NULL) + { + cl_int result = clReleaseCommandQueue(interop_queue); + if (result != CL_SUCCESS) + { + return TEST_FAIL; + } + } + + if (interop_context != NULL) + { + cl_int result = clReleaseContext(interop_context); + if (result != CL_SUCCESS) + { + return TEST_FAIL; + } + } + + return TEST_PASS; + }); +} + +REGISTER_TEST(enumeration) +{ + return RunD3D10TargetTest( + device, [&](const DirectX10Wrapper::DeviceEntry* target) { + cl_uint num_devices = 0; + TestAdapterEnumeration(State.platform, target->dx_adapter.Get(), + target->dx_device.Get(), &num_devices); + }); +} + +REGISTER_TEST(create_context) +{ + return RunD3D10InteropTest(device, + [](const DirectX10Wrapper::DeviceEntry*, + cl_context, cl_command_queue) {}); +} - HarnessD3D10_TestStats(); +REGISTER_TEST(buffer) +{ + return RunD3D10InteropTest( + device, + [](const DirectX10Wrapper::DeviceEntry* target, + cl_context interop_context, cl_command_queue interop_queue) { + TestDeviceBuffer(interop_context, interop_queue, + target->dx_device.Get()); + }); +} + +REGISTER_TEST(texture2d) +{ + return RunD3D10InteropTest( + device, + [device](const DirectX10Wrapper::DeviceEntry* target, + cl_context interop_context, cl_command_queue interop_queue) { + TestDeviceTexture2D(device, interop_context, interop_queue, + target->dx_device.Get()); + }); +} + +REGISTER_TEST(texture3d) +{ + return RunD3D10InteropTest( + device, + [device](const DirectX10Wrapper::DeviceEntry* target, + cl_context interop_context, cl_command_queue interop_queue) { + TestDeviceTexture3D(device, interop_context, interop_queue, + target->dx_device.Get()); + }); +} + +REGISTER_TEST(misc) +{ + return RunD3D10InteropTest( + device, + [device](const DirectX10Wrapper::DeviceEntry* target, + cl_context interop_context, cl_command_queue interop_queue) { + TestDeviceMisc(device, interop_context, interop_queue, + target->dx_device.Get()); + }); } void TestAdapterEnumeration(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* pDevice, cl_uint* num_devices) @@ -97,43 +261,32 @@ void TestAdapterEnumeration(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3 cl_int result; - HarnessD3D10_TestBegin("cl_device_id Enumeration"); - - // get the cl_device_ids for the adapter - { - result = clGetDeviceIDsFromD3D10KHR( - platform, - CL_D3D10_DXGI_ADAPTER_KHR, - pAdapter, - CL_ALL_DEVICES_FOR_D3D10_KHR, - 0, - NULL, - &num_adapter_devices); - TestRequire( - (result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND), - "clGetDeviceIDsFromD3D10KHR failed."); - - if (result == CL_DEVICE_NOT_FOUND) - { - TestPrint("No devices found for adapter.\n"); - } - else - { - // if there were devices, query them - adapter_devices = new cl_device_id[num_adapter_devices]; - result = clGetDeviceIDsFromD3D10KHR( - platform, - CL_D3D10_DXGI_ADAPTER_KHR, - pAdapter, - CL_ALL_DEVICES_FOR_D3D10_KHR, - num_adapter_devices, - adapter_devices, - NULL); - TestRequire( - (result == CL_SUCCESS), - "clGetDeviceIDsFromD3D10KHR failed."); - } - } + log_info("cl_device_id Enumeration"); + + // get the cl_device_ids for the adapter + { + result = clGetDeviceIDsFromD3D10KHR( + platform, CL_D3D10_DXGI_ADAPTER_KHR, pAdapter, + CL_ALL_DEVICES_FOR_D3D10_KHR, 0, NULL, &num_adapter_devices); + TestRequire((result == CL_SUCCESS || result == CL_DEVICE_NOT_FOUND), + "clGetDeviceIDsFromD3D10KHR failed."); + + if (result == CL_DEVICE_NOT_FOUND) + { + TestPrint("No devices found for adapter.\n"); + } + else + { + // if there were devices, query them + adapter_devices = new cl_device_id[num_adapter_devices]; + result = clGetDeviceIDsFromD3D10KHR( + platform, CL_D3D10_DXGI_ADAPTER_KHR, pAdapter, + CL_ALL_DEVICES_FOR_D3D10_KHR, num_adapter_devices, + adapter_devices, NULL); + TestRequire((result == CL_SUCCESS), + "clGetDeviceIDsFromD3D10KHR failed."); + } + } // get the cl_device_ids for the device (if it was successfully created) if (pDevice) @@ -200,112 +353,6 @@ void TestAdapterEnumeration(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3 } *num_devices = num_device_devices; - - HarnessD3D10_TestEnd(); -} - -void TestAdapterDevices(cl_platform_id platform, IDXGIAdapter* pAdapter, ID3D10Device* pDevice, cl_uint num_devices_expected) -{ - cl_int result; - cl_uint num_devices = 0; - cl_device_id* devices = NULL; - - devices = new cl_device_id[num_devices_expected]; - NonTestRequire( - devices, - "Memory allocation failure."); - - result = clGetDeviceIDsFromD3D10KHR( - platform, - CL_D3D10_DEVICE_KHR, - pDevice, - CL_ALL_DEVICES_FOR_D3D10_KHR, - num_devices_expected, - devices, - &num_devices); - NonTestRequire( - (result == CL_SUCCESS), - "clGetDeviceIDsFromD3D10KHR failed."); - NonTestRequire( - (num_devices == num_devices_expected), - "clGetDeviceIDsFromD3D10KHR returned an unexpected number of devices."); - - for (cl_uint i = 0; i < num_devices; ++i) - { - // make sure the device supports the extension - if (!is_extension_available(devices[i], "cl_khr_d3d10_sharing")) { - TestPrint("Device does not support cl_khr_d3d10_sharing extension\n"); - continue; - } - - TestDevice(devices[i], pDevice); - } -} - -void TestDevice(cl_device_id device, ID3D10Device* pDevice) -{ - char device_name[1024]; - cl_int result = CL_SUCCESS; - cl_context context = NULL; - cl_command_queue command_queue = NULL; - cl_bool prefer_shared_resources = CL_FALSE; - ID3D10Device* clDevice = NULL; - - result = clGetDeviceInfo( - device, - CL_DEVICE_NAME, - sizeof(device_name), - device_name, - NULL); - NonTestRequire(CL_SUCCESS == result, "clGetDeviceInfo with CL_DEVICE_NAME failed"); - TestPrint("--------------------\n"); - TestPrint("Testing cl_device_id\n"); - TestPrint("Name=%s\n", device_name); - TestPrint("--------------------\n"); - - if (!TestDeviceContextCreate(device, pDevice, &context, &command_queue) ) - { - return; - } - - // make sure that we can query the shared resource preference - result = clGetContextInfo( - context, - CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR, - sizeof(prefer_shared_resources), - &prefer_shared_resources, - NULL); - NonTestRequire(CL_SUCCESS == result, "clGetContextInfo with CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR failed"); - - // run buffer tests - TestDeviceBuffer( - context, - command_queue, - pDevice); - - // run 2D texture tests - TestDeviceTexture2D( - device, - context, - command_queue, - pDevice); - - // run 3D texture tests - TestDeviceTexture3D( - device, - context, - command_queue, - pDevice); - - // run misc tests - TestDeviceMisc( - device, - context, - command_queue, - pDevice); - - clReleaseContext(context); - clReleaseCommandQueue(command_queue); } bool TestDeviceContextCreate( @@ -322,7 +369,7 @@ bool TestDeviceContextCreate( bool succeeded = false; - HarnessD3D10_TestBegin("Context creation"); + log_info("Context creation"); cl_context_properties properties[5]; @@ -414,18 +461,5 @@ bool TestDeviceContextCreate( clReleaseCommandQueue(command_queue); } } - HarnessD3D10_TestEnd(); return succeeded; } - -#else - -#include "errorHelpers.h" - -int main(int argc, char* argv[]) -{ - log_info( "Windows-specific test skipped.\n" ); - return 0; -} - -#endif diff --git a/test_conformance/d3d10/misc.cpp b/test_conformance/d3d10/misc.cpp index 4ccd492e16..13e1f28fb9 100644 --- a/test_conformance/d3d10/misc.cpp +++ b/test_conformance/d3d10/misc.cpp @@ -26,7 +26,7 @@ void SubTestMiscMultipleCreates( cl_mem mem[5] = {NULL, NULL, NULL, NULL, NULL}; cl_int result = CL_SUCCESS; - HarnessD3D10_TestBegin("Misc: Multiple Creates"); + log_info("Misc: Multiple Creates"); // create the D3D10 resources { @@ -116,8 +116,6 @@ void SubTestMiscMultipleCreates( { pTexture->Release(); } - - HarnessD3D10_TestEnd(); } void SubTestMiscAcquireRelease( @@ -132,7 +130,7 @@ void SubTestMiscAcquireRelease( cl_int result = CL_SUCCESS; cl_mem mem[2] = {NULL, NULL}; - HarnessD3D10_TestBegin("Misc: Acquire Release"); + log_info("Misc: Acquire Release"); // create the D3D10 resources { @@ -236,8 +234,6 @@ void SubTestMiscAcquireRelease( { pTexture->Release(); } - - HarnessD3D10_TestEnd(); } void TestDeviceMisc( diff --git a/test_conformance/d3d10/texture2d.cpp b/test_conformance/d3d10/texture2d.cpp index 123ba3f896..11e35a2144 100644 --- a/test_conformance/d3d10/texture2d.cpp +++ b/test_conformance/d3d10/texture2d.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#define _CRT_SECURE_NO_WARNINGS #include "harness.h" Texture2DSize texture2DSizes[] = @@ -168,12 +167,10 @@ void SubTestTexture2D( cl_int result = CL_SUCCESS; - HarnessD3D10_TestBegin("2D Texture: Format=%s, Width=%d, Height=%d, MipLevels=%d, ArraySize=%d", - format->name_format, - size->Width, - size->Height, - size->MipLevels, - size->ArraySize); + log_info("2D Texture: Format=%s, Width=%d, Height=%d, MipLevels=%d, " + "ArraySize=%d", + format->name_format, size->Width, size->Height, size->MipLevels, + size->ArraySize); struct { @@ -617,8 +614,6 @@ void SubTestTexture2D( TestRequire(result == CL_SUCCESS, "clReleaseEvent for event failed."); } } - - HarnessD3D10_TestEnd(); } void TestDeviceTexture2D( diff --git a/test_conformance/d3d10/texture3d.cpp b/test_conformance/d3d10/texture3d.cpp index 39bcff4732..6cd1a1c19e 100644 --- a/test_conformance/d3d10/texture3d.cpp +++ b/test_conformance/d3d10/texture3d.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#define _CRT_SECURE_NO_WARNINGS #include "harness.h" Texture3DSize texture3DSizes[] = @@ -102,11 +101,9 @@ void SubTestTexture3D( cl_int result = CL_SUCCESS; - HarnessD3D10_TestBegin("3D Texture: Format=%s, Width=%d, Height=%d, Depth=%d, MipLevels=%d", - format->name_format, - size->Width, - size->Height, - size->Depth, + log_info( + "3D Texture: Format=%s, Width=%d, Height=%d, Depth=%d, MipLevels=%d", + format->name_format, size->Width, size->Height, size->Depth, size->MipLevels); struct @@ -464,8 +461,6 @@ void SubTestTexture3D( { clReleaseMemObject(subResourceInfo[i].mem); } - - HarnessD3D10_TestEnd(); } diff --git a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/CMakeLists.txt b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/CMakeLists.txt index 08b03b422e..552688cb98 100644 --- a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/CMakeLists.txt @@ -20,7 +20,6 @@ if (WIN32) PROPERTIES LANGUAGE CXX) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - include_directories("../../common/directx_wrapper") include(../../CMakeCommon.txt) endif (WIN32) diff --git a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/semaphore_dx_fence_base.h b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/semaphore_dx_fence_base.h index 31488d9d5a..0d9e5e134a 100644 --- a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/semaphore_dx_fence_base.h +++ b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/semaphore_dx_fence_base.h @@ -67,7 +67,7 @@ struct DXFenceTestBase "supported import types"); // Import D3D12 fence into OpenCL - fence_wrapper = new DirectXFenceWrapper(dx_wrapper.getDXDevice()); + fence_wrapper = new DirectX12FenceWrapper(dx_wrapper.getDXDevice()); semaphore = createSemaphoreFromFence(fence_wrapper->get()); test_assert_error(!!semaphore, "Could not create semaphore"); @@ -83,12 +83,12 @@ struct DXFenceTestBase cl_context context = nullptr; cl_command_queue queue = nullptr; cl_int num_elems = 0; - DirectXWrapper dx_wrapper; + DirectX12Wrapper dx_wrapper; cl_semaphore_payload_khr semaphore_payload = 1; cl_semaphore_khr semaphore = nullptr; HANDLE fence_handle = nullptr; - DirectXFenceWrapper *fence_wrapper = nullptr; + DirectX12FenceWrapper *fence_wrapper = nullptr; clCreateSemaphoreWithPropertiesKHR_fn clCreateSemaphoreWithPropertiesKHR = nullptr; diff --git a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/test_external_semaphore_dx_fence.cpp b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/test_external_semaphore_dx_fence.cpp index db303bf6f1..2535c40b82 100644 --- a/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/test_external_semaphore_dx_fence.cpp +++ b/test_conformance/extensions/cl_khr_external_semaphore_dx_fence/test_external_semaphore_dx_fence.cpp @@ -191,7 +191,7 @@ struct MultipleWaitSignal final : DXFenceTestBase int SetUp() override { DXFenceTestBase::SetUp(); - fence_wrapper_2 = new DirectXFenceWrapper(dx_wrapper.getDXDevice()); + fence_wrapper_2 = new DirectX12FenceWrapper(dx_wrapper.getDXDevice()); semaphore_2 = createSemaphoreFromFence(fence_wrapper_2->get()); test_assert_error(!!semaphore_2, "Could not create semaphore"); @@ -282,7 +282,7 @@ struct MultipleWaitSignal final : DXFenceTestBase protected: cl_semaphore_khr semaphore_2 = nullptr; HANDLE fence_handle_2 = nullptr; - DirectXFenceWrapper *fence_wrapper_2 = nullptr; + DirectX12FenceWrapper *fence_wrapper_2 = nullptr; }; // Confirm that multiple waits in OpenCL followed by signals in DX12 and waits