nvk: Add graphics state to command buffers

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand 2023-01-30 20:11:52 -06:00 committed by Marge Bot
parent 0f203b2b44
commit db2cf498ce
4 changed files with 51 additions and 12 deletions

View file

@ -11,6 +11,7 @@ nvk_files = files(
'nvk_cmd_buffer.h',
'nvk_cmd_copy.c',
'nvk_cmd_dispatch.c',
'nvk_cmd_draw.c',
'nvk_compute_pipeline.c',
'nvk_descriptor_set.h',
'nvk_descriptor_set.c',

View file

@ -73,6 +73,11 @@ nvk_create_cmd_buffer(struct nvk_device *device,
return result;
}
cmd_buffer->vk.dynamic_graphics_state.vi =
&cmd_buffer->state.gfx._dynamic_vi;
cmd_buffer->vk.dynamic_graphics_state.ms.sample_locations =
&cmd_buffer->state.gfx._dynamic_ms_sl;
cmd_buffer->pool = pool;
list_addtail(&cmd_buffer->pool_link, &pool->cmd_buffers);
@ -341,6 +346,7 @@ nvk_BeginCommandBuffer(VkCommandBuffer commandBuffer,
cmd->reset_on_submit = false;
nvk_cmd_buffer_begin_compute(cmd, pBeginInfo);
nvk_cmd_buffer_begin_graphics(cmd, pBeginInfo);
return VK_SUCCESS;
}
@ -366,6 +372,16 @@ nvk_CmdBindPipeline(VkCommandBuffer commandBuffer,
VK_FROM_HANDLE(nvk_pipeline, pipeline, _pipeline);
switch (pipelineBindPoint) {
case VK_PIPELINE_BIND_POINT_GRAPHICS:
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
if (!pipeline->shaders[s].bo)
continue;
nouveau_ws_push_ref(cmd->push, pipeline->shaders[s].bo,
NOUVEAU_WS_BO_RD);
}
cmd->state.gfx.pipeline = (struct nvk_graphics_pipeline *)pipeline;
break;
case VK_PIPELINE_BIND_POINT_COMPUTE:
assert(pipeline->type == NVK_PIPELINE_COMPUTE);
nouveau_ws_push_ref(cmd->push,
@ -431,17 +447,18 @@ nvk_CmdPushConstants(VkCommandBuffer commandBuffer,
const void *pValues)
{
VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer);
if (stageFlags & VK_SHADER_STAGE_ALL_GRAPHICS) {
struct nvk_descriptor_state *desc =
nvk_get_descriptors_state(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS);
memcpy(desc->root.push + offset, pValues, size);
}
if (stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) {
struct nvk_descriptor_state *desc =
nvk_get_descriptors_state(cmd, VK_PIPELINE_BIND_POINT_COMPUTE);
memcpy(desc->root.push + offset, pValues, size);
}
// if (stageFlags & VK_SHADER_STAGE_ALL_GRAPHICS) {
// struct nvk_descriptor_state *desc =
// nvk_get_descriptors_state(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS);
//
// memcpy(desc->root.push + offset, pValues, size);
// }
}

View file

@ -48,6 +48,15 @@ struct nvk_descriptor_state {
uint32_t sets_dirty;
};
struct nvk_graphics_state {
struct nvk_graphics_pipeline *pipeline;
struct nvk_descriptor_state descriptors;
/* Needed by vk_command_buffer::dynamic_graphics_state */
struct vk_vertex_input_state _dynamic_vi;
struct vk_sample_locations_state _dynamic_ms_sl;
};
struct nvk_compute_state {
struct nvk_compute_pipeline *pipeline;
struct nvk_descriptor_state descriptors;
@ -68,6 +77,7 @@ struct nvk_cmd_buffer {
struct list_head pool_link;
struct {
struct nvk_graphics_state gfx;
struct nvk_compute_state cs;
} state;
@ -80,19 +90,23 @@ struct nvk_cmd_buffer {
uint64_t tls_space_needed;
};
VkResult nvk_reset_cmd_buffer(struct nvk_cmd_buffer *cmd_buffer);
void nvk_cmd_buffer_begin_compute(struct nvk_cmd_buffer *cmd,
const VkCommandBufferBeginInfo *pBeginInfo);
VK_DEFINE_HANDLE_CASTS(nvk_cmd_buffer, vk.base, VkCommandBuffer,
VK_OBJECT_TYPE_COMMAND_BUFFER)
VkResult nvk_reset_cmd_buffer(struct nvk_cmd_buffer *cmd_buffer);
void nvk_cmd_buffer_begin_graphics(struct nvk_cmd_buffer *cmd,
const VkCommandBufferBeginInfo *pBeginInfo);
void nvk_cmd_buffer_begin_compute(struct nvk_cmd_buffer *cmd,
const VkCommandBufferBeginInfo *pBeginInfo);
static inline struct nvk_descriptor_state *
nvk_get_descriptors_state(struct nvk_cmd_buffer *cmd,
VkPipelineBindPoint bind_point)
{
switch (bind_point) {
case VK_PIPELINE_BIND_POINT_GRAPHICS:
return &cmd->state.gfx.descriptors;
case VK_PIPELINE_BIND_POINT_COMPUTE:
return &cmd->state.cs.descriptors;
default:

View file

@ -0,0 +1,7 @@
#include "nvk_cmd_buffer.h"
void
nvk_cmd_buffer_begin_graphics(struct nvk_cmd_buffer *cmd,
const VkCommandBufferBeginInfo *pBeginInfo)
{
}