Lines Matching refs:ctx
92 get_shader_module_for_stage(struct zink_context *ctx, struct zink_screen *screen,
107 if (ctx && zs->nir->info.num_inlinable_uniforms &&
108 ctx->inlinable_uniforms_valid_mask & BITFIELD64_BIT(pstage)) {
133 assert(ctx); //TODO async
189 update_gfx_shader_modules(struct zink_context *ctx,
200 struct zink_shader_module *zm = get_shader_module_for_stage(ctx, screen, prog->shaders[pstage], prog, state);
283 zink_update_gfx_program(struct zink_context *ctx, struct zink_gfx_program *prog)
285 update_gfx_shader_modules(ctx, zink_screen(ctx->base.screen), prog, ctx->dirty_shader_stages & prog->stages_present, &ctx->gfx_pipeline_state);
289 update_cs_shader_module(struct zink_context *ctx, struct zink_compute_program *comp)
291 struct zink_screen *screen = zink_screen(ctx->base.screen);
296 struct zink_shader_key *key = &ctx->compute_pipeline_state.key;
298 if (ctx && zs->nir->info.num_inlinable_uniforms &&
299 ctx->inlinable_uniforms_valid_mask & BITFIELD64_BIT(PIPE_SHADER_COMPUTE)) {
350 ctx->compute_pipeline_state.final_hash ^= ctx->compute_pipeline_state.module_hash;
352 ctx->compute_pipeline_state.module_hash = zm->hash;
353 ctx->compute_pipeline_state.final_hash ^= ctx->compute_pipeline_state.module_hash;
354 ctx->compute_pipeline_state.module_changed = true;
358 zink_update_compute_program(struct zink_context *ctx)
360 update_cs_shader_module(ctx, ctx->curr_compute);
430 zink_create_gfx_program(struct zink_context *ctx,
434 struct zink_screen *screen = zink_screen(ctx->base.screen);
483 zink_gfx_program_reference(ctx, NULL, prog);
489 if (!screen->descriptor_program_init(ctx, &prog->base))
497 zink_destroy_gfx_program(ctx, prog);
512 zink_program_update_compute_pipeline_state(struct zink_context *ctx, struct zink_compute_program *comp, const uint block[3])
518 if (ctx->compute_pipeline_state.use_local_size != use_local_size)
519 ctx->compute_pipeline_state.dirty = true;
520 ctx->compute_pipeline_state.use_local_size = use_local_size;
522 if (ctx->compute_pipeline_state.use_local_size) {
523 for (int i = 0; i < ARRAY_SIZE(ctx->compute_pipeline_state.local_size); i++) {
524 if (ctx->compute_pipeline_state.local_size[i] != block[i])
525 ctx->compute_pipeline_state.dirty = true;
526 ctx->compute_pipeline_state.local_size[i] = block[i];
529 ctx->compute_pipeline_state.local_size[0] =
530 ctx->compute_pipeline_state.local_size[1] =
531 ctx->compute_pipeline_state.local_size[2] = 0;
544 zink_create_compute_program(struct zink_context *ctx, struct zink_shader *shader)
546 struct zink_screen *screen = zink_screen(ctx->base.screen);
569 if (!screen->descriptor_program_init(ctx, &comp->base))
577 zink_destroy_compute_program(ctx, comp);
582 zink_program_get_descriptor_usage(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type)
591 zs = ctx->gfx_stages[stage];
594 zs = ctx->compute_stage;
618 zink_program_descriptor_is_buffer(struct zink_context *ctx, enum pipe_shader_type stage, enum zink_descriptor_type type, unsigned i)
627 zs = ctx->gfx_stages[stage];
630 zs = ctx->compute_stage;
683 zink_destroy_gfx_program(struct zink_context *ctx,
686 struct zink_screen *screen = zink_screen(ctx->base.screen);
725 screen->descriptor_program_deinit(ctx, &prog->base);
731 zink_destroy_compute_program(struct zink_context *ctx,
734 struct zink_screen *screen = zink_screen(ctx->base.screen);
755 screen->descriptor_program_deinit(ctx, &comp->base);
794 check_vertex_strides(struct zink_context *ctx)
796 const struct zink_vertex_elements_state *ves = ctx->element_state;
798 const struct pipe_vertex_buffer *vb = ctx->vertex_buffers + ves->binding_map[i];
807 zink_get_gfx_pipeline(struct zink_context *ctx,
812 struct zink_screen *screen = zink_screen(ctx->base.screen);
821 (have_EXT_vertex_input_dynamic_state || !ctx->vertex_state_changed) &&
834 if (!have_EXT_vertex_input_dynamic_state && ctx->vertex_state_changed) {
838 uses_dynamic_stride = check_vertex_strides(ctx);
846 const unsigned buffer_id = ctx->element_state->binding_map[i];
847 struct pipe_vertex_buffer *vb = ctx->vertex_buffers + buffer_id;
858 ctx->vertex_state_changed = false;
865 ctx->element_state->binding_map,
930 bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
934 ctx->shader_has_inlinable_uniforms_mask |= 1 << stage;
936 ctx->shader_has_inlinable_uniforms_mask &= ~(1 << stage);
939 if (ctx->compute_stage) {
940 ctx->compute_pipeline_state.final_hash ^= ctx->compute_pipeline_state.module_hash;
941 ctx->compute_pipeline_state.module = VK_NULL_HANDLE;
942 ctx->compute_pipeline_state.module_hash = 0;
944 if (shader && shader != ctx->compute_stage) {
945 struct hash_entry *entry = _mesa_hash_table_search(&ctx->compute_program_cache, shader);
947 ctx->compute_pipeline_state.dirty = true;
948 ctx->curr_compute = entry->data;
950 struct zink_compute_program *comp = zink_create_compute_program(ctx, shader);
951 _mesa_hash_table_insert(&ctx->compute_program_cache, comp->shader, comp);
952 ctx->compute_pipeline_state.dirty = true;
953 ctx->curr_compute = comp;
954 zink_batch_reference_program(&ctx->batch, &ctx->curr_compute->base);
956 ctx->compute_pipeline_state.module_hash = ctx->curr_compute->curr->hash;
957 ctx->compute_pipeline_state.module = ctx->curr_compute->curr->shader;
958 ctx->compute_pipeline_state.final_hash ^= ctx->compute_pipeline_state.module_hash;
959 if (ctx->compute_pipeline_state.key.base.nonseamless_cube_mask)
960 ctx->dirty_shader_stages |= BITFIELD_BIT(PIPE_SHADER_COMPUTE);
962 ctx->curr_compute = NULL;
963 ctx->compute_stage = shader;
964 zink_select_launch_grid(ctx);
966 if (ctx->gfx_stages[stage])
967 ctx->gfx_hash ^= ctx->gfx_stages[stage]->hash;
968 ctx->gfx_stages[stage] = shader;
969 ctx->gfx_dirty = ctx->gfx_stages[PIPE_SHADER_FRAGMENT] && ctx->gfx_stages[PIPE_SHADER_VERTEX];
970 ctx->gfx_pipeline_state.modules_changed = true;
972 ctx->shader_stages |= BITFIELD_BIT(stage);
973 ctx->gfx_hash ^= ctx->gfx_stages[stage]->hash;
975 ctx->gfx_pipeline_state.modules[stage] = VK_NULL_HANDLE;
976 if (ctx->curr_program)
977 ctx->gfx_pipeline_state.final_hash ^= ctx->curr_program->last_variant_hash;
978 ctx->curr_program = NULL;
979 ctx->shader_stages &= ~BITFIELD_BIT(stage);
985 bind_last_vertex_stage(struct zink_context *ctx)
987 enum pipe_shader_type old = ctx->last_vertex_stage ? pipe_shader_type_from_mesa(ctx->last_vertex_stage->nir->info.stage) : PIPE_SHADER_TYPES;
988 if (ctx->gfx_stages[PIPE_SHADER_GEOMETRY])
989 ctx->last_vertex_stage = ctx->gfx_stages[PIPE_SHADER_GEOMETRY];
990 else if (ctx->gfx_stages[PIPE_SHADER_TESS_EVAL])
991 ctx->last_vertex_stage = ctx->gfx_stages[PIPE_SHADER_TESS_EVAL];
993 ctx->last_vertex_stage = ctx->gfx_stages[PIPE_SHADER_VERTEX];
994 enum pipe_shader_type current = ctx->last_vertex_stage ? pipe_shader_type_from_mesa(ctx->last_vertex_stage->nir->info.stage) : PIPE_SHADER_VERTEX;
997 memset(&ctx->gfx_pipeline_state.shader_keys.key[old].key.vs_base, 0, sizeof(struct zink_vs_key_base));
998 ctx->dirty_shader_stages |= BITFIELD_BIT(old);
1001 memset(&ctx->gfx_pipeline_state.shader_keys.key[PIPE_SHADER_VERTEX].key.vs_base, 0, sizeof(struct zink_vs_key_base));
1004 unsigned num_viewports = ctx->vp_state.num_viewports;
1005 struct zink_screen *screen = zink_screen(ctx->base.screen);
1007 if (ctx->last_vertex_stage) {
1008 if (ctx->last_vertex_stage->nir->info.outputs_written & (VARYING_BIT_VIEWPORT | VARYING_BIT_VIEWPORT_MASK))
1009 ctx->vp_state.num_viewports = MIN2(screen->info.props.limits.maxViewports, PIPE_MAX_VIEWPORTS);
1011 ctx->vp_state.num_viewports = 1;
1013 ctx->vp_state.num_viewports = 1;
1015 ctx->vp_state_changed |= num_viewports != ctx->vp_state.num_viewports;
1017 if (ctx->gfx_pipeline_state.dyn_state1.num_viewports != ctx->vp_state.num_viewports)
1018 ctx->gfx_pipeline_state.dirty = true;
1019 ctx->gfx_pipeline_state.dyn_state1.num_viewports = ctx->vp_state.num_viewports;
1021 ctx->last_vertex_stage_dirty = true;
1029 struct zink_context *ctx = zink_context(pctx);
1030 if (!cso && !ctx->gfx_stages[PIPE_SHADER_VERTEX])
1032 bind_stage(ctx, PIPE_SHADER_VERTEX, cso);
1033 bind_last_vertex_stage(ctx);
1036 ctx->shader_reads_drawid = BITSET_TEST(zs->nir->info.system_values_read, SYSTEM_VALUE_DRAW_ID);
1037 ctx->shader_reads_basevertex = BITSET_TEST(zs->nir->info.system_values_read, SYSTEM_VALUE_BASE_VERTEX);
1039 ctx->shader_reads_drawid = false;
1040 ctx->shader_reads_basevertex = false;
1049 zink_update_fs_key_samples(struct zink_context *ctx)
1051 if (!ctx->gfx_stages[PIPE_SHADER_FRAGMENT])
1053 nir_shader *nir = ctx->gfx_stages[PIPE_SHADER_FRAGMENT]->nir;
1055 bool samples = zink_get_fs_key(ctx)->samples;
1056 if (samples != (ctx->fb_state.samples > 1))
1057 zink_set_fs_key(ctx)->samples = ctx->fb_state.samples > 1;
1066 zink_update_fs_key_samples(struct zink_context *ctx)
1068 if (!ctx->gfx_stages[PIPE_SHADER_FRAGMENT])
1070 nir_shader *nir = ctx->gfx_stages[PIPE_SHADER_FRAGMENT]->nir;
1072 bool samples = zink_get_fs_key(ctx)->samples;
1073 if (samples != (ctx->fb_state.samples > 1))
1074 zink_set_fs_key(ctx)->samples = ctx->fb_state.samples > 1;
1082 struct zink_context *ctx = zink_context(pctx);
1083 if (!cso && !ctx->gfx_stages[PIPE_SHADER_FRAGMENT])
1085 bind_stage(ctx, PIPE_SHADER_FRAGMENT, cso);
1086 ctx->fbfetch_outputs = 0;
1088 nir_shader *nir = ctx->gfx_stages[PIPE_SHADER_FRAGMENT]->nir;
1090 nir_foreach_shader_out_variable(var, ctx->gfx_stages[PIPE_SHADER_FRAGMENT]->nir) {
1092 ctx->fbfetch_outputs |= BITFIELD_BIT(var->data.location - FRAG_RESULT_DATA0);
1095 zink_update_fs_key_samples(ctx);
1097 zink_update_fbfetch(ctx);
1104 struct zink_context *ctx = zink_context(pctx);
1105 if (!cso && !ctx->gfx_stages[PIPE_SHADER_GEOMETRY])
1107 bool had_points = ctx->gfx_stages[PIPE_SHADER_GEOMETRY] ? ctx->gfx_stages[PIPE_SHADER_GEOMETRY]->nir->info.gs.output_primitive == SHADER_PRIM_POINTS : false;
1108 bind_stage(ctx, PIPE_SHADER_GEOMETRY, cso);
1109 bind_last_vertex_stage(ctx);
1111 if (!had_points && ctx->last_vertex_stage->nir->info.gs.output_primitive == SHADER_PRIM_POINTS)
1112 ctx->gfx_pipeline_state.has_points++;
1115 ctx->gfx_pipeline_state.has_points--;
1130 struct zink_context *ctx = zink_context(pctx);
1131 if (!cso && !ctx->gfx_stages[PIPE_SHADER_TESS_EVAL])
1133 if (!!ctx->gfx_stages[PIPE_SHADER_TESS_EVAL] != !!cso) {
1136 if (ctx->gfx_stages[PIPE_SHADER_TESS_EVAL]->generated)
1137 ctx->gfx_stages[PIPE_SHADER_TESS_CTRL] = NULL;
1140 bind_stage(ctx, PIPE_SHADER_TESS_EVAL, cso);
1141 bind_last_vertex_stage(ctx);
1198 zink_program_init(struct zink_context *ctx)
1200 ctx->base.create_vs_state = zink_create_cached_shader_state;
1201 ctx->base.bind_vs_state = zink_bind_vs_state;
1202 ctx->base.delete_vs_state = zink_delete_cached_shader_state;
1204 ctx->base.create_fs_state = zink_create_cached_shader_state;
1205 ctx->base.bind_fs_state = zink_bind_fs_state;
1206 ctx->base.delete_fs_state = zink_delete_cached_shader_state;
1208 ctx->base.create_gs_state = zink_create_cached_shader_state;
1209 ctx->base.bind_gs_state = zink_bind_gs_state;
1210 ctx->base.delete_gs_state = zink_delete_cached_shader_state;
1212 ctx->base.create_tcs_state = zink_create_cached_shader_state;
1213 ctx->base.bind_tcs_state = zink_bind_tcs_state;
1214 ctx->base.delete_tcs_state = zink_delete_cached_shader_state;
1216 ctx->base.create_tes_state = zink_create_cached_shader_state;
1217 ctx->base.bind_tes_state = zink_bind_tes_state;
1218 ctx->base.delete_tes_state = zink_delete_cached_shader_state;
1220 ctx->base.create_compute_state = zink_create_cs_state;
1221 ctx->base.bind_compute_state = zink_bind_cs_state;
1222 ctx->base.delete_compute_state = zink_delete_shader_state;
1226 zink_set_rasterizer_discard(struct zink_context *ctx, bool disable)
1228 bool value = disable ? false : (ctx->rast_state ? ctx->rast_state->base.rasterizer_discard : false);
1229 bool changed = ctx->gfx_pipeline_state.dyn_state2.rasterizer_discard != value;
1230 ctx->gfx_pipeline_state.dyn_state2.rasterizer_discard = value;
1233 if (!zink_screen(ctx->base.screen)->info.have_EXT_extended_dynamic_state2)
1234 ctx->gfx_pipeline_state.dirty |= true;
1235 ctx->rasterizer_discard_changed = true;