Commit 0c27d244 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Create Vulkan buffer views for unordered access view counters.

parent 3d10118b
......@@ -1218,6 +1218,8 @@ struct wined3d_view_vk_destroy_ctx
struct wined3d_device_vk *device_vk;
VkBufferView *vk_buffer_view;
VkImageView *vk_image_view;
struct wined3d_bo_vk *vk_counter_bo;
VkBufferView *vk_counter_view;
uint64_t *command_buffer_id;
void *object;
struct wined3d_view_vk_destroy_ctx *free;
......@@ -1260,6 +1262,21 @@ static void wined3d_view_vk_destroy_object(void *object)
TRACE("Destroyed image view 0x%s.\n", wine_dbgstr_longlong(*ctx->vk_image_view));
}
}
if (ctx->vk_counter_bo && ctx->vk_counter_bo->vk_buffer)
wined3d_context_vk_destroy_bo(wined3d_context_vk(context), ctx->vk_counter_bo);
if (ctx->vk_counter_view)
{
if (context)
{
wined3d_context_vk_destroy_buffer_view(wined3d_context_vk(context),
*ctx->vk_counter_view, *ctx->command_buffer_id);
}
else
{
VK_CALL(vkDestroyBufferView(device_vk->vk_device, *ctx->vk_counter_view, NULL));
TRACE("Destroyed counter buffer view 0x%s.\n", wine_dbgstr_longlong(*ctx->vk_counter_view));
}
}
if (context)
context_release(context);
......@@ -1269,7 +1286,8 @@ static void wined3d_view_vk_destroy_object(void *object)
}
static void wined3d_view_vk_destroy(struct wined3d_device *device, VkBufferView *vk_buffer_view,
VkImageView *vk_image_view, uint64_t *command_buffer_id, void *view_vk)
VkImageView *vk_image_view, struct wined3d_bo_vk *vk_counter_bo,
VkBufferView *vk_counter_view, uint64_t *command_buffer_id, void *view_vk)
{
struct wined3d_view_vk_destroy_ctx *ctx, c;
......@@ -1278,6 +1296,8 @@ static void wined3d_view_vk_destroy(struct wined3d_device *device, VkBufferView
ctx->device_vk = wined3d_device_vk(device);
ctx->vk_buffer_view = vk_buffer_view;
ctx->vk_image_view = vk_image_view;
ctx->vk_counter_bo = vk_counter_bo;
ctx->vk_counter_view = vk_counter_view;
ctx->command_buffer_id = command_buffer_id;
ctx->object = view_vk;
ctx->free = ctx != &c ? ctx : NULL;
......@@ -1302,7 +1322,8 @@ static void adapter_vk_destroy_rendertarget_view(struct wined3d_rendertarget_vie
if (swapchain_count)
wined3d_device_incref(device);
wined3d_rendertarget_view_cleanup(&view_vk->v);
wined3d_view_vk_destroy(device, NULL, &view_vk->vk_image_view, &view_vk->command_buffer_id, view_vk);
wined3d_view_vk_destroy(device, NULL, &view_vk->vk_image_view,
NULL, NULL, &view_vk->command_buffer_id, view_vk);
if (swapchain_count)
wined3d_device_decref(device);
}
......@@ -1355,7 +1376,8 @@ static void adapter_vk_destroy_shader_resource_view(struct wined3d_shader_resour
else
vk_image_view = &view_vk->u.vk_image_info.imageView;
wined3d_shader_resource_view_cleanup(&srv_vk->v);
wined3d_view_vk_destroy(device, vk_buffer_view, vk_image_view, &view_vk->command_buffer_id, srv_vk);
wined3d_view_vk_destroy(device, vk_buffer_view, vk_image_view,
NULL, NULL, &view_vk->command_buffer_id, srv_vk);
if (swapchain_count)
wined3d_device_decref(device);
}
......@@ -1408,7 +1430,8 @@ static void adapter_vk_destroy_unordered_access_view(struct wined3d_unordered_ac
else
vk_image_view = &view_vk->u.vk_image_info.imageView;
wined3d_unordered_access_view_cleanup(&uav_vk->v);
wined3d_view_vk_destroy(device, vk_buffer_view, vk_image_view, &view_vk->command_buffer_id, uav_vk);
wined3d_view_vk_destroy(device, vk_buffer_view, vk_image_view, &uav_vk->counter_bo,
&uav_vk->vk_counter_view, &view_vk->command_buffer_id, uav_vk);
if (swapchain_count)
wined3d_device_decref(device);
}
......
......@@ -1459,13 +1459,16 @@ static void wined3d_unordered_access_view_vk_cs_init(void *object)
struct wined3d_view_vk *view_vk = &uav_vk->view_vk;
struct wined3d_view_desc *desc = &uav_vk->v.desc;
const struct wined3d_format_vk *format_vk;
const struct wined3d_vk_info *vk_info;
struct wined3d_texture_vk *texture_vk;
struct wined3d_context_vk *context_vk;
struct wined3d_device_vk *device_vk;
VkBufferViewCreateInfo create_info;
struct wined3d_resource *resource;
VkBufferView vk_buffer_view;
uint32_t default_flags = 0;
VkImageView vk_image_view;
VkResult vr;
resource = uav_vk->v.resource;
device_vk = wined3d_device_vk(resource->device);
......@@ -1474,16 +1477,53 @@ static void wined3d_unordered_access_view_vk_cs_init(void *object)
if (resource->type == WINED3D_RTYPE_BUFFER)
{
context_vk = wined3d_context_vk(context_acquire(&device_vk->d, NULL, 0));
vk_buffer_view = wined3d_view_vk_create_buffer_view(context_vk,
desc, wined3d_buffer_vk(buffer_from_resource(resource)), format_vk);
vk_info = context_vk->vk_info;
if ((vk_buffer_view = wined3d_view_vk_create_buffer_view(context_vk,
desc, wined3d_buffer_vk(buffer_from_resource(resource)), format_vk)))
{
TRACE("Created buffer view 0x%s.\n", wine_dbgstr_longlong(vk_buffer_view));
uav_vk->view_vk.u.vk_buffer_view = vk_buffer_view;
}
if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND))
{
if (!wined3d_context_vk_create_bo(context_vk, sizeof(uint32_t), VK_BUFFER_USAGE_TRANSFER_SRC_BIT
| VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &uav_vk->counter_bo))
{
ERR("Failed to create counter bo.\n");
context_release(&context_vk->c);
if (!vk_buffer_view)
return;
}
TRACE("Created buffer view 0x%s.\n", wine_dbgstr_longlong(vk_buffer_view));
VK_CALL(vkCmdFillBuffer(wined3d_context_vk_get_command_buffer(context_vk),
uav_vk->counter_bo.vk_buffer, uav_vk->counter_bo.buffer_offset, sizeof(uint32_t), 0));
wined3d_context_vk_reference_bo(context_vk, &uav_vk->counter_bo);
uav_vk->view_vk.u.vk_buffer_view = vk_buffer_view;
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
create_info.pNext = NULL;
create_info.flags = 0;
create_info.buffer = uav_vk->counter_bo.vk_buffer;
create_info.format = VK_FORMAT_R32_UINT;
create_info.offset = uav_vk->counter_bo.buffer_offset;
create_info.range = sizeof(uint32_t);
if ((vr = VK_CALL(vkCreateBufferView(device_vk->vk_device,
&create_info, NULL, &uav_vk->vk_counter_view))) < 0)
{
ERR("Failed to create counter buffer view, vr %s.\n", wined3d_debug_vkresult(vr));
}
else
{
TRACE("Created counter buffer view 0x%s.\n", wine_dbgstr_longlong(uav_vk->vk_counter_view));
uav_vk->v.counter_bo = (uintptr_t)&uav_vk->counter_bo;
}
}
context_release(&context_vk->c);
return;
}
......
......@@ -4671,6 +4671,9 @@ struct wined3d_unordered_access_view_vk
{
struct wined3d_unordered_access_view v;
struct wined3d_view_vk view_vk;
VkBufferView vk_counter_view;
struct wined3d_bo_vk counter_bo;
};
static inline struct wined3d_unordered_access_view_vk *wined3d_unordered_access_view_vk(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment