From: Józef Kucia jkucia@codeweavers.com
Adds flexibility for future API extensions.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- demos/demo_xcb.h | 2 ++ include/vkd3d.h | 20 ++++++++++++++++++++ libs/vkd3d-utils/vkd3d_utils_main.c | 4 ++++ libs/vkd3d/device.c | 12 +++++++++++- libs/vkd3d/resource.c | 10 ++++++++++ libs/vkd3d/vkd3d_main.c | 7 +++++++ tests/vkd3d_api.c | 4 ++++ 7 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/demos/demo_xcb.h b/demos/demo_xcb.h index 053db0df9bab..38715565267e 100644 --- a/demos/demo_xcb.h +++ b/demos/demo_xcb.h @@ -446,6 +446,8 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c vkWaitForFences(vk_device, 1, &vk_fence, VK_TRUE, UINT64_MAX); vkResetFences(vk_device, 1, &vk_fence);
+ resource_create_info.type = VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO; + resource_create_info.next = NULL; resource_create_info.desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resource_create_info.desc.Alignment = 0; resource_create_info.desc.Width = desc->width; diff --git a/include/vkd3d.h b/include/vkd3d.h index 692b58d70065..7c5f6441e9d9 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -34,6 +34,17 @@ extern "C" { #endif /* __cplusplus */
+#define VKD3D_FORCE_32_BIT_ENUM(name) name##_FORCE_32BIT = 0x7fffffff + +enum vkd3d_structure_type +{ + VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_STRUCTURE_TYPE), +}; + typedef bool (*PFN_vkd3d_signal_event)(HANDLE event);
typedef void * (*PFN_vkd3d_thread)(void *data); @@ -45,6 +56,9 @@ struct vkd3d_instance;
struct vkd3d_instance_create_info { + enum vkd3d_structure_type type; + const void *next; + PFN_vkd3d_signal_event pfn_signal_event; PFN_vkd3d_create_thread pfn_create_thread; PFN_vkd3d_join_thread pfn_join_thread; @@ -59,6 +73,9 @@ struct vkd3d_instance_create_info
struct vkd3d_device_create_info { + enum vkd3d_structure_type type; + const void *next; + D3D_FEATURE_LEVEL minimum_feature_level;
struct vkd3d_instance *instance; @@ -79,6 +96,9 @@ struct vkd3d_device_create_info
struct vkd3d_image_resource_create_info { + enum vkd3d_structure_type type; + const void *next; + VkImage vk_image; D3D12_RESOURCE_DESC desc; unsigned int flags; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index ba64d406983c..adafb00bddc8 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -48,12 +48,16 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, FIXME("Ignoring adapter %p.\n", adapter);
memset(&instance_create_info, 0, sizeof(instance_create_info)); + instance_create_info.type = VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.next = NULL; instance_create_info.pfn_signal_event = vkd3d_signal_event; instance_create_info.wchar_size = sizeof(WCHAR); instance_create_info.instance_extensions = instance_extensions; instance_create_info.instance_extension_count = ARRAY_SIZE(instance_extensions);
memset(&device_create_info, 0, sizeof(device_create_info)); + device_create_info.type = VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.next = NULL; device_create_info.minimum_feature_level = minimum_feature_level; device_create_info.instance_create_info = &instance_create_info; device_create_info.device_extensions = device_extensions; diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index d61c331929f7..57b94b64239d 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -342,7 +342,17 @@ HRESULT vkd3d_create_instance(const struct vkd3d_instance_create_info *create_in struct vkd3d_instance *object; HRESULT hr;
- TRACE("create_info %p.\n", create_info); + TRACE("create_info %p, instance %p.\n", create_info, instance); + + if (!create_info || !instance) + return E_INVALIDARG; + if (create_info->type != VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO) + { + WARN("Invalid structure type %#x.\n", create_info->type); + return E_INVALIDARG; + } + if (create_info->next) + WARN("Unhandled next %p.\n", create_info->next);
if (!(object = vkd3d_malloc(sizeof(*object)))) return E_OUTOFMEMORY; diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 4746ee2cf59b..e37b03bc005f 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -805,6 +805,16 @@ HRESULT vkd3d_create_image_resource(ID3D12Device *device,
TRACE("device %p, create_info %p, resource %p.\n", device, create_info, resource);
+ if (!create_info || !resource) + return E_INVALIDARG; + if (create_info->type != VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO) + { + WARN("Invalid structure type %#x.\n", create_info->type); + return E_INVALIDARG; + } + if (create_info->next) + WARN("Unhandled next %p.\n", create_info->next); + if (!(object = vkd3d_malloc(sizeof(*object)))) return E_OUTOFMEMORY;
diff --git a/libs/vkd3d/vkd3d_main.c b/libs/vkd3d/vkd3d_main.c index b58e6e5ac53c..97d642a7cf91 100644 --- a/libs/vkd3d/vkd3d_main.c +++ b/libs/vkd3d/vkd3d_main.c @@ -30,6 +30,13 @@ HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,
if (!create_info || !device) return E_INVALIDARG; + if (create_info->type != VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO) + { + WARN("Invalid structure type %#x.\n", create_info->type); + return E_INVALIDARG; + } + if (create_info->next) + WARN("Unhandled next %p.\n", create_info->next); if (!create_info->instance && !create_info->instance_create_info) { ERR("Instance or instance create info is required.\n"); diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c index 4b3466edc919..439cb6364eb8 100644 --- a/tests/vkd3d_api.c +++ b/tests/vkd3d_api.c @@ -62,12 +62,14 @@ static bool signal_event(HANDLE event)
static const struct vkd3d_instance_create_info instance_default_create_info = { + .type = VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .wchar_size = sizeof(WCHAR), .pfn_signal_event = signal_event, };
static const struct vkd3d_device_create_info device_default_create_info = { + .type = VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .minimum_feature_level = D3D_FEATURE_LEVEL_11_0, .instance_create_info = &instance_default_create_info, }; @@ -849,6 +851,8 @@ static void test_vulkan_resource_present_state(void) vk_memory = allocate_vulkan_image_memory(device, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, vk_image);
+ resource_create_info.type = VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO; + resource_create_info.next = NULL; resource_create_info.vk_image = vk_image; resource_create_info.desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resource_create_info.desc.Alignment = 0;