zink: flatten out draw templates a bit
having this be super granular was a neat idea, but really I don't care even a little bit about a driver that's weirdly implementing *only* dynamic vertex input or *only* dynamic state2 this massively cuts down the combinatorics and provides a more accurate gauge of driver feature levels, since this is the general level of support that they're likely to have Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13715>
This commit is contained in:
parent
3d80d6b696
commit
8626949f07
|
@ -171,17 +171,9 @@ typedef enum {
|
|||
typedef enum {
|
||||
ZINK_NO_DYNAMIC_STATE,
|
||||
ZINK_DYNAMIC_STATE,
|
||||
} zink_dynamic_state;
|
||||
|
||||
typedef enum {
|
||||
ZINK_NO_DYNAMIC_STATE2,
|
||||
ZINK_DYNAMIC_STATE2,
|
||||
} zink_dynamic_state2;
|
||||
|
||||
typedef enum {
|
||||
ZINK_NO_DYNAMIC_VERTEX_INPUT,
|
||||
ZINK_DYNAMIC_VERTEX_INPUT,
|
||||
} zink_dynamic_vertex_input;
|
||||
} zink_dynamic_state;
|
||||
|
||||
struct zink_context {
|
||||
struct pipe_context base;
|
||||
|
|
|
@ -120,7 +120,7 @@ barrier_draw_buffers(struct zink_context *ctx, const struct pipe_draw_info *dinf
|
|||
}
|
||||
}
|
||||
|
||||
template <zink_dynamic_state HAS_DYNAMIC_STATE, zink_dynamic_vertex_input HAS_VERTEX_INPUT>
|
||||
template <zink_dynamic_state DYNAMIC_STATE>
|
||||
static void
|
||||
zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
|
|||
if (vb->buffer.resource) {
|
||||
buffers[i] = ctx->vbufs[buffer_id];
|
||||
assert(buffers[i]);
|
||||
if (HAS_VERTEX_INPUT)
|
||||
if (DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT)
|
||||
elems->hw_state.dynbindings[i].stride = vb->stride;
|
||||
buffer_offsets[i] = ctx->vbuf_offsets[buffer_id];
|
||||
buffer_strides[i] = vb->stride;
|
||||
|
@ -149,12 +149,12 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
|
|||
buffers[i] = zink_resource(ctx->dummy_vertex_buffer)->obj->buffer;
|
||||
buffer_offsets[i] = 0;
|
||||
buffer_strides[i] = 0;
|
||||
if (HAS_VERTEX_INPUT)
|
||||
if (DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT)
|
||||
elems->hw_state.dynbindings[i].stride = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (HAS_DYNAMIC_STATE && !HAS_VERTEX_INPUT)
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE && DYNAMIC_STATE != ZINK_DYNAMIC_VERTEX_INPUT)
|
||||
VKCTX(CmdBindVertexBuffers2EXT)(batch->state->cmdbuf, 0,
|
||||
elems->hw_state.num_bindings,
|
||||
buffers, buffer_offsets, NULL, buffer_strides);
|
||||
|
@ -163,7 +163,7 @@ zink_bind_vertex_buffers(struct zink_batch *batch, struct zink_context *ctx)
|
|||
elems->hw_state.num_bindings,
|
||||
buffers, buffer_offsets);
|
||||
|
||||
if (HAS_VERTEX_INPUT)
|
||||
if (DYNAMIC_STATE == ZINK_DYNAMIC_VERTEX_INPUT)
|
||||
VKCTX(CmdSetVertexInputEXT)(batch->state->cmdbuf,
|
||||
elems->hw_state.num_bindings, elems->hw_state.dynbindings,
|
||||
elems->hw_state.num_attribs, elems->hw_state.dynattribs);
|
||||
|
@ -448,8 +448,7 @@ hack_conditional_render(struct pipe_context *pctx,
|
|||
return true;
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, zink_dynamic_state2 HAS_DYNAMIC_STATE2,
|
||||
zink_dynamic_vertex_input HAS_VERTEX_INPUT, bool BATCH_CHANGED>
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state DYNAMIC_STATE, bool BATCH_CHANGED>
|
||||
void
|
||||
zink_draw_vbo(struct pipe_context *pctx,
|
||||
const struct pipe_draw_info *dinfo,
|
||||
|
@ -570,7 +569,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
struct zink_resource *res = zink_resource(index_buffer);
|
||||
VKCTX(CmdBindIndexBuffer)(batch->state->cmdbuf, res->obj->buffer, index_offset, index_type[index_size >> 1]);
|
||||
}
|
||||
if (!HAS_DYNAMIC_STATE2) {
|
||||
if (DYNAMIC_STATE < ZINK_DYNAMIC_STATE2) {
|
||||
if (ctx->gfx_pipeline_state.primitive_restart != dinfo->primitive_restart)
|
||||
ctx->gfx_pipeline_state.dirty = true;
|
||||
ctx->gfx_pipeline_state.primitive_restart = dinfo->primitive_restart;
|
||||
|
@ -580,10 +579,10 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
zink_emit_stream_output_targets(pctx);
|
||||
|
||||
bool pipeline_changed = false;
|
||||
if (!HAS_DYNAMIC_STATE)
|
||||
if (DYNAMIC_STATE == ZINK_NO_DYNAMIC_STATE)
|
||||
pipeline_changed = update_gfx_pipeline<BATCH_CHANGED>(ctx, batch->state, mode);
|
||||
|
||||
if (BATCH_CHANGED || ctx->vp_state_changed || (!HAS_DYNAMIC_STATE && pipeline_changed)) {
|
||||
if (BATCH_CHANGED || ctx->vp_state_changed || (DYNAMIC_STATE == ZINK_NO_DYNAMIC_STATE && pipeline_changed)) {
|
||||
VkViewport viewports[PIPE_MAX_VIEWPORTS];
|
||||
for (unsigned i = 0; i < ctx->vp_state.num_viewports; i++) {
|
||||
VkViewport viewport = {
|
||||
|
@ -598,12 +597,12 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
};
|
||||
viewports[i] = viewport;
|
||||
}
|
||||
if (HAS_DYNAMIC_STATE)
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE)
|
||||
VKCTX(CmdSetViewportWithCountEXT)(batch->state->cmdbuf, ctx->vp_state.num_viewports, viewports);
|
||||
else
|
||||
VKCTX(CmdSetViewport)(batch->state->cmdbuf, 0, ctx->vp_state.num_viewports, viewports);
|
||||
}
|
||||
if (BATCH_CHANGED || ctx->scissor_changed || ctx->vp_state_changed || (!HAS_DYNAMIC_STATE && pipeline_changed)) {
|
||||
if (BATCH_CHANGED || ctx->scissor_changed || ctx->vp_state_changed || (DYNAMIC_STATE == ZINK_NO_DYNAMIC_STATE && pipeline_changed)) {
|
||||
VkRect2D scissors[PIPE_MAX_VIEWPORTS];
|
||||
if (ctx->rast_state->base.scissor) {
|
||||
for (unsigned i = 0; i < ctx->vp_state.num_viewports; i++) {
|
||||
|
@ -620,7 +619,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
scissors[i].extent.height = ctx->fb_state.height;
|
||||
}
|
||||
}
|
||||
if (HAS_DYNAMIC_STATE)
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE)
|
||||
VKCTX(CmdSetScissorWithCountEXT)(batch->state->cmdbuf, ctx->vp_state.num_viewports, scissors);
|
||||
else
|
||||
VKCTX(CmdSetScissor)(batch->state->cmdbuf, 0, ctx->vp_state.num_viewports, scissors);
|
||||
|
@ -636,7 +635,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
ctx->stencil_ref_changed = false;
|
||||
}
|
||||
|
||||
if (HAS_DYNAMIC_STATE && (BATCH_CHANGED || ctx->dsa_state_changed)) {
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE && (BATCH_CHANGED || ctx->dsa_state_changed)) {
|
||||
VKCTX(CmdSetDepthBoundsTestEnableEXT)(batch->state->cmdbuf, dsa_state->hw_state.depth_bounds_test);
|
||||
if (dsa_state->hw_state.depth_bounds_test)
|
||||
VKCTX(CmdSetDepthBounds)(batch->state->cmdbuf,
|
||||
|
@ -674,7 +673,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
ctx->dsa_state_changed = false;
|
||||
|
||||
bool rast_state_changed = ctx->rast_state_changed;
|
||||
if (HAS_DYNAMIC_STATE && (BATCH_CHANGED || rast_state_changed))
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE && (BATCH_CHANGED || rast_state_changed))
|
||||
VKCTX(CmdSetFrontFaceEXT)(batch->state->cmdbuf, ctx->gfx_pipeline_state.dyn_state1.front_face);
|
||||
if ((BATCH_CHANGED || rast_state_changed) &&
|
||||
screen->info.have_EXT_line_rasterization && rast_state->base.line_stipple_enable)
|
||||
|
@ -716,7 +715,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
}
|
||||
ctx->rast_state_changed = false;
|
||||
|
||||
if (HAS_DYNAMIC_STATE) {
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE) {
|
||||
if (ctx->sample_locations_changed) {
|
||||
VkSampleLocationsInfoEXT loc;
|
||||
zink_init_vk_sample_locations(ctx, &loc);
|
||||
|
@ -732,7 +731,7 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
ctx->blend_state_changed = false;
|
||||
|
||||
if (BATCH_CHANGED || ctx->vertex_buffers_dirty)
|
||||
zink_bind_vertex_buffers<HAS_DYNAMIC_STATE, HAS_VERTEX_INPUT>(batch, ctx);
|
||||
zink_bind_vertex_buffers<DYNAMIC_STATE>(batch, ctx);
|
||||
|
||||
zink_query_update_gs_states(ctx);
|
||||
|
||||
|
@ -741,13 +740,13 @@ zink_draw_vbo(struct pipe_context *pctx,
|
|||
zink_select_draw_vbo(ctx);
|
||||
}
|
||||
|
||||
if (HAS_DYNAMIC_STATE) {
|
||||
if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE) {
|
||||
update_gfx_pipeline<BATCH_CHANGED>(ctx, batch->state, mode);
|
||||
if (BATCH_CHANGED || mode_changed)
|
||||
VKCTX(CmdSetPrimitiveTopologyEXT)(batch->state->cmdbuf, zink_primitive_topology(mode));
|
||||
}
|
||||
|
||||
if (HAS_DYNAMIC_STATE2 && (BATCH_CHANGED || ctx->primitive_restart != dinfo->primitive_restart)) {
|
||||
if (DYNAMIC_STATE >= ZINK_DYNAMIC_STATE2 && (BATCH_CHANGED || ctx->primitive_restart != dinfo->primitive_restart)) {
|
||||
VKCTX(CmdSetPrimitiveRestartEnableEXT)(batch->state->cmdbuf, dinfo->primitive_restart);
|
||||
ctx->primitive_restart = dinfo->primitive_restart;
|
||||
}
|
||||
|
@ -917,50 +916,34 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
|
|||
pctx->flush(pctx, NULL, 0);
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, zink_dynamic_state2 HAS_DYNAMIC_STATE2,
|
||||
zink_dynamic_vertex_input HAS_VERTEX_INPUT, bool BATCH_CHANGED>
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state DYNAMIC_STATE, bool BATCH_CHANGED>
|
||||
static void
|
||||
init_batch_changed_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
init_batch_changed_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][4][2])
|
||||
{
|
||||
draw_vbo_array[HAS_MULTIDRAW][HAS_DYNAMIC_STATE][HAS_DYNAMIC_STATE2][HAS_VERTEX_INPUT][BATCH_CHANGED] =
|
||||
zink_draw_vbo<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, HAS_DYNAMIC_STATE2, HAS_VERTEX_INPUT, BATCH_CHANGED>;
|
||||
draw_vbo_array[HAS_MULTIDRAW][DYNAMIC_STATE][BATCH_CHANGED] =
|
||||
zink_draw_vbo<HAS_MULTIDRAW, DYNAMIC_STATE, BATCH_CHANGED>;
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, zink_dynamic_state2 HAS_DYNAMIC_STATE2,
|
||||
zink_dynamic_vertex_input HAS_VERTEX_INPUT>
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state DYNAMIC_STATE>
|
||||
static void
|
||||
init_vertex_input_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
init_dynamic_state_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][4][2])
|
||||
{
|
||||
init_batch_changed_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, HAS_DYNAMIC_STATE2, HAS_VERTEX_INPUT, false>(ctx, draw_vbo_array);
|
||||
init_batch_changed_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, HAS_DYNAMIC_STATE2, HAS_VERTEX_INPUT, true>(ctx, draw_vbo_array);
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, zink_dynamic_state2 HAS_DYNAMIC_STATE2>
|
||||
static void
|
||||
init_dynamic_state2_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
{
|
||||
init_vertex_input_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, HAS_DYNAMIC_STATE2, ZINK_NO_DYNAMIC_VERTEX_INPUT>(ctx, draw_vbo_array);
|
||||
init_vertex_input_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, HAS_DYNAMIC_STATE2, ZINK_DYNAMIC_VERTEX_INPUT>(ctx, draw_vbo_array);
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE>
|
||||
static void
|
||||
init_dynamic_state_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
{
|
||||
init_dynamic_state2_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, ZINK_NO_DYNAMIC_STATE2>(ctx, draw_vbo_array);
|
||||
init_dynamic_state2_functions<HAS_MULTIDRAW, HAS_DYNAMIC_STATE, ZINK_DYNAMIC_STATE2>(ctx, draw_vbo_array);
|
||||
init_batch_changed_functions<HAS_MULTIDRAW, DYNAMIC_STATE, false>(ctx, draw_vbo_array);
|
||||
init_batch_changed_functions<HAS_MULTIDRAW, DYNAMIC_STATE, true>(ctx, draw_vbo_array);
|
||||
}
|
||||
|
||||
template <zink_multidraw HAS_MULTIDRAW>
|
||||
static void
|
||||
init_multidraw_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
init_multidraw_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][4][2])
|
||||
{
|
||||
init_dynamic_state_functions<HAS_MULTIDRAW, ZINK_NO_DYNAMIC_STATE>(ctx, draw_vbo_array);
|
||||
init_dynamic_state_functions<HAS_MULTIDRAW, ZINK_DYNAMIC_STATE>(ctx, draw_vbo_array);
|
||||
init_dynamic_state_functions<HAS_MULTIDRAW, ZINK_DYNAMIC_STATE2>(ctx, draw_vbo_array);
|
||||
init_dynamic_state_functions<HAS_MULTIDRAW, ZINK_DYNAMIC_VERTEX_INPUT>(ctx, draw_vbo_array);
|
||||
}
|
||||
|
||||
static void
|
||||
init_all_draw_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][2][2][2][2])
|
||||
init_all_draw_functions(struct zink_context *ctx, pipe_draw_vbo_func draw_vbo_array[2][4][2])
|
||||
{
|
||||
init_multidraw_functions<ZINK_NO_MULTIDRAW>(ctx, draw_vbo_array);
|
||||
init_multidraw_functions<ZINK_MULTIDRAW>(ctx, draw_vbo_array);
|
||||
|
@ -1048,13 +1031,24 @@ extern "C"
|
|||
void
|
||||
zink_init_draw_functions(struct zink_context *ctx, struct zink_screen *screen)
|
||||
{
|
||||
pipe_draw_vbo_func draw_vbo_array[2][2][2][2] //multidraw, dynamic state, dynamic state2, dynamic vertex input,
|
||||
pipe_draw_vbo_func draw_vbo_array[2][4] //multidraw, zink_dynamic_state
|
||||
[2]; //batch changed
|
||||
zink_dynamic_state dynamic;
|
||||
if (screen->info.have_EXT_extended_dynamic_state) {
|
||||
if (screen->info.have_EXT_extended_dynamic_state2) {
|
||||
if (screen->info.have_EXT_vertex_input_dynamic_state)
|
||||
dynamic = ZINK_DYNAMIC_VERTEX_INPUT;
|
||||
else
|
||||
dynamic = ZINK_DYNAMIC_STATE2;
|
||||
} else {
|
||||
dynamic = ZINK_DYNAMIC_STATE;
|
||||
}
|
||||
} else {
|
||||
dynamic = ZINK_NO_DYNAMIC_STATE;
|
||||
}
|
||||
init_all_draw_functions(ctx, draw_vbo_array);
|
||||
memcpy(ctx->draw_vbo, &draw_vbo_array[screen->info.have_EXT_multi_draw]
|
||||
[screen->info.have_EXT_extended_dynamic_state]
|
||||
[screen->info.have_EXT_extended_dynamic_state2]
|
||||
[screen->info.have_EXT_vertex_input_dynamic_state],
|
||||
[dynamic],
|
||||
sizeof(ctx->draw_vbo));
|
||||
|
||||
/* Bind a fake draw_vbo, so that draw_vbo isn't NULL, which would skip
|
||||
|
|
Loading…
Reference in New Issue