1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
/*
* Copyright 2016-2018 Józef Kucia for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "d3d12_crosstest.h"
#define recreate_command_list(a, b, c) recreate_command_list_(__LINE__, a, b, c)
static void recreate_command_list_(unsigned int line, ID3D12Device *device,
ID3D12CommandAllocator *allocator, ID3D12GraphicsCommandList **command_list)
{
HRESULT hr;
hr = ID3D12CommandAllocator_Reset(allocator);
ok_(line)(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
ID3D12GraphicsCommandList_Release(*command_list);
hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)command_list);
ok_(line)(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
}
static void test_invalid_resource_barriers(void)
{
ID3D12Resource *texture, *readback_buffer, *upload_buffer;
ID3D12CommandAllocator *command_allocator;
ID3D12GraphicsCommandList *command_list;
ID3D12CommandQueue *queue;
ID3D12Device *device;
ULONG refcount;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device.\n");
return;
}
queue = create_command_queue(device, D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_PRIORITY_NORMAL);
hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_DIRECT,
&IID_ID3D12CommandAllocator, (void **)&command_allocator);
ok(hr == S_OK, "Failed to create command allocator, hr %#x.\n", hr);
hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
texture = create_default_texture(device, 32, 32, DXGI_FORMAT_R8G8B8A8_UNORM,
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
upload_buffer = create_upload_buffer(device, 32, NULL);
readback_buffer = create_readback_buffer(device, 32);
/* The following invalid barrier is not detected by the runtime. */
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
reset_command_list(command_list, command_allocator);
/* The before state does not match with the previous state. */
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_SOURCE);
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
hr = ID3D12GraphicsCommandList_Close(command_list);
/* The returned error code has changed after a Windows update. */
ok(hr == S_OK || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
if (hr == S_OK)
{
exec_command_list(queue, command_list);
wait_queue_idle(device, queue);
}
recreate_command_list(device, command_allocator, &command_list);
/* The before state does not match with the previous state. */
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
hr = ID3D12GraphicsCommandList_Close(command_list);
/* The returned error code has changed after a Windows update. */
ok(hr == S_OK || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
if (hr == S_OK)
{
exec_command_list(queue, command_list);
wait_queue_idle(device, queue);
}
recreate_command_list(device, command_allocator, &command_list);
/* Exactly one write state or a combination of read-only states are allowed. */
transition_resource_state(command_list, texture,
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
/* Readback resources cannot transition from D3D12_RESOURCE_STATE_COPY_DEST. */
transition_resource_state(command_list, readback_buffer,
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
/* Upload resources cannot transition from D3D12_RESOURCE_STATE_GENERIC_READ. */
transition_resource_state(command_list, upload_buffer,
D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_COMMON);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
/* NULL resource. */
transition_resource_state(command_list, NULL,
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
ID3D12CommandAllocator_Release(command_allocator);
ID3D12CommandQueue_Release(queue);
ID3D12GraphicsCommandList_Release(command_list);
ID3D12Resource_Release(readback_buffer);
ID3D12Resource_Release(texture);
ID3D12Resource_Release(upload_buffer);
refcount = ID3D12Device_Release(device);
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
}
static void test_invalid_copy_texture_region(void)
{
ID3D12Resource *dst_texture, *src_texture, *dst_buffer, *src_buffer;
D3D12_TEXTURE_COPY_LOCATION src_location, dst_location;
ID3D12CommandAllocator *command_allocator;
ID3D12GraphicsCommandList *command_list;
ID3D12Device *device;
ULONG refcount;
D3D12_BOX box;
HRESULT hr;
if (!(device = create_device()))
{
skip("Failed to create device.\n");
return;
}
hr = ID3D12Device_CreateCommandAllocator(device, D3D12_COMMAND_LIST_TYPE_DIRECT,
&IID_ID3D12CommandAllocator, (void **)&command_allocator);
ok(hr == S_OK, "Failed to create command allocator, hr %#x.\n", hr);
hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
src_buffer = create_upload_buffer(device, 0x40000, NULL);
dst_buffer = create_default_buffer(device, 0x40000, 0, D3D12_RESOURCE_STATE_COPY_DEST);
src_texture = create_default_texture(device, 64, 64,
DXGI_FORMAT_BC3_UNORM, 0, D3D12_RESOURCE_STATE_COPY_SOURCE);
dst_texture = create_default_texture(device, 64, 64,
DXGI_FORMAT_BC3_UNORM, 0, D3D12_RESOURCE_STATE_COPY_DEST);
dst_location.pResource = dst_texture;
dst_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
dst_location.SubresourceIndex = 0;
src_location.pResource = src_buffer;
src_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
src_location.PlacedFootprint.Offset = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
src_location.PlacedFootprint.Footprint.Format = DXGI_FORMAT_BC3_UNORM;
src_location.PlacedFootprint.Footprint.Width = 64;
src_location.PlacedFootprint.Footprint.Height = 63; /* height must be multiple of block size */
src_location.PlacedFootprint.Footprint.Depth = 1;
src_location.PlacedFootprint.Footprint.RowPitch
= 64 / format_block_width(DXGI_FORMAT_BC3_UNORM) * format_size(DXGI_FORMAT_BC3_UNORM);
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, NULL);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
src_location.PlacedFootprint.Footprint.Width = 4;
src_location.PlacedFootprint.Footprint.Height = 4;
/* dst y must be multiple of block size */
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 3, 0, &src_location, NULL);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
/* row pitch must be multiple of D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT */
src_location.PlacedFootprint.Footprint.RowPitch
= 64 / format_block_width(DXGI_FORMAT_BC3_UNORM) * format_size(DXGI_FORMAT_BC3_UNORM) + 1;
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, NULL);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
dst_location.pResource = dst_buffer;
dst_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
dst_location.PlacedFootprint.Offset = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
dst_location.PlacedFootprint.Footprint.Format = DXGI_FORMAT_BC3_UNORM;
dst_location.PlacedFootprint.Footprint.Width = 64;
dst_location.PlacedFootprint.Footprint.Height = 64;
dst_location.PlacedFootprint.Footprint.Depth = 1;
dst_location.PlacedFootprint.Footprint.RowPitch
= 64 / format_block_width(DXGI_FORMAT_BC3_UNORM) * format_size(DXGI_FORMAT_BC3_UNORM);
src_location.pResource = src_texture;
src_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
src_location.SubresourceIndex = 0;
/* coordinates must be multiple of block size */
set_box(&box, 0, 0, 0, 31, 31, 1);
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, &box);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
ID3D12Resource_Release(src_texture);
src_texture = create_default_texture2d(device, 4, 4, 1, 3, DXGI_FORMAT_BC3_UNORM,
D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_SOURCE);
src_location.pResource = src_texture;
src_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
src_location.SubresourceIndex = 1;
/* coordinates must be multiple of block size even for smallest miplevels */
set_box(&box, 0, 0, 0, 2, 2, 1);
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, &box);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
recreate_command_list(device, command_allocator, &command_list);
src_location.SubresourceIndex = 2;
/* coordinates must be multiple of block size even for smallest miplevels */
set_box(&box, 0, 0, 0, 1, 1, 1);
ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
&dst_location, 0, 0, 0, &src_location, &box);
hr = ID3D12GraphicsCommandList_Close(command_list);
todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
ID3D12CommandAllocator_Release(command_allocator);
ID3D12GraphicsCommandList_Release(command_list);
ID3D12Resource_Release(dst_buffer);
ID3D12Resource_Release(src_buffer);
ID3D12Resource_Release(src_texture);
ID3D12Resource_Release(dst_texture);
refcount = ID3D12Device_Release(device);
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
}
static void test_invalid_unordered_access_views(void)
{
D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc;
D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
ID3D12DescriptorHeap *heap;
ID3D12Resource *buffer;
ID3D12Device *device;
ULONG refcount;
if (!(device = create_device()))
{
skip("Failed to create device.\n");
return;
}
heap = create_gpu_descriptor_heap(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 16);
buffer = create_default_buffer(device, 64 * sizeof(float),
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
cpu_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(heap);
/* Buffer views cannot be created for compressed formats. */
uav_desc.Format = DXGI_FORMAT_BC1_UNORM;
uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uav_desc.Buffer.FirstElement = 0;
uav_desc.Buffer.NumElements = 64;
uav_desc.Buffer.StructureByteStride = 0;
uav_desc.Buffer.CounterOffsetInBytes = 0;
uav_desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
ID3D12Device_CreateUnorderedAccessView(device, buffer, NULL, &uav_desc, cpu_handle);
ID3D12DescriptorHeap_Release(heap);
ID3D12Resource_Release(buffer);
refcount = ID3D12Device_Release(device);
ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
}
START_TEST(d3d12_invalid_usage)
{
parse_args(argc, argv);
enable_d3d12_debug_layer(argc, argv);
init_adapter_info();
run_test(test_invalid_resource_barriers);
run_test(test_invalid_copy_texture_region);
run_test(test_invalid_unordered_access_views);
}
|