mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Add tests for cl_khr_external_semaphore_dx_fence (#2482)
- Add tests to import DirectX 12 fences as semaphores. - Add tests to export semaphores as DirectX 12 fences. - Add queries tests. - Add negative tests. Fixes: https://github.com/KhronosGroup/OpenCL-CTS/issues/2480
This commit is contained in:
13
test_conformance/common/directx_wrapper/CMakeLists.txt
Normal file
13
test_conformance/common/directx_wrapper/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
set(DIRECTX_WRAPPER_SOURCES
|
||||
directx_wrapper.cpp
|
||||
)
|
||||
|
||||
add_library(directx_wrapper STATIC ${DIRECTX_WRAPPER_SOURCES})
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include_directories(${CLConform_INCLUDE_DIR})
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(directx_wrapper d3d12)
|
||||
endif ()
|
||||
71
test_conformance/common/directx_wrapper/directx_wrapper.cpp
Normal file
71
test_conformance/common/directx_wrapper/directx_wrapper.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Copyright (c) 2025 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
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include "directx_wrapper.hpp"
|
||||
|
||||
DirectXWrapper::DirectXWrapper()
|
||||
{
|
||||
|
||||
HRESULT hr = D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0,
|
||||
IID_PPV_ARGS(&dx_device));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::runtime_error("Failed to create DirectX 12 device");
|
||||
}
|
||||
|
||||
D3D12_COMMAND_QUEUE_DESC desc{};
|
||||
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
hr = dx_device->CreateCommandQueue(&desc, IID_PPV_ARGS(&dx_command_queue));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::runtime_error("Failed to create DirectX 12 command queue");
|
||||
}
|
||||
|
||||
hr = dx_device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
IID_PPV_ARGS(&dx_command_allocator));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Failed to create DirectX 12 command allocator");
|
||||
}
|
||||
}
|
||||
|
||||
ID3D12Device* DirectXWrapper::getDXDevice() const { return dx_device.Get(); }
|
||||
|
||||
ID3D12CommandQueue* DirectXWrapper::getDXCommandQueue() const
|
||||
{
|
||||
return dx_command_queue.Get();
|
||||
}
|
||||
ID3D12CommandAllocator* DirectXWrapper::getDXCommandAllocator() const
|
||||
{
|
||||
return dx_command_allocator.Get();
|
||||
}
|
||||
|
||||
DirectXFenceWrapper::DirectXFenceWrapper(ID3D12Device* dx_device)
|
||||
: dx_device(dx_device)
|
||||
{
|
||||
if (!dx_device)
|
||||
{
|
||||
throw std::runtime_error("ID3D12Device is not valid");
|
||||
}
|
||||
const HRESULT hr = dx_device->CreateFence(0, D3D12_FENCE_FLAG_SHARED,
|
||||
IID_PPV_ARGS(&dx_fence));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::runtime_error("Failed to create the DirectX fence");
|
||||
}
|
||||
}
|
||||
47
test_conformance/common/directx_wrapper/directx_wrapper.hpp
Normal file
47
test_conformance/common/directx_wrapper/directx_wrapper.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright (c) 2025 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
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <wrl/client.h>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
class DirectXWrapper {
|
||||
public:
|
||||
DirectXWrapper();
|
||||
|
||||
ID3D12Device* getDXDevice() const;
|
||||
ID3D12CommandQueue* getDXCommandQueue() const;
|
||||
ID3D12CommandAllocator* getDXCommandAllocator() const;
|
||||
|
||||
protected:
|
||||
ComPtr<ID3D12Device> dx_device = nullptr;
|
||||
ComPtr<ID3D12CommandQueue> dx_command_queue = nullptr;
|
||||
ComPtr<ID3D12CommandAllocator> dx_command_allocator = nullptr;
|
||||
};
|
||||
|
||||
class DirectXFenceWrapper {
|
||||
public:
|
||||
DirectXFenceWrapper(ID3D12Device* dx_device);
|
||||
ID3D12Fence* operator*() const { return dx_fence.Get(); }
|
||||
|
||||
private:
|
||||
ComPtr<ID3D12Fence> dx_fence = nullptr;
|
||||
ComPtr<ID3D12Device> dx_device = nullptr;
|
||||
};
|
||||
Reference in New Issue
Block a user