Commit 9049104d authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Implement adapter_vk_dispatch_compute().

parent c484ba1c
...@@ -1509,7 +1509,45 @@ static void adapter_vk_draw_primitive(struct wined3d_device *device, ...@@ -1509,7 +1509,45 @@ static void adapter_vk_draw_primitive(struct wined3d_device *device,
static void adapter_vk_dispatch_compute(struct wined3d_device *device, static void adapter_vk_dispatch_compute(struct wined3d_device *device,
const struct wined3d_state *state, const struct wined3d_dispatch_parameters *parameters) const struct wined3d_state *state, const struct wined3d_dispatch_parameters *parameters)
{ {
FIXME("device %p, state %p, parameters %p.\n", device, state, parameters); struct wined3d_buffer_vk *indirect_vk = NULL;
const struct wined3d_vk_info *vk_info;
struct wined3d_context_vk *context_vk;
VkCommandBuffer vk_command_buffer;
TRACE("device %p, state %p, parameters %p.\n", device, state, parameters);
context_vk = wined3d_context_vk(context_acquire(device, NULL, 0));
vk_info = context_vk->vk_info;
if (parameters->indirect)
indirect_vk = wined3d_buffer_vk(parameters->u.indirect.buffer);
if (!(vk_command_buffer = wined3d_context_vk_apply_compute_state(context_vk, state, indirect_vk)))
{
ERR("Failed to apply compute state.\n");
context_release(&context_vk->c);
return;
}
if (parameters->indirect)
{
struct wined3d_bo_vk *bo = &indirect_vk->bo;
wined3d_context_vk_reference_bo(context_vk, bo);
VK_CALL(vkCmdDispatchIndirect(vk_command_buffer, bo->vk_buffer,
bo->buffer_offset + parameters->u.indirect.offset));
}
else
{
const struct wined3d_direct_dispatch_parameters *direct = &parameters->u.direct;
VK_CALL(vkCmdDispatch(vk_command_buffer, direct->group_count_x, direct->group_count_y, direct->group_count_z));
}
VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, 0, 0, NULL, 0, NULL, 0, NULL));
context_release(&context_vk->c);
} }
void adapter_vk_clear_uav(struct wined3d_context *context, void adapter_vk_clear_uav(struct wined3d_context *context,
......
...@@ -1123,6 +1123,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co ...@@ -1123,6 +1123,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co
} }
reg_maps->resource_info[reg_idx].type = semantic->resource_type; reg_maps->resource_info[reg_idx].type = semantic->resource_type;
reg_maps->resource_info[reg_idx].data_type = semantic->resource_data_type; reg_maps->resource_info[reg_idx].data_type = semantic->resource_data_type;
wined3d_bitmap_set(reg_maps->resource_map, reg_idx);
break; break;
case WINED3DSPR_UAV: case WINED3DSPR_UAV:
...@@ -1146,9 +1147,14 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co ...@@ -1146,9 +1147,14 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co
{ {
struct wined3d_shader_register *reg = &ins.declaration.src.reg; struct wined3d_shader_register *reg = &ins.declaration.src.reg;
if (reg->idx[0].offset >= WINED3D_MAX_CBS) if (reg->idx[0].offset >= WINED3D_MAX_CBS)
{
ERR("Invalid CB index %u.\n", reg->idx[0].offset); ERR("Invalid CB index %u.\n", reg->idx[0].offset);
}
else else
{
reg_maps->cb_sizes[reg->idx[0].offset] = reg->idx[1].offset; reg_maps->cb_sizes[reg->idx[0].offset] = reg->idx[1].offset;
wined3d_bitmap_set(&reg_maps->cb_map, reg->idx[0].offset);
}
} }
else if (ins.handler_idx == WINED3DSIH_DCL_GLOBAL_FLAGS) else if (ins.handler_idx == WINED3DSIH_DCL_GLOBAL_FLAGS)
{ {
...@@ -1266,6 +1272,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co ...@@ -1266,6 +1272,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co
reg_maps->resource_info[reg_idx].type = WINED3D_SHADER_RESOURCE_BUFFER; reg_maps->resource_info[reg_idx].type = WINED3D_SHADER_RESOURCE_BUFFER;
reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_UINT; reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_UINT;
reg_maps->resource_info[reg_idx].flags = WINED3D_VIEW_BUFFER_RAW; reg_maps->resource_info[reg_idx].flags = WINED3D_VIEW_BUFFER_RAW;
wined3d_bitmap_set(reg_maps->resource_map, reg_idx);
} }
else if (ins.handler_idx == WINED3DSIH_DCL_RESOURCE_STRUCTURED) else if (ins.handler_idx == WINED3DSIH_DCL_RESOURCE_STRUCTURED)
{ {
...@@ -1279,6 +1286,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co ...@@ -1279,6 +1286,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co
reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_UINT; reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_UINT;
reg_maps->resource_info[reg_idx].flags = 0; reg_maps->resource_info[reg_idx].flags = 0;
reg_maps->resource_info[reg_idx].stride = ins.declaration.structured_resource.byte_stride / 4; reg_maps->resource_info[reg_idx].stride = ins.declaration.structured_resource.byte_stride / 4;
wined3d_bitmap_set(reg_maps->resource_map, reg_idx);
} }
else if (ins.handler_idx == WINED3DSIH_DCL_SAMPLER) else if (ins.handler_idx == WINED3DSIH_DCL_SAMPLER)
{ {
...@@ -1605,6 +1613,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co ...@@ -1605,6 +1613,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, DWORD co
reg_maps->resource_info[reg_idx].type = WINED3D_SHADER_RESOURCE_TEXTURE_2D; reg_maps->resource_info[reg_idx].type = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_FLOAT; reg_maps->resource_info[reg_idx].data_type = WINED3D_DATA_FLOAT;
shader_record_sample(reg_maps, reg_idx, reg_idx, reg_idx); shader_record_sample(reg_maps, reg_idx, reg_idx, reg_idx);
wined3d_bitmap_set(reg_maps->resource_map, reg_idx);
/* texbem is only valid with < 1.4 pixel shaders */ /* texbem is only valid with < 1.4 pixel shaders */
if (ins.handler_idx == WINED3DSIH_TEXBEM if (ins.handler_idx == WINED3DSIH_TEXBEM
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
struct wined3d_fragment_pipe_ops; struct wined3d_fragment_pipe_ops;
struct wined3d_adapter; struct wined3d_adapter;
struct wined3d_buffer_vk;
struct wined3d_context; struct wined3d_context;
struct wined3d_gl_info; struct wined3d_gl_info;
struct wined3d_state; struct wined3d_state;
...@@ -304,6 +305,7 @@ GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f) DECLSPEC_HIDDEN; ...@@ -304,6 +305,7 @@ GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f) DECLSPEC_HIDDEN;
VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN; VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
VkCompareOp vk_compare_op_from_wined3d(enum wined3d_cmp_func op) DECLSPEC_HIDDEN; VkCompareOp vk_compare_op_from_wined3d(enum wined3d_cmp_func op) DECLSPEC_HIDDEN;
VkImageViewType vk_image_view_type_from_wined3d(enum wined3d_resource_type type, uint32_t flags) DECLSPEC_HIDDEN; VkImageViewType vk_image_view_type_from_wined3d(enum wined3d_resource_type type, uint32_t flags) DECLSPEC_HIDDEN;
VkShaderStageFlagBits vk_shader_stage_from_wined3d(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN;
static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func) static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func)
{ {
...@@ -1034,8 +1036,10 @@ struct wined3d_shader_reg_maps ...@@ -1034,8 +1036,10 @@ struct wined3d_shader_reg_maps
WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */ WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */
WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */ WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */
UINT cb_sizes[WINED3D_MAX_CBS]; UINT cb_sizes[WINED3D_MAX_CBS];
uint32_t cb_map; /* WINED3D_MAX_CBS, 15 */
struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS]; struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS];
uint32_t resource_map[WINED3D_BITMAP_SIZE(MAX_SHADER_RESOURCE_VIEWS)];
struct wined3d_shader_sampler_map sampler_map; struct wined3d_shader_sampler_map sampler_map;
DWORD sampler_comparison_mode; DWORD sampler_comparison_mode;
BYTE bumpmat; /* WINED3D_MAX_TEXTURES, 8 */ BYTE bumpmat; /* WINED3D_MAX_TEXTURES, 8 */
...@@ -2230,6 +2234,7 @@ enum wined3d_retired_object_type_vk ...@@ -2230,6 +2234,7 @@ enum wined3d_retired_object_type_vk
{ {
WINED3D_RETIRED_FREE_VK, WINED3D_RETIRED_FREE_VK,
WINED3D_RETIRED_FRAMEBUFFER_VK, WINED3D_RETIRED_FRAMEBUFFER_VK,
WINED3D_RETIRED_DESCRIPTOR_POOL_VK,
WINED3D_RETIRED_MEMORY_VK, WINED3D_RETIRED_MEMORY_VK,
WINED3D_RETIRED_ALLOCATOR_BLOCK_VK, WINED3D_RETIRED_ALLOCATOR_BLOCK_VK,
WINED3D_RETIRED_BO_SLAB_SLICE_VK, WINED3D_RETIRED_BO_SLAB_SLICE_VK,
...@@ -2247,6 +2252,7 @@ struct wined3d_retired_object_vk ...@@ -2247,6 +2252,7 @@ struct wined3d_retired_object_vk
{ {
struct wined3d_retired_object_vk *next; struct wined3d_retired_object_vk *next;
VkFramebuffer vk_framebuffer; VkFramebuffer vk_framebuffer;
VkDescriptorPool vk_descriptor_pool;
VkDeviceMemory vk_memory; VkDeviceMemory vk_memory;
struct wined3d_allocator_block *block; struct wined3d_allocator_block *block;
struct struct
...@@ -2293,12 +2299,46 @@ struct wined3d_render_pass_vk ...@@ -2293,12 +2299,46 @@ struct wined3d_render_pass_vk
VkRenderPass vk_render_pass; VkRenderPass vk_render_pass;
}; };
enum wined3d_shader_descriptor_type
{
WINED3D_SHADER_DESCRIPTOR_TYPE_CBV,
WINED3D_SHADER_DESCRIPTOR_TYPE_SRV,
WINED3D_SHADER_DESCRIPTOR_TYPE_UAV,
WINED3D_SHADER_DESCRIPTOR_TYPE_UAV_COUNTER,
WINED3D_SHADER_DESCRIPTOR_TYPE_SAMPLER,
};
struct wined3d_shader_resource_binding
{
enum wined3d_shader_type shader_type;
enum wined3d_shader_descriptor_type shader_descriptor_type;
size_t resource_idx;
enum wined3d_shader_resource_type resource_type;
enum wined3d_data_type resource_data_type;
size_t binding_idx;
};
struct wined3d_shader_resource_bindings
{
struct wined3d_shader_resource_binding *bindings;
SIZE_T size, count;
};
struct wined3d_context_vk struct wined3d_context_vk
{ {
struct wined3d_context c; struct wined3d_context c;
const struct wined3d_vk_info *vk_info; const struct wined3d_vk_info *vk_info;
uint32_t update_compute_pipeline : 1;
uint32_t padding : 31;
struct
{
VkPipeline vk_pipeline;
struct wined3d_shader_resource_bindings bindings;
} compute;
VkCommandPool vk_command_pool; VkCommandPool vk_command_pool;
struct wined3d_command_buffer_vk current_command_buffer; struct wined3d_command_buffer_vk current_command_buffer;
uint64_t completed_command_buffer_id; uint64_t completed_command_buffer_id;
...@@ -2310,6 +2350,10 @@ struct wined3d_context_vk ...@@ -2310,6 +2350,10 @@ struct wined3d_context_vk
SIZE_T buffer_count; SIZE_T buffer_count;
} submitted; } submitted;
VkDescriptorPool vk_descriptor_pool;
VkPipelineLayout vk_pipeline_layout;
VkDescriptorSetLayout vk_set_layout;
struct wined3d_retired_objects_vk retired; struct wined3d_retired_objects_vk retired;
struct wine_rb_tree render_passes; struct wine_rb_tree render_passes;
struct wine_rb_tree bo_slab_available; struct wine_rb_tree bo_slab_available;
...@@ -2324,6 +2368,8 @@ struct wined3d_allocator_block *wined3d_context_vk_allocate_memory(struct wined3 ...@@ -2324,6 +2368,8 @@ struct wined3d_allocator_block *wined3d_context_vk_allocate_memory(struct wined3
unsigned int memory_type, VkDeviceSize size, VkDeviceMemory *vk_memory) DECLSPEC_HIDDEN; unsigned int memory_type, VkDeviceSize size, VkDeviceMemory *vk_memory) DECLSPEC_HIDDEN;
VkDeviceMemory wined3d_context_vk_allocate_vram_chunk_memory(struct wined3d_context_vk *context_vk, VkDeviceMemory wined3d_context_vk_allocate_vram_chunk_memory(struct wined3d_context_vk *context_vk,
unsigned int pool, size_t size) DECLSPEC_HIDDEN; unsigned int pool, size_t size) DECLSPEC_HIDDEN;
VkCommandBuffer wined3d_context_vk_apply_compute_state(struct wined3d_context_vk *context_vk,
const struct wined3d_state *state, struct wined3d_buffer_vk *indirect_vk) DECLSPEC_HIDDEN;
void wined3d_context_vk_cleanup(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN; void wined3d_context_vk_cleanup(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDeviceSize size, BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDeviceSize size,
VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo) DECLSPEC_HIDDEN; VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo) DECLSPEC_HIDDEN;
...@@ -3621,13 +3667,6 @@ static inline struct wined3d_device_vk *wined3d_device_vk(struct wined3d_device ...@@ -3621,13 +3667,6 @@ static inline struct wined3d_device_vk *wined3d_device_vk(struct wined3d_device
return CONTAINING_RECORD(device, struct wined3d_device_vk, d); return CONTAINING_RECORD(device, struct wined3d_device_vk, d);
} }
static inline BOOL isStateDirty(const struct wined3d_context *context, unsigned int state_id)
{
unsigned int idx = state_id / (sizeof(*context->dirty_graphics_states) * CHAR_BIT);
unsigned int shift = state_id & ((sizeof(*context->dirty_graphics_states) * CHAR_BIT) - 1);
return context->dirty_graphics_states[idx] & (1u << shift);
}
static inline float wined3d_alpha_ref(const struct wined3d_state *state) static inline float wined3d_alpha_ref(const struct wined3d_state *state)
{ {
return (state->render_states[WINED3D_RS_ALPHAREF] & 0xff) / 255.0f; return (state->render_states[WINED3D_RS_ALPHAREF] & 0xff) / 255.0f;
...@@ -5634,6 +5673,11 @@ static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *v ...@@ -5634,6 +5673,11 @@ static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *v
*max_z = max(vp->max_z, vp->min_z + 0.001f); *max_z = max(vp->max_z, vp->min_z + 0.001f);
} }
static inline BOOL wined3d_bitmap_set(uint32_t *map, unsigned int idx)
{
return map[idx >> 5] |= (1u << (idx & 0x1f));
}
static inline BOOL wined3d_bitmap_is_set(const uint32_t *map, unsigned int idx) static inline BOOL wined3d_bitmap_is_set(const uint32_t *map, unsigned int idx)
{ {
return map[idx >> 5] & (1u << (idx & 0x1f)); return map[idx >> 5] & (1u << (idx & 0x1f));
...@@ -5693,6 +5737,21 @@ static inline BOOL wined3d_bitmap_get_range(const DWORD *bitmap, unsigned int bi ...@@ -5693,6 +5737,21 @@ static inline BOOL wined3d_bitmap_get_range(const DWORD *bitmap, unsigned int bi
return TRUE; return TRUE;
} }
static inline bool wined3d_context_is_graphics_state_dirty(const struct wined3d_context *context, unsigned int state_id)
{
return wined3d_bitmap_is_set(context->dirty_graphics_states, state_id);
}
static inline bool wined3d_context_is_compute_state_dirty(const struct wined3d_context *context, unsigned int state_id)
{
return wined3d_bitmap_is_set(context->dirty_compute_states, state_id - STATE_COMPUTE_OFFSET);
}
static inline bool isStateDirty(const struct wined3d_context *context, unsigned int state_id)
{
return wined3d_context_is_graphics_state_dirty(context, state_id);
}
static inline VkImageAspectFlags vk_aspect_mask_from_format(const struct wined3d_format *format) static inline VkImageAspectFlags vk_aspect_mask_from_format(const struct wined3d_format *format)
{ {
VkImageAspectFlags mask = 0; VkImageAspectFlags mask = 0;
......
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