Commit 9b9bde8d authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Implement Vulkan constant buffer descriptors.

parent 9049104d
......@@ -810,6 +810,7 @@ static void *adapter_vk_map_bo_address(struct wined3d_context *context,
{
struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
const struct wined3d_vk_info *vk_info;
struct wined3d_bo_user_vk *bo_user_vk;
struct wined3d_device_vk *device_vk;
VkCommandBuffer vk_command_buffer;
VkBufferMemoryBarrier vk_barrier;
......@@ -830,8 +831,15 @@ static void *adapter_vk_map_bo_address(struct wined3d_context *context,
{
if (wined3d_context_vk_create_bo(context_vk, bo->size, bo->usage, bo->memory_type, &tmp))
{
list_move_head(&tmp.users, &bo->users);
wined3d_context_vk_destroy_bo(context_vk, bo);
*bo = tmp;
list_init(&bo->users);
list_move_head(&bo->users, &tmp.users);
LIST_FOR_EACH_ENTRY(bo_user_vk, &bo->users, struct wined3d_bo_user_vk, entry)
{
bo_user_vk->valid = false;
}
goto map;
}
......
......@@ -1593,12 +1593,27 @@ static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buf
return FALSE;
}
list_init(&buffer_vk->bo_user.entry);
list_add_head(&buffer_vk->bo.users, &buffer_vk->bo_user.entry);
buffer_vk->b.buffer_object = (uintptr_t)&buffer_vk->bo;
buffer_invalidate_bo_range(&buffer_vk->b, 0, 0);
return TRUE;
}
const VkDescriptorBufferInfo *wined3d_buffer_vk_get_buffer_info(struct wined3d_buffer_vk *buffer_vk)
{
if (buffer_vk->bo_user.valid)
return &buffer_vk->buffer_info;
buffer_vk->buffer_info.buffer = buffer_vk->bo.vk_buffer;
buffer_vk->buffer_info.offset = buffer_vk->bo.buffer_offset;
buffer_vk->buffer_info.range = buffer_vk->b.resource.size;
buffer_vk->bo_user.valid = true;
return &buffer_vk->buffer_info;
}
static BOOL wined3d_buffer_vk_prepare_location(struct wined3d_buffer *buffer,
struct wined3d_context *context, unsigned int location)
{
......@@ -1630,6 +1645,8 @@ static void wined3d_buffer_vk_unload_location(struct wined3d_buffer *buffer,
switch (location)
{
case WINED3D_LOCATION_BUFFER:
buffer_vk->bo_user.valid = false;
list_remove(&buffer_vk->bo_user.entry);
wined3d_context_vk_destroy_bo(context_vk, &buffer_vk->bo);
buffer_vk->bo.vk_buffer = VK_NULL_HANDLE;
buffer_vk->bo.memory = NULL;
......
......@@ -44,6 +44,8 @@ struct shader_spirv_compute_program_vk
{
VkShaderModule vk_module;
VkPipeline vk_pipeline;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_set_layout;
};
static void shader_spirv_handle_instruction(const struct wined3d_shader_instruction *ins)
......@@ -65,8 +67,7 @@ static struct shader_spirv_compute_program_vk *shader_spirv_find_compute_program
struct wined3d_device_vk *device_vk = wined3d_device_vk(context_vk->c.device);
const struct wined3d_vk_info *vk_info = context_vk->vk_info;
struct shader_spirv_compute_program_vk *program;
VkDescriptorSetLayoutCreateInfo set_layout_desc;
VkPipelineLayoutCreateInfo pipeline_layout_desc;
struct wined3d_pipeline_layout_vk *layout;
VkComputePipelineCreateInfo pipeline_info;
VkResult vr;
......@@ -82,40 +83,15 @@ static struct shader_spirv_compute_program_vk *shader_spirv_find_compute_program
return NULL;
}
if (!context_vk->vk_pipeline_layout)
if (!(layout = wined3d_context_vk_get_pipeline_layout(context_vk,
bindings->vk_bindings, bindings->vk_binding_count)))
{
set_layout_desc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
set_layout_desc.pNext = NULL;
set_layout_desc.flags = 0;
set_layout_desc.bindingCount = 0;
set_layout_desc.pBindings = NULL;
if ((vr = VK_CALL(vkCreateDescriptorSetLayout(device_vk->vk_device,
&set_layout_desc, NULL, &context_vk->vk_set_layout))) < 0)
{
WARN("Failed to create Vulkan descriptor set layout, vr %s.\n", wined3d_debug_vkresult(vr));
VK_CALL(vkDestroyShaderModule(device_vk->vk_device, program->vk_module, NULL));
heap_free(program);
return NULL;
}
pipeline_layout_desc.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipeline_layout_desc.pNext = NULL;
pipeline_layout_desc.flags = 0;
pipeline_layout_desc.setLayoutCount = 1;
pipeline_layout_desc.pSetLayouts = &context_vk->vk_set_layout;
pipeline_layout_desc.pushConstantRangeCount = 0;
pipeline_layout_desc.pPushConstantRanges = NULL;
if ((vr = VK_CALL(vkCreatePipelineLayout(device_vk->vk_device,
&pipeline_layout_desc, NULL, &context_vk->vk_pipeline_layout))) < 0)
{
WARN("Failed to create Vulkan pipeline layout, vr %s.\n", wined3d_debug_vkresult(vr));
VK_CALL(vkDestroyDescriptorSetLayout(device_vk->vk_device, context_vk->vk_set_layout, NULL));
VK_CALL(vkDestroyShaderModule(device_vk->vk_device, program->vk_module, NULL));
heap_free(program);
return NULL;
}
VK_CALL(vkDestroyShaderModule(device_vk->vk_device, program->vk_module, NULL));
heap_free(program);
return NULL;
}
program->vk_set_layout = layout->vk_set_layout;
program->vk_pipeline_layout = layout->vk_pipeline_layout;
pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
pipeline_info.pNext = NULL;
......@@ -127,7 +103,7 @@ static struct shader_spirv_compute_program_vk *shader_spirv_find_compute_program
pipeline_info.stage.pName = "main";
pipeline_info.stage.pSpecializationInfo = NULL;
pipeline_info.stage.module = program->vk_module;
pipeline_info.layout = context_vk->vk_pipeline_layout;
pipeline_info.layout = program->vk_pipeline_layout;
pipeline_info.basePipelineHandle = VK_NULL_HANDLE;
pipeline_info.basePipelineIndex = -1;
if ((vr = VK_CALL(vkCreateComputePipelines(device_vk->vk_device,
......@@ -342,9 +318,17 @@ static void shader_spirv_select_compute(void *shader_priv,
program = NULL;
if (program)
{
context_vk->compute.vk_pipeline = program->vk_pipeline;
context_vk->compute.vk_set_layout = program->vk_set_layout;
context_vk->compute.vk_pipeline_layout = program->vk_pipeline_layout;
}
else
{
context_vk->compute.vk_pipeline = VK_NULL_HANDLE;
context_vk->compute.vk_set_layout = VK_NULL_HANDLE;
context_vk->compute.vk_pipeline_layout = VK_NULL_HANDLE;
}
}
static void shader_spirv_disable(void *shader_priv, struct wined3d_context *context)
......
......@@ -1540,6 +1540,12 @@ static inline GLuint wined3d_bo_gl_id(uintptr_t bo)
return bo ? ((struct wined3d_bo_gl *)bo)->id : 0;
}
struct wined3d_bo_user_vk
{
struct list entry;
bool valid;
};
struct wined3d_bo_vk
{
VkBuffer vk_buffer;
......@@ -1554,6 +1560,7 @@ struct wined3d_bo_vk
VkBufferUsageFlags usage;
VkMemoryPropertyFlags memory_type;
struct list users;
uint64_t command_buffer_id;
};
......@@ -2299,6 +2306,20 @@ struct wined3d_render_pass_vk
VkRenderPass vk_render_pass;
};
struct wined3d_pipeline_layout_key_vk
{
VkDescriptorSetLayoutBinding *bindings;
SIZE_T binding_count;
};
struct wined3d_pipeline_layout_vk
{
struct wine_rb_entry entry;
struct wined3d_pipeline_layout_key_vk key;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_set_layout;
};
enum wined3d_shader_descriptor_type
{
WINED3D_SHADER_DESCRIPTOR_TYPE_CBV,
......@@ -2324,6 +2345,12 @@ struct wined3d_shader_resource_bindings
SIZE_T size, count;
};
struct wined3d_shader_descriptor_writes_vk
{
VkWriteDescriptorSet *writes;
SIZE_T size, count;
};
struct wined3d_context_vk
{
struct wined3d_context c;
......@@ -2336,6 +2363,8 @@ struct wined3d_context_vk
struct
{
VkPipeline vk_pipeline;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_set_layout;
struct wined3d_shader_resource_bindings bindings;
} compute;
......@@ -2350,12 +2379,13 @@ struct wined3d_context_vk
SIZE_T buffer_count;
} submitted;
struct wined3d_shader_descriptor_writes_vk descriptor_writes;
VkDescriptorPool vk_descriptor_pool;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_set_layout;
struct wined3d_retired_objects_vk retired;
struct wine_rb_tree render_passes;
struct wine_rb_tree pipeline_layouts;
struct wine_rb_tree bo_slab_available;
};
......@@ -2390,6 +2420,8 @@ void wined3d_context_vk_destroy_memory(struct wined3d_context_vk *context_vk,
void wined3d_context_vk_destroy_sampler(struct wined3d_context_vk *context_vk,
VkSampler vk_sampler, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
struct wined3d_pipeline_layout_vk *wined3d_context_vk_get_pipeline_layout(struct wined3d_context_vk *context_vk,
VkDescriptorSetLayoutBinding *bindings, SIZE_T binding_count) DECLSPEC_HIDDEN;
VkRenderPass wined3d_context_vk_get_render_pass(struct wined3d_context_vk *context_vk,
const struct wined3d_fb_state *fb, unsigned int rt_count,
bool depth_stencil, uint32_t clear_flags) DECLSPEC_HIDDEN;
......@@ -4547,6 +4579,8 @@ struct wined3d_buffer_vk
struct wined3d_buffer b;
struct wined3d_bo_vk bo;
struct wined3d_bo_user_vk bo_user;
VkDescriptorBufferInfo buffer_info;
};
static inline struct wined3d_buffer_vk *wined3d_buffer_vk(struct wined3d_buffer *buffer)
......@@ -4554,6 +4588,7 @@ static inline struct wined3d_buffer_vk *wined3d_buffer_vk(struct wined3d_buffer
return CONTAINING_RECORD(buffer, struct wined3d_buffer_vk, b);
}
const VkDescriptorBufferInfo *wined3d_buffer_vk_get_buffer_info(struct wined3d_buffer_vk *buffer_vk) DECLSPEC_HIDDEN;
HRESULT wined3d_buffer_vk_init(struct wined3d_buffer_vk *buffer_vk, struct wined3d_device *device,
const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
......
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