From 9262f87249bba264c740b697532617ce94b518fc Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 30 Sep 2016 13:03:45 +0200 Subject: [PATCH] libs/vkd3d: Allocate CPU memory for descriptors. --- libs/vkd3d/device.c | 21 +++++++++++++++++++-- libs/vkd3d/resource.c | 18 +++++++++++++++++- libs/vkd3d/vkd3d_private.h | 24 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 49c24860..5246f701 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -685,9 +685,26 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateDescriptorHeap(ID3D12Device static UINT STDMETHODCALLTYPE d3d12_device_GetDescriptorHandleIncrementSize(ID3D12Device *iface, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type) { - FIXME("iface %p, descriptor_heap_type %#x stub!\n", iface, descriptor_heap_type); + TRACE("iface %p, descriptor_heap_type %#x.\n", iface, descriptor_heap_type); - return 0; + switch (descriptor_heap_type) + { + case D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV: + return sizeof(struct d3d12_cbv_srv_uav_desc); + + case D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER: + return sizeof(struct d3d12_sampler_desc); + + case D3D12_DESCRIPTOR_HEAP_TYPE_RTV: + return sizeof(struct d3d12_rtv_desc); + + case D3D12_DESCRIPTOR_HEAP_TYPE_DSV: + return sizeof(struct d3d12_dsv_desc); + + default: + FIXME("Unhandled type %#x.\n", descriptor_heap_type); + return 0; + } } static HRESULT STDMETHODCALLTYPE d3d12_device_CreateRootSignature(ID3D12Device *iface, diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index ead88d73..37f04f3b 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -830,12 +830,28 @@ static void d3d12_descriptor_heap_init(struct d3d12_descriptor_heap *descriptor_ HRESULT d3d12_descriptor_heap_create(struct d3d12_device *device, const D3D12_DESCRIPTOR_HEAP_DESC *desc, struct d3d12_descriptor_heap **descriptor_heap) { + size_t max_descriptor_count, descriptor_size; struct d3d12_descriptor_heap *object; - if (!(object = vkd3d_malloc(sizeof(*object)))) + if (!(descriptor_size = ID3D12Device_GetDescriptorHandleIncrementSize(&device->ID3D12Device_iface, desc->Type))) + { + WARN("No descriptor size for descriptor type %#x.\n", desc->Type); + return E_INVALIDARG; + } + + max_descriptor_count = (~(size_t)0 - sizeof(*object)) / descriptor_size; + if (desc->NumDescriptors > max_descriptor_count) + { + WARN("Invalid descriptor count %u (max %zu).\n", desc->NumDescriptors, max_descriptor_count); + return E_OUTOFMEMORY; + } + + if (!(object = vkd3d_malloc(offsetof(struct d3d12_descriptor_heap, + descriptors[descriptor_size * desc->NumDescriptors])))) return E_OUTOFMEMORY; d3d12_descriptor_heap_init(object, device, desc); + memset(object->descriptors, 0, descriptor_size * desc->NumDescriptors); TRACE("Created descriptor heap %p.\n", object); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 640b2ea2..b0ae62d1 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -33,6 +33,8 @@ #include +#define VKD3D_DESCRIPTOR_MAGIC_FREE 0x00000000u + struct d3d12_command_list; struct d3d12_device; @@ -83,6 +85,26 @@ HRESULT d3d12_committed_resource_create(struct d3d12_device *device, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, const D3D12_CLEAR_VALUE *optimized_clear_value, struct d3d12_resource **resource) DECLSPEC_HIDDEN; +struct d3d12_cbv_srv_uav_desc +{ + uint32_t magic; +}; + +struct d3d12_sampler_desc +{ + uint32_t magic; +}; + +struct d3d12_rtv_desc +{ + uint32_t magic; +}; + +struct d3d12_dsv_desc +{ + uint32_t magic; +}; + /* ID3D12DescriptorHeap */ struct d3d12_descriptor_heap { @@ -92,6 +114,8 @@ struct d3d12_descriptor_heap D3D12_DESCRIPTOR_HEAP_DESC desc; struct d3d12_device *device; + + BYTE descriptors[]; }; HRESULT d3d12_descriptor_heap_create(struct d3d12_device *device,