@@ -530,6 +530,7 @@ update_cs_shader_module(struct zink_context *ctx, struct zink_compute_program *c
530
530
void
531
531
zink_update_compute_program (struct zink_context * ctx )
532
532
{
533
+ util_queue_fence_wait (& ctx -> curr_compute -> base .cache_fence );
533
534
update_cs_shader_module (ctx , ctx -> curr_compute );
534
535
}
535
536
@@ -740,8 +741,29 @@ precompile_compute_job(void *data, void *gdata, int thread_index)
740
741
struct zink_compute_program * comp = data ;
741
742
struct zink_screen * screen = gdata ;
742
743
744
+ comp -> shader = zink_shader_create (screen , comp -> nir , NULL );
745
+ comp -> curr = comp -> module = CALLOC_STRUCT (zink_shader_module );
746
+ assert (comp -> module );
747
+ comp -> module -> shader = zink_shader_compile (screen , comp -> shader , comp -> shader -> nir , NULL );
748
+ assert (comp -> module -> shader );
749
+ util_dynarray_init (& comp -> shader_cache [0 ], NULL );
750
+ util_dynarray_init (& comp -> shader_cache [1 ], NULL );
751
+
752
+ struct blob blob = {0 };
753
+ blob_init (& blob );
754
+ nir_serialize (& blob , comp -> shader -> nir , true);
755
+
756
+ struct mesa_sha1 sha1_ctx ;
757
+ _mesa_sha1_init (& sha1_ctx );
758
+ _mesa_sha1_update (& sha1_ctx , blob .data , blob .size );
759
+ _mesa_sha1_final (& sha1_ctx , comp -> base .sha1 );
760
+ blob_finish (& blob );
761
+
762
+ zink_descriptor_program_init (comp -> base .ctx , & comp -> base );
763
+
743
764
zink_screen_get_pipeline_cache (screen , & comp -> base , true);
744
- comp -> base_pipeline = zink_create_compute_pipeline (screen , comp , NULL );
765
+ if (comp -> base .can_precompile )
766
+ comp -> base_pipeline = zink_create_compute_pipeline (screen , comp , NULL );
745
767
if (comp -> base_pipeline )
746
768
zink_screen_update_pipeline_cache (screen , & comp -> base , true);
747
769
}
@@ -752,49 +774,19 @@ create_compute_program(struct zink_context *ctx, nir_shader *nir)
752
774
struct zink_screen * screen = zink_screen (ctx -> base .screen );
753
775
struct zink_compute_program * comp = create_program (ctx , true);
754
776
if (!comp )
755
- goto fail ;
756
-
757
- comp -> shader = zink_shader_create (screen , nir , NULL );
758
- comp -> curr = comp -> module = CALLOC_STRUCT (zink_shader_module );
759
- assert (comp -> module );
760
- comp -> module -> shader = zink_shader_compile (screen , comp -> shader , comp -> shader -> nir , NULL );
761
- assert (comp -> module -> shader );
762
- util_dynarray_init (& comp -> shader_cache [0 ], NULL );
763
- util_dynarray_init (& comp -> shader_cache [1 ], NULL );
777
+ return NULL ;
778
+ comp -> nir = nir ;
764
779
765
780
comp -> use_local_size = !(nir -> info .workgroup_size [0 ] ||
766
781
nir -> info .workgroup_size [1 ] ||
767
782
nir -> info .workgroup_size [2 ]);
768
-
783
+ comp -> base . can_precompile = ! comp -> use_local_size && ( screen -> info . have_EXT_non_seamless_cube_map || ! zink_shader_has_cubes ( nir ));
769
784
_mesa_hash_table_init (& comp -> pipelines , comp , NULL , comp -> use_local_size ?
770
785
equals_compute_pipeline_state_local_size :
771
786
equals_compute_pipeline_state );
772
-
773
- struct blob blob = {0 };
774
- blob_init (& blob );
775
- nir_serialize (& blob , nir , true);
776
-
777
- struct mesa_sha1 sha1_ctx ;
778
- _mesa_sha1_init (& sha1_ctx );
779
- _mesa_sha1_update (& sha1_ctx , blob .data , blob .size );
780
- _mesa_sha1_final (& sha1_ctx , comp -> base .sha1 );
781
- blob_finish (& blob );
782
-
783
- if (!zink_descriptor_program_init (ctx , & comp -> base ))
784
- goto fail ;
785
-
786
- if (comp -> use_local_size || (!screen -> info .have_EXT_non_seamless_cube_map && comp -> shader -> has_cubes )) {
787
- zink_screen_get_pipeline_cache (screen , & comp -> base , false);
788
- } else {
789
- comp -> base .can_precompile = true;
790
- util_queue_add_job (& screen -> cache_get_thread , comp , & comp -> base .cache_fence , precompile_compute_job , NULL , 0 );
791
- }
787
+ util_queue_add_job (& screen -> cache_get_thread , comp , & comp -> base .cache_fence ,
788
+ precompile_compute_job , NULL , 0 );
792
789
return comp ;
793
-
794
- fail :
795
- if (comp )
796
- zink_destroy_compute_program (ctx , comp );
797
- return NULL ;
798
790
}
799
791
800
792
uint32_t
@@ -988,6 +980,12 @@ zink_destroy_compute_program(struct zink_context *ctx,
988
980
ralloc_free (comp );
989
981
}
990
982
983
+ ALWAYS_INLINE static bool
984
+ compute_can_shortcut (const struct zink_compute_program * comp )
985
+ {
986
+ return !comp -> use_local_size && !comp -> curr -> num_uniforms && !comp -> curr -> has_nonseamless ;
987
+ }
988
+
991
989
VkPipeline
992
990
zink_get_compute_pipeline (struct zink_screen * screen ,
993
991
struct zink_compute_program * comp ,
@@ -1007,21 +1005,22 @@ zink_get_compute_pipeline(struct zink_screen *screen,
1007
1005
state -> dirty = false;
1008
1006
state -> final_hash ^= state -> hash ;
1009
1007
}
1010
- if (!comp -> use_local_size && !comp -> curr -> num_uniforms && !comp -> curr -> has_nonseamless && comp -> base_pipeline ) {
1008
+
1009
+ util_queue_fence_wait (& comp -> base .cache_fence );
1010
+ if (comp -> base_pipeline && compute_can_shortcut (comp )) {
1011
1011
state -> pipeline = comp -> base_pipeline ;
1012
1012
return state -> pipeline ;
1013
1013
}
1014
1014
entry = _mesa_hash_table_search_pre_hashed (& comp -> pipelines , state -> final_hash , state );
1015
1015
1016
1016
if (!entry ) {
1017
- util_queue_fence_wait (& comp -> base .cache_fence );
1018
1017
VkPipeline pipeline = zink_create_compute_pipeline (screen , comp , state );
1019
1018
1020
1019
if (pipeline == VK_NULL_HANDLE )
1021
1020
return VK_NULL_HANDLE ;
1022
1021
1023
1022
zink_screen_update_pipeline_cache (screen , & comp -> base , false);
1024
- if (! comp -> use_local_size && ! comp -> curr -> num_uniforms && ! comp -> curr -> has_nonseamless ) {
1023
+ if (compute_can_shortcut ( comp ) ) {
1025
1024
/* don't add base pipeline to cache */
1026
1025
state -> pipeline = comp -> base_pipeline = pipeline ;
1027
1026
return state -> pipeline ;
@@ -1234,7 +1233,7 @@ zink_bind_cs_state(struct pipe_context *pctx,
1234
1233
{
1235
1234
struct zink_context * ctx = zink_context (pctx );
1236
1235
struct zink_compute_program * comp = cso ;
1237
- if (comp && comp -> shader -> nir -> info .num_inlinable_uniforms )
1236
+ if (comp && comp -> nir -> info .num_inlinable_uniforms )
1238
1237
ctx -> shader_has_inlinable_uniforms_mask |= 1 << MESA_SHADER_COMPUTE ;
1239
1238
else
1240
1239
ctx -> shader_has_inlinable_uniforms_mask &= ~(1 << MESA_SHADER_COMPUTE );
@@ -1249,7 +1248,8 @@ zink_bind_cs_state(struct pipe_context *pctx,
1249
1248
ctx -> curr_compute = comp ;
1250
1249
if (comp && comp != ctx -> curr_compute ) {
1251
1250
ctx -> compute_pipeline_state .module_hash = ctx -> curr_compute -> curr -> hash ;
1252
- ctx -> compute_pipeline_state .module = ctx -> curr_compute -> curr -> shader ;
1251
+ if (util_queue_fence_is_signalled (& comp -> base .cache_fence ))
1252
+ ctx -> compute_pipeline_state .module = ctx -> curr_compute -> curr -> shader ;
1253
1253
ctx -> compute_pipeline_state .final_hash ^= ctx -> compute_pipeline_state .module_hash ;
1254
1254
if (ctx -> compute_pipeline_state .key .base .nonseamless_cube_mask )
1255
1255
ctx -> dirty_shader_stages |= BITFIELD_BIT (MESA_SHADER_COMPUTE );
0 commit comments