From 9c6c7cb78fa6c6106b1a583d70be9f2052dcd210 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 9 Oct 2023 17:13:40 +0200 Subject: [PATCH] vkd3d: Add partial implementation for CreateCommittedResource1(). --- libs/vkd3d/device.c | 19 +++++++++++++++---- libs/vkd3d/resource.c | 6 +++++- libs/vkd3d/vkd3d_private.h | 3 ++- tests/d3d12.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 3e17400a..2d7051f3 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -3626,7 +3626,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommittedResource(ID3D12Devi optimized_clear_value, debugstr_guid(iid), resource); if (FAILED(hr = d3d12_committed_resource_create(device, heap_properties, heap_flags, - desc, initial_state, optimized_clear_value, &object))) + desc, initial_state, optimized_clear_value, NULL, &object))) { *resource = NULL; return hr; @@ -4012,12 +4012,23 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommittedResource1(ID3D12Dev const D3D12_CLEAR_VALUE *optimized_clear_value, ID3D12ProtectedResourceSession *protected_session, REFIID iid, void **resource) { - FIXME("iface %p, heap_properties %p, heap_flags %#x, desc %p, initial_state %#x, " - "optimized_clear_value %p, protected_session %p, iid %s, resource %p stub!\n", + struct d3d12_device *device = impl_from_ID3D12Device5(iface); + struct d3d12_resource *object; + HRESULT hr; + + TRACE("iface %p, heap_properties %p, heap_flags %#x, desc %p, initial_state %#x, " + "optimized_clear_value %p, protected_session %p, iid %s, resource %p.\n", iface, heap_properties, heap_flags, desc, initial_state, optimized_clear_value, protected_session, debugstr_guid(iid), resource); - return E_NOTIMPL; + if (FAILED(hr = d3d12_committed_resource_create(device, heap_properties, heap_flags, + desc, initial_state, optimized_clear_value, protected_session, &object))) + { + *resource = NULL; + return hr; + } + + return return_interface(&object->ID3D12Resource_iface, &IID_ID3D12Resource, iid, resource); } static HRESULT STDMETHODCALLTYPE d3d12_device_CreateHeap1(ID3D12Device5 *iface, diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index ad1d2d66..8898c247 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2076,7 +2076,8 @@ static HRESULT vkd3d_allocate_resource_memory( HRESULT d3d12_committed_resource_create(struct d3d12_device *device, const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, - const D3D12_CLEAR_VALUE *optimized_clear_value, struct d3d12_resource **resource) + const D3D12_CLEAR_VALUE *optimized_clear_value, ID3D12ProtectedResourceSession *protected_session, + struct d3d12_resource **resource) { struct d3d12_resource *object; HRESULT hr; @@ -2087,6 +2088,9 @@ HRESULT d3d12_committed_resource_create(struct d3d12_device *device, return E_INVALIDARG; } + if (protected_session) + FIXME("Protected session is not supported.\n"); + if (FAILED(hr = d3d12_resource_create(device, heap_properties, heap_flags, desc, initial_state, optimized_clear_value, &object))) return hr; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 625a4312..2e9845df 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -773,7 +773,8 @@ void d3d12_resource_get_tiling(struct d3d12_device *device, const struct d3d12_r HRESULT d3d12_committed_resource_create(struct d3d12_device *device, const D3D12_HEAP_PROPERTIES *heap_properties, D3D12_HEAP_FLAGS heap_flags, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, - const D3D12_CLEAR_VALUE *optimized_clear_value, struct d3d12_resource **resource); + const D3D12_CLEAR_VALUE *optimized_clear_value, ID3D12ProtectedResourceSession *protected_session, + struct d3d12_resource **resource); HRESULT d3d12_placed_resource_create(struct d3d12_device *device, struct d3d12_heap *heap, uint64_t heap_offset, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, const D3D12_CLEAR_VALUE *optimized_clear_value, struct d3d12_resource **resource); diff --git a/tests/d3d12.c b/tests/d3d12.c index 3fa9ec4e..bfbbf804 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -1547,6 +1547,7 @@ static void test_create_committed_resource(void) D3D12_CLEAR_VALUE clear_value; D3D12_RESOURCE_STATES state; ID3D12Resource *resource; + ID3D12Device4 *device4; unsigned int i; ULONG refcount; HRESULT hr; @@ -1837,6 +1838,38 @@ static void test_create_committed_resource(void) ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr); } + if (SUCCEEDED(ID3D12Device_QueryInterface(device, &IID_ID3D12Device4, (void **)&device4))) + { + memset(&heap_properties, 0, sizeof(heap_properties)); + heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT; + + resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + resource_desc.Alignment = 0; + resource_desc.Width = 32; + resource_desc.Height = 32; + resource_desc.DepthOrArraySize = 1; + resource_desc.MipLevels = 1; + resource_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + resource_desc.SampleDesc.Count = 1; + resource_desc.SampleDesc.Quality = 0; + resource_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; + resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + + clear_value.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + clear_value.Color[0] = 1.0f; + clear_value.Color[1] = 0.0f; + clear_value.Color[2] = 0.0f; + clear_value.Color[3] = 1.0f; + + hr = ID3D12Device4_CreateCommittedResource1(device4, &heap_properties, D3D12_HEAP_FLAG_NONE, + &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, &clear_value, NULL, + &IID_ID3D12Resource, (void **)&resource); + ok(hr == S_OK, "Failed to create committed resource, hr %#x.\n", hr); + ID3D12Resource_Release(resource); + + ID3D12Device4_Release(device4); + } + refcount = ID3D12Device_Release(device); ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount); }