gallium: cso context support mesh shader

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36976>
This commit is contained in:
Qiang Yu 2025-02-27 17:44:08 +08:00
parent bbd97a59c0
commit 6459dacb8b
9 changed files with 112 additions and 11 deletions

View file

@ -110,6 +110,8 @@ struct cso_context_priv {
void *tessctrl_shader, *tessctrl_shader_saved;
void *tesseval_shader, *tesseval_shader_saved;
void *compute_shader, *compute_shader_saved;
void *task_shader, *task_shader_saved;
void *mesh_shader, *mesh_shader_saved;
void *velements, *velements_saved;
struct pipe_query *render_condition, *render_condition_saved;
enum pipe_render_cond_flag render_condition_mode, render_condition_mode_saved;
@ -1171,6 +1173,82 @@ cso_restore_compute_samplers(struct cso_context_priv *ctx)
}
void
cso_set_task_shader_handle(struct cso_context *cso, void *handle)
{
struct cso_context_priv *ctx = (struct cso_context_priv *)cso;
assert(ctx->has_task_mesh_shader || !handle);
if (ctx->has_task_mesh_shader && ctx->task_shader != handle) {
ctx->task_shader = handle;
ctx->base.pipe->bind_ts_state(ctx->base.pipe, handle);
}
}
static void
cso_save_task_shader(struct cso_context_priv *ctx)
{
if (!ctx->has_task_mesh_shader)
return;
assert(!ctx->task_shader_saved);
ctx->task_shader_saved = ctx->task_shader;
}
static void
cso_restore_task_shader(struct cso_context_priv *ctx)
{
if (!ctx->has_task_mesh_shader)
return;
if (ctx->task_shader_saved != ctx->task_shader) {
ctx->base.pipe->bind_ts_state(ctx->base.pipe, ctx->task_shader_saved);
ctx->task_shader = ctx->task_shader_saved;
}
ctx->task_shader_saved = NULL;
}
void
cso_set_mesh_shader_handle(struct cso_context *cso, void *handle)
{
struct cso_context_priv *ctx = (struct cso_context_priv *)cso;
assert(ctx->has_task_mesh_shader || !handle);
if (ctx->has_task_mesh_shader && ctx->mesh_shader != handle) {
ctx->mesh_shader = handle;
ctx->base.pipe->bind_ms_state(ctx->base.pipe, handle);
}
}
static void
cso_save_mesh_shader(struct cso_context_priv *ctx)
{
if (!ctx->has_task_mesh_shader)
return;
assert(!ctx->mesh_shader_saved);
ctx->mesh_shader_saved = ctx->mesh_shader;
}
static void
cso_restore_mesh_shader(struct cso_context_priv *ctx)
{
if (!ctx->has_task_mesh_shader)
return;
if (ctx->mesh_shader_saved != ctx->mesh_shader) {
ctx->base.pipe->bind_ms_state(ctx->base.pipe, ctx->mesh_shader_saved);
ctx->mesh_shader = ctx->mesh_shader_saved;
}
ctx->mesh_shader_saved = NULL;
}
static void *
cso_get_vertex_elements(struct cso_context_priv *ctx,
const struct cso_velems_state *velems)
@ -1697,6 +1775,10 @@ cso_save_state(struct cso_context *ctx, unsigned state_mask)
cso_save_viewport(cso);
if (state_mask & CSO_BIT_PAUSE_QUERIES)
cso->base.pipe->set_active_query_state(cso->base.pipe, false);
if (state_mask & CSO_BIT_TASK_SHADER)
cso_save_task_shader(cso);
if (state_mask & CSO_BIT_MESH_SHADER)
cso_save_mesh_shader(cso);
}
@ -1759,6 +1841,10 @@ cso_restore_state(struct cso_context *ctx, unsigned unbind)
cso_restore_stream_outputs(cso);
if (state_mask & CSO_BIT_PAUSE_QUERIES)
cso->base.pipe->set_active_query_state(cso->base.pipe, true);
if (state_mask & CSO_BIT_TASK_SHADER)
cso_restore_task_shader(cso);
if (state_mask & CSO_BIT_MESH_SHADER)
cso_restore_mesh_shader(cso);
cso->saved_state = 0;
}

View file

@ -129,6 +129,8 @@ void cso_set_geometry_shader_handle(struct cso_context *ctx, void *handle);
void cso_set_tessctrl_shader_handle(struct cso_context *ctx, void *handle);
void cso_set_tesseval_shader_handle(struct cso_context *ctx, void *handle);
void cso_set_compute_shader_handle(struct cso_context *ctx, void *handle);
void cso_set_task_shader_handle(struct cso_context *ctx, void *handle);
void cso_set_mesh_shader_handle(struct cso_context *ctx, void *handle);
void
@ -179,12 +181,16 @@ cso_set_render_condition(struct cso_context *cso,
#define CSO_BIT_VERTEX_SHADER 0x20000
#define CSO_BIT_VIEWPORT 0x40000
#define CSO_BIT_PAUSE_QUERIES 0x80000
#define CSO_BIT_TASK_SHADER 0x100000
#define CSO_BIT_MESH_SHADER 0x200000
#define CSO_BITS_ALL_SHADERS (CSO_BIT_VERTEX_SHADER | \
CSO_BIT_FRAGMENT_SHADER | \
CSO_BIT_GEOMETRY_SHADER | \
CSO_BIT_TESSCTRL_SHADER | \
CSO_BIT_TESSEVAL_SHADER)
CSO_BIT_TESSEVAL_SHADER | \
CSO_BIT_TASK_SHADER | \
CSO_BIT_MESH_SHADER)
#define CSO_BIT_COMPUTE_SHADER (1<<0)
#define CSO_BIT_COMPUTE_SAMPLERS (1<<1)

View file

@ -518,15 +518,11 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
CSO_BIT_MIN_SAMPLES |
CSO_BIT_BLEND |
CSO_BIT_DEPTH_STENCIL_ALPHA |
CSO_BIT_FRAGMENT_SHADER |
CSO_BIT_FRAGMENT_SAMPLERS |
CSO_BIT_RASTERIZER |
CSO_BIT_VIEWPORT |
CSO_BIT_STREAM_OUTPUTS |
CSO_BIT_GEOMETRY_SHADER |
CSO_BIT_TESSCTRL_SHADER |
CSO_BIT_TESSEVAL_SHADER |
CSO_BIT_VERTEX_SHADER |
CSO_BITS_ALL_SHADERS |
CSO_BIT_VERTEX_ELEMENTS |
CSO_BIT_PAUSE_QUERIES |
CSO_BIT_RENDER_CONDITION));
@ -574,6 +570,8 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
cso_set_vertex_shader_handle(cso, hud->vs_color);
cso_set_vertex_elements(cso, &hud->velems);
cso_set_render_condition(cso, NULL, false, 0);

View file

@ -119,11 +119,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
/* save state (restored below) */
cso_save_state(cso, (CSO_BIT_BLEND |
CSO_BIT_DEPTH_STENCIL_ALPHA |
CSO_BIT_FRAGMENT_SHADER |
CSO_BIT_FRAMEBUFFER |
CSO_BIT_TESSCTRL_SHADER |
CSO_BIT_TESSEVAL_SHADER |
CSO_BIT_GEOMETRY_SHADER |
CSO_BIT_RASTERIZER |
CSO_BIT_SAMPLE_MASK |
CSO_BIT_MIN_SAMPLES |
@ -131,7 +127,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
CSO_BIT_STENCIL_REF |
CSO_BIT_STREAM_OUTPUTS |
CSO_BIT_VERTEX_ELEMENTS |
CSO_BIT_VERTEX_SHADER |
CSO_BITS_ALL_SHADERS |
CSO_BIT_VIEWPORT |
CSO_BIT_PAUSE_QUERIES |
CSO_BIT_RENDER_CONDITION));
@ -143,6 +139,8 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
cso_set_render_condition(cso, NULL, false, 0);
// Kept only for this frame.

View file

@ -226,6 +226,8 @@ setup_render_state(struct gl_context *ctx,
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
/* user samplers, plus our bitmap sampler */
{

View file

@ -296,6 +296,8 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
set_clearcolor_fs(st, (union pipe_color_union*)&ctx->Color.ClearColor);
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
if (num_layers > 1)
set_vertex_shader_layered(st);

View file

@ -805,6 +805,8 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
/* user samplers, plus the drawpix samplers */
{

View file

@ -251,6 +251,8 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
CSO_BIT_TESSCTRL_SHADER |
CSO_BIT_TESSEVAL_SHADER |
CSO_BIT_GEOMETRY_SHADER |
CSO_BIT_TASK_SHADER |
CSO_BIT_MESH_SHADER |
CSO_BIT_VERTEX_ELEMENTS));
{
@ -260,6 +262,8 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
for (i = 0; i < numAttribs; i++) {
velems.velems[i].src_offset = i * 4 * sizeof(float);

View file

@ -210,6 +210,9 @@ st_pbo_draw(struct st_context *st, const struct st_pbo_addresses *addr,
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_task_shader_handle(cso, NULL);
cso_set_mesh_shader_handle(cso, NULL);
/* Upload vertices */
{
struct pipe_vertex_buffer vbo = {0};