zink: use smallest int type possible for decompose shader key
this reduces the component key size for decomposition by up to 75%, down to as low as 2 bytes, which is more optimal for both hashing and memcmp of the key it will become more useful as further changes are added to improve vertex format support, enabling the keysize to remain relatively small Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12771>
This commit is contained in:
parent
1542f3eb47
commit
727e10d290
|
@ -807,8 +807,21 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shad
|
|||
case MESA_SHADER_VERTEX: {
|
||||
uint32_t decomposed_attrs = 0, decomposed_attrs_without_w = 0;
|
||||
const struct zink_vs_key *vs_key = zink_vs_key(key);
|
||||
decomposed_attrs = vs_key->decomposed_attrs;
|
||||
decomposed_attrs_without_w = vs_key->decomposed_attrs_without_w;
|
||||
switch (vs_key->size) {
|
||||
case 4:
|
||||
decomposed_attrs = vs_key->u32.decomposed_attrs;
|
||||
decomposed_attrs_without_w = vs_key->u32.decomposed_attrs_without_w;
|
||||
break;
|
||||
case 2:
|
||||
decomposed_attrs = vs_key->u16.decomposed_attrs;
|
||||
decomposed_attrs_without_w = vs_key->u16.decomposed_attrs_without_w;
|
||||
break;
|
||||
case 1:
|
||||
decomposed_attrs = vs_key->u8.decomposed_attrs;
|
||||
decomposed_attrs_without_w = vs_key->u8.decomposed_attrs_without_w;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (decomposed_attrs || decomposed_attrs_without_w)
|
||||
NIR_PASS_V(nir, decompose_attribs, decomposed_attrs, decomposed_attrs_without_w);
|
||||
FALLTHROUGH;
|
||||
|
|
|
@ -134,9 +134,24 @@ shader_key_vs_gen(struct zink_context *ctx, struct zink_shader *zs,
|
|||
{
|
||||
struct zink_vs_key *vs_key = &key->key.vs;
|
||||
shader_key_vs_base_gen(ctx, zs, shaders, key);
|
||||
vs_key->decomposed_attrs = ctx->element_state->decomposed_attrs;
|
||||
vs_key->decomposed_attrs_without_w = ctx->element_state->decomposed_attrs_without_w;
|
||||
key->size += 2 * 4;
|
||||
unsigned size = MAX2(ctx->element_state->decomposed_attrs_size, ctx->element_state->decomposed_attrs_without_w_size);
|
||||
switch (size) {
|
||||
case 1:
|
||||
vs_key->u8.decomposed_attrs = ctx->element_state->decomposed_attrs;
|
||||
vs_key->u8.decomposed_attrs_without_w = ctx->element_state->decomposed_attrs_without_w;
|
||||
break;
|
||||
case 2:
|
||||
vs_key->u16.decomposed_attrs = ctx->element_state->decomposed_attrs;
|
||||
vs_key->u16.decomposed_attrs_without_w = ctx->element_state->decomposed_attrs_without_w;
|
||||
break;
|
||||
case 4:
|
||||
vs_key->u32.decomposed_attrs = ctx->element_state->decomposed_attrs;
|
||||
vs_key->u32.decomposed_attrs_without_w = ctx->element_state->decomposed_attrs_without_w;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
vs_key->size = size;
|
||||
key->size += 2 * size;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -35,8 +35,22 @@ struct zink_vs_key_base {
|
|||
struct zink_vs_key {
|
||||
struct zink_vs_key_base base;
|
||||
uint8_t pad;
|
||||
uint32_t decomposed_attrs;
|
||||
uint32_t decomposed_attrs_without_w;
|
||||
union {
|
||||
struct {
|
||||
uint32_t decomposed_attrs;
|
||||
uint32_t decomposed_attrs_without_w;
|
||||
} u32;
|
||||
struct {
|
||||
uint16_t decomposed_attrs;
|
||||
uint16_t decomposed_attrs_without_w;
|
||||
} u16;
|
||||
struct {
|
||||
uint8_t decomposed_attrs;
|
||||
uint8_t decomposed_attrs_without_w;
|
||||
} u8;
|
||||
};
|
||||
// not hashed
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
struct zink_fs_key {
|
||||
|
|
|
@ -99,6 +99,7 @@ zink_create_vertex_elements_state(struct pipe_context *pctx,
|
|||
ves->decomposed_attrs_size = size;
|
||||
} else {
|
||||
ves->decomposed_attrs_without_w |= BITFIELD_BIT(i);
|
||||
ves->decomposed_attrs_without_w_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ struct zink_vertex_elements_state {
|
|||
uint32_t decomposed_attrs;
|
||||
unsigned decomposed_attrs_size;
|
||||
uint32_t decomposed_attrs_without_w;
|
||||
unsigned decomposed_attrs_without_w_size;
|
||||
struct zink_vertex_elements_hw_state hw_state;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue