From: Józef Kucia jkucia@codeweavers.com
In order to hold a reference to IDXGIAdapter.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- include/vkd3d.h | 2 ++ libs/vkd3d/device.c | 12 +++++++ libs/vkd3d/vkd3d.map | 1 + libs/vkd3d/vkd3d_private.h | 1 + tests/vkd3d_api.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+)
diff --git a/include/vkd3d.h b/include/vkd3d.h index 8f2c9b52b2a3..32e81234d8f8 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -69,6 +69,7 @@ struct vkd3d_device_create_info const char * const *device_extensions; uint32_t device_extension_count;
+ IUnknown *parent; LUID adapter_luid; };
@@ -84,6 +85,7 @@ ULONG vkd3d_instance_incref(struct vkd3d_instance *instance);
HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info, REFIID iid, void **device); +IUnknown *vkd3d_get_device_parent(ID3D12Device *device); VkDevice vkd3d_get_vk_device(ID3D12Device *device); VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device); struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device); diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 865801465011..c59ba87945e3 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -1216,6 +1216,8 @@ static ULONG STDMETHODCALLTYPE d3d12_device_Release(ID3D12Device *iface) VK_CALL(vkDestroyPipelineCache(device->vk_device, device->vk_pipeline_cache, NULL)); d3d12_device_destroy_vkd3d_queues(device); VK_CALL(vkDestroyDevice(device->vk_device, NULL)); + if (device->parent) + IUnknown_Release(device->parent); vkd3d_instance_decref(device->vkd3d_instance);
vkd3d_free(device); @@ -2174,6 +2176,9 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
d3d12_device_init_pipeline_cache(device);
+ if ((device->parent = create_info->parent)) + IUnknown_AddRef(device->parent); + return S_OK; }
@@ -2199,6 +2204,13 @@ HRESULT d3d12_device_create(struct vkd3d_instance *instance, return S_OK; }
+IUnknown *vkd3d_get_device_parent(ID3D12Device *device) +{ + struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); + + return d3d12_device->parent; +} + VkDevice vkd3d_get_vk_device(ID3D12Device *device) { struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device); diff --git a/libs/vkd3d/vkd3d.map b/libs/vkd3d/vkd3d.map index 246275b97a30..7d0f83889957 100644 --- a/libs/vkd3d/vkd3d.map +++ b/libs/vkd3d/vkd3d.map @@ -6,6 +6,7 @@ global: vkd3d_create_image_resource; vkd3d_create_instance; vkd3d_create_root_signature_deserializer; + vkd3d_get_device_parent; vkd3d_get_vk_device; vkd3d_get_vk_format; vkd3d_get_vk_physical_device; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 691305158bd7..acf7824ab0b3 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -666,6 +666,7 @@ struct d3d12_device vkd3d_create_thread_pfn create_thread; vkd3d_join_thread_pfn join_thread;
+ IUnknown *parent; LUID adapter_luid; };
diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c index fc8d985981f5..71357377be10 100644 --- a/tests/vkd3d_api.c +++ b/tests/vkd3d_api.c @@ -24,6 +24,13 @@ #include "vkd3d_test.h" #include <vkd3d.h>
+static ULONG get_refcount(void *iface) +{ + IUnknown *unk = iface; + IUnknown_AddRef(unk); + return IUnknown_Release(unk); +} + static ULONG resource_get_internal_refcount(ID3D12Resource *resource) { vkd3d_resource_incref(resource); @@ -561,6 +568,87 @@ static void test_adapter_luid(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+struct parent +{ + IUnknown IUnknown_iface; + LONG refcount; +}; + +static struct parent *parent_from_IUnknown(IUnknown *iface) +{ + return CONTAINING_RECORD(iface, struct parent, IUnknown_iface); +} + +static HRESULT STDMETHODCALLTYPE parent_QueryInterface(IUnknown *iface, + REFIID iid, void **object) +{ + if (IsEqualGUID(iid, &IID_IUnknown)) + { + IUnknown_AddRef(iface); + *object = iface; + return S_OK; + } + + ok(false, "Unexpected QueryInterface() call.\n"); + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE parent_AddRef(IUnknown *iface) +{ + struct parent *parent = parent_from_IUnknown(iface); + + return InterlockedIncrement(&parent->refcount); +} + +static ULONG STDMETHODCALLTYPE parent_Release(IUnknown *iface) +{ + struct parent *parent = parent_from_IUnknown(iface); + + return InterlockedDecrement(&parent->refcount); +} + +static const struct IUnknownVtbl parent_vtbl = +{ + parent_QueryInterface, + parent_AddRef, + parent_Release, +}; + +static void test_device_parent(void) +{ + struct vkd3d_device_create_info create_info; + struct parent parent_impl; + ID3D12Device *device; + IUnknown *unknown; + IUnknown *parent; + ULONG refcount; + HRESULT hr; + + parent_impl.IUnknown_iface.lpVtbl = &parent_vtbl; + parent_impl.refcount = 1; + parent = &parent_impl.IUnknown_iface; + + refcount = get_refcount(parent); + ok(refcount == 1, "Got unexpected refcount %u.\n", refcount); + + create_info = device_default_create_info; + create_info.parent = parent; + hr = vkd3d_create_device(&create_info, &IID_ID3D12Device, (void **)&device); + ok(hr == S_OK, "Failed to create device, hr %#x.\n", hr); + + refcount = get_refcount(parent); + ok(refcount == 2, "Got unexpected refcount %u.\n", refcount); + + unknown = vkd3d_get_device_parent(device); + ok(unknown == parent, "Got device parent %p, expected %p.\n", unknown, parent); + + refcount = ID3D12Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + + refcount = get_refcount(parent); + ok(refcount == 1, "Got unexpected refcount %u.\n", refcount); +} + static void test_vkd3d_queue(void) { ID3D12CommandQueue *direct_queue, *compute_queue, *copy_queue; @@ -666,6 +754,7 @@ START_TEST(vkd3d_api) run_test(test_additional_device_extensions); run_test(test_physical_device); run_test(test_adapter_luid); + run_test(test_device_parent); run_test(test_vkd3d_queue); run_test(test_resource_internal_refcount); }
From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- libs/vkd3d-shader/spirv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index d92b7b1336b7..6eb1537f0b86 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -87,6 +87,10 @@ static void vkd3d_spirv_validate(const struct vkd3d_shader_code *spirv) {}
#endif /* HAVE_SPIRV_TOOLS */
+#define VKD3D_SPIRV_GENERATOR_ID 18 +#define VKD3D_SPIRV_GENERATOR_VERSION 0 +#define VKD3D_SPIRV_GENERATOR_MAGIC ((VKD3D_SPIRV_GENERATOR_ID << 16) | VKD3D_SPIRV_GENERATOR_VERSION) + struct vkd3d_spirv_stream { uint32_t *words; @@ -1535,7 +1539,7 @@ static bool vkd3d_spirv_compile_module(struct vkd3d_spirv_builder *builder,
vkd3d_spirv_build_word(&stream, SpvMagicNumber); vkd3d_spirv_build_word(&stream, SpvVersion); - vkd3d_spirv_build_word(&stream, 0); /* generator */ + vkd3d_spirv_build_word(&stream, VKD3D_SPIRV_GENERATOR_MAGIC); vkd3d_spirv_build_word(&stream, builder->current_id); /* bound */ vkd3d_spirv_build_word(&stream, 0); /* schema, reserved */
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- include/vkd3d_shader.h | 26 +++++++++++++++++++------- libs/vkd3d-shader/spirv.c | 6 +++--- 2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 52b1b9ea0707..48b51898d453 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -25,21 +25,25 @@ extern "C" { #endif /* __cplusplus */
+#define VKD3D_FORCE_32_BIT_ENUM(name) name##_FORCE_32BIT = 0x7fffffff + enum vkd3d_shader_compiler_option { VKD3D_SHADER_STRIP_DEBUG = 0x00000001,
- VKD3D_SHADER_COMPILER_OPTIONS_FORCE_32_BIT = 0x7fffffff, + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILER_OPTION), };
enum vkd3d_shader_visibility { - VKD3D_SHADER_VISIBILITY_ALL, - VKD3D_SHADER_VISIBILITY_VERTEX, - VKD3D_SHADER_VISIBILITY_HULL, - VKD3D_SHADER_VISIBILITY_DOMAIN, - VKD3D_SHADER_VISIBILITY_GEOMETRY, - VKD3D_SHADER_VISIBILITY_PIXEL, + VKD3D_SHADER_VISIBILITY_ALL = 0, + VKD3D_SHADER_VISIBILITY_VERTEX = 1, + VKD3D_SHADER_VISIBILITY_HULL = 2, + VKD3D_SHADER_VISIBILITY_DOMAIN = 3, + VKD3D_SHADER_VISIBILITY_GEOMETRY = 4, + VKD3D_SHADER_VISIBILITY_PIXEL = 5, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_VISIBILITY), };
struct vkd3d_shader_code @@ -55,6 +59,8 @@ enum vkd3d_shader_descriptor_type VKD3D_SHADER_DESCRIPTOR_TYPE_SRV, /* t# */ VKD3D_SHADER_DESCRIPTOR_TYPE_UAV, /* u# */ VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, /* s# */ + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_DESCRIPTOR_TYPE), };
struct vkd3d_shader_descriptor_binding @@ -119,6 +125,8 @@ void vkd3d_shader_free_root_signature(D3D12_ROOT_SIGNATURE_DESC *root_signature) enum vkd3d_root_signature_version { VKD3D_ROOT_SIGNATURE_VERSION_1_0 = 0x1, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_ROOT_SIGNATURE_VERSION), };
HRESULT vkd3d_shader_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *root_signature, @@ -143,6 +151,8 @@ enum vkd3d_component_type VKD3D_TYPE_FLOAT = 3, VKD3D_TYPE_BOOL, VKD3D_TYPE_COUNT, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_COMPONENT_TYPE), };
enum vkd3d_sysval_semantic @@ -163,6 +173,8 @@ enum vkd3d_sysval_semantic VKD3D_SV_TESS_FACTOR_TRIINT = 14, VKD3D_SV_TESS_FACTOR_LINEDET = 15, VKD3D_SV_TESS_FACTOR_LINEDEN = 16, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SYSVAL_SEMANTIC), };
struct vkd3d_shader_signature_element diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 6eb1537f0b86..f984e624b466 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -1919,10 +1919,10 @@ static bool vkd3d_dxbc_compiler_check_shader_visibility(struct vkd3d_dxbc_compil return compiler->shader_type == VKD3D_SHADER_TYPE_GEOMETRY; case VKD3D_SHADER_VISIBILITY_PIXEL: return compiler->shader_type == VKD3D_SHADER_TYPE_PIXEL; + default: + ERR("Invalid shader visibility %#x.\n", visibility); + return false; } - - ERR("Invalid shader visibility %#x.\n", visibility); - return false; }
static struct vkd3d_push_constant_buffer_binding *vkd3d_dxbc_compiler_find_push_constant_buffer(
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com