mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
310 lines
12 KiB
C
310 lines
12 KiB
C
/*
|
|
* Copyright 2016 Józef Kucia for CodeWeavers
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
|
|
/* Hack for MinGW-w64 headers.
|
|
*
|
|
* We want to use WIDL C inline wrappers because some methods
|
|
* in D3D12 interfaces return aggregate objects. Unfortunately,
|
|
* WIDL C inline wrappers are broken when used with MinGW-w64
|
|
* headers because FORCEINLINE expands to extern inline
|
|
* which leads to the "multiple storage classes in declaration
|
|
* specifiers" compiler error.
|
|
*/
|
|
#ifdef __MINGW32__
|
|
# include <_mingw.h>
|
|
# ifdef __MINGW64_VERSION_MAJOR
|
|
# undef __forceinline
|
|
# define __forceinline __inline__ __attribute__((__always_inline__,__gnu_inline__))
|
|
# endif
|
|
|
|
# define _HRESULT_DEFINED
|
|
typedef int HRESULT;
|
|
#endif
|
|
|
|
#define INITGUID
|
|
#define COBJMACROS
|
|
#include "vkd3d_test.h"
|
|
#include "vkd3d_windows.h"
|
|
|
|
#define WIDL_C_INLINE_WRAPPERS
|
|
#include "d3d12.h"
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
|
|
|
#define get_refcount(a) get_refcount_((IUnknown *)a)
|
|
static ULONG get_refcount_(IUnknown *iface)
|
|
{
|
|
IUnknown_AddRef(iface);
|
|
return IUnknown_Release(iface);
|
|
}
|
|
|
|
#define check_interface(a, b, c) check_interface_(__LINE__, (IUnknown *)a, b, c)
|
|
static void check_interface_(unsigned int line, IUnknown *iface, REFIID riid, BOOL supported)
|
|
{
|
|
HRESULT hr, expected_hr;
|
|
IUnknown *unk;
|
|
|
|
expected_hr = supported ? S_OK : E_NOINTERFACE;
|
|
|
|
hr = IUnknown_QueryInterface(iface, riid, (void **)&unk);
|
|
ok_(line)(hr == expected_hr, "Got hr %#x, expected %#x.\n", hr, expected_hr);
|
|
if (SUCCEEDED(hr))
|
|
IUnknown_Release(unk);
|
|
}
|
|
|
|
static ID3D12Device *create_device(void)
|
|
{
|
|
ID3D12Device *device;
|
|
HRESULT hr;
|
|
|
|
if (FAILED(hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&device)))
|
|
return NULL;
|
|
|
|
return device;
|
|
}
|
|
|
|
static void test_create_device(void)
|
|
{
|
|
ID3D12Device *device;
|
|
ULONG refcount;
|
|
HRESULT hr;
|
|
|
|
if (!(device = create_device()))
|
|
{
|
|
skip("Failed to create device.\n");
|
|
return;
|
|
}
|
|
|
|
check_interface(device, &IID_ID3D12Object, TRUE);
|
|
check_interface(device, &IID_ID3D12DeviceChild, FALSE);
|
|
check_interface(device, &IID_ID3D12Pageable, FALSE);
|
|
check_interface(device, &IID_ID3D12Device, TRUE);
|
|
|
|
refcount = ID3D12Device_Release(device);
|
|
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
|
|
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == S_OK, "D3D12CreateDevice failed, hr %#x.\n", hr);
|
|
ID3D12Device_Release(device);
|
|
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_9_1, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_9_2, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_9_3, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_10_0, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_10_1, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
|
|
hr = D3D12CreateDevice(NULL, 0, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "D3D12CreateDevice failed, hr %#x.\n", hr);
|
|
hr = D3D12CreateDevice(NULL, ~0u, &IID_ID3D12Device, (void **)&device);
|
|
ok(hr == E_INVALIDARG, "D3D12CreateDevice failed, hr %#x.\n", hr);
|
|
}
|
|
|
|
static void test_node_count(void)
|
|
{
|
|
ID3D12Device *device;
|
|
UINT node_count;
|
|
ULONG refcount;
|
|
|
|
if (!(device = create_device()))
|
|
{
|
|
skip("Failed to create device.\n");
|
|
return;
|
|
}
|
|
|
|
node_count = ID3D12Device_GetNodeCount(device);
|
|
trace("Node count: %u.\n", node_count);
|
|
ok(1 <= node_count && node_count <= 32, "Got unexpected node count %u.\n", node_count);
|
|
|
|
refcount = ID3D12Device_Release(device);
|
|
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
|
|
}
|
|
|
|
static void test_check_feature_support(void)
|
|
{
|
|
D3D12_FEATURE_DATA_FEATURE_LEVELS feature_levels;
|
|
D3D_FEATURE_LEVEL max_supported_feature_level;
|
|
ID3D12Device *device;
|
|
ULONG refcount;
|
|
HRESULT hr;
|
|
|
|
static const D3D_FEATURE_LEVEL all_feature_levels[] =
|
|
{
|
|
D3D_FEATURE_LEVEL_12_1,
|
|
D3D_FEATURE_LEVEL_12_0,
|
|
D3D_FEATURE_LEVEL_11_1,
|
|
D3D_FEATURE_LEVEL_11_0,
|
|
D3D_FEATURE_LEVEL_10_1,
|
|
D3D_FEATURE_LEVEL_10_0,
|
|
D3D_FEATURE_LEVEL_9_3,
|
|
D3D_FEATURE_LEVEL_9_2,
|
|
D3D_FEATURE_LEVEL_9_1,
|
|
};
|
|
static const D3D_FEATURE_LEVEL d3d12_feature_levels[] =
|
|
{
|
|
D3D_FEATURE_LEVEL_12_1,
|
|
D3D_FEATURE_LEVEL_12_0,
|
|
D3D_FEATURE_LEVEL_11_1,
|
|
D3D_FEATURE_LEVEL_11_0,
|
|
};
|
|
static const D3D_FEATURE_LEVEL d3d_9_x_feature_levels[] =
|
|
{
|
|
D3D_FEATURE_LEVEL_9_3,
|
|
D3D_FEATURE_LEVEL_9_2,
|
|
D3D_FEATURE_LEVEL_9_1,
|
|
};
|
|
static const D3D_FEATURE_LEVEL invalid_feature_levels[] =
|
|
{
|
|
0x0000,
|
|
0x3000,
|
|
};
|
|
|
|
if (!(device = create_device()))
|
|
{
|
|
skip("Failed to create device.\n");
|
|
return;
|
|
}
|
|
|
|
/* Feature levels */
|
|
memset(&feature_levels, 0, sizeof(feature_levels));
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels));
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
|
|
feature_levels.NumFeatureLevels = ARRAY_SIZE(all_feature_levels);
|
|
feature_levels.pFeatureLevelsRequested = all_feature_levels;
|
|
feature_levels.MaxSupportedFeatureLevel = 0;
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels));
|
|
ok(SUCCEEDED(hr), "CheckFeatureSupport failed, hr %#x.\n", hr);
|
|
trace("Max supported feature level %#x.\n", feature_levels.MaxSupportedFeatureLevel);
|
|
max_supported_feature_level = feature_levels.MaxSupportedFeatureLevel;
|
|
|
|
feature_levels.NumFeatureLevels = ARRAY_SIZE(d3d12_feature_levels);
|
|
feature_levels.pFeatureLevelsRequested = d3d12_feature_levels;
|
|
feature_levels.MaxSupportedFeatureLevel = 0;
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels));
|
|
ok(SUCCEEDED(hr), "CheckFeatureSupport failed, hr %#x.\n", hr);
|
|
ok(feature_levels.MaxSupportedFeatureLevel == max_supported_feature_level,
|
|
"Got unexpected feature level %#x, expected %#x.\n",
|
|
feature_levels.MaxSupportedFeatureLevel, max_supported_feature_level);
|
|
|
|
/* Check invalid size. */
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels) + 1);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels) - 1);
|
|
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
|
|
|
|
feature_levels.NumFeatureLevels = ARRAY_SIZE(d3d_9_x_feature_levels);
|
|
feature_levels.pFeatureLevelsRequested = d3d_9_x_feature_levels;
|
|
feature_levels.MaxSupportedFeatureLevel = 0;
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels));
|
|
ok(SUCCEEDED(hr), "CheckFeatureSupport failed, hr %#x.\n", hr);
|
|
ok(feature_levels.MaxSupportedFeatureLevel == D3D_FEATURE_LEVEL_9_3,
|
|
"Got unexpected max feature level %#x.\n", feature_levels.MaxSupportedFeatureLevel);
|
|
|
|
feature_levels.NumFeatureLevels = ARRAY_SIZE(invalid_feature_levels);
|
|
feature_levels.pFeatureLevelsRequested = invalid_feature_levels;
|
|
feature_levels.MaxSupportedFeatureLevel = 0;
|
|
hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FEATURE_LEVELS,
|
|
&feature_levels, sizeof(feature_levels));
|
|
ok(SUCCEEDED(hr), "CheckFeatureSupport failed, hr %#x.\n", hr);
|
|
ok(feature_levels.MaxSupportedFeatureLevel == 0x3000,
|
|
"Got unexpected max feature level %#x.\n", feature_levels.MaxSupportedFeatureLevel);
|
|
|
|
refcount = ID3D12Device_Release(device);
|
|
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
|
|
}
|
|
|
|
static void test_create_command_queue(void)
|
|
{
|
|
D3D12_COMMAND_QUEUE_DESC desc, result_desc;
|
|
ID3D12Device *device, *tmp_device;
|
|
ID3D12CommandQueue *queue;
|
|
ULONG refcount;
|
|
HRESULT hr;
|
|
|
|
if (!(device = create_device()))
|
|
{
|
|
skip("Failed to create device.\n");
|
|
return;
|
|
}
|
|
|
|
desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
|
|
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
desc.NodeMask = 0;
|
|
hr = ID3D12Device_CreateCommandQueue(device, &desc, &IID_ID3D12CommandQueue, (void **)&queue);
|
|
ok(SUCCEEDED(hr), "CreateCommandQueue failed, hr %#x.\n", hr);
|
|
|
|
refcount = get_refcount(device);
|
|
ok(refcount == 2, "Got unexpected refcount %u.\n", (unsigned int)refcount);
|
|
hr = ID3D12CommandQueue_GetDevice(queue, &IID_ID3D12Device, (void **)&tmp_device);
|
|
ok(SUCCEEDED(hr), "GetDevice failed, hr %#x.\n", hr);
|
|
refcount = get_refcount(device);
|
|
ok(refcount == 3, "Got unexpected refcount %u.\n", (unsigned int)refcount);
|
|
refcount = ID3D12Device_Release(tmp_device);
|
|
ok(refcount == 2, "Got unexpected refcount %u.\n", (unsigned int)refcount);
|
|
|
|
check_interface(queue, &IID_ID3D12Object, TRUE);
|
|
check_interface(queue, &IID_ID3D12DeviceChild, TRUE);
|
|
check_interface(queue, &IID_ID3D12Pageable, TRUE);
|
|
check_interface(queue, &IID_ID3D12CommandQueue, TRUE);
|
|
|
|
result_desc = ID3D12CommandQueue_GetDesc(queue);
|
|
ok(result_desc.Type == desc.Type, "Got unexpected type %#x.\n", result_desc.Type);
|
|
ok(result_desc.Priority == desc.Priority, "Got unexpected priority %#x.\n", result_desc.Priority);
|
|
ok(result_desc.Flags == desc.Flags, "Got unexpected flags %#x.\n", result_desc.Flags);
|
|
ok(result_desc.NodeMask == 0x1, "Got unexpected node mask 0x%08x.\n", result_desc.NodeMask);
|
|
|
|
refcount = ID3D12CommandQueue_Release(queue);
|
|
ok(!refcount, "ID3D12CommandQueue has %u references left.\n", (unsigned int)refcount);
|
|
|
|
refcount = ID3D12Device_Release(device);
|
|
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
|
|
}
|
|
|
|
START_TEST(d3d12)
|
|
{
|
|
ID3D12Debug *debug;
|
|
|
|
if (SUCCEEDED(D3D12GetDebugInterface(&IID_ID3D12Debug, (void **)&debug)))
|
|
{
|
|
ID3D12Debug_EnableDebugLayer(debug);
|
|
ID3D12Debug_Release(debug);
|
|
}
|
|
|
|
test_create_device();
|
|
test_node_count();
|
|
test_check_feature_support();
|
|
test_create_command_queue();
|
|
}
|