libs/vkd3d: Export a function to create a d3d12 resource from a Vulkan image.

This commit is contained in:
Henri Verbeet 2016-10-17 18:38:39 +02:00
parent fcc9f9b294
commit 2a49173b60
4 changed files with 44 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include "vkd3d_windows.h" #include "vkd3d_windows.h"
#include "d3d12.h" #include "d3d12.h"
#include <vulkan/vulkan.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -41,6 +42,8 @@ struct vkd3d_device_create_info
HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info, HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,
REFIID riid, void **device); REFIID riid, void **device);
HRESULT vkd3d_create_image_resource(ID3D12Device *device, const D3D12_RESOURCE_DESC *desc,
VkImage vk_image, ID3D12Resource **resource);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1091,6 +1091,14 @@ static const struct ID3D12DeviceVtbl d3d12_device_vtbl =
d3d12_device_GetAdapterLuid, d3d12_device_GetAdapterLuid,
}; };
struct d3d12_device *unsafe_impl_from_ID3D12Device(ID3D12Device *iface)
{
if (!iface)
return NULL;
assert(iface->lpVtbl == &d3d12_device_vtbl);
return impl_from_ID3D12Device(iface);
}
static HRESULT d3d12_device_init(struct d3d12_device *device, static HRESULT d3d12_device_init(struct d3d12_device *device,
const struct vkd3d_device_create_info *create_info) const struct vkd3d_device_create_info *create_info)
{ {

View File

@ -324,6 +324,9 @@ static void vkd3d_destroy_resource(struct d3d12_resource *resource, struct d3d12
{ {
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
if (resource->external)
return;
switch (resource->desc.Dimension) switch (resource->desc.Dimension)
{ {
case D3D12_RESOURCE_DIMENSION_BUFFER: case D3D12_RESOURCE_DIMENSION_BUFFER:
@ -670,6 +673,7 @@ static HRESULT d3d12_committed_resource_init(struct d3d12_resource *resource, st
return E_INVALIDARG; return E_INVALIDARG;
} }
resource->external = false;
resource->map_count = 0; resource->map_count = 0;
resource->map_data = NULL; resource->map_data = NULL;
@ -704,6 +708,33 @@ HRESULT d3d12_committed_resource_create(struct d3d12_device *device,
return S_OK; return S_OK;
} }
HRESULT vkd3d_create_image_resource(ID3D12Device *device, const D3D12_RESOURCE_DESC *desc,
VkImage vk_image, ID3D12Resource **resource)
{
struct d3d12_device *d3d12_device = unsafe_impl_from_ID3D12Device(device);
struct d3d12_resource *object;
if (!(object = vkd3d_malloc(sizeof(*object))))
return E_OUTOFMEMORY;
object->ID3D12Resource_iface.lpVtbl = &d3d12_resource_vtbl;
object->refcount = 1;
object->desc = *desc;
object->u.vk_image = vk_image;
object->vk_memory = VK_NULL_HANDLE;
object->external = true;
object->map_count = 0;
object->map_data = NULL;
object->device = d3d12_device;
ID3D12Device_AddRef(&d3d12_device->ID3D12Device_iface);
TRACE("Created resource %p.\n", object);
*resource = &object->ID3D12Resource_iface;
return S_OK;
}
/* RTVs */ /* RTVs */
static void d3d12_rtv_desc_destroy(struct d3d12_rtv_desc *rtv, struct d3d12_device *device) static void d3d12_rtv_desc_destroy(struct d3d12_rtv_desc *rtv, struct d3d12_device *device)
{ {

View File

@ -24,7 +24,6 @@
#define __VKD3D_PRIVATE_H #define __VKD3D_PRIVATE_H
#define VK_NO_PROTOTYPES #define VK_NO_PROTOTYPES
#include <vulkan/vulkan.h>
#define COBJMACROS #define COBJMACROS
#define NONAMELESSUNION #define NONAMELESSUNION
@ -129,6 +128,7 @@ struct d3d12_resource
VkImage vk_image; VkImage vk_image;
} u; } u;
VkDeviceMemory vk_memory; VkDeviceMemory vk_memory;
bool external;
unsigned int map_count; unsigned int map_count;
void *map_data; void *map_data;
@ -344,6 +344,7 @@ struct d3d12_device
HRESULT d3d12_device_create(const struct vkd3d_device_create_info *create_info, HRESULT d3d12_device_create(const struct vkd3d_device_create_info *create_info,
struct d3d12_device **device) DECLSPEC_HIDDEN; struct d3d12_device **device) DECLSPEC_HIDDEN;
struct d3d12_device *unsafe_impl_from_ID3D12Device(ID3D12Device *iface) DECLSPEC_HIDDEN;
/* utils */ /* utils */
struct vkd3d_format struct vkd3d_format