From: Conor McCarthy cmccarthy@codeweavers.com
Allows changing n with a much smaller patch. --- libs/vkd3d/device.c | 100 ++++++++++++++++++------------------- libs/vkd3d/resource.c | 2 +- libs/vkd3d/vkd3d_private.h | 6 ++- 3 files changed, 55 insertions(+), 53 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index b9a8943c..f625d9b9 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2452,12 +2452,12 @@ static void vkd3d_desc_object_cache_cleanup(struct vkd3d_desc_object_cache *cach }
/* ID3D12Device */ -static inline struct d3d12_device *impl_from_ID3D12Device(ID3D12Device *iface) +static inline struct d3d12_device *impl_from_ID3D12Device(d3d12_device_iface *iface) { return CONTAINING_RECORD(iface, struct d3d12_device, ID3D12Device_iface); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_QueryInterface(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_QueryInterface(d3d12_device_iface *iface, REFIID riid, void **object) { TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); @@ -2477,7 +2477,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_QueryInterface(ID3D12Device *iface return E_NOINTERFACE; }
-static ULONG STDMETHODCALLTYPE d3d12_device_AddRef(ID3D12Device *iface) +static ULONG STDMETHODCALLTYPE d3d12_device_AddRef(d3d12_device_iface *iface) { struct d3d12_device *device = impl_from_ID3D12Device(iface); ULONG refcount = InterlockedIncrement(&device->refcount); @@ -2487,7 +2487,7 @@ static ULONG STDMETHODCALLTYPE d3d12_device_AddRef(ID3D12Device *iface) return refcount; }
-static ULONG STDMETHODCALLTYPE d3d12_device_Release(ID3D12Device *iface) +static ULONG STDMETHODCALLTYPE d3d12_device_Release(d3d12_device_iface *iface) { struct d3d12_device *device = impl_from_ID3D12Device(iface); ULONG refcount = InterlockedDecrement(&device->refcount); @@ -2523,7 +2523,7 @@ static ULONG STDMETHODCALLTYPE d3d12_device_Release(ID3D12Device *iface) return refcount; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_GetPrivateData(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_GetPrivateData(d3d12_device_iface *iface, REFGUID guid, UINT *data_size, void *data) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2534,7 +2534,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_GetPrivateData(ID3D12Device *iface return vkd3d_get_private_data(&device->private_store, guid, data_size, data); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateData(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateData(d3d12_device_iface *iface, REFGUID guid, UINT data_size, const void *data) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2545,7 +2545,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateData(ID3D12Device *iface return vkd3d_set_private_data(&device->private_store, guid, data_size, data); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateDataInterface(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateDataInterface(d3d12_device_iface *iface, REFGUID guid, const IUnknown *data) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2555,7 +2555,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_SetPrivateDataInterface(ID3D12Devi return vkd3d_set_private_data_interface(&device->private_store, guid, data); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_SetName(ID3D12Device *iface, const WCHAR *name) +static HRESULT STDMETHODCALLTYPE d3d12_device_SetName(d3d12_device_iface *iface, const WCHAR *name) { struct d3d12_device *device = impl_from_ID3D12Device(iface);
@@ -2565,14 +2565,14 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_SetName(ID3D12Device *iface, const VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, name); }
-static UINT STDMETHODCALLTYPE d3d12_device_GetNodeCount(ID3D12Device *iface) +static UINT STDMETHODCALLTYPE d3d12_device_GetNodeCount(d3d12_device_iface *iface) { TRACE("iface %p.\n", iface);
return 1; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandQueue(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandQueue(d3d12_device_iface *iface, const D3D12_COMMAND_QUEUE_DESC *desc, REFIID riid, void **command_queue) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2589,7 +2589,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandQueue(ID3D12Device *i riid, command_queue); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandAllocator(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandAllocator(d3d12_device_iface *iface, D3D12_COMMAND_LIST_TYPE type, REFIID riid, void **command_allocator) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2606,7 +2606,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandAllocator(ID3D12Devic riid, command_allocator); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateGraphicsPipelineState(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateGraphicsPipelineState(d3d12_device_iface *iface, const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc, REFIID riid, void **pipeline_state) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2623,7 +2623,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateGraphicsPipelineState(ID3D12 &IID_ID3D12PipelineState, riid, pipeline_state); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateComputePipelineState(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateComputePipelineState(d3d12_device_iface *iface, const D3D12_COMPUTE_PIPELINE_STATE_DESC *desc, REFIID riid, void **pipeline_state) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -2640,7 +2640,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateComputePipelineState(ID3D12D &IID_ID3D12PipelineState, riid, pipeline_state); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandList(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandList(d3d12_device_iface *iface, UINT node_mask, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator *command_allocator, ID3D12PipelineState *initial_pipeline_state, REFIID riid, void **command_list) { @@ -2767,7 +2767,7 @@ bool d3d12_device_is_uma(struct d3d12_device *device, bool *coherent) return true; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CheckFeatureSupport(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CheckFeatureSupport(d3d12_device_iface *iface, D3D12_FEATURE feature, void *feature_data, UINT feature_data_size) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3269,7 +3269,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CheckFeatureSupport(ID3D12Device * } }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateDescriptorHeap(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateDescriptorHeap(d3d12_device_iface *iface, const D3D12_DESCRIPTOR_HEAP_DESC *desc, REFIID riid, void **descriptor_heap) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3286,7 +3286,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateDescriptorHeap(ID3D12Device &IID_ID3D12DescriptorHeap, riid, descriptor_heap); }
-static UINT STDMETHODCALLTYPE d3d12_device_GetDescriptorHandleIncrementSize(ID3D12Device *iface, +static UINT STDMETHODCALLTYPE d3d12_device_GetDescriptorHandleIncrementSize(d3d12_device_iface *iface, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type) { TRACE("iface %p, descriptor_heap_type %#x.\n", iface, descriptor_heap_type); @@ -3309,7 +3309,7 @@ static UINT STDMETHODCALLTYPE d3d12_device_GetDescriptorHandleIncrementSize(ID3D } }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateRootSignature(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateRootSignature(d3d12_device_iface *iface, UINT node_mask, const void *bytecode, SIZE_T bytecode_length, REFIID riid, void **root_signature) { @@ -3329,7 +3329,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateRootSignature(ID3D12Device * &IID_ID3D12RootSignature, riid, root_signature); }
-static void STDMETHODCALLTYPE d3d12_device_CreateConstantBufferView(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateConstantBufferView(d3d12_device_iface *iface, const D3D12_CONSTANT_BUFFER_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3341,7 +3341,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateConstantBufferView(ID3D12Device d3d12_desc_write_atomic(d3d12_desc_from_cpu_handle(descriptor), &tmp, device); }
-static void STDMETHODCALLTYPE d3d12_device_CreateShaderResourceView(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateShaderResourceView(d3d12_device_iface *iface, ID3D12Resource *resource, const D3D12_SHADER_RESOURCE_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { @@ -3355,7 +3355,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateShaderResourceView(ID3D12Device d3d12_desc_write_atomic(d3d12_desc_from_cpu_handle(descriptor), &tmp, device); }
-static void STDMETHODCALLTYPE d3d12_device_CreateUnorderedAccessView(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateUnorderedAccessView(d3d12_device_iface *iface, ID3D12Resource *resource, ID3D12Resource *counter_resource, const D3D12_UNORDERED_ACCESS_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { @@ -3370,7 +3370,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateUnorderedAccessView(ID3D12Devic d3d12_desc_write_atomic(d3d12_desc_from_cpu_handle(descriptor), &tmp, device); }
-static void STDMETHODCALLTYPE d3d12_device_CreateRenderTargetView(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateRenderTargetView(d3d12_device_iface *iface, ID3D12Resource *resource, const D3D12_RENDER_TARGET_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { @@ -3381,7 +3381,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateRenderTargetView(ID3D12Device * impl_from_ID3D12Device(iface), unsafe_impl_from_ID3D12Resource(resource), desc); }
-static void STDMETHODCALLTYPE d3d12_device_CreateDepthStencilView(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateDepthStencilView(d3d12_device_iface *iface, ID3D12Resource *resource, const D3D12_DEPTH_STENCIL_VIEW_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { @@ -3392,7 +3392,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateDepthStencilView(ID3D12Device * impl_from_ID3D12Device(iface), unsafe_impl_from_ID3D12Resource(resource), desc); }
-static void STDMETHODCALLTYPE d3d12_device_CreateSampler(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CreateSampler(d3d12_device_iface *iface, const D3D12_SAMPLER_DESC *desc, D3D12_CPU_DESCRIPTOR_HANDLE descriptor) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3404,7 +3404,7 @@ static void STDMETHODCALLTYPE d3d12_device_CreateSampler(ID3D12Device *iface, d3d12_desc_write_atomic(d3d12_desc_from_cpu_handle(descriptor), &tmp, device); }
-static void STDMETHODCALLTYPE d3d12_device_CopyDescriptors(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CopyDescriptors(d3d12_device_iface *iface, UINT dst_descriptor_range_count, const D3D12_CPU_DESCRIPTOR_HANDLE *dst_descriptor_range_offsets, const UINT *dst_descriptor_range_sizes, UINT src_descriptor_range_count, const D3D12_CPU_DESCRIPTOR_HANDLE *src_descriptor_range_offsets, @@ -3465,7 +3465,7 @@ static void STDMETHODCALLTYPE d3d12_device_CopyDescriptors(ID3D12Device *iface, } }
-static void STDMETHODCALLTYPE d3d12_device_CopyDescriptorsSimple(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_CopyDescriptorsSimple(d3d12_device_iface *iface, UINT descriptor_count, const D3D12_CPU_DESCRIPTOR_HANDLE dst_descriptor_range_offset, const D3D12_CPU_DESCRIPTOR_HANDLE src_descriptor_range_offset, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type) @@ -3480,7 +3480,7 @@ static void STDMETHODCALLTYPE d3d12_device_CopyDescriptorsSimple(ID3D12Device *i }
static D3D12_RESOURCE_ALLOCATION_INFO * STDMETHODCALLTYPE d3d12_device_GetResourceAllocationInfo( - ID3D12Device *iface, D3D12_RESOURCE_ALLOCATION_INFO *info, UINT visible_mask, + d3d12_device_iface *iface, D3D12_RESOURCE_ALLOCATION_INFO *info, UINT visible_mask, UINT count, const D3D12_RESOURCE_DESC *resource_descs) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3556,7 +3556,7 @@ invalid: return info; }
-static D3D12_HEAP_PROPERTIES * STDMETHODCALLTYPE d3d12_device_GetCustomHeapProperties(ID3D12Device *iface, +static D3D12_HEAP_PROPERTIES * STDMETHODCALLTYPE d3d12_device_GetCustomHeapProperties(d3d12_device_iface *iface, D3D12_HEAP_PROPERTIES *heap_properties, UINT node_mask, D3D12_HEAP_TYPE heap_type) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3599,7 +3599,7 @@ static D3D12_HEAP_PROPERTIES * STDMETHODCALLTYPE d3d12_device_GetCustomHeapPrope return heap_properties; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommittedResource(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommittedResource(d3d12_device_iface *iface, 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, REFIID iid, void **resource) @@ -3623,7 +3623,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommittedResource(ID3D12Devi return return_interface(&object->ID3D12Resource_iface, &IID_ID3D12Resource, iid, resource); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateHeap(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateHeap(d3d12_device_iface *iface, const D3D12_HEAP_DESC *desc, REFIID iid, void **heap) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3642,7 +3642,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateHeap(ID3D12Device *iface, return return_interface(&object->ID3D12Heap_iface, &IID_ID3D12Heap, iid, heap); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreatePlacedResource(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreatePlacedResource(d3d12_device_iface *iface, ID3D12Heap *heap, UINT64 heap_offset, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, const D3D12_CLEAR_VALUE *optimized_clear_value, REFIID iid, void **resource) @@ -3666,7 +3666,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreatePlacedResource(ID3D12Device return return_interface(&object->ID3D12Resource_iface, &IID_ID3D12Resource, iid, resource); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateReservedResource(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateReservedResource(d3d12_device_iface *iface, const D3D12_RESOURCE_DESC *desc, D3D12_RESOURCE_STATES initial_state, const D3D12_CLEAR_VALUE *optimized_clear_value, REFIID iid, void **resource) { @@ -3684,7 +3684,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateReservedResource(ID3D12Devic return return_interface(&object->ID3D12Resource_iface, &IID_ID3D12Resource, iid, resource); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateSharedHandle(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateSharedHandle(d3d12_device_iface *iface, ID3D12DeviceChild *object, const SECURITY_ATTRIBUTES *attributes, DWORD access, const WCHAR *name, HANDLE *handle) { @@ -3696,7 +3696,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateSharedHandle(ID3D12Device *i return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandle(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandle(d3d12_device_iface *iface, HANDLE handle, REFIID riid, void **object) { FIXME("iface %p, handle %p, riid %s, object %p stub!\n", @@ -3705,7 +3705,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandle(ID3D12Device *ifa return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandleByName(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandleByName(d3d12_device_iface *iface, const WCHAR *name, DWORD access, HANDLE *handle) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3716,7 +3716,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_OpenSharedHandleByName(ID3D12Devic return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_MakeResident(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_MakeResident(d3d12_device_iface *iface, UINT object_count, ID3D12Pageable * const *objects) { FIXME_ONCE("iface %p, object_count %u, objects %p stub!\n", @@ -3725,7 +3725,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_MakeResident(ID3D12Device *iface, return S_OK; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_Evict(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_Evict(d3d12_device_iface *iface, UINT object_count, ID3D12Pageable * const *objects) { FIXME_ONCE("iface %p, object_count %u, objects %p stub!\n", @@ -3734,7 +3734,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_Evict(ID3D12Device *iface, return S_OK; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateFence(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateFence(d3d12_device_iface *iface, UINT64 initial_value, D3D12_FENCE_FLAGS flags, REFIID riid, void **fence) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3750,7 +3750,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateFence(ID3D12Device *iface, return return_interface(&object->ID3D12Fence_iface, &IID_ID3D12Fence, riid, fence); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_GetDeviceRemovedReason(ID3D12Device *iface) +static HRESULT STDMETHODCALLTYPE d3d12_device_GetDeviceRemovedReason(d3d12_device_iface *iface) { struct d3d12_device *device = impl_from_ID3D12Device(iface);
@@ -3759,7 +3759,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_GetDeviceRemovedReason(ID3D12Devic return device->removed_reason; }
-static void STDMETHODCALLTYPE d3d12_device_GetCopyableFootprints(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_GetCopyableFootprints(d3d12_device_iface *iface, const D3D12_RESOURCE_DESC *desc, UINT first_sub_resource, UINT sub_resource_count, UINT64 base_offset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *layouts, UINT *row_counts, UINT64 *row_sizes, UINT64 *total_bytes) @@ -3844,7 +3844,7 @@ static void STDMETHODCALLTYPE d3d12_device_GetCopyableFootprints(ID3D12Device *i *total_bytes = total; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateQueryHeap(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateQueryHeap(d3d12_device_iface *iface, const D3D12_QUERY_HEAP_DESC *desc, REFIID iid, void **heap) { struct d3d12_device *device = impl_from_ID3D12Device(iface); @@ -3860,14 +3860,14 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateQueryHeap(ID3D12Device *ifac return return_interface(&object->ID3D12QueryHeap_iface, &IID_ID3D12QueryHeap, iid, heap); }
-static HRESULT STDMETHODCALLTYPE d3d12_device_SetStablePowerState(ID3D12Device *iface, BOOL enable) +static HRESULT STDMETHODCALLTYPE d3d12_device_SetStablePowerState(d3d12_device_iface *iface, BOOL enable) { FIXME("iface %p, enable %#x stub!\n", iface, enable);
return E_NOTIMPL; }
-static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandSignature(ID3D12Device *iface, +static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandSignature(d3d12_device_iface *iface, const D3D12_COMMAND_SIGNATURE_DESC *desc, ID3D12RootSignature *root_signature, REFIID iid, void **command_signature) { @@ -3885,7 +3885,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateCommandSignature(ID3D12Devic &IID_ID3D12CommandSignature, iid, command_signature); }
-static void STDMETHODCALLTYPE d3d12_device_GetResourceTiling(ID3D12Device *iface, +static void STDMETHODCALLTYPE d3d12_device_GetResourceTiling(d3d12_device_iface *iface, ID3D12Resource *resource, UINT *total_tile_count, D3D12_PACKED_MIP_INFO *packed_mip_info, D3D12_TILE_SHAPE *standard_tile_shape, UINT *sub_resource_tiling_count, UINT first_sub_resource_tiling, @@ -3899,7 +3899,7 @@ static void STDMETHODCALLTYPE d3d12_device_GetResourceTiling(ID3D12Device *iface sub_resource_tilings); }
-static LUID * STDMETHODCALLTYPE d3d12_device_GetAdapterLuid(ID3D12Device *iface, LUID *luid) +static LUID * STDMETHODCALLTYPE d3d12_device_GetAdapterLuid(d3d12_device_iface *iface, LUID *luid) { struct d3d12_device *device = impl_from_ID3D12Device(iface);
@@ -3961,7 +3961,7 @@ static const struct ID3D12DeviceVtbl d3d12_device_vtbl = d3d12_device_GetAdapterLuid, };
-struct d3d12_device *unsafe_impl_from_ID3D12Device(ID3D12Device *iface) +struct d3d12_device *unsafe_impl_from_ID3D12Device(d3d12_device_iface *iface) { if (!iface) return NULL; @@ -4172,28 +4172,28 @@ HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_ha
IUnknown *vkd3d_get_device_parent(ID3D12Device *device) { - struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); + struct d3d12_device *d3d12_device = impl_from_ID3D12Device((d3d12_device_iface *)device);
return d3d12_device->parent; }
VkDevice vkd3d_get_vk_device(ID3D12Device *device) { - struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); + struct d3d12_device *d3d12_device = impl_from_ID3D12Device((d3d12_device_iface *)device);
return d3d12_device->vk_device; }
VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device) { - struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); + struct d3d12_device *d3d12_device = impl_from_ID3D12Device((d3d12_device_iface *)device);
return d3d12_device->vk_physical_device; }
struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device) { - struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); + struct d3d12_device *d3d12_device = impl_from_ID3D12Device((d3d12_device_iface *)device);
return d3d12_device->vkd3d_instance; } diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 4c07d326..a59b46d3 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -2025,7 +2025,7 @@ HRESULT d3d12_reserved_resource_create(struct d3d12_device *device, HRESULT vkd3d_create_image_resource(ID3D12Device *device, const struct vkd3d_image_resource_create_info *create_info, ID3D12Resource **resource) { - struct d3d12_device *d3d12_device = unsafe_impl_from_ID3D12Device(device); + struct d3d12_device *d3d12_device = unsafe_impl_from_ID3D12Device((d3d12_device_iface *)device); struct d3d12_resource *object; HRESULT hr;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index c5259420..eeea6fea 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1653,10 +1653,12 @@ struct vkd3d_desc_object_cache
#define VKD3D_DESCRIPTOR_POOL_COUNT 6
+typedef ID3D12Device d3d12_device_iface; + /* ID3D12Device */ struct d3d12_device { - ID3D12Device ID3D12Device_iface; + d3d12_device_iface ID3D12Device_iface; LONG refcount;
VkDevice vk_device; @@ -1722,7 +1724,7 @@ struct vkd3d_queue *d3d12_device_get_vkd3d_queue(struct d3d12_device *device, D3 bool d3d12_device_is_uma(struct d3d12_device *device, bool *coherent); void d3d12_device_mark_as_removed(struct d3d12_device *device, HRESULT reason, const char *message, ...) VKD3D_PRINTF_FUNC(3, 4); -struct d3d12_device *unsafe_impl_from_ID3D12Device(ID3D12Device *iface); +struct d3d12_device *unsafe_impl_from_ID3D12Device(d3d12_device_iface *iface);
static inline HRESULT d3d12_device_query_interface(struct d3d12_device *device, REFIID iid, void **object) {
From: Conor McCarthy cmccarthy@codeweavers.com
--- include/vkd3d_windows.h | 1 + libs/vkd3d/device.c | 33 ++++++++++++++++++++++++++++++++- libs/vkd3d/vkd3d_private.h | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/include/vkd3d_windows.h b/include/vkd3d_windows.h index 002ff667..2daa74e9 100644 --- a/include/vkd3d_windows.h +++ b/include/vkd3d_windows.h @@ -64,6 +64,7 @@ typedef int HRESULT;
# define DXGI_ERROR_NOT_FOUND _HRESULT_TYPEDEF_(0x887a0002) # define DXGI_ERROR_MORE_DATA _HRESULT_TYPEDEF_(0x887a0003) +# define DXGI_ERROR_UNSUPPORTED _HRESULT_TYPEDEF_(0x887a0004)
# define D3DERR_INVALIDCALL _HRESULT_TYPEDEF_(0x8876086c)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index f625d9b9..8f0d09bd 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2463,6 +2463,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_QueryInterface(d3d12_device_iface TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
if (IsEqualGUID(riid, &IID_ID3D12Device) + || IsEqualGUID(riid, &IID_ID3D12Device1) || IsEqualGUID(riid, &IID_ID3D12Object) || IsEqualGUID(riid, &IID_IUnknown)) { @@ -3910,7 +3911,33 @@ static LUID * STDMETHODCALLTYPE d3d12_device_GetAdapterLuid(d3d12_device_iface * return luid; }
-static const struct ID3D12DeviceVtbl d3d12_device_vtbl = +static HRESULT STDMETHODCALLTYPE d3d12_device_CreatePipelineLibrary(d3d12_device_iface *iface, + const void *blob, SIZE_T blob_size, REFIID iid, void **lib) +{ + FIXME("iface %p, blob %p, blob_size %lu, iid %s, lib %p stub!\n", iface, blob, blob_size, debugstr_guid(iid), lib); + + return DXGI_ERROR_UNSUPPORTED; +} + +static HRESULT STDMETHODCALLTYPE d3d12_device_SetEventOnMultipleFenceCompletion(d3d12_device_iface *iface, + ID3D12Fence *const *fences, const UINT64 *values, UINT fence_count, + D3D12_MULTIPLE_FENCE_WAIT_FLAGS flags, HANDLE event) +{ + FIXME("iface %p, fences %p, values %p, fence_count %u, flags %#x, event %p stub!\n", + iface, fences, values, fence_count, flags, event); + + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_device_SetResidencyPriority(d3d12_device_iface *iface, + UINT object_count, ID3D12Pageable *const *objects, const D3D12_RESIDENCY_PRIORITY *priorities) +{ + FIXME_ONCE("iface %p, object_count %u, objects %p, priorities %p stub!\n", iface, object_count, objects, priorities); + + return S_OK; +} + +static const struct ID3D12Device1Vtbl d3d12_device_vtbl = { /* IUnknown methods */ d3d12_device_QueryInterface, @@ -3959,6 +3986,10 @@ static const struct ID3D12DeviceVtbl d3d12_device_vtbl = d3d12_device_CreateCommandSignature, d3d12_device_GetResourceTiling, d3d12_device_GetAdapterLuid, + /* ID3D12Device1 methods */ + d3d12_device_CreatePipelineLibrary, + d3d12_device_SetEventOnMultipleFenceCompletion, + d3d12_device_SetResidencyPriority, };
struct d3d12_device *unsafe_impl_from_ID3D12Device(d3d12_device_iface *iface) diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index eeea6fea..9ef3a6c6 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1653,7 +1653,7 @@ struct vkd3d_desc_object_cache
#define VKD3D_DESCRIPTOR_POOL_COUNT 6
-typedef ID3D12Device d3d12_device_iface; +typedef ID3D12Device1 d3d12_device_iface;
/* ID3D12Device */ struct d3d12_device
From: Conor McCarthy cmccarthy@codeweavers.com
Based on vkd3d-proton patches by Philip Rebohle and Hans-Kristian Arntzen. --- include/vkd3d_d3d12.idl | 70 +++++++ libs/vkd3d/device.c | 37 +++- libs/vkd3d/state.c | 394 +++++++++++++++++++++++++++++++------ libs/vkd3d/vkd3d_private.h | 40 +++- 4 files changed, 480 insertions(+), 61 deletions(-)
diff --git a/include/vkd3d_d3d12.idl b/include/vkd3d_d3d12.idl index 06287f5a..992bdcac 100644 --- a/include/vkd3d_d3d12.idl +++ b/include/vkd3d_d3d12.idl @@ -38,6 +38,7 @@ cpp_quote("#define D3D12_DEFAULT_BLEND_FACTOR_BLUE (1.0f)") cpp_quote("#define D3D12_DEFAULT_BLEND_FACTOR_GREEN (1.0f)") cpp_quote("#define D3D12_DEFAULT_BLEND_FACTOR_RED (1.0f)") const UINT D3D12_DEFAULT_DEPTH_BIAS = 0; +const UINT D3D12_DEFAULT_SAMPLE_MASK = 0xffffffff; cpp_quote("#define D3D12_DEFAULT_DEPTH_BIAS_CLAMP (0.0f)") cpp_quote("#define D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS (0.0f)") const UINT D3D12_DEFAULT_STENCIL_READ_MASK = 0xff; @@ -1430,6 +1431,19 @@ typedef struct D3D12_DEPTH_STENCIL_DESC D3D12_DEPTH_STENCILOP_DESC BackFace; } D3D12_DEPTH_STENCIL_DESC;
+typedef struct D3D12_DEPTH_STENCIL_DESC1 +{ + BOOL DepthEnable; + D3D12_DEPTH_WRITE_MASK DepthWriteMask; + D3D12_COMPARISON_FUNC DepthFunc; + BOOL StencilEnable; + UINT8 StencilReadMask; + UINT8 StencilWriteMask; + D3D12_DEPTH_STENCILOP_DESC FrontFace; + D3D12_DEPTH_STENCILOP_DESC BackFace; + BOOL DepthBoundsTestEnable; +} D3D12_DEPTH_STENCIL_DESC1; + typedef enum D3D12_BLEND { D3D12_BLEND_ZERO = 1, @@ -1606,6 +1620,62 @@ typedef enum D3D12_PRIMITIVE_TOPOLOGY_TYPE D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH = 4, } D3D12_PRIMITIVE_TOPOLOGY_TYPE;
+typedef struct D3D12_RT_FORMAT_ARRAY +{ + DXGI_FORMAT RTFormats[8]; + UINT NumRenderTargets; +} D3D12_RT_FORMAT_ARRAY; + +typedef enum D3D12_VIEW_INSTANCING_FLAGS +{ + D3D12_VIEW_INSTANCING_FLAG_NONE = 0, + D3D12_VIEW_INSTANCING_FLAG_ENABLE_VIEW_INSTANCE_MASKING = 0x1, +} D3D12_VIEW_INSTANCING_FLAGS; +cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(D3D12_VIEW_INSTANCING_FLAGS);") + +typedef struct D3D12_VIEW_INSTANCE_LOCATION +{ + UINT ViewportArrayIndex; + UINT RenderTargetArrayIndex; +} D3D12_VIEW_INSTANCE_LOCATION; + +typedef struct D3D12_VIEW_INSTANCING_DESC +{ + UINT ViewInstanceCount; + const D3D12_VIEW_INSTANCE_LOCATION *pViewInstanceLocations; + D3D12_VIEW_INSTANCING_FLAGS Flags; +} D3D12_VIEW_INSTANCING_DESC; + +typedef enum D3D12_PIPELINE_STATE_SUBOBJECT_TYPE +{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE = 0, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS = 1, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS = 2, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS = 3, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS = 4, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS = 5, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS = 6, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT = 7, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND = 8, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK = 9, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER = 10, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL = 11, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT = 12, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE = 13, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY = 14, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS = 15, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT = 16, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC = 17, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK = 18, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO = 19, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS = 20, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1 = 21, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING = 22, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS = 24, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS = 25, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID = 26, +} D3D12_PIPELINE_STATE_SUBOBJECT_TYPE; + typedef struct D3D12_CACHED_PIPELINE_STATE { const void *pCachedBlob; diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 8f0d09bd..222555d4 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2464,6 +2464,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_QueryInterface(d3d12_device_iface
if (IsEqualGUID(riid, &IID_ID3D12Device) || IsEqualGUID(riid, &IID_ID3D12Device1) + || IsEqualGUID(riid, &IID_ID3D12Device2) || IsEqualGUID(riid, &IID_ID3D12Object) || IsEqualGUID(riid, &IID_IUnknown)) { @@ -2611,13 +2612,17 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateGraphicsPipelineState(d3d12_ const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc, REFIID riid, void **pipeline_state) { struct d3d12_device *device = impl_from_ID3D12Device(iface); + struct d3d12_pipeline_state_desc pipeline_desc; struct d3d12_pipeline_state *object; HRESULT hr;
TRACE("iface %p, desc %p, riid %s, pipeline_state %p.\n", iface, desc, debugstr_guid(riid), pipeline_state);
- if (FAILED(hr = d3d12_pipeline_state_create_graphics(device, desc, &object))) + if (FAILED(hr = pipeline_state_desc_from_d3d12_graphics_desc(&pipeline_desc, desc))) + return hr; + + if (FAILED(hr = d3d12_pipeline_state_create_graphics(device, &pipeline_desc, &object))) return hr;
return return_interface(&object->ID3D12PipelineState_iface, @@ -2628,13 +2633,17 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateComputePipelineState(d3d12_d const D3D12_COMPUTE_PIPELINE_STATE_DESC *desc, REFIID riid, void **pipeline_state) { struct d3d12_device *device = impl_from_ID3D12Device(iface); + struct d3d12_pipeline_state_desc pipeline_desc; struct d3d12_pipeline_state *object; HRESULT hr;
TRACE("iface %p, desc %p, riid %s, pipeline_state %p.\n", iface, desc, debugstr_guid(riid), pipeline_state);
- if (FAILED(hr = d3d12_pipeline_state_create_compute(device, desc, &object))) + if (FAILED(hr = pipeline_state_desc_from_d3d12_compute_desc(&pipeline_desc, desc))) + return hr; + + if (FAILED(hr = d3d12_pipeline_state_create_compute(device, &pipeline_desc, &object))) return hr;
return return_interface(&object->ID3D12PipelineState_iface, @@ -3937,7 +3946,27 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_SetResidencyPriority(d3d12_device_ return S_OK; }
-static const struct ID3D12Device1Vtbl d3d12_device_vtbl = +static HRESULT STDMETHODCALLTYPE d3d12_device_CreatePipelineState(d3d12_device_iface *iface, + const D3D12_PIPELINE_STATE_STREAM_DESC *desc, REFIID riid, void **pipeline_state) +{ + struct d3d12_device *device = impl_from_ID3D12Device(iface); + struct d3d12_pipeline_state_desc pipeline_desc; + struct d3d12_pipeline_state *object; + VkPipelineBindPoint bind_point; + HRESULT hr; + + TRACE("iface %p, desc %p, riid %s, pipeline_state %p.\n", iface, desc, debugstr_guid(riid), pipeline_state); + + if (FAILED(hr = pipeline_state_desc_from_d3d12_stream_desc(&pipeline_desc, desc, &bind_point))) + return hr; + + if (FAILED(hr = d3d12_pipeline_state_create(device, bind_point, &pipeline_desc, &object))) + return hr; + + return return_interface(&object->ID3D12PipelineState_iface, &IID_ID3D12PipelineState, riid, pipeline_state); +} + +static const struct ID3D12Device2Vtbl d3d12_device_vtbl = { /* IUnknown methods */ d3d12_device_QueryInterface, @@ -3990,6 +4019,8 @@ static const struct ID3D12Device1Vtbl d3d12_device_vtbl = d3d12_device_CreatePipelineLibrary, d3d12_device_SetEventOnMultipleFenceCompletion, d3d12_device_SetResidencyPriority, + /* ID3D12Device2 methods */ + d3d12_device_CreatePipelineState, };
struct d3d12_device *unsafe_impl_from_ID3D12Device(d3d12_device_iface *iface) diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 2d813824..a7392035 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1736,6 +1736,247 @@ void vkd3d_render_pass_cache_cleanup(struct vkd3d_render_pass_cache *cache, cache->render_passes = NULL; }
+static void d3d12_promote_depth_stencil_desc(D3D12_DEPTH_STENCIL_DESC1 *dst, const D3D12_DEPTH_STENCIL_DESC *src) +{ + dst->DepthEnable = src->DepthEnable; + dst->DepthWriteMask = src->DepthWriteMask; + dst->DepthFunc = src->DepthFunc; + dst->StencilEnable = src->StencilEnable; + dst->StencilReadMask = src->StencilReadMask; + dst->StencilWriteMask = src->StencilWriteMask; + dst->FrontFace = src->FrontFace; + dst->BackFace = src->BackFace; + dst->DepthBoundsTestEnable = FALSE; +} + +static void d3d12_init_pipeline_state_desc(struct d3d12_pipeline_state_desc *desc) +{ + D3D12_DEPTH_STENCIL_DESC1 *ds_state = &desc->depth_stencil_state; + D3D12_RASTERIZER_DESC *rs_state = &desc->rasterizer_state; + D3D12_BLEND_DESC *blend_state = &desc->blend_state; + DXGI_SAMPLE_DESC *sample_desc = &desc->sample_desc; + + memset(desc, 0, sizeof(*desc)); + ds_state->DepthEnable = TRUE; + ds_state->DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + ds_state->DepthFunc = D3D12_COMPARISON_FUNC_LESS; + ds_state->StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK; + ds_state->StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK; + ds_state->FrontFace.StencilFunc = ds_state->BackFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS; + ds_state->FrontFace.StencilDepthFailOp = ds_state->BackFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP; + ds_state->FrontFace.StencilPassOp = ds_state->BackFace.StencilPassOp = D3D12_STENCIL_OP_KEEP; + ds_state->FrontFace.StencilFailOp = ds_state->BackFace.StencilFailOp = D3D12_STENCIL_OP_KEEP; + + rs_state->FillMode = D3D12_FILL_MODE_SOLID; + rs_state->CullMode = D3D12_CULL_MODE_BACK; + rs_state->DepthClipEnable = TRUE; + rs_state->ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF; + + blend_state->RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; + + sample_desc->Count = 1; + sample_desc->Quality = 0; + + desc->sample_mask = D3D12_DEFAULT_SAMPLE_MASK; +} + +HRESULT pipeline_state_desc_from_d3d12_graphics_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_GRAPHICS_PIPELINE_STATE_DESC *d3d12_desc) +{ + memset(desc, 0, sizeof(*desc)); + desc->root_signature = d3d12_desc->pRootSignature; + desc->vs = d3d12_desc->VS; + desc->ps = d3d12_desc->PS; + desc->ds = d3d12_desc->DS; + desc->hs = d3d12_desc->HS; + desc->gs = d3d12_desc->GS; + desc->stream_output = d3d12_desc->StreamOutput; + desc->blend_state = d3d12_desc->BlendState; + desc->sample_mask = d3d12_desc->SampleMask; + desc->rasterizer_state = d3d12_desc->RasterizerState; + d3d12_promote_depth_stencil_desc(&desc->depth_stencil_state, &d3d12_desc->DepthStencilState); + desc->input_layout = d3d12_desc->InputLayout; + desc->strip_cut_value = d3d12_desc->IBStripCutValue; + desc->primitive_topology_type = d3d12_desc->PrimitiveTopologyType; + desc->rtv_formats.NumRenderTargets = d3d12_desc->NumRenderTargets; + memcpy(desc->rtv_formats.RTFormats, d3d12_desc->RTVFormats, sizeof(desc->rtv_formats.RTFormats)); + desc->dsv_format = d3d12_desc->DSVFormat; + desc->sample_desc = d3d12_desc->SampleDesc; + desc->node_mask = d3d12_desc->NodeMask; + desc->cached_pso = d3d12_desc->CachedPSO; + desc->flags = d3d12_desc->Flags; + return S_OK; +} + +HRESULT pipeline_state_desc_from_d3d12_compute_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_COMPUTE_PIPELINE_STATE_DESC *d3d12_desc) +{ + memset(desc, 0, sizeof(*desc)); + desc->root_signature = d3d12_desc->pRootSignature; + desc->cs = d3d12_desc->CS; + desc->node_mask = d3d12_desc->NodeMask; + desc->cached_pso = d3d12_desc->CachedPSO; + desc->flags = d3d12_desc->Flags; + return S_OK; +} + +#define VKD3D_HANDLE_SUBOBJECT_EXPLICIT(type_enum, type_name, assignment) \ + case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ ## type_enum: \ + {\ + const struct\ + {\ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; \ + type_name data; \ + } *subobject = (void *)stream_ptr; \ + if (stream_ptr + sizeof(*subobject) > stream_end) \ + { \ + WARN("Invalid pipeline state stream.\n"); \ + return E_INVALIDARG; \ + } \ + stream_ptr += align(sizeof(*subobject), sizeof(void*)); \ + assignment; \ + break;\ + } + +#define VKD3D_HANDLE_SUBOBJECT(type_enum, type, left_side) \ + VKD3D_HANDLE_SUBOBJECT_EXPLICIT(type_enum, type, left_side = subobject->data) + +static VkShaderStageFlags pipeline_state_desc_get_shader_stages(const struct d3d12_pipeline_state_desc *desc) +{ + VkShaderStageFlags result = 0; + + if (desc->vs.BytecodeLength && desc->vs.pShaderBytecode) + result |= VK_SHADER_STAGE_VERTEX_BIT; + if (desc->hs.BytecodeLength && desc->hs.pShaderBytecode) + result |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + if (desc->ds.BytecodeLength && desc->ds.pShaderBytecode) + result |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + if (desc->gs.BytecodeLength && desc->gs.pShaderBytecode) + result |= VK_SHADER_STAGE_GEOMETRY_BIT; + if (desc->ps.BytecodeLength && desc->ps.pShaderBytecode) + result |= VK_SHADER_STAGE_FRAGMENT_BIT; + if (desc->cs.BytecodeLength && desc->cs.pShaderBytecode) + result |= VK_SHADER_STAGE_COMPUTE_BIT; + + /* If we use rasterizer discard, force fragment shader to not exist. + * See VUID-VkGraphicsPipelineCreateInfo-pStages-06894. */ + if (desc->stream_output.NumEntries && + desc->stream_output.RasterizedStream == D3D12_SO_NO_RASTERIZED_STREAM) + { + result &= ~VK_SHADER_STAGE_FRAGMENT_BIT; + } + + return result; +} + +HRESULT pipeline_state_desc_from_d3d12_stream_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_PIPELINE_STATE_STREAM_DESC *d3d12_desc, VkPipelineBindPoint *vk_bind_point) +{ + VkShaderStageFlags defined_stages, disallowed_stages; + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE subobject_type; + const char *stream_ptr, *stream_end; + uint64_t defined_subobjects = 0; + uint64_t subobject_bit; + + /* Initialize defaults for undefined subobjects */ + d3d12_init_pipeline_state_desc(desc); + + /* Structs are packed, but padded so that their size + * is always a multiple of the size of a pointer. */ + stream_ptr = d3d12_desc->pPipelineStateSubobjectStream; + stream_end = stream_ptr + d3d12_desc->SizeInBytes; + + while (stream_ptr < stream_end) + { + if (stream_ptr + sizeof(subobject_type) > stream_end) + { + WARN("Invalid pipeline state stream.\n"); + return E_INVALIDARG; + } + + subobject_type = *(const D3D12_PIPELINE_STATE_SUBOBJECT_TYPE *)stream_ptr; + subobject_bit = 1ull << subobject_type; + + if (defined_subobjects & subobject_bit) + { + WARN("Duplicate pipeline subobject type %u.\n", subobject_type); + return E_INVALIDARG; + } + + defined_subobjects |= subobject_bit; + + switch (subobject_type) + { + VKD3D_HANDLE_SUBOBJECT(ROOT_SIGNATURE, ID3D12RootSignature*, desc->root_signature); + VKD3D_HANDLE_SUBOBJECT(VS, D3D12_SHADER_BYTECODE, desc->vs); + VKD3D_HANDLE_SUBOBJECT(PS, D3D12_SHADER_BYTECODE, desc->ps); + VKD3D_HANDLE_SUBOBJECT(DS, D3D12_SHADER_BYTECODE, desc->ds); + VKD3D_HANDLE_SUBOBJECT(HS, D3D12_SHADER_BYTECODE, desc->hs); + VKD3D_HANDLE_SUBOBJECT(GS, D3D12_SHADER_BYTECODE, desc->gs); + VKD3D_HANDLE_SUBOBJECT(CS, D3D12_SHADER_BYTECODE, desc->cs); + VKD3D_HANDLE_SUBOBJECT(STREAM_OUTPUT, D3D12_STREAM_OUTPUT_DESC, desc->stream_output); + VKD3D_HANDLE_SUBOBJECT(BLEND, D3D12_BLEND_DESC, desc->blend_state); + VKD3D_HANDLE_SUBOBJECT(SAMPLE_MASK, UINT, desc->sample_mask); + VKD3D_HANDLE_SUBOBJECT(RASTERIZER, D3D12_RASTERIZER_DESC, desc->rasterizer_state); + VKD3D_HANDLE_SUBOBJECT_EXPLICIT(DEPTH_STENCIL, D3D12_DEPTH_STENCIL_DESC, + d3d12_promote_depth_stencil_desc(&desc->depth_stencil_state, &subobject->data)); + VKD3D_HANDLE_SUBOBJECT(INPUT_LAYOUT, D3D12_INPUT_LAYOUT_DESC, desc->input_layout); + VKD3D_HANDLE_SUBOBJECT(IB_STRIP_CUT_VALUE, D3D12_INDEX_BUFFER_STRIP_CUT_VALUE, desc->strip_cut_value); + VKD3D_HANDLE_SUBOBJECT(PRIMITIVE_TOPOLOGY, D3D12_PRIMITIVE_TOPOLOGY_TYPE, desc->primitive_topology_type); + VKD3D_HANDLE_SUBOBJECT(RENDER_TARGET_FORMATS, D3D12_RT_FORMAT_ARRAY, desc->rtv_formats); + VKD3D_HANDLE_SUBOBJECT(DEPTH_STENCIL_FORMAT, DXGI_FORMAT, desc->dsv_format); + VKD3D_HANDLE_SUBOBJECT(SAMPLE_DESC, DXGI_SAMPLE_DESC, desc->sample_desc); + VKD3D_HANDLE_SUBOBJECT(NODE_MASK, UINT, desc->node_mask); + VKD3D_HANDLE_SUBOBJECT(CACHED_PSO, D3D12_CACHED_PIPELINE_STATE, desc->cached_pso); + VKD3D_HANDLE_SUBOBJECT(FLAGS, D3D12_PIPELINE_STATE_FLAGS, desc->flags); + VKD3D_HANDLE_SUBOBJECT(DEPTH_STENCIL1, D3D12_DEPTH_STENCIL_DESC1, desc->depth_stencil_state); + VKD3D_HANDLE_SUBOBJECT(VIEW_INSTANCING, D3D12_VIEW_INSTANCING_DESC, desc->view_instancing_desc); + + case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS: + FIXME("Amplification shaders are not supported yet.\n"); + return E_INVALIDARG; + + case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS: + FIXME("Mesh shaders are not supported yet.\n"); + return E_INVALIDARG; + + default: + FIXME("Unhandled pipeline subobject type %u.\n", subobject_type); + return E_INVALIDARG; + } + } + + /* Deduce pipeline type from specified shaders */ + defined_stages = pipeline_state_desc_get_shader_stages(desc); + + if (defined_stages & VK_SHADER_STAGE_VERTEX_BIT) + { + disallowed_stages = VK_SHADER_STAGE_COMPUTE_BIT; + *vk_bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS; + } + else if (defined_stages & VK_SHADER_STAGE_COMPUTE_BIT) + { + disallowed_stages = VK_SHADER_STAGE_VERTEX_BIT; + *vk_bind_point = VK_PIPELINE_BIND_POINT_COMPUTE; + } + else + { + WARN("Cannot deduce pipeline type from shader stages 0x%#x.\n", defined_stages); + return E_INVALIDARG; + } + + if (defined_stages & disallowed_stages) + { + WARN("Invalid combination of shader stages 0x%#x.\n", defined_stages); + return E_INVALIDARG; + } + + return S_OK; +} + +#undef VKD3D_HANDLE_SUBOBJECT +#undef VKD3D_HANDLE_SUBOBJECT_EXPLICIT + struct vkd3d_pipeline_key { D3D12_PRIMITIVE_TOPOLOGY topology; @@ -2193,7 +2434,7 @@ static HRESULT d3d12_pipeline_state_find_and_init_uav_counters(struct d3d12_pipe }
static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *state, - struct d3d12_device *device, const D3D12_COMPUTE_PIPELINE_STATE_DESC *desc) + struct d3d12_device *device, const struct d3d12_pipeline_state_desc *desc) { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; struct vkd3d_shader_interface_info shader_interface; @@ -2208,14 +2449,14 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
memset(&state->uav_counters, 0, sizeof(state->uav_counters));
- if (!(root_signature = unsafe_impl_from_ID3D12RootSignature(desc->pRootSignature))) + if (!(root_signature = unsafe_impl_from_ID3D12RootSignature(desc->root_signature))) { WARN("Root signature is NULL.\n"); return E_INVALIDARG; }
if (FAILED(hr = d3d12_pipeline_state_find_and_init_uav_counters(state, device, root_signature, - &desc->CS, VK_SHADER_STAGE_COMPUTE_BIT))) + &desc->cs, VK_SHADER_STAGE_COMPUTE_BIT))) return hr;
memset(&target_info, 0, sizeof(target_info)); @@ -2256,7 +2497,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
vk_pipeline_layout = state->uav_counters.vk_pipeline_layout ? state->uav_counters.vk_pipeline_layout : root_signature->vk_pipeline_layout; - if (FAILED(hr = vkd3d_create_compute_pipeline(device, &desc->CS, &shader_interface, + if (FAILED(hr = vkd3d_create_compute_pipeline(device, &desc->cs, &shader_interface, vk_pipeline_layout, &state->u.compute.vk_pipeline))) { WARN("Failed to create Vulkan compute pipeline, hr %#x.\n", hr); @@ -2278,7 +2519,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st }
HRESULT d3d12_pipeline_state_create_compute(struct d3d12_device *device, - const D3D12_COMPUTE_PIPELINE_STATE_DESC *desc, struct d3d12_pipeline_state **state) + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state) { struct d3d12_pipeline_state *object; HRESULT hr; @@ -2457,7 +2698,7 @@ static void vk_stencil_op_state_from_d3d12(struct VkStencilOpState *vk_desc, }
static void ds_desc_from_d3d12(struct VkPipelineDepthStencilStateCreateInfo *vk_desc, - const D3D12_DEPTH_STENCIL_DESC *d3d12_desc) + const D3D12_DEPTH_STENCIL_DESC1 *d3d12_desc) { memset(vk_desc, 0, sizeof(*vk_desc)); vk_desc->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; @@ -2738,12 +2979,12 @@ static VkLogicOp vk_logic_op_from_d3d12(D3D12_LOGIC_OP op) }
static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *state, - struct d3d12_device *device, const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc) + struct d3d12_device *device, const struct d3d12_pipeline_state_desc *desc) { unsigned int ps_output_swizzle[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT]; struct d3d12_graphics_pipeline_state *graphics = &state->u.graphics; const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; - const D3D12_STREAM_OUTPUT_DESC *so_desc = &desc->StreamOutput; + const D3D12_STREAM_OUTPUT_DESC *so_desc = &desc->stream_output; VkVertexInputBindingDivisorDescriptionEXT *binding_divisor; const struct vkd3d_vulkan_info *vk_info = &device->vk_info; uint32_t instance_divisors[D3D12_VS_INPUT_REGISTER_COUNT]; @@ -2787,11 +3028,11 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s } shader_stages[] = { - {VK_SHADER_STAGE_VERTEX_BIT, offsetof(D3D12_GRAPHICS_PIPELINE_STATE_DESC, VS)}, - {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, offsetof(D3D12_GRAPHICS_PIPELINE_STATE_DESC, HS)}, - {VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, offsetof(D3D12_GRAPHICS_PIPELINE_STATE_DESC, DS)}, - {VK_SHADER_STAGE_GEOMETRY_BIT, offsetof(D3D12_GRAPHICS_PIPELINE_STATE_DESC, GS)}, - {VK_SHADER_STAGE_FRAGMENT_BIT, offsetof(D3D12_GRAPHICS_PIPELINE_STATE_DESC, PS)}, + {VK_SHADER_STAGE_VERTEX_BIT, offsetof(struct d3d12_pipeline_state_desc, vs)}, + {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, offsetof(struct d3d12_pipeline_state_desc, hs)}, + {VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, offsetof(struct d3d12_pipeline_state_desc, ds)}, + {VK_SHADER_STAGE_GEOMETRY_BIT, offsetof(struct d3d12_pipeline_state_desc, gs)}, + {VK_SHADER_STAGE_FRAGMENT_BIT, offsetof(struct d3d12_pipeline_state_desc, ps)}, };
state->ID3D12PipelineState_iface.lpVtbl = &d3d12_pipeline_state_vtbl; @@ -2802,26 +3043,26 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
memset(&input_signature, 0, sizeof(input_signature));
- for (i = desc->NumRenderTargets; i < ARRAY_SIZE(desc->RTVFormats); ++i) + for (i = desc->rtv_formats.NumRenderTargets; i < ARRAY_SIZE(desc->rtv_formats.RTFormats); ++i) { - if (desc->RTVFormats[i] != DXGI_FORMAT_UNKNOWN) + if (desc->rtv_formats.RTFormats[i] != DXGI_FORMAT_UNKNOWN) { WARN("Format must be set to DXGI_FORMAT_UNKNOWN for inactive render targets.\n"); return E_INVALIDARG; } }
- if (!(root_signature = unsafe_impl_from_ID3D12RootSignature(desc->pRootSignature))) + if (!(root_signature = unsafe_impl_from_ID3D12RootSignature(desc->root_signature))) { WARN("Root signature is NULL.\n"); return E_INVALIDARG; }
- sample_count = vk_samples_from_dxgi_sample_desc(&desc->SampleDesc); - if (desc->SampleDesc.Count != 1 && desc->SampleDesc.Quality) - WARN("Ignoring sample quality %u.\n", desc->SampleDesc.Quality); + sample_count = vk_samples_from_dxgi_sample_desc(&desc->sample_desc); + if (desc->sample_desc.Count != 1 && desc->sample_desc.Quality) + WARN("Ignoring sample quality %u.\n", desc->sample_desc.Quality);
- rt_count = desc->NumRenderTargets; + rt_count = desc->rtv_formats.NumRenderTargets; if (rt_count > ARRAY_SIZE(graphics->blend_attachments)) { FIXME("NumRenderTargets %zu > %zu, ignoring extra formats.\n", @@ -2829,40 +3070,40 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s rt_count = ARRAY_SIZE(graphics->blend_attachments); }
- graphics->om_logic_op_enable = desc->BlendState.RenderTarget[0].LogicOpEnable + graphics->om_logic_op_enable = desc->blend_state.RenderTarget[0].LogicOpEnable && device->feature_options.OutputMergerLogicOp; graphics->om_logic_op = graphics->om_logic_op_enable - ? vk_logic_op_from_d3d12(desc->BlendState.RenderTarget[0].LogicOp) + ? vk_logic_op_from_d3d12(desc->blend_state.RenderTarget[0].LogicOp) : VK_LOGIC_OP_COPY; - if (desc->BlendState.RenderTarget[0].LogicOpEnable && !graphics->om_logic_op_enable) + if (desc->blend_state.RenderTarget[0].LogicOpEnable && !graphics->om_logic_op_enable) WARN("The device does not support output merger logic ops. Ignoring logic op %#x.\n", - desc->BlendState.RenderTarget[0].LogicOp); + desc->blend_state.RenderTarget[0].LogicOp);
graphics->null_attachment_mask = 0; for (i = 0; i < rt_count; ++i) { const D3D12_RENDER_TARGET_BLEND_DESC *rt_desc;
- if (desc->RTVFormats[i] == DXGI_FORMAT_UNKNOWN) + if (desc->rtv_formats.RTFormats[i] == DXGI_FORMAT_UNKNOWN) { graphics->null_attachment_mask |= 1u << i; ps_output_swizzle[i] = VKD3D_SHADER_NO_SWIZZLE; graphics->rtv_formats[i] = VK_FORMAT_UNDEFINED; } - else if ((format = vkd3d_get_format(device, desc->RTVFormats[i], false))) + else if ((format = vkd3d_get_format(device, desc->rtv_formats.RTFormats[i], false))) { ps_output_swizzle[i] = vkd3d_get_rt_format_swizzle(format); graphics->rtv_formats[i] = format->vk_format; } else { - WARN("Invalid RTV format %#x.\n", desc->RTVFormats[i]); + WARN("Invalid RTV format %#x.\n", desc->rtv_formats.RTFormats[i]); hr = E_INVALIDARG; goto fail; }
- rt_desc = &desc->BlendState.RenderTarget[desc->BlendState.IndependentBlendEnable ? i : 0]; - if (desc->BlendState.IndependentBlendEnable && rt_desc->LogicOpEnable) + rt_desc = &desc->blend_state.RenderTarget[desc->blend_state.IndependentBlendEnable ? i : 0]; + if (desc->blend_state.IndependentBlendEnable && rt_desc->LogicOpEnable) { WARN("IndependentBlendEnable must be FALSE when logic operations are enabled.\n"); hr = E_INVALIDARG; @@ -2881,8 +3122,8 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s graphics->rtv_formats[i] = VK_FORMAT_UNDEFINED; graphics->rt_count = rt_count;
- ds_desc_from_d3d12(&graphics->ds_desc, &desc->DepthStencilState); - if (desc->DSVFormat == DXGI_FORMAT_UNKNOWN + ds_desc_from_d3d12(&graphics->ds_desc, &desc->depth_stencil_state); + if (desc->dsv_format == DXGI_FORMAT_UNKNOWN && graphics->ds_desc.depthTestEnable && !graphics->ds_desc.depthWriteEnable && graphics->ds_desc.depthCompareOp == VK_COMPARE_OP_ALWAYS && !graphics->ds_desc.stencilTestEnable) { @@ -2893,13 +3134,13 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s graphics->dsv_format = VK_FORMAT_UNDEFINED; if (graphics->ds_desc.depthTestEnable || graphics->ds_desc.stencilTestEnable) { - if (desc->DSVFormat == DXGI_FORMAT_UNKNOWN) + if (desc->dsv_format == DXGI_FORMAT_UNKNOWN) { WARN("DSV format is DXGI_FORMAT_UNKNOWN.\n"); graphics->dsv_format = VK_FORMAT_UNDEFINED; graphics->null_attachment_mask |= dsv_attachment_mask(graphics); } - else if ((format = vkd3d_get_format(device, desc->DSVFormat, true))) + else if ((format = vkd3d_get_format(device, desc->dsv_format, true))) { if (!(format->vk_aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) FIXME("Format %#x is not depth/stencil format.\n", format->dxgi_format); @@ -2908,12 +3149,12 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s } else { - WARN("Invalid DSV format %#x.\n", desc->DSVFormat); + WARN("Invalid DSV format %#x.\n", desc->dsv_format); hr = E_INVALIDARG; goto fail; }
- if (!desc->PS.pShaderBytecode) + if (!desc->ps.pShaderBytecode) { if (FAILED(hr = create_shader_stage(device, &graphics->stages[graphics->stage_count], VK_SHADER_STAGE_FRAGMENT_BIT, &default_ps, NULL))) @@ -2936,7 +3177,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s ps_target_info.extension_count = vk_info->shader_extension_count; ps_target_info.parameters = ps_shader_parameters; ps_target_info.parameter_count = ARRAY_SIZE(ps_shader_parameters); - ps_target_info.dual_source_blending = is_dual_source_blending(&desc->BlendState.RenderTarget[0]); + ps_target_info.dual_source_blending = is_dual_source_blending(&desc->blend_state.RenderTarget[0]); ps_target_info.output_swizzles = ps_output_swizzle; ps_target_info.output_swizzle_count = rt_count;
@@ -2946,11 +3187,11 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s hr = E_INVALIDARG; goto fail; } - if (ps_target_info.dual_source_blending && desc->BlendState.IndependentBlendEnable) + if (ps_target_info.dual_source_blending && desc->blend_state.IndependentBlendEnable) { - for (i = 1; i < ARRAY_SIZE(desc->BlendState.RenderTarget); ++i) + for (i = 1; i < ARRAY_SIZE(desc->blend_state.RenderTarget); ++i) { - if (desc->BlendState.RenderTarget[i].BlendEnable) + if (desc->blend_state.RenderTarget[i].BlendEnable) { WARN("Blend enable cannot be set for render target %u when dual source blending is used.\n", i); hr = E_INVALIDARG; @@ -2992,9 +3233,9 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s xfb_info.buffer_strides = so_desc->pBufferStrides; xfb_info.buffer_stride_count = so_desc->NumStrides;
- if (desc->GS.pShaderBytecode) + if (desc->gs.pShaderBytecode) xfb_stage = VK_SHADER_STAGE_GEOMETRY_BIT; - else if (desc->DS.pShaderBytecode) + else if (desc->ds.pShaderBytecode) xfb_stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; else xfb_stage = VK_SHADER_STAGE_VERTEX_BIT; @@ -3046,7 +3287,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: - if (desc->PrimitiveTopologyType != D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH) + if (desc->primitive_topology_type != D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH) { WARN("D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH must be used with tessellation shaders.\n"); hr = E_INVALIDARG; @@ -3088,7 +3329,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s ++graphics->stage_count; }
- graphics->attribute_count = desc->InputLayout.NumElements; + graphics->attribute_count = desc->input_layout.NumElements; if (graphics->attribute_count > ARRAY_SIZE(graphics->attributes)) { FIXME("InputLayout.NumElements %zu > %zu, ignoring extra elements.\n", @@ -3104,13 +3345,13 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s goto fail; }
- if (FAILED(hr = compute_input_layout_offsets(device, &desc->InputLayout, aligned_offsets))) + if (FAILED(hr = compute_input_layout_offsets(device, &desc->input_layout, aligned_offsets))) goto fail;
graphics->instance_divisor_count = 0; for (i = 0, j = 0, mask = 0; i < graphics->attribute_count; ++i) { - const D3D12_INPUT_ELEMENT_DESC *e = &desc->InputLayout.pInputElementDescs[i]; + const D3D12_INPUT_ELEMENT_DESC *e = &desc->input_layout.pInputElementDescs[i]; const struct vkd3d_shader_signature_element *signature_element;
/* TODO: DXGI_FORMAT_UNKNOWN will succeed here, which may not match @@ -3194,30 +3435,30 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s graphics->attribute_count = j; vkd3d_shader_free_shader_signature(&input_signature);
- switch (desc->IBStripCutValue) + switch (desc->strip_cut_value) { case D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_DISABLED: case D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF: case D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFFFFFF: - graphics->index_buffer_strip_cut_value = desc->IBStripCutValue; + graphics->index_buffer_strip_cut_value = desc->strip_cut_value; break; default: - WARN("Invalid index buffer strip cut value %#x.\n", desc->IBStripCutValue); + WARN("Invalid index buffer strip cut value %#x.\n", desc->strip_cut_value); hr = E_INVALIDARG; goto fail; }
is_dsv_format_unknown = graphics->null_attachment_mask & dsv_attachment_mask(graphics);
- rs_desc_from_d3d12(&graphics->rs_desc, &desc->RasterizerState); + rs_desc_from_d3d12(&graphics->rs_desc, &desc->rasterizer_state); have_attachment = graphics->rt_count || graphics->dsv_format || is_dsv_format_unknown; - if ((!have_attachment && !(desc->PS.pShaderBytecode && desc->PS.BytecodeLength)) + if ((!have_attachment && !(desc->ps.pShaderBytecode && desc->ps.BytecodeLength)) || (graphics->xfb_enabled && so_desc->RasterizedStream == D3D12_SO_NO_RASTERIZED_STREAM)) graphics->rs_desc.rasterizerDiscardEnable = VK_TRUE;
rs_stream_info_from_d3d12(&graphics->rs_stream_info, &graphics->rs_desc, so_desc, vk_info); if (vk_info->EXT_depth_clip_enable) - rs_depth_clip_info_from_d3d12(&graphics->rs_depth_clip_info, &graphics->rs_desc, &desc->RasterizerState); + rs_depth_clip_info_from_d3d12(&graphics->rs_depth_clip_info, &graphics->rs_desc, &desc->rasterizer_state);
graphics->ms_desc.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; graphics->ms_desc.pNext = NULL; @@ -3226,16 +3467,23 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s graphics->ms_desc.sampleShadingEnable = VK_FALSE; graphics->ms_desc.minSampleShading = 0.0f; graphics->ms_desc.pSampleMask = NULL; - if (desc->SampleMask != ~0u) + if (desc->sample_mask != ~0u) { assert(DIV_ROUND_UP(sample_count, 32) <= ARRAY_SIZE(graphics->sample_mask)); - graphics->sample_mask[0] = desc->SampleMask; + graphics->sample_mask[0] = desc->sample_mask; graphics->sample_mask[1] = 0xffffffffu; graphics->ms_desc.pSampleMask = graphics->sample_mask; } - graphics->ms_desc.alphaToCoverageEnable = desc->BlendState.AlphaToCoverageEnable; + graphics->ms_desc.alphaToCoverageEnable = desc->blend_state.AlphaToCoverageEnable; graphics->ms_desc.alphaToOneEnable = VK_FALSE;
+ if (desc->view_instancing_desc.ViewInstanceCount) + { + FIXME("View instancing is not supported yet.\n"); + hr = E_INVALIDARG; + goto fail; + } + /* We defer creating the render pass for pipelines wth DSVFormat equal to * DXGI_FORMAT_UNKNOWN. We take the actual DSV format from the bound DSV. */ if (is_dsv_format_unknown) @@ -3269,7 +3517,7 @@ fail: }
HRESULT d3d12_pipeline_state_create_graphics(struct d3d12_device *device, - const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc, struct d3d12_pipeline_state **state) + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state) { struct d3d12_pipeline_state *object; HRESULT hr; @@ -3290,6 +3538,42 @@ HRESULT d3d12_pipeline_state_create_graphics(struct d3d12_device *device, return S_OK; }
+HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindPoint bind_point, + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state) +{ + struct d3d12_pipeline_state *object; + HRESULT hr; + + if (!(object = vkd3d_calloc(1, sizeof(*object)))) + return E_OUTOFMEMORY; + + switch (bind_point) + { + case VK_PIPELINE_BIND_POINT_COMPUTE: + hr = d3d12_pipeline_state_init_compute(object, device, desc); + break; + + case VK_PIPELINE_BIND_POINT_GRAPHICS: + hr = d3d12_pipeline_state_init_graphics(object, device, desc); + break; + + default: + WARN("Invalid bind point %u.", bind_point); + hr = E_INVALIDARG; + } + + if (FAILED(hr)) + { + vkd3d_free(object); + return hr; + } + + TRACE("Created pipeline state %p.\n", object); + + *state = object; + return S_OK; +} + static enum VkPrimitiveTopology vk_topology_from_d3d12_topology(D3D12_PRIMITIVE_TOPOLOGY topology) { switch (topology) diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 9ef3a6c6..2e5ac747 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1264,10 +1264,44 @@ static inline bool d3d12_pipeline_state_has_unknown_dsv_format(struct d3d12_pipe return false; }
+struct d3d12_pipeline_state_desc +{ + ID3D12RootSignature *root_signature; + D3D12_SHADER_BYTECODE vs; + D3D12_SHADER_BYTECODE ps; + D3D12_SHADER_BYTECODE ds; + D3D12_SHADER_BYTECODE hs; + D3D12_SHADER_BYTECODE gs; + D3D12_SHADER_BYTECODE cs; + D3D12_STREAM_OUTPUT_DESC stream_output; + D3D12_BLEND_DESC blend_state; + unsigned int sample_mask; + D3D12_RASTERIZER_DESC rasterizer_state; + D3D12_DEPTH_STENCIL_DESC1 depth_stencil_state; + D3D12_INPUT_LAYOUT_DESC input_layout; + D3D12_INDEX_BUFFER_STRIP_CUT_VALUE strip_cut_value; + D3D12_PRIMITIVE_TOPOLOGY_TYPE primitive_topology_type; + D3D12_RT_FORMAT_ARRAY rtv_formats; + DXGI_FORMAT dsv_format; + DXGI_SAMPLE_DESC sample_desc; + D3D12_VIEW_INSTANCING_DESC view_instancing_desc; + unsigned int node_mask; + D3D12_CACHED_PIPELINE_STATE cached_pso; + D3D12_PIPELINE_STATE_FLAGS flags; +}; + +HRESULT pipeline_state_desc_from_d3d12_graphics_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_GRAPHICS_PIPELINE_STATE_DESC *d3d12_desc); +HRESULT pipeline_state_desc_from_d3d12_compute_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_COMPUTE_PIPELINE_STATE_DESC *d3d12_desc); +HRESULT pipeline_state_desc_from_d3d12_stream_desc(struct d3d12_pipeline_state_desc *desc, + const D3D12_PIPELINE_STATE_STREAM_DESC *d3d12_desc, VkPipelineBindPoint *vk_bind_point); HRESULT d3d12_pipeline_state_create_compute(struct d3d12_device *device, - const D3D12_COMPUTE_PIPELINE_STATE_DESC *desc, struct d3d12_pipeline_state **state); + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state); HRESULT d3d12_pipeline_state_create_graphics(struct d3d12_device *device, - const D3D12_GRAPHICS_PIPELINE_STATE_DESC *desc, struct d3d12_pipeline_state **state); + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state); +HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindPoint bind_point, + const struct d3d12_pipeline_state_desc *desc, struct d3d12_pipeline_state **state); VkPipeline d3d12_pipeline_state_get_or_create_pipeline(struct d3d12_pipeline_state *state, D3D12_PRIMITIVE_TOPOLOGY topology, const uint32_t *strides, VkFormat dsv_format, VkRenderPass *vk_render_pass); struct d3d12_pipeline_state *unsafe_impl_from_ID3D12PipelineState(ID3D12PipelineState *iface); @@ -1653,7 +1687,7 @@ struct vkd3d_desc_object_cache
#define VKD3D_DESCRIPTOR_POOL_COUNT 6
-typedef ID3D12Device1 d3d12_device_iface; +typedef ID3D12Device2 d3d12_device_iface;
/* ID3D12Device */ struct d3d12_device
From: Conor McCarthy cmccarthy@codeweavers.com
Based on vkd3d-proton patches by Hans-Kristian Arntzen and Philip Rebohle. --- tests/d3d12.c | 571 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 571 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index 2f1c905f..425469f1 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -3095,6 +3095,576 @@ static void test_create_graphics_pipeline_state(void) ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount); }
+union d3d12_root_signature_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + ID3D12RootSignature *root_signature; + }; + void *dummy_align; +}; + +union d3d12_shader_bytecode_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_SHADER_BYTECODE shader_bytecode; + }; + void *dummy_align; +}; + +union d3d12_stream_output_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_STREAM_OUTPUT_DESC stream_output_desc; + }; + void *dummy_align; +}; + +union d3d12_blend_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_BLEND_DESC blend_desc; + }; + void *dummy_align; +}; + +union d3d12_sample_mask_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + UINT sample_mask; + }; + void *dummy_align; +}; + +union d3d12_rasterizer_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_RASTERIZER_DESC rasterizer_desc; + }; + void *dummy_align; +}; + +union d3d12_depth_stencil_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_DEPTH_STENCIL_DESC depth_stencil_desc; + }; + void *dummy_align; +}; + +union d3d12_input_layout_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_INPUT_LAYOUT_DESC input_layout; + }; + void *dummy_align; +}; + +union d3d12_ib_strip_cut_value_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_INDEX_BUFFER_STRIP_CUT_VALUE strip_cut_value; + }; + void *dummy_align; +}; + +union d3d12_primitive_topology_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_PRIMITIVE_TOPOLOGY_TYPE primitive_topology_type; + }; + void *dummy_align; +}; + +union d3d12_render_target_formats_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_RT_FORMAT_ARRAY render_target_formats; + }; + void *dummy_align; +}; + +union d3d12_depth_stencil_format_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + DXGI_FORMAT depth_stencil_format; + }; + void *dummy_align; +}; + +union d3d12_sample_desc_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + DXGI_SAMPLE_DESC sample_desc; + }; + void *dummy_align; +}; + +union d3d12_node_mask_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + UINT node_mask; + }; + void *dummy_align; +}; + +union d3d12_cached_pso_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_CACHED_PIPELINE_STATE cached_pso; + }; + void *dummy_align; +}; + +union d3d12_flags_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_PIPELINE_STATE_FLAGS flags; + }; + void *dummy_align; +}; + +union d3d12_depth_stencil1_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_DEPTH_STENCIL_DESC1 depth_stencil_desc; + }; + void *dummy_align; +}; + +union d3d12_view_instancing_subobject +{ + struct + { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; + D3D12_VIEW_INSTANCING_DESC view_instancing_desc; + }; + void *dummy_align; +}; + +static void test_create_pipeline_state(void) +{ + D3D12_ROOT_SIGNATURE_DESC root_signature_desc; + ID3D12RootSignature *root_signature; + ID3D12PipelineState *pipeline_state; + ID3D12Device2 *device2; + ID3D12Device *device; + unsigned int i; + ULONG refcount; + HRESULT hr; + + static const DWORD cs_code[] = + { +#if 0 + [numthreads(1, 1, 1)] + void main() { } +#endif + 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003, + 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a, + 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e, + }; + + static const DWORD vs_code[] = + { +#if 0 + float4 main(float4 pos : POS) : SV_POSITION { + return pos; + } +#endif + 0x43425844, 0xd0f999d3, 0x5250b8b9, 0x32f55488, 0x0498c795, 0x00000001, 0x000000d4, 0x00000003, + 0x0000002c, 0x00000058, 0x0000008c, 0x4e475349, 0x00000024, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00534f50, 0x4e47534f, 0x0000002c, + 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, + 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853, 0x00000040, 0x00010050, 0x00000010, 0x0100086a, + 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, + 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, + }; + + static const DWORD ps_code[] = + { +#if 0 + float4 main() : SV_TARGET { + return float4(1.0f, 1.0f, 1.0f, 1.0f); + } +#endif + 0x43425844, 0x29b14cf3, 0xb991cf90, 0x9e455ffc, 0x4675b046, 0x00000001, 0x000000b4, 0x00000003, + 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, + 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, + 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050, 0x0000000f, + 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, + 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e, + }; + + static const union d3d12_root_signature_subobject root_signature_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE, + NULL, /* fill in dynamically */ + }}; + + static const union d3d12_shader_bytecode_subobject vs_subobject = {{ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS, { vs_code, sizeof(vs_code) } }}; + static const union d3d12_shader_bytecode_subobject ps_subobject = {{ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS, { ps_code, sizeof(ps_code) } }}; + static const union d3d12_shader_bytecode_subobject cs_subobject = {{ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS, { cs_code, sizeof(cs_code) } }}; + + static const D3D12_SO_DECLARATION_ENTRY so_entries[] = + { + { 0, "SV_POSITION", 0, 0, 4, 0 }, + }; + + static const UINT so_strides[] = { 16u }; + + static const union d3d12_stream_output_subobject stream_output_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT, + { so_entries, ARRAY_SIZE(so_entries), + so_strides, ARRAY_SIZE(so_strides), + D3D12_SO_NO_RASTERIZED_STREAM }, + }}; + + static const union d3d12_blend_subobject blend_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND, + { FALSE, TRUE, + {{ FALSE, FALSE, + D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD, + D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD, + D3D12_LOGIC_OP_NOOP, 0xf }}, + } + }}; + + static const union d3d12_sample_mask_subobject sample_mask_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK, + 0xffffffffu + }}; + + static const union d3d12_rasterizer_subobject rasterizer_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER, + { D3D12_FILL_MODE_SOLID, D3D12_CULL_MODE_BACK, + FALSE, 0, 0.0f, 0.0f, TRUE, FALSE, FALSE, 0, + D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF }, + }}; + + static const union d3d12_depth_stencil_subobject depth_stencil_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, + { TRUE, D3D12_DEPTH_WRITE_MASK_ALL, D3D12_COMPARISON_FUNC_LESS_EQUAL, TRUE, 0xff, 0xff, + { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_INCR, D3D12_COMPARISON_FUNC_EQUAL }, + { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_INCR, D3D12_COMPARISON_FUNC_EQUAL } }, + }}; + + static const D3D12_INPUT_ELEMENT_DESC input_elements[] = + { + { "POS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, + }; + + static const union d3d12_input_layout_subobject input_layout_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT, + { input_elements, ARRAY_SIZE(input_elements) }, + }}; + + static const union d3d12_ib_strip_cut_value_subobject ib_strip_cut_value_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE, + D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFFFFFF, + }}; + + static const union d3d12_primitive_topology_subobject primitive_topology_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY, + D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, + }}; + + static const union d3d12_render_target_formats_subobject render_target_formats_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS, + { { DXGI_FORMAT_R8G8B8A8_UNORM }, 1 }, + }}; + + static const union d3d12_depth_stencil_format_subobject depth_stencil_format_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, + DXGI_FORMAT_D32_FLOAT_S8X24_UINT, + }}; + + static const union d3d12_sample_desc_subobject sample_desc_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC, + { 1, 0 }, + }}; + + static const union d3d12_node_mask_subobject node_mask_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK, + 0x0, + }}; + + static const union d3d12_cached_pso_subobject cached_pso_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO, + { NULL, 0 }, + }}; + + static const union d3d12_flags_subobject flags_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS, + D3D12_PIPELINE_STATE_FLAG_NONE, + }}; + + static const union d3d12_depth_stencil1_subobject depth_stencil1_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, + { TRUE, D3D12_DEPTH_WRITE_MASK_ALL, D3D12_COMPARISON_FUNC_LESS_EQUAL, TRUE, 0xff, 0xff, + { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_INCR, D3D12_COMPARISON_FUNC_EQUAL }, + { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_INCR, D3D12_COMPARISON_FUNC_EQUAL } }, + }}; + + static const union d3d12_view_instancing_subobject view_instancing_subobject = + {{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING, + { 0, NULL, D3D12_VIEW_INSTANCING_FLAG_NONE }, + }}; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject vertex_shader; + union d3d12_shader_bytecode_subobject pixel_shader; + union d3d12_blend_subobject blend; + union d3d12_sample_mask_subobject sample_mask; + union d3d12_rasterizer_subobject rasterizer; + union d3d12_depth_stencil1_subobject depth_stencil; + union d3d12_input_layout_subobject input_layout; + union d3d12_ib_strip_cut_value_subobject strip_cut; + union d3d12_primitive_topology_subobject primitive_topology; + union d3d12_render_target_formats_subobject render_target_formats; + union d3d12_depth_stencil_format_subobject depth_stencil_format; + union d3d12_sample_desc_subobject sample_desc; + union d3d12_node_mask_subobject node_mask; + union d3d12_cached_pso_subobject cached_pso; + union d3d12_flags_subobject flags; + union d3d12_view_instancing_subobject view_instancing; + } + pipeline_desc_1 = + { + root_signature_subobject, + vs_subobject, + ps_subobject, + blend_subobject, + sample_mask_subobject, + rasterizer_subobject, + depth_stencil1_subobject, + input_layout_subobject, + ib_strip_cut_value_subobject, + primitive_topology_subobject, + render_target_formats_subobject, + depth_stencil_format_subobject, + sample_desc_subobject, + node_mask_subobject, + cached_pso_subobject, + flags_subobject, + view_instancing_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject compute_shader; + } + pipeline_desc_2 = + { + root_signature_subobject, cs_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject vertex_shader; + union d3d12_stream_output_subobject stream_output; + union d3d12_input_layout_subobject input_layout; + } + pipeline_desc_3 = + { + root_signature_subobject, vs_subobject, stream_output_subobject, + input_layout_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + } + pipeline_desc_4 = + { + root_signature_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject cs; + union d3d12_shader_bytecode_subobject vs; + } + pipeline_desc_5 = + { + root_signature_subobject, cs_subobject, vs_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject cs; + union d3d12_shader_bytecode_subobject ps; + union d3d12_rasterizer_subobject rasterizer; + } + pipeline_desc_6 = + { + root_signature_subobject, cs_subobject, ps_subobject, + rasterizer_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_depth_stencil_subobject depth_stencil; + union d3d12_depth_stencil_format_subobject depth_stencil_format; + union d3d12_input_layout_subobject input_layout; + union d3d12_shader_bytecode_subobject vertex_shader; + } + pipeline_desc_7 = + { + root_signature_subobject, depth_stencil_subobject, depth_stencil_format_subobject, + input_layout_subobject, vs_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject cs; + union d3d12_shader_bytecode_subobject cs2; + } + pipeline_desc_8 = + { + root_signature_subobject, cs_subobject, cs_subobject, + }; + + struct + { + union d3d12_root_signature_subobject root_signature; + union d3d12_shader_bytecode_subobject vs; + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE extra_type; + } + pipeline_desc_9 = + { + root_signature_subobject, vs_subobject, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL + }; + + struct + { + D3D12_PIPELINE_STATE_STREAM_DESC stream_desc; + HRESULT expected_result; + } + tests[] = { + { { sizeof(pipeline_desc_1), &pipeline_desc_1 }, S_OK }, + { { sizeof(pipeline_desc_2), &pipeline_desc_2 }, S_OK }, + { { sizeof(pipeline_desc_3), &pipeline_desc_3 }, S_OK }, + { { sizeof(pipeline_desc_4), &pipeline_desc_4 }, E_INVALIDARG }, + { { sizeof(pipeline_desc_5), &pipeline_desc_5 }, E_INVALIDARG }, + { { sizeof(pipeline_desc_6), &pipeline_desc_6 }, S_OK }, + { { sizeof(pipeline_desc_7), &pipeline_desc_7 }, S_OK }, + { { sizeof(pipeline_desc_8), &pipeline_desc_8 }, E_INVALIDARG }, + { { sizeof(pipeline_desc_9), &pipeline_desc_9 }, E_INVALIDARG }, + }; + + if (!(device = create_device())) + { + skip("Failed to create device.\n"); + return; + } + + if (ID3D12Device_QueryInterface(device, &IID_ID3D12Device2, (void **)&device2)) + { + skip("ID3D12Device2 not supported.\n"); + ID3D12Device_Release(device); + return; + } + + root_signature_desc.NumParameters = 0; + root_signature_desc.pParameters = NULL; + root_signature_desc.NumStaticSamplers = 0; + root_signature_desc.pStaticSamplers = NULL; + root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_STREAM_OUTPUT | + D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; + hr = create_root_signature(device, &root_signature_desc, &root_signature); + ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + union d3d12_root_signature_subobject *rs_subobject; + vkd3d_test_push_context("Test %u", i); + + /* Assign root signature. To keep things simple, assume that the root + * signature is always the first element in each pipeline stream */ + rs_subobject = tests[i].stream_desc.pPipelineStateSubobjectStream; + + if (rs_subobject && rs_subobject->type == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE) + rs_subobject->root_signature = root_signature; + + hr = ID3D12Device2_CreatePipelineState(device2, &tests[i].stream_desc, &IID_ID3D12PipelineState, (void **)&pipeline_state); + ok(hr == tests[i].expected_result, "Got unexpected return value %#x.\n", hr); + + if (hr == S_OK) + { + refcount = ID3D12PipelineState_Release(pipeline_state); + ok(!refcount, "ID3D12PipelineState has %u references left.\n", (unsigned int)refcount); + } + + vkd3d_test_pop_context(); + } + + refcount = ID3D12RootSignature_Release(root_signature); + ok(!refcount, "ID3D12RootSignature has %u references left.\n", (unsigned int)refcount); + refcount = ID3D12Device2_Release(device2); + ok(refcount == 1, "ID3D12Device2 has %u references left.\n", (unsigned int)refcount); + refcount = ID3D12Device_Release(device); + ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount); +} + static void test_create_fence(void) { ID3D12Device *device, *tmp_device; @@ -36467,6 +37037,7 @@ START_TEST(d3d12) run_test(test_root_signature_limits); run_test(test_create_compute_pipeline_state); run_test(test_create_graphics_pipeline_state); + run_test(test_create_pipeline_state); run_test(test_create_fence); run_test(test_object_interface); run_test(test_multithread_private_data);
From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d/device.c | 4 +--- libs/vkd3d/state.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 222555d4..1175817f 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -1521,9 +1521,7 @@ static HRESULT vkd3d_init_device_caps(struct d3d12_device *device, device->feature_options1.ExpandedComputeResourceStates = TRUE; device->feature_options1.Int64ShaderOps = features->shaderInt64;
- /* Depth bounds test is enabled in D3D12_DEPTH_STENCIL_DESC1, which is not - * supported. */ - device->feature_options2.DepthBoundsTestSupported = FALSE; + device->feature_options2.DepthBoundsTestSupported = features->depthBounds; /* d3d12_command_list_SetSamplePositions() is not implemented. */ device->feature_options2.ProgrammableSamplePositionsTier = D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED;
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index a7392035..f6ab254a 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2714,7 +2714,7 @@ static void ds_desc_from_d3d12(struct VkPipelineDepthStencilStateCreateInfo *vk_ vk_desc->depthWriteEnable = VK_FALSE; vk_desc->depthCompareOp = VK_COMPARE_OP_NEVER; } - vk_desc->depthBoundsTestEnable = VK_FALSE; + vk_desc->depthBoundsTestEnable = d3d12_desc->DepthBoundsTestEnable; if ((vk_desc->stencilTestEnable = d3d12_desc->StencilEnable)) { vk_stencil_op_state_from_d3d12(&vk_desc->front, &d3d12_desc->FrontFace, @@ -3123,6 +3123,12 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s graphics->rt_count = rt_count;
ds_desc_from_d3d12(&graphics->ds_desc, &desc->depth_stencil_state); + if (graphics->ds_desc.depthBoundsTestEnable && !device->feature_options2.DepthBoundsTestSupported) + { + WARN("Depth bounds test not supported by device.\n"); + hr = E_INVALIDARG; + goto fail; + } if (desc->dsv_format == DXGI_FORMAT_UNKNOWN && graphics->ds_desc.depthTestEnable && !graphics->ds_desc.depthWriteEnable && graphics->ds_desc.depthCompareOp == VK_COMPARE_OP_ALWAYS && !graphics->ds_desc.stencilTestEnable) @@ -3132,7 +3138,8 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s }
graphics->dsv_format = VK_FORMAT_UNDEFINED; - if (graphics->ds_desc.depthTestEnable || graphics->ds_desc.stencilTestEnable) + if (graphics->ds_desc.depthTestEnable || graphics->ds_desc.stencilTestEnable + || graphics->ds_desc.depthBoundsTestEnable) { if (desc->dsv_format == DXGI_FORMAT_UNKNOWN) {
I'm not quite sure how I feel about the d3d12_device_iface typedef, so I'd like to hear from others on that one. On the one hand, this is probably one of the few legitimate uses of "typedef". On the other hand, it does add a layer of obfuscation, and I'm not sure it's solving a problem that's in dire need of solving.
if (IsEqualGUID(riid, &IID_ID3D12Device) + || IsEqualGUID(riid, &IID_ID3D12Device1) || IsEqualGUID(riid, &IID_ID3D12Object) || IsEqualGUID(riid, &IID_IUnknown))
By convention, we check the newest IID first.
+typedef enum D3D12_PIPELINE_STATE_SUBOBJECT_TYPE +{ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE = 0, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS = 1, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS = 2, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS = 3, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS = 4, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS = 5, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS = 6, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT = 7, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND = 8, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK = 9, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER = 10, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL = 11, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT = 12, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE = 13, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY = 14, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS = 15, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT = 16, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC = 17, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK = 18, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO = 19, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS = 20, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1 = 21, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING = 22, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS = 24, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS = 25, + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID = 26, +} D3D12_PIPELINE_STATE_SUBOBJECT_TYPE;
We haven't been entirely consistent about it, but in general we prefer defining enum values in hexadecimal, matching the way we typically print them in debug traces.
+#define VKD3D_HANDLE_SUBOBJECT_EXPLICIT(type_enum, type_name, assignment) \ + case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ ## type_enum: \ + {\ + const struct\ + {\ + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; \ + type_name data; \ + } *subobject = (void *)stream_ptr; \ + if (stream_ptr + sizeof(*subobject) > stream_end) \ + { \ + WARN("Invalid pipeline state stream.\n"); \ + return E_INVALIDARG; \ + } \ + stream_ptr += align(sizeof(*subobject), sizeof(void*)); \ + assignment; \ + break;\ + } + +#define VKD3D_HANDLE_SUBOBJECT(type_enum, type, left_side) \ + VKD3D_HANDLE_SUBOBJECT_EXPLICIT(type_enum, type, left_side = subobject->data)
Do we need the macros?
The ID3D12Device2 and depth bounds test bits probably each deserve their own series.