zink: add a per-stage mask for ubo binds

optimizing buffer replacement was never so difficult

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11747>
This commit is contained in:
Mike Blumenkrantz
2021-05-11 10:09:06 -04:00
parent 496b794b10
commit 4a194b7bbf
2 changed files with 9 additions and 6 deletions

View File

@@ -999,12 +999,13 @@ zink_set_inlinable_constants(struct pipe_context *pctx,
}
ALWAYS_INLINE static void
unbind_ubo(struct zink_context *ctx, struct zink_resource *res, bool is_compute)
unbind_ubo(struct zink_context *ctx, struct zink_resource *res, enum pipe_shader_type pstage, unsigned slot)
{
if (!res)
return;
res->ubo_bind_count[is_compute]--;
update_res_bind_count(ctx, res, is_compute, true);
res->ubo_bind_mask[pstage] &= ~BITFIELD_BIT(slot);
res->ubo_bind_count[pstage == PIPE_SHADER_COMPUTE]--;
update_res_bind_count(ctx, res, pstage == PIPE_SHADER_COMPUTE, true);
}
static void
@@ -1029,10 +1030,11 @@ zink_set_constant_buffer(struct pipe_context *pctx,
struct zink_resource *new_res = zink_resource(buffer);
if (new_res) {
if (new_res != res) {
unbind_ubo(ctx, res, shader == PIPE_SHADER_COMPUTE);
unbind_ubo(ctx, res, shader, index);
new_res->bind_history |= BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_UBO);
new_res->bind_stages |= 1 << shader;
new_res->ubo_bind_count[shader == PIPE_SHADER_COMPUTE]++;
new_res->ubo_bind_mask[shader] |= BITFIELD_BIT(index);
update_res_bind_count(ctx, new_res, shader == PIPE_SHADER_COMPUTE, false);
}
zink_batch_resource_usage_set(&ctx->batch, new_res, false);
@@ -1060,7 +1062,7 @@ zink_set_constant_buffer(struct pipe_context *pctx,
ctx->di.num_ubos[shader] = index + 1;
} else {
if (res)
unbind_ubo(ctx, res, shader == PIPE_SHADER_COMPUTE);
unbind_ubo(ctx, res, shader, index);
update = !!ctx->ubos[shader][index].buffer;
pipe_resource_reference(&ctx->ubos[shader][index].buffer, NULL);

View File

@@ -105,7 +105,8 @@ struct zink_resource {
struct {
struct util_range valid_buffer_range;
uint16_t vbo_bind_count;
uint16_t ubo_bind_count[2];
uint8_t ubo_bind_count[2];
uint32_t ubo_bind_mask[PIPE_SHADER_TYPES];
};
struct {
VkFormat format;