From a9d8d606ccf3d809a9adfd529be8d1ceaf1dd799 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 28 Jul 2022 13:18:47 +1000 Subject: [PATCH] llvmpipe/gallivm/draw: introduce a buffer type. In order to do vulkan properly we need to move towards proper descriptor based operations for the shader. This is a bit of a precursor, this consolidates the ubo/ssbo stuff into a buffer type and uses that in the backend. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/draw/draw_llvm.c | 113 ++++++----------- src/gallium/auxiliary/draw/draw_llvm.h | 115 ++++++------------ .../draw/draw_pt_fetch_shade_pipeline_llvm.c | 52 ++++---- .../auxiliary/gallivm/lp_bld_jit_types.c | 105 ++++++++++++++++ .../auxiliary/gallivm/lp_bld_jit_types.h | 56 +++++++++ src/gallium/auxiliary/gallivm/lp_bld_nir.h | 2 - .../auxiliary/gallivm/lp_bld_nir_soa.c | 15 ++- src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 2 - .../auxiliary/gallivm/lp_bld_tgsi_soa.c | 18 +-- src/gallium/auxiliary/meson.build | 2 + src/gallium/drivers/llvmpipe/lp_jit.c | 36 ++---- src/gallium/drivers/llvmpipe/lp_jit.h | 29 +---- src/gallium/drivers/llvmpipe/lp_linear.c | 4 +- src/gallium/drivers/llvmpipe/lp_setup.c | 14 +-- src/gallium/drivers/llvmpipe/lp_setup_tri.c | 2 +- src/gallium/drivers/llvmpipe/lp_state_cs.c | 24 ++-- src/gallium/drivers/llvmpipe/lp_state_fs.c | 5 - 17 files changed, 313 insertions(+), 281 deletions(-) create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_jit_types.c create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_jit_types.h diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index aaf4b309a86..afa389a6844 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -309,32 +309,28 @@ create_jit_image_type(struct gallivm_state *gallivm, const char *struct_name) static LLVMTypeRef create_jit_context_type(struct gallivm_state *gallivm, const char *struct_name) { + LLVMTypeRef buffer_type = lp_build_create_jit_buffer_type(gallivm); LLVMTypeRef texture_type = create_jit_texture_type(gallivm, "texture"); LLVMTypeRef sampler_type = create_jit_sampler_type(gallivm, "sampler"); LLVMTypeRef image_type = create_jit_image_type(gallivm, "image"); LLVMTargetDataRef target = gallivm->target; LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); - LLVMTypeRef int_type = LLVMInt32TypeInContext(gallivm->context); LLVMTypeRef elem_types[DRAW_JIT_CTX_NUM_FIELDS]; - elem_types[DRAW_JIT_CTX_CONSTANTS] = LLVMArrayType(LLVMPointerType(float_type, 0), LP_MAX_TGSI_CONST_BUFFERS); - elem_types[DRAW_JIT_CTX_NUM_CONSTANTS] = LLVMArrayType(int_type, LP_MAX_TGSI_CONST_BUFFERS); + elem_types[DRAW_JIT_CTX_CONSTANTS] = LLVMArrayType(buffer_type, LP_MAX_TGSI_CONST_BUFFERS); elem_types[DRAW_JIT_CTX_PLANES] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), DRAW_TOTAL_CLIP_PLANES), 0); elem_types[DRAW_JIT_CTX_VIEWPORT] = LLVMPointerType(float_type, 0); elem_types[DRAW_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type, PIPE_MAX_SHADER_SAMPLER_VIEWS); elem_types[DRAW_JIT_CTX_SAMPLERS] = LLVMArrayType(sampler_type, PIPE_MAX_SAMPLERS); elem_types[DRAW_JIT_CTX_IMAGES] = LLVMArrayType(image_type, PIPE_MAX_SHADER_IMAGES); - elem_types[DRAW_JIT_CTX_SSBOS] = LLVMArrayType(LLVMPointerType(int_type, 0), LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[DRAW_JIT_CTX_NUM_SSBOS] = LLVMArrayType(int_type, LP_MAX_TGSI_SHADER_BUFFERS); + elem_types[DRAW_JIT_CTX_SSBOS] = LLVMArrayType(buffer_type, LP_MAX_TGSI_SHADER_BUFFERS); elem_types[DRAW_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(float_type, 0); LLVMTypeRef context_type = LLVMStructTypeInContext(gallivm->context, elem_types, ARRAY_SIZE(elem_types), 0); (void) target; /* silence unused var warning for non-debug build */ - LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants, + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, constants, target, context_type, DRAW_JIT_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, num_vs_constants, - target, context_type, DRAW_JIT_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes, target, context_type, DRAW_JIT_CTX_PLANES); LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, viewports, @@ -347,10 +343,8 @@ create_jit_context_type(struct gallivm_state *gallivm, const char *struct_name) DRAW_JIT_CTX_SAMPLERS); LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, images, target, context_type, DRAW_JIT_CTX_IMAGES); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_ssbos, + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, ssbos, target, context_type, DRAW_JIT_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, num_vs_ssbos, - target, context_type, DRAW_JIT_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, aniso_filter_table, target, context_type, DRAW_JIT_CTX_ANISO_FILTER_TABLE); LP_CHECK_STRUCT_SIZE(struct draw_jit_context, @@ -366,6 +360,7 @@ create_jit_context_type(struct gallivm_state *gallivm, const char *struct_name) static LLVMTypeRef create_gs_jit_context_type(struct gallivm_state *gallivm, unsigned vector_length, + LLVMTypeRef buffer_type, LLVMTypeRef texture_type, LLVMTypeRef sampler_type, LLVMTypeRef image_type, const char *struct_name) @@ -376,10 +371,8 @@ create_gs_jit_context_type(struct gallivm_state *gallivm, LLVMTypeRef elem_types[DRAW_GS_JIT_CTX_NUM_FIELDS]; LLVMTypeRef context_type; - elem_types[DRAW_GS_JIT_CTX_CONSTANTS] = LLVMArrayType(LLVMPointerType(float_type, 0), /* constants */ + elem_types[DRAW_GS_JIT_CTX_CONSTANTS] = LLVMArrayType(buffer_type, /* constants */ LP_MAX_TGSI_CONST_BUFFERS); - elem_types[DRAW_GS_JIT_CTX_NUM_CONSTANTS] = LLVMArrayType(int_type, /* num_constants */ - LP_MAX_TGSI_CONST_BUFFERS); elem_types[DRAW_GS_JIT_CTX_PLANES] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), DRAW_TOTAL_CLIP_PLANES), 0); elem_types[DRAW_GS_JIT_CTX_VIEWPORT] = LLVMPointerType(float_type, 0); /* viewports */ @@ -396,10 +389,8 @@ create_gs_jit_context_type(struct gallivm_state *gallivm, elem_types[DRAW_GS_JIT_CTX_EMITTED_PRIMS] = LLVMPointerType(LLVMVectorType(int_type, vector_length), 0); - elem_types[DRAW_GS_JIT_CTX_SSBOS] = LLVMArrayType(LLVMPointerType(int_type, 0), /* ssbos */ + elem_types[DRAW_GS_JIT_CTX_SSBOS] = LLVMArrayType(buffer_type, /* ssbos */ LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[DRAW_GS_JIT_CTX_NUM_SSBOS] = LLVMArrayType(int_type, /* num_ssbos */ - LP_MAX_TGSI_SHADER_BUFFERS); elem_types[DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(float_type, 0); /* aniso table */ context_type = LLVMStructTypeInContext(gallivm->context, elem_types, @@ -408,8 +399,6 @@ create_gs_jit_context_type(struct gallivm_state *gallivm, (void) target; /* silence unused var warning for non-debug build */ LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, constants, target, context_type, DRAW_GS_JIT_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, num_constants, - target, context_type, DRAW_GS_JIT_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, planes, target, context_type, DRAW_GS_JIT_CTX_PLANES); LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, viewports, @@ -431,8 +420,6 @@ create_gs_jit_context_type(struct gallivm_state *gallivm, DRAW_GS_JIT_CTX_EMITTED_PRIMS); LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, ssbos, target, context_type, DRAW_GS_JIT_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, num_ssbos, - target, context_type, DRAW_GS_JIT_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, images, target, context_type, DRAW_GS_JIT_CTX_IMAGES); LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, aniso_filter_table, @@ -547,20 +534,19 @@ create_jit_vertex_header(struct gallivm_state *gallivm, int data_elems) static LLVMTypeRef create_tcs_jit_context_type(struct gallivm_state *gallivm, unsigned vector_length, + LLVMTypeRef buffer_type, LLVMTypeRef texture_type, LLVMTypeRef sampler_type, LLVMTypeRef image_type, const char *struct_name) { LLVMTargetDataRef target = gallivm->target; LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); - LLVMTypeRef int_type = LLVMInt32TypeInContext(gallivm->context); LLVMTypeRef elem_types[DRAW_TCS_JIT_CTX_NUM_FIELDS]; LLVMTypeRef context_type; - elem_types[DRAW_TCS_JIT_CTX_CONSTANTS] = LLVMArrayType(LLVMPointerType(float_type, 0), /* constants */ + + elem_types[DRAW_TCS_JIT_CTX_CONSTANTS] = LLVMArrayType(buffer_type, /* constants */ LP_MAX_TGSI_CONST_BUFFERS); - elem_types[DRAW_TCS_JIT_CTX_NUM_CONSTANTS] = LLVMArrayType(int_type, /* num_constants */ - LP_MAX_TGSI_CONST_BUFFERS); elem_types[DRAW_TCS_JIT_CTX_DUMMY1] = LLVMInt32TypeInContext(gallivm->context); elem_types[DRAW_TCS_JIT_CTX_DUMMY2] = LLVMInt32TypeInContext(gallivm->context); @@ -571,19 +557,16 @@ create_tcs_jit_context_type(struct gallivm_state *gallivm, elem_types[DRAW_TCS_JIT_CTX_IMAGES] = LLVMArrayType(image_type, PIPE_MAX_SHADER_IMAGES); /* images */ - elem_types[DRAW_TCS_JIT_CTX_SSBOS] = LLVMArrayType(LLVMPointerType(int_type, 0), /* ssbos */ + elem_types[DRAW_TCS_JIT_CTX_SSBOS] = LLVMArrayType(buffer_type, /* ssbos */ LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[DRAW_TCS_JIT_CTX_NUM_SSBOS] = LLVMArrayType(int_type, /* num_ssbos */ - LP_MAX_TGSI_SHADER_BUFFERS); elem_types[DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(float_type, 0); /* aniso table */ + context_type = LLVMStructTypeInContext(gallivm->context, elem_types, ARRAY_SIZE(elem_types), 0); (void) target; /* silence unused var warning for non-debug build */ LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, constants, target, context_type, DRAW_TCS_JIT_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, num_constants, - target, context_type, DRAW_TCS_JIT_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, textures, target, context_type, DRAW_TCS_JIT_CTX_TEXTURES); @@ -592,8 +575,6 @@ create_tcs_jit_context_type(struct gallivm_state *gallivm, DRAW_TCS_JIT_CTX_SAMPLERS); LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, ssbos, target, context_type, DRAW_TCS_JIT_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, num_ssbos, - target, context_type, DRAW_TCS_JIT_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, images, target, context_type, DRAW_TCS_JIT_CTX_IMAGES); LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, aniso_filter_table, @@ -648,20 +629,18 @@ create_tes_jit_input_deref_type(struct gallivm_state *gallivm) static LLVMTypeRef create_tes_jit_context_type(struct gallivm_state *gallivm, unsigned vector_length, + LLVMTypeRef buffer_type, LLVMTypeRef texture_type, LLVMTypeRef sampler_type, LLVMTypeRef image_type, const char *struct_name) { LLVMTargetDataRef target = gallivm->target; LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); - LLVMTypeRef int_type = LLVMInt32TypeInContext(gallivm->context); LLVMTypeRef elem_types[DRAW_TES_JIT_CTX_NUM_FIELDS]; LLVMTypeRef context_type; - elem_types[DRAW_TES_JIT_CTX_CONSTANTS] = LLVMArrayType(LLVMPointerType(float_type, 0), /* constants */ + elem_types[DRAW_TES_JIT_CTX_CONSTANTS] = LLVMArrayType(buffer_type, /* constants */ LP_MAX_TGSI_CONST_BUFFERS); - elem_types[DRAW_TES_JIT_CTX_NUM_CONSTANTS] = LLVMArrayType(int_type, /* num_constants */ - LP_MAX_TGSI_CONST_BUFFERS); elem_types[DRAW_TES_JIT_CTX_DUMMY1] = LLVMInt32TypeInContext(gallivm->context); elem_types[DRAW_TES_JIT_CTX_DUMMY2] = LLVMInt32TypeInContext(gallivm->context); @@ -672,19 +651,16 @@ create_tes_jit_context_type(struct gallivm_state *gallivm, elem_types[DRAW_TES_JIT_CTX_IMAGES] = LLVMArrayType(image_type, PIPE_MAX_SHADER_IMAGES); /* images */ - elem_types[DRAW_TES_JIT_CTX_SSBOS] = LLVMArrayType(LLVMPointerType(int_type, 0), /* ssbos */ + elem_types[DRAW_TES_JIT_CTX_SSBOS] = LLVMArrayType(buffer_type, /* ssbos */ LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[DRAW_TES_JIT_CTX_NUM_SSBOS] = LLVMArrayType(int_type, /* num_ssbos */ - LP_MAX_TGSI_SHADER_BUFFERS); elem_types[DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(float_type, 0); /* aniso table */ + context_type = LLVMStructTypeInContext(gallivm->context, elem_types, ARRAY_SIZE(elem_types), 0); (void) target; /* silence unused var warning for non-debug build */ LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, constants, target, context_type, DRAW_TES_JIT_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, num_constants, - target, context_type, DRAW_TES_JIT_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, textures, target, context_type, DRAW_TES_JIT_CTX_TEXTURES); @@ -693,8 +669,6 @@ create_tes_jit_context_type(struct gallivm_state *gallivm, DRAW_TES_JIT_CTX_SAMPLERS); LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, ssbos, target, context_type, DRAW_TES_JIT_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, num_ssbos, - target, context_type, DRAW_TES_JIT_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct draw_tes_jit_context, images, target, context_type, DRAW_TES_JIT_CTX_IMAGES); LP_CHECK_MEMBER_OFFSET(struct draw_tcs_jit_context, aniso_filter_table, @@ -968,13 +942,9 @@ generate_vs(struct draw_llvm_variant *variant, struct draw_llvm *llvm = variant->llvm; const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; LLVMValueRef consts_ptr = - draw_jit_context_vs_constants(variant, context_ptr); - LLVMValueRef num_consts_ptr = - draw_jit_context_num_vs_constants(variant, context_ptr); + draw_jit_context_constants(variant, context_ptr); LLVMValueRef ssbos_ptr = - draw_jit_context_vs_ssbos(variant, context_ptr); - LLVMValueRef num_ssbos_ptr = - draw_jit_context_num_vs_ssbos(variant, context_ptr); + draw_jit_context_ssbos(variant, context_ptr); struct lp_build_tgsi_params params; memset(¶ms, 0, sizeof(params)); @@ -982,14 +952,12 @@ generate_vs(struct draw_llvm_variant *variant, params.type = vs_type; params.mask = bld_mask; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = system_values; params.inputs = inputs; params.context_ptr = context_ptr; params.sampler = draw_sampler; params.info = &llvm->draw->vs.vertex_shader->info; params.ssbo_ptr = ssbos_ptr; - params.ssbo_sizes_ptr = num_ssbos_ptr; params.image = draw_image; params.aniso_filter_table = draw_jit_context_aniso_filter_table(variant, context_ptr); @@ -2689,14 +2657,16 @@ static void create_gs_jit_types(struct draw_gs_llvm_variant *var) { struct gallivm_state *gallivm = var->gallivm; - LLVMTypeRef texture_type, sampler_type, image_type; + LLVMTypeRef texture_type, sampler_type, image_type, buffer_type; texture_type = create_jit_texture_type(gallivm, "texture"); sampler_type = create_jit_sampler_type(gallivm, "sampler"); image_type = create_jit_image_type(gallivm, "image"); + buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_gs_jit_context_type(gallivm, var->shader->base.vector_length, + buffer_type, texture_type, sampler_type, image_type, "draw_gs_jit_context"); @@ -2760,8 +2730,8 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, unsigned i; struct draw_gs_llvm_iface gs_iface; const struct tgsi_token *tokens = variant->shader->base.state.tokens; - LLVMValueRef consts_ptr, num_consts_ptr; - LLVMValueRef ssbos_ptr, num_ssbos_ptr; + LLVMValueRef consts_ptr; + LLVMValueRef ssbos_ptr; LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][TGSI_NUM_CHANNELS]; struct lp_build_mask_context mask; const struct tgsi_shader_info *gs_info = &variant->shader->base.info; @@ -2845,12 +2815,8 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, gs_type.length = vector_length; consts_ptr = draw_gs_jit_context_constants(variant, context_ptr); - num_consts_ptr = - draw_gs_jit_context_num_constants(variant, context_ptr); ssbos_ptr = draw_gs_jit_context_ssbos(variant, context_ptr); - num_ssbos_ptr = - draw_gs_jit_context_num_ssbos(variant, context_ptr); /* code generated texture sampling */ sampler = draw_llvm_sampler_soa_create(variant->key.samplers, @@ -2879,14 +2845,12 @@ draw_gs_llvm_generate(struct draw_llvm *llvm, params.type = gs_type; params.mask = &mask; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = &system_values; params.context_ptr = context_ptr; params.sampler = sampler; params.info = &llvm->draw->gs.geometry_shader->info; params.gs_iface = (const struct lp_build_gs_iface *)&gs_iface; params.ssbo_ptr = ssbos_ptr; - params.ssbo_sizes_ptr = num_ssbos_ptr; params.image = image; params.gs_vertex_streams = variant->shader->base.num_vertex_streams; params.aniso_filter_table = draw_gs_jit_context_aniso_filter_table(variant, context_ptr); @@ -3075,14 +3039,16 @@ static void create_tcs_jit_types(struct draw_tcs_llvm_variant *var) { struct gallivm_state *gallivm = var->gallivm; - LLVMTypeRef texture_type, sampler_type, image_type; + LLVMTypeRef texture_type, sampler_type, image_type, buffer_type; texture_type = create_jit_texture_type(gallivm, "texture"); sampler_type = create_jit_sampler_type(gallivm, "sampler"); image_type = create_jit_image_type(gallivm, "image"); + buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_tcs_jit_context_type(gallivm, 0, + buffer_type, texture_type, sampler_type, image_type, "draw_tcs_jit_context"); @@ -3350,8 +3316,8 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, unsigned i; struct draw_tcs_llvm_iface tcs_iface; struct lp_build_mask_context mask; - LLVMValueRef consts_ptr, num_consts_ptr; - LLVMValueRef ssbos_ptr, num_ssbos_ptr; + LLVMValueRef consts_ptr; + LLVMValueRef ssbos_ptr; struct lp_type tcs_type; unsigned vector_length = variant->shader->base.vector_length; @@ -3489,12 +3455,8 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, view_index = LLVMGetParam(variant_coro, 5); consts_ptr = draw_tcs_jit_context_constants(variant, context_ptr); - num_consts_ptr = - draw_tcs_jit_context_num_constants(variant, context_ptr); ssbos_ptr = draw_tcs_jit_context_ssbos(variant, context_ptr); - num_ssbos_ptr = - draw_tcs_jit_context_num_ssbos(variant, context_ptr); sampler = draw_llvm_sampler_soa_create(variant->key.samplers, MAX2(variant->key.nr_samplers, variant->key.nr_sampler_views)); @@ -3541,13 +3503,11 @@ draw_tcs_llvm_generate(struct draw_llvm *llvm, params.type = tcs_type; params.mask = &mask; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = &system_values; params.context_ptr = context_ptr; params.sampler = sampler; params.info = &llvm->draw->tcs.tess_ctrl_shader->info; params.ssbo_ptr = ssbos_ptr; - params.ssbo_sizes_ptr = num_ssbos_ptr; params.image = image; params.coro = &coro_info; params.tcs_iface = &tcs_iface.base; @@ -3737,14 +3697,16 @@ static void create_tes_jit_types(struct draw_tes_llvm_variant *var) { struct gallivm_state *gallivm = var->gallivm; - LLVMTypeRef texture_type, sampler_type, image_type; + LLVMTypeRef texture_type, sampler_type, image_type, buffer_type; texture_type = create_jit_texture_type(gallivm, "texture"); sampler_type = create_jit_sampler_type(gallivm, "sampler"); image_type = create_jit_image_type(gallivm, "image"); + buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_tes_jit_context_type(gallivm, 0, + buffer_type, texture_type, sampler_type, image_type, "draw_tes_jit_context"); @@ -3924,8 +3886,8 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, struct draw_tes_llvm_iface tes_iface; LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][TGSI_NUM_CHANNELS]; struct lp_build_mask_context mask; - LLVMValueRef consts_ptr, num_consts_ptr; - LLVMValueRef ssbos_ptr, num_ssbos_ptr; + LLVMValueRef consts_ptr; + LLVMValueRef ssbos_ptr; LLVMValueRef step; struct lp_type tes_type; unsigned vector_length = variant->shader->base.vector_length; @@ -4006,12 +3968,9 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, lp_build_context_init(&bldvec, variant->gallivm, lp_int_type(tes_type)); consts_ptr = draw_tes_jit_context_constants(variant, context_ptr); - num_consts_ptr = - draw_tes_jit_context_num_constants(variant, context_ptr); ssbos_ptr = draw_tes_jit_context_ssbos(variant, context_ptr); - num_ssbos_ptr = - draw_tes_jit_context_num_ssbos(variant, context_ptr); + sampler = draw_llvm_sampler_soa_create(variant->key.samplers, MAX2(variant->key.nr_samplers, variant->key.nr_sampler_views)); @@ -4071,13 +4030,11 @@ draw_tes_llvm_generate(struct draw_llvm *llvm, params.type = tes_type; params.mask = &mask; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = &system_values; params.context_ptr = context_ptr; params.sampler = sampler; params.info = &llvm->draw->tes.tess_eval_shader->info; params.ssbo_ptr = ssbos_ptr; - params.ssbo_sizes_ptr = num_ssbos_ptr; params.image = image; params.tes_iface = &tes_iface.base; params.aniso_filter_table = draw_tes_jit_context_aniso_filter_table(variant, context_ptr); diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index 54a992db175..b67d7d041ed 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -36,6 +36,7 @@ #include "gallivm/lp_bld_sample.h" #include "gallivm/lp_bld_limits.h" +#include "gallivm/lp_bld_jit_types.h" #include "pipe/p_context.h" #include "util/list.h" @@ -159,8 +160,7 @@ enum { */ struct draw_jit_context { - const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; float (*planes) [DRAW_TOTAL_CLIP_PLANES][4]; struct pipe_viewport_state *viewports; @@ -168,31 +168,25 @@ struct draw_jit_context struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS]; struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; - const uint32_t *vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_vs_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; const float *aniso_filter_table; }; enum { DRAW_JIT_CTX_CONSTANTS = 0, - DRAW_JIT_CTX_NUM_CONSTANTS = 1, - DRAW_JIT_CTX_PLANES = 2, - DRAW_JIT_CTX_VIEWPORT = 3, - DRAW_JIT_CTX_TEXTURES = 4, - DRAW_JIT_CTX_SAMPLERS = 5, - DRAW_JIT_CTX_IMAGES = 6, - DRAW_JIT_CTX_SSBOS = 7, - DRAW_JIT_CTX_NUM_SSBOS = 8, - DRAW_JIT_CTX_ANISO_FILTER_TABLE = 9, + DRAW_JIT_CTX_PLANES = 1, + DRAW_JIT_CTX_VIEWPORT = 2, + DRAW_JIT_CTX_TEXTURES = 3, + DRAW_JIT_CTX_SAMPLERS = 4, + DRAW_JIT_CTX_IMAGES = 5, + DRAW_JIT_CTX_SSBOS = 6, + DRAW_JIT_CTX_ANISO_FILTER_TABLE = 7, DRAW_JIT_CTX_NUM_FIELDS }; -#define draw_jit_context_vs_constants(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants") - -#define draw_jit_context_num_vs_constants(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants") +#define draw_jit_context_constants(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_CONSTANTS, "constants") #define draw_jit_context_planes(_gallivm, _type, _ptr) \ lp_build_struct_get2(_gallivm, _type, _ptr, DRAW_JIT_CTX_PLANES, "planes") @@ -209,11 +203,8 @@ enum { #define draw_jit_context_images(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_IMAGES, "images") -#define draw_jit_context_vs_ssbos(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_SSBOS, "vs_ssbos") - -#define draw_jit_context_num_vs_ssbos(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_NUM_SSBOS, "num_vs_ssbos") +#define draw_jit_context_ssbos(_variant, _ptr) \ + lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_SSBOS, "ssbos") #define draw_jit_context_aniso_filter_table(_variant, _ptr) \ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") @@ -261,8 +252,7 @@ enum { */ struct draw_gs_jit_context { - const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; float (*planes) [DRAW_TOTAL_CLIP_PLANES][4]; struct pipe_viewport_state *viewports; @@ -275,17 +265,15 @@ struct draw_gs_jit_context int **prim_lengths; int *emitted_vertices; int *emitted_prims; - const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; const float *aniso_filter_table; }; enum { DRAW_GS_JIT_CTX_CONSTANTS = 0, - DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1, - DRAW_GS_JIT_CTX_PLANES = 2, - DRAW_GS_JIT_CTX_VIEWPORT = 3, + DRAW_GS_JIT_CTX_PLANES = 1, + DRAW_GS_JIT_CTX_VIEWPORT = 2, /* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES * and DRAW_JIT_CTX_SAMPLERS, because they both need * to be at exactly the same locations as they are in the @@ -293,21 +281,17 @@ enum { DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES, DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS, DRAW_GS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES, - DRAW_GS_JIT_CTX_PRIM_LENGTHS = 7, - DRAW_GS_JIT_CTX_EMITTED_VERTICES = 8, - DRAW_GS_JIT_CTX_EMITTED_PRIMS = 9, - DRAW_GS_JIT_CTX_SSBOS = 10, - DRAW_GS_JIT_CTX_NUM_SSBOS = 11, - DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE = 12, - DRAW_GS_JIT_CTX_NUM_FIELDS = 13 + DRAW_GS_JIT_CTX_PRIM_LENGTHS = 6, + DRAW_GS_JIT_CTX_EMITTED_VERTICES = 7, + DRAW_GS_JIT_CTX_EMITTED_PRIMS = 8, + DRAW_GS_JIT_CTX_SSBOS = 9, + DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE = 10, + DRAW_GS_JIT_CTX_NUM_FIELDS = 11 }; #define draw_gs_jit_context_constants(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants") -#define draw_gs_jit_context_num_constants(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants") - #define draw_gs_jit_context_planes(_gallivm, _ptr) \ lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes") @@ -335,15 +319,11 @@ enum { #define draw_gs_jit_context_ssbos(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_SSBOS, "ssbos") -#define draw_gs_jit_context_num_ssbos(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_NUM_SSBOS, "num_ssbos") - #define draw_gs_jit_context_aniso_filter_table(_variant, _ptr) \ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_GS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") struct draw_tcs_jit_context { - const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; int dummy1; int dummy2; @@ -353,32 +333,26 @@ struct draw_tcs_jit_context { struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS]; struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; - const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; const float *aniso_filter_table; }; enum { DRAW_TCS_JIT_CTX_CONSTANTS = 0, - DRAW_TCS_JIT_CTX_NUM_CONSTANTS = 1, - DRAW_TCS_JIT_CTX_DUMMY1 = 2, - DRAW_TCS_JIT_CTX_DUMMY2 = 3, + DRAW_TCS_JIT_CTX_DUMMY1 = 1, + DRAW_TCS_JIT_CTX_DUMMY2 = 2, DRAW_TCS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES, DRAW_TCS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS, DRAW_TCS_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES, - DRAW_TCS_JIT_CTX_SSBOS = 7, - DRAW_TCS_JIT_CTX_NUM_SSBOS = 8, - DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE = 9, - DRAW_TCS_JIT_CTX_NUM_FIELDS = 10, + DRAW_TCS_JIT_CTX_SSBOS = 6, + DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE = 7, + DRAW_TCS_JIT_CTX_NUM_FIELDS = 8, }; #define draw_tcs_jit_context_constants(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_CONSTANTS, "constants") -#define draw_tcs_jit_context_num_constants(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_NUM_CONSTANTS, "num_constants") - #define draw_tcs_jit_context_textures(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TCS_JIT_CTX_TEXTURES, "textures") @@ -391,15 +365,11 @@ enum { #define draw_tcs_jit_context_ssbos(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_SSBOS, "ssbos") -#define draw_tcs_jit_context_num_ssbos(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_NUM_SSBOS, "num_ssbos") - #define draw_tcs_jit_context_aniso_filter_table(_variant, _ptr) \ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TCS_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") struct draw_tes_jit_context { - const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; int dummy1; int dummy2; @@ -409,32 +379,26 @@ struct draw_tes_jit_context { struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS]; struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; - const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; const float *aniso_filter_table; }; enum { DRAW_TES_JIT_CTX_CONSTANTS = 0, - DRAW_TES_JIT_CTX_NUM_CONSTANTS = 1, - DRAW_TES_JIT_CTX_DUMMY1 = 2, - DRAW_TES_JIT_CTX_DUMMY2 = 3, + DRAW_TES_JIT_CTX_DUMMY1 = 1, + DRAW_TES_JIT_CTX_DUMMY2 = 2, DRAW_TES_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES, DRAW_TES_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS, DRAW_TES_JIT_CTX_IMAGES = DRAW_JIT_CTX_IMAGES, - DRAW_TES_JIT_CTX_SSBOS = 7, - DRAW_TES_JIT_CTX_NUM_SSBOS = 8, - DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE = 9, - DRAW_TES_JIT_CTX_NUM_FIELDS = 10, + DRAW_TES_JIT_CTX_SSBOS = 6, + DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE = 7, + DRAW_TES_JIT_CTX_NUM_FIELDS = 8, }; #define draw_tes_jit_context_constants(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_CONSTANTS, "constants") -#define draw_tes_jit_context_num_constants(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_NUM_CONSTANTS, "num_constants") - #define draw_tes_jit_context_textures(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_TES_JIT_CTX_TEXTURES, "textures") @@ -447,9 +411,6 @@ enum { #define draw_tes_jit_context_ssbos(_variant, _ptr) \ lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_SSBOS, "ssbos") -#define draw_tes_jit_context_num_ssbos(_variant, _ptr) \ - lp_build_struct_get_ptr2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_NUM_SSBOS, "num_ssbos") - #define draw_tes_jit_context_aniso_filter_table(_variant, _ptr) \ lp_build_struct_get2(_variant->gallivm, _variant->context_type, _ptr, DRAW_TES_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table") diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c index 9e353adce3a..5d37c430094 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c @@ -439,76 +439,76 @@ llvm_middle_end_bind_parameters(struct draw_pt_middle_end *middle) struct draw_llvm *llvm = fpme->llvm; unsigned i; - for (i = 0; i < ARRAY_SIZE(llvm->jit_context.vs_constants); ++i) { + for (i = 0; i < ARRAY_SIZE(llvm->jit_context.constants); ++i) { /* * There could be a potential issue with rounding this up, as the * shader expects 16-byte allocations, the fix is likely to move * to LOAD intrinsic in the future and remove the vec4 constraint. */ int num_consts = get_num_consts_robust(draw, draw->pt.user.vs_constants_size, i); - llvm->jit_context.vs_constants[i] = draw->pt.user.vs_constants[i]; - llvm->jit_context.num_vs_constants[i] = num_consts; + llvm->jit_context.constants[i].f = draw->pt.user.vs_constants[i]; + llvm->jit_context.constants[i].num_elements = num_consts; if (num_consts == 0) { - llvm->jit_context.vs_constants[i] = fake_const_buf; + llvm->jit_context.constants[i].f = fake_const_buf; } } - for (i = 0; i < ARRAY_SIZE(llvm->jit_context.vs_ssbos); ++i) { + for (i = 0; i < ARRAY_SIZE(llvm->jit_context.ssbos); ++i) { int num_ssbos = draw->pt.user.vs_ssbos_size[i]; - llvm->jit_context.vs_ssbos[i] = draw->pt.user.vs_ssbos[i]; - llvm->jit_context.num_vs_ssbos[i] = num_ssbos; + llvm->jit_context.ssbos[i].u = draw->pt.user.vs_ssbos[i]; + llvm->jit_context.ssbos[i].num_elements = num_ssbos; if (num_ssbos == 0) { - llvm->jit_context.vs_ssbos[i] = (const uint32_t *)fake_const_buf; + llvm->jit_context.ssbos[i].u = (const uint32_t *)fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->gs_jit_context.constants); ++i) { int num_consts = get_num_consts_robust(draw, draw->pt.user.gs_constants_size, i); - llvm->gs_jit_context.constants[i] = draw->pt.user.gs_constants[i]; - llvm->gs_jit_context.num_constants[i] = num_consts; + llvm->gs_jit_context.constants[i].f = draw->pt.user.gs_constants[i]; + llvm->gs_jit_context.constants[i].num_elements = num_consts; if (num_consts == 0) { - llvm->gs_jit_context.constants[i] = fake_const_buf; + llvm->gs_jit_context.constants[i].f = fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->gs_jit_context.ssbos); ++i) { int num_ssbos = draw->pt.user.gs_ssbos_size[i]; - llvm->gs_jit_context.ssbos[i] = draw->pt.user.gs_ssbos[i]; - llvm->gs_jit_context.num_ssbos[i] = num_ssbos; + llvm->gs_jit_context.ssbos[i].u = draw->pt.user.gs_ssbos[i]; + llvm->gs_jit_context.ssbos[i].num_elements = num_ssbos; if (num_ssbos == 0) { - llvm->gs_jit_context.ssbos[i] = (const uint32_t *)fake_const_buf; + llvm->gs_jit_context.ssbos[i].u = (const uint32_t *)fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->tcs_jit_context.constants); ++i) { int num_consts = get_num_consts_robust(draw, draw->pt.user.tcs_constants_size, i); - llvm->tcs_jit_context.constants[i] = draw->pt.user.tcs_constants[i]; - llvm->tcs_jit_context.num_constants[i] = num_consts; + llvm->tcs_jit_context.constants[i].f = draw->pt.user.tcs_constants[i]; + llvm->tcs_jit_context.constants[i].num_elements = num_consts; if (num_consts == 0) { - llvm->tcs_jit_context.constants[i] = fake_const_buf; + llvm->tcs_jit_context.constants[i].f = fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->tcs_jit_context.ssbos); ++i) { int num_ssbos = draw->pt.user.tcs_ssbos_size[i]; - llvm->tcs_jit_context.ssbos[i] = draw->pt.user.tcs_ssbos[i]; - llvm->tcs_jit_context.num_ssbos[i] = num_ssbos; + llvm->tcs_jit_context.ssbos[i].u = draw->pt.user.tcs_ssbos[i]; + llvm->tcs_jit_context.ssbos[i].num_elements = num_ssbos; if (num_ssbos == 0) { - llvm->tcs_jit_context.ssbos[i] = (const uint32_t *)fake_const_buf; + llvm->tcs_jit_context.ssbos[i].u = (const uint32_t *)fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->tes_jit_context.constants); ++i) { int num_consts = get_num_consts_robust(draw, draw->pt.user.tes_constants_size, i); - llvm->tes_jit_context.constants[i] = draw->pt.user.tes_constants[i]; - llvm->tes_jit_context.num_constants[i] = num_consts; + llvm->tes_jit_context.constants[i].f = draw->pt.user.tes_constants[i]; + llvm->tes_jit_context.constants[i].num_elements = num_consts; if (num_consts == 0) { - llvm->tes_jit_context.constants[i] = fake_const_buf; + llvm->tes_jit_context.constants[i].f = fake_const_buf; } } for (i = 0; i < ARRAY_SIZE(llvm->tes_jit_context.ssbos); ++i) { int num_ssbos = draw->pt.user.tes_ssbos_size[i]; - llvm->tes_jit_context.ssbos[i] = draw->pt.user.tes_ssbos[i]; - llvm->tes_jit_context.num_ssbos[i] = num_ssbos; + llvm->tes_jit_context.ssbos[i].u = draw->pt.user.tes_ssbos[i]; + llvm->tes_jit_context.ssbos[i].num_elements = num_ssbos; if (num_ssbos == 0) { - llvm->tes_jit_context.ssbos[i] = (const uint32_t *)fake_const_buf; + llvm->tes_jit_context.ssbos[i].u = (const uint32_t *)fake_const_buf; } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c new file mode 100644 index 00000000000..6e6c63db9f3 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Red Hat. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_struct.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_ir_common.h" +#include "lp_bld_jit_types.h" + + +LLVMTypeRef +lp_build_create_jit_buffer_type(struct gallivm_state *gallivm) +{ + LLVMContextRef lc = gallivm->context; + LLVMTypeRef buffer_type; + LLVMTypeRef elem_types[LP_JIT_BUFFER_NUM_FIELDS]; + + elem_types[LP_JIT_BUFFER_BASE] = LLVMPointerType(LLVMInt32TypeInContext(lc), 0); + elem_types[LP_JIT_BUFFER_NUM_ELEMENTS] = LLVMInt32TypeInContext(lc); + + buffer_type = LLVMStructTypeInContext(lc, elem_types, + ARRAY_SIZE(elem_types), 0); + + LP_CHECK_MEMBER_OFFSET(struct lp_jit_buffer, f, + gallivm->target, buffer_type, + LP_JIT_BUFFER_BASE); + + LP_CHECK_MEMBER_OFFSET(struct lp_jit_buffer, num_elements, + gallivm->target, buffer_type, + LP_JIT_BUFFER_NUM_ELEMENTS); + return buffer_type; +} + +static LLVMValueRef +lp_llvm_buffer_member(struct gallivm_state *gallivm, + LLVMValueRef buffers_ptr, + LLVMValueRef buffers_offset, + unsigned buffers_limit, + unsigned member_index, + const char *member_name, + boolean emit_load) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices[3]; + + indices[0] = lp_build_const_int32(gallivm, 0); + LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, buffers_offset, lp_build_const_int32(gallivm, buffers_limit), ""); + indices[1] = LLVMBuildSelect(gallivm->builder, cond, buffers_offset, lp_build_const_int32(gallivm, 0), ""); + indices[2] = lp_build_const_int32(gallivm, member_index); + + LLVMValueRef ptr = + LLVMBuildGEP(builder, buffers_ptr, indices, ARRAY_SIZE(indices), ""); + + LLVMValueRef res = emit_load ? LLVMBuildLoad(builder, ptr, "") : ptr; + + lp_build_name(res, "buffer.%s", member_name); + + return res; +} + +/** + * Helper macro to instantiate the functions that generate the code to + * fetch the members of lp_jit_buffer to fulfill the sampler code + * generator requests. + * + * This complexity is the price we have to pay to keep the image + * sampler code generator a reusable module without dependencies to + * llvmpipe internals. + */ +#define LP_LLVM_BUFFER_MEMBER(_name, _index, _emit_load) \ + LLVMValueRef \ + lp_llvm_buffer_##_name(struct gallivm_state *gallivm, \ + LLVMValueRef buffers_ptr, \ + LLVMValueRef buffers_offset, unsigned buffers_limit) \ + { \ + return lp_llvm_buffer_member(gallivm, buffers_ptr, \ + buffers_offset, buffers_limit, \ + _index, #_name, _emit_load ); \ + } + +LP_LLVM_BUFFER_MEMBER(base, LP_JIT_BUFFER_BASE, TRUE) +LP_LLVM_BUFFER_MEMBER(num_elements, LP_JIT_BUFFER_NUM_ELEMENTS, TRUE) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h new file mode 100644 index 00000000000..557ce3a659e --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Red Hat. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef LP_BLD_JIT_TYPES_H +#define LP_BLD_JIT_TYPES_H + +struct lp_jit_buffer +{ + union { + const uint32_t *u; + const float *f; + }; + uint32_t num_elements; +}; + +enum { + LP_JIT_BUFFER_BASE = 0, + LP_JIT_BUFFER_NUM_ELEMENTS, + LP_JIT_BUFFER_NUM_FIELDS, +}; + +LLVMTypeRef +lp_build_create_jit_buffer_type(struct gallivm_state *gallivm); + +LLVMValueRef +lp_llvm_buffer_base(struct gallivm_state *gallivm, + LLVMValueRef buffers_ptr, + LLVMValueRef buffers_offset, unsigned buffers_limit); + +LLVMValueRef +lp_llvm_buffer_num_elements(struct gallivm_state *gallivm, + LLVMValueRef buffers_ptr, + LLVMValueRef buffers_offset, unsigned buffers_limit); + + +#endif diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h b/src/gallium/auxiliary/gallivm/lp_bld_nir.h index 055794f7c63..e5c7e6ddde8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h @@ -242,7 +242,6 @@ struct lp_build_nir_soa_context struct lp_build_context uint_elem_bld; LLVMValueRef consts_ptr; - LLVMValueRef const_sizes_ptr; LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS]; LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS]; const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS]; @@ -251,7 +250,6 @@ struct lp_build_nir_soa_context LLVMValueRef thread_data_ptr; LLVMValueRef ssbo_ptr; - LLVMValueRef ssbo_sizes_ptr; LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS]; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 5a92fdbc996..94dcace50e3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -30,6 +30,7 @@ #include "lp_bld_gather.h" #include "lp_bld_const.h" #include "lp_bld_struct.h" +#include "lp_bld_jit_types.h" #include "lp_bld_arit.h" #include "lp_bld_bitarit.h" #include "lp_bld_coro.h" @@ -1064,8 +1065,8 @@ static void emit_load_ubo(struct lp_build_nir_context *bld_base, LLVMBuilderRef builder = gallivm->builder; struct lp_build_context *uint_bld = &bld_base->uint_bld; struct lp_build_context *bld_broad = get_int_bld(bld_base, true, bit_size); - LLVMValueRef consts_ptr = lp_build_array_get(gallivm, bld->consts_ptr, index); - LLVMValueRef num_consts = lp_build_array_get(gallivm, bld->const_sizes_ptr, index); + LLVMValueRef consts_ptr = lp_llvm_buffer_base(gallivm, bld->consts_ptr, index, LP_MAX_TGSI_CONST_BUFFERS); + LLVMValueRef num_consts = lp_llvm_buffer_num_elements(gallivm, bld->consts_ptr, index, LP_MAX_TGSI_CONST_BUFFERS); unsigned size_shift = bit_size_to_shift_size(bit_size); if (size_shift) offset = lp_build_shr(uint_bld, offset, lp_build_const_int_vec(gallivm, uint_bld->type, size_shift)); @@ -1158,8 +1159,8 @@ ssbo_base_pointer(struct lp_build_nir_context *bld_base, uint32_t shift_val = bit_size_to_shift_size(bit_size); LLVMValueRef ssbo_idx = LLVMBuildExtractElement(gallivm->builder, index, invocation, ""); - LLVMValueRef ssbo_size_ptr = lp_build_array_get(gallivm, bld->ssbo_sizes_ptr, ssbo_idx); - LLVMValueRef ssbo_ptr = lp_build_array_get(gallivm, bld->ssbo_ptr, ssbo_idx); + LLVMValueRef ssbo_size_ptr = lp_llvm_buffer_num_elements(gallivm, bld->ssbo_ptr, ssbo_idx, LP_MAX_TGSI_SHADER_BUFFERS); + LLVMValueRef ssbo_ptr = lp_llvm_buffer_base(gallivm, bld->ssbo_ptr, ssbo_idx, LP_MAX_TGSI_SHADER_BUFFERS); if (bounds) *bounds = LLVMBuildAShr(gallivm->builder, ssbo_size_ptr, lp_build_const_int32(gallivm, shift_val), ""); @@ -1540,8 +1541,8 @@ static LLVMValueRef emit_get_ssbo_size(struct lp_build_nir_context *bld_base, struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder; struct lp_build_context *bld_broad = &bld_base->uint_bld; - LLVMValueRef size_ptr = lp_build_array_get(bld_base->base.gallivm, bld->ssbo_sizes_ptr, - LLVMBuildExtractElement(builder, index, lp_build_const_int32(gallivm, 0), "")); + LLVMValueRef size_ptr = lp_llvm_buffer_num_elements(gallivm, bld->ssbo_ptr, LLVMBuildExtractElement(builder, index, lp_build_const_int32(gallivm, 0), ""), LP_MAX_TGSI_SHADER_BUFFERS); + return lp_build_broadcast_scalar(bld_broad, size_ptr); } @@ -2780,9 +2781,7 @@ void lp_build_nir_soa(struct gallivm_state *gallivm, bld.inputs = params->inputs; bld.outputs = outputs; bld.consts_ptr = params->consts_ptr; - bld.const_sizes_ptr = params->const_sizes_ptr; bld.ssbo_ptr = params->ssbo_ptr; - bld.ssbo_sizes_ptr = params->ssbo_sizes_ptr; bld.sampler = params->sampler; // bld.bld_base.info = params->info; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 6f18d057feb..30bcb26e116 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -522,7 +522,6 @@ struct lp_build_tgsi_soa_context LLVMValueRef max_output_vertices_vec; LLVMValueRef consts_ptr; - LLVMValueRef const_sizes_ptr; LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS]; LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS]; const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS]; @@ -531,7 +530,6 @@ struct lp_build_tgsi_soa_context LLVMValueRef thread_data_ptr; LLVMValueRef ssbo_ptr; - LLVMValueRef ssbo_sizes_ptr; LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS]; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index aa10100ab05..290cea44ca5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -68,6 +68,7 @@ #include "lp_bld_printf.h" #include "lp_bld_sample.h" #include "lp_bld_struct.h" +#include "lp_bld_jit_types.h" #define DUMP_GS_EMITS 0 @@ -2958,10 +2959,11 @@ lp_emit_declaration_soa( unsigned idx2D = decl->Dim.Index2D; LLVMValueRef index2D = lp_build_const_int32(gallivm, idx2D); assert(idx2D < LP_MAX_TGSI_CONST_BUFFERS); - bld->consts[idx2D] = - lp_build_array_get(gallivm, bld->consts_ptr, index2D); - bld->consts_sizes[idx2D] = - lp_build_array_get(gallivm, bld->const_sizes_ptr, index2D); + bld->consts[idx2D] = lp_llvm_buffer_base(gallivm, bld->consts_ptr, + index2D, LP_MAX_TGSI_CONST_BUFFERS); + bld->consts[idx2D] = LLVMBuildBitCast(gallivm->builder, bld->consts[idx2D], LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0), ""); + bld->consts_sizes[idx2D] = lp_llvm_buffer_num_elements(gallivm, bld->consts_ptr, + index2D, LP_MAX_TGSI_CONST_BUFFERS); } break; case TGSI_FILE_BUFFER: @@ -2970,9 +2972,11 @@ lp_emit_declaration_soa( LLVMValueRef index = lp_build_const_int32(gallivm, idx); assert(idx < LP_MAX_TGSI_SHADER_BUFFERS); bld->ssbos[idx] = - lp_build_array_get(gallivm, bld->ssbo_ptr, index); + lp_llvm_buffer_base(gallivm, bld->ssbo_ptr, + index, LP_MAX_TGSI_SHADER_BUFFERS); bld->ssbo_sizes[idx] = - lp_build_array_get(gallivm, bld->ssbo_sizes_ptr, index); + lp_llvm_buffer_num_elements(gallivm, bld->ssbo_ptr, + index, LP_MAX_TGSI_SHADER_BUFFERS); } break; @@ -4451,9 +4455,7 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm, bld.inputs = params->inputs; bld.outputs = outputs; bld.consts_ptr = params->consts_ptr; - bld.const_sizes_ptr = params->const_sizes_ptr; bld.ssbo_ptr = params->ssbo_ptr; - bld.ssbo_sizes_ptr = params->ssbo_sizes_ptr; bld.sampler = params->sampler; bld.bld_base.info = params->info; bld.indirect_files = params->info->indirect_files; diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 2a2b2a56e50..184e1c87f34 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -371,6 +371,8 @@ if draw_with_llvm 'gallivm/lp_bld_intr.h', 'gallivm/lp_bld_ir_common.c', 'gallivm/lp_bld_ir_common.h', + 'gallivm/lp_bld_jit_types.h', + 'gallivm/lp_bld_jit_types.c', 'gallivm/lp_bld_limits.h', 'gallivm/lp_bld_logic.c', 'gallivm/lp_bld_logic.h', diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 3c763240a97..fa26b1d1d8f 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -189,7 +189,7 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) { struct gallivm_state *gallivm = lp->gallivm; LLVMContextRef lc = gallivm->context; - LLVMTypeRef viewport_type, texture_type, sampler_type, image_type; + LLVMTypeRef viewport_type, texture_type, sampler_type, image_type, buffer_type; LLVMTypeRef linear_elem_type; /* struct lp_jit_viewport */ @@ -212,6 +212,7 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) gallivm->target, viewport_type); } + buffer_type = lp_build_create_jit_buffer_type(gallivm); texture_type = create_jit_texture_type(gallivm); sampler_type = create_jit_sampler_type(gallivm); image_type = create_jit_image_type(gallivm); @@ -221,10 +222,8 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) LLVMTypeRef elem_types[LP_JIT_CTX_COUNT]; LLVMTypeRef context_type; - elem_types[LP_JIT_CTX_CONSTANTS] = - LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc), 0), LP_MAX_TGSI_CONST_BUFFERS); - elem_types[LP_JIT_CTX_NUM_CONSTANTS] = - LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_CONST_BUFFERS); + elem_types[LP_JIT_CTX_CONSTANTS] = LLVMArrayType(buffer_type, + LP_MAX_TGSI_CONST_BUFFERS); elem_types[LP_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type, PIPE_MAX_SHADER_SAMPLER_VIEWS); elem_types[LP_JIT_CTX_SAMPLERS] = LLVMArrayType(sampler_type, @@ -240,18 +239,13 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) elem_types[LP_JIT_CTX_VIEWPORTS] = LLVMPointerType(viewport_type, 0); elem_types[LP_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0); elem_types[LP_JIT_CTX_SSBOS] = - LLVMArrayType(LLVMPointerType(LLVMInt32TypeInContext(lc), 0), LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[LP_JIT_CTX_NUM_SSBOS] = - LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_SHADER_BUFFERS); + LLVMArrayType(buffer_type, LP_MAX_TGSI_SHADER_BUFFERS); context_type = LLVMStructTypeInContext(lc, elem_types, ARRAY_SIZE(elem_types), 0); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, constants, gallivm->target, context_type, LP_JIT_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, num_constants, - gallivm->target, context_type, - LP_JIT_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, textures, gallivm->target, context_type, LP_JIT_CTX_TEXTURES); @@ -282,9 +276,6 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, ssbos, gallivm->target, context_type, LP_JIT_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, num_ssbos, - gallivm->target, context_type, - LP_JIT_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, sample_mask, gallivm->target, context_type, LP_JIT_CTX_SAMPLE_MASK); @@ -418,8 +409,9 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) { struct gallivm_state *gallivm = lp->gallivm; LLVMContextRef lc = gallivm->context; - LLVMTypeRef texture_type, sampler_type, image_type; + LLVMTypeRef texture_type, sampler_type, image_type, buffer_type; + buffer_type = lp_build_create_jit_buffer_type(gallivm); texture_type = create_jit_texture_type(gallivm); sampler_type = create_jit_sampler_type(gallivm); image_type = create_jit_image_type(gallivm); @@ -445,9 +437,7 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) LLVMTypeRef cs_context_type; elem_types[LP_JIT_CS_CTX_CONSTANTS] = - LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc), 0), LP_MAX_TGSI_CONST_BUFFERS); - elem_types[LP_JIT_CS_CTX_NUM_CONSTANTS] = - LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_CONST_BUFFERS); + LLVMArrayType(buffer_type, LP_MAX_TGSI_CONST_BUFFERS); elem_types[LP_JIT_CS_CTX_TEXTURES] = LLVMArrayType(texture_type, PIPE_MAX_SHADER_SAMPLER_VIEWS); elem_types[LP_JIT_CS_CTX_SAMPLERS] = LLVMArrayType(sampler_type, @@ -455,9 +445,7 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) elem_types[LP_JIT_CS_CTX_IMAGES] = LLVMArrayType(image_type, PIPE_MAX_SHADER_IMAGES); elem_types[LP_JIT_CS_CTX_SSBOS] = - LLVMArrayType(LLVMPointerType(LLVMInt32TypeInContext(lc), 0), LP_MAX_TGSI_SHADER_BUFFERS); - elem_types[LP_JIT_CS_CTX_NUM_SSBOS] = - LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_SHADER_BUFFERS); + LLVMArrayType(buffer_type, LP_MAX_TGSI_SHADER_BUFFERS); elem_types[LP_JIT_CS_CTX_SHARED_SIZE] = LLVMInt32TypeInContext(lc); @@ -471,9 +459,6 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, constants, gallivm->target, cs_context_type, LP_JIT_CS_CTX_CONSTANTS); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, num_constants, - gallivm->target, cs_context_type, - LP_JIT_CS_CTX_NUM_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, textures, gallivm->target, cs_context_type, LP_JIT_CS_CTX_TEXTURES); @@ -486,9 +471,6 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, ssbos, gallivm->target, cs_context_type, LP_JIT_CS_CTX_SSBOS); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, num_ssbos, - gallivm->target, cs_context_type, - LP_JIT_CS_CTX_NUM_SSBOS); LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, shared_size, gallivm->target, cs_context_type, LP_JIT_CS_CTX_SHARED_SIZE); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index f46a6bd03d3..529c1d5945b 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -38,6 +38,7 @@ #include "gallivm/lp_bld_struct.h" #include "gallivm/lp_bld_limits.h" +#include "gallivm/lp_bld_jit_types.h" #include "pipe/p_state.h" #include "lp_texture.h" @@ -153,8 +154,7 @@ enum { */ struct lp_jit_context { - const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; @@ -169,8 +169,7 @@ struct lp_jit_context struct lp_jit_viewport *viewports; - const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; uint32_t sample_mask; @@ -184,7 +183,6 @@ struct lp_jit_context */ enum { LP_JIT_CTX_CONSTANTS = 0, - LP_JIT_CTX_NUM_CONSTANTS, LP_JIT_CTX_TEXTURES, LP_JIT_CTX_SAMPLERS, LP_JIT_CTX_IMAGES, @@ -195,7 +193,6 @@ enum { LP_JIT_CTX_F_BLEND_COLOR, LP_JIT_CTX_VIEWPORTS, LP_JIT_CTX_SSBOS, - LP_JIT_CTX_NUM_SSBOS, LP_JIT_CTX_SAMPLE_MASK, LP_JIT_CTX_ANISO_FILTER_TABLE, LP_JIT_CTX_COUNT @@ -205,9 +202,6 @@ enum { #define lp_jit_context_constants(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants") -#define lp_jit_context_num_constants(_gallivm, _ptr) \ - lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants") - #define lp_jit_context_textures(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures") @@ -238,9 +232,6 @@ enum { #define lp_jit_context_ssbos(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos") -#define lp_jit_context_num_ssbos(_gallivm, _ptr) \ - lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos") - #define lp_jit_context_sample_mask(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLE_MASK, "sample_mask") @@ -439,15 +430,13 @@ enum { struct lp_jit_cs_context { - const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; - int num_constants[LP_MAX_TGSI_CONST_BUFFERS]; + struct lp_jit_buffer constants[LP_MAX_TGSI_CONST_BUFFERS]; struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; - const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; - int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; + struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; void *kernel_args; @@ -462,12 +451,10 @@ struct lp_jit_cs_context */ enum { LP_JIT_CS_CTX_CONSTANTS = 0, - LP_JIT_CS_CTX_NUM_CONSTANTS, LP_JIT_CS_CTX_TEXTURES, /* must match the LP_JIT_CTX_TEXTURES */ LP_JIT_CS_CTX_SAMPLERS, LP_JIT_CS_CTX_IMAGES, LP_JIT_CS_CTX_SSBOS, - LP_JIT_CS_CTX_NUM_SSBOS, LP_JIT_CS_CTX_KERNEL_ARGS, LP_JIT_CS_CTX_SHARED_SIZE, LP_JIT_CS_CTX_ANISO_FILTER_TABLE, @@ -477,9 +464,6 @@ enum { #define lp_jit_cs_context_constants(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants") -#define lp_jit_cs_context_num_constants(_gallivm, _ptr) \ - lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants") - #define lp_jit_cs_context_textures(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures") @@ -492,9 +476,6 @@ enum { #define lp_jit_cs_context_ssbos(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos") -#define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \ - lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos") - #define lp_jit_cs_context_shared_size(_gallivm, _ptr) \ lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size") diff --git a/src/gallium/drivers/llvmpipe/lp_linear.c b/src/gallium/drivers/llvmpipe/lp_linear.c index c4a81ec05b4..e950ba6cfd6 100644 --- a/src/gallium/drivers/llvmpipe/lp_linear.c +++ b/src/gallium/drivers/llvmpipe/lp_linear.c @@ -104,10 +104,10 @@ lp_fs_linear_run(const struct lp_rast_state *state, if (variant->shader->base.type == PIPE_SHADER_IR_TGSI) { nr_consts = (info->base.file_max[TGSI_FILE_CONSTANT] + 1) * 4; } else { - nr_consts = state->jit_context.num_constants[0]; + nr_consts = state->jit_context.constants[0].num_elements; } for (int i = 0; i < nr_consts; i++){ - float val = state->jit_context.constants[0][i]; + float val = state->jit_context.constants[0].f[i]; if (val < 0.0f || val > 1.0f) { if (LP_DEBUG & DEBUG_LINEAR2) debug_printf(" -- const[%d] out of range %f\n", i, val); diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 4adfa705914..cf2317186ee 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -1277,19 +1277,19 @@ try_update_scene_state(struct lp_setup_context *setup) setup->constants[i].stored_size = current_size; setup->constants[i].stored_data = stored; } - setup->fs.current.jit_context.constants[i] = + setup->fs.current.jit_context.constants[i].f = setup->constants[i].stored_data; } else { setup->constants[i].stored_size = 0; setup->constants[i].stored_data = NULL; - setup->fs.current.jit_context.constants[i] = fake_const_buf; + setup->fs.current.jit_context.constants[i].f = fake_const_buf; } const int num_constants = DIV_ROUND_UP(setup->constants[i].stored_size, lp_get_constant_buffer_stride(scene->pipe->screen)); - setup->fs.current.jit_context.num_constants[i] = num_constants; + setup->fs.current.jit_context.constants[i].num_elements = num_constants; setup->dirty |= LP_SETUP_NEW_FS; } } @@ -1306,13 +1306,13 @@ try_update_scene_state(struct lp_setup_context *setup) if (current_data) { current_data += setup->ssbos[i].current.buffer_offset; - setup->fs.current.jit_context.ssbos[i] = + setup->fs.current.jit_context.ssbos[i].u = (const uint32_t *)current_data; - setup->fs.current.jit_context.num_ssbos[i] = + setup->fs.current.jit_context.ssbos[i].num_elements = setup->ssbos[i].current.buffer_size; } else { - setup->fs.current.jit_context.ssbos[i] = NULL; - setup->fs.current.jit_context.num_ssbos[i] = 0; + setup->fs.current.jit_context.ssbos[i].u = NULL; + setup->fs.current.jit_context.ssbos[i].num_elements = 0; } setup->dirty |= LP_SETUP_NEW_FS; } diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c index 00f07beba48..f372316b416 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c @@ -240,7 +240,7 @@ check_opaque(const struct lp_setup_context *setup, const struct lp_tgsi_channel_info *alpha_info = &variant->shader->info.cbuf[0][3]; if (alpha_info->file == TGSI_FILE_CONSTANT) { - const float *constants = setup->fs.current.jit_context.constants[0]; + const float *constants = setup->fs.current.jit_context.constants[0].f; float alpha = constants[alpha_info->u.index*4 + alpha_info->swizzle]; return alpha == 1.0f; diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c index 273dd8b944b..f64fd84d0bc 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c @@ -319,8 +319,8 @@ generate_compute(struct llvmpipe_context *lp, block = LLVMAppendBasicBlockInContext(gallivm->context, coro, "entry"); LLVMPositionBuilderAtEnd(builder, block); { - LLVMValueRef consts_ptr, num_consts_ptr; - LLVMValueRef ssbo_ptr, num_ssbo_ptr; + LLVMValueRef consts_ptr; + LLVMValueRef ssbo_ptr; LLVMValueRef shared_ptr; LLVMValueRef kernel_args_ptr; struct lp_build_mask_context mask; @@ -328,9 +328,7 @@ generate_compute(struct llvmpipe_context *lp, memset(&system_values, 0, sizeof(system_values)); consts_ptr = lp_jit_cs_context_constants(gallivm, context_ptr); - num_consts_ptr = lp_jit_cs_context_num_constants(gallivm, context_ptr); ssbo_ptr = lp_jit_cs_context_ssbos(gallivm, context_ptr); - num_ssbo_ptr = lp_jit_cs_context_num_ssbos(gallivm, context_ptr); kernel_args_ptr = lp_jit_cs_context_kernel_args(gallivm, context_ptr); shared_ptr = lp_jit_cs_thread_data_shared(gallivm, thread_data_ptr); @@ -437,13 +435,11 @@ generate_compute(struct llvmpipe_context *lp, params.type = cs_type; params.mask = &mask; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = &system_values; params.context_ptr = context_ptr; params.sampler = sampler; params.info = &shader->info.base; params.ssbo_ptr = ssbo_ptr; - params.ssbo_sizes_ptr = num_ssbo_ptr; params.image = image; params.shared_ptr = shared_ptr; params.coro = &coro_info; @@ -1239,14 +1235,14 @@ update_csctx_consts(struct llvmpipe_context *llvmpipe) if (current_data && current_size >= sizeof(float)) { current_data += csctx->constants[i].current.buffer_offset; - csctx->cs.current.jit_context.constants[i] = (const float *)current_data; - csctx->cs.current.jit_context.num_constants[i] = + csctx->cs.current.jit_context.constants[i].f = (const float *)current_data; + csctx->cs.current.jit_context.constants[i].num_elements = DIV_ROUND_UP(csctx->constants[i].current.buffer_size, lp_get_constant_buffer_stride(llvmpipe->pipe.screen)); } else { static const float fake_const_buf[4]; - csctx->cs.current.jit_context.constants[i] = fake_const_buf; - csctx->cs.current.jit_context.num_constants[i] = 0; + csctx->cs.current.jit_context.constants[i].f = fake_const_buf; + csctx->cs.current.jit_context.constants[i].num_elements = 0; } } } @@ -1266,11 +1262,11 @@ update_csctx_ssbo(struct llvmpipe_context *llvmpipe) if (current_data) { current_data += csctx->ssbos[i].current.buffer_offset; - csctx->cs.current.jit_context.ssbos[i] = (const uint32_t *)current_data; - csctx->cs.current.jit_context.num_ssbos[i] = csctx->ssbos[i].current.buffer_size; + csctx->cs.current.jit_context.ssbos[i].u = (const uint32_t *)current_data; + csctx->cs.current.jit_context.ssbos[i].num_elements = csctx->ssbos[i].current.buffer_size; } else { - csctx->cs.current.jit_context.ssbos[i] = NULL; - csctx->cs.current.jit_context.num_ssbos[i] = 0; + csctx->cs.current.jit_context.ssbos[i].u = NULL; + csctx->cs.current.jit_context.ssbos[i].num_elements = 0; } } } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 658642664ee..76d27ff59f3 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -728,11 +728,8 @@ generate_fs_loop(struct gallivm_state *gallivm, stencil_refs[1] = lp_build_broadcast(gallivm, int_vec_type, stencil_refs[1]); LLVMValueRef consts_ptr = lp_jit_context_constants(gallivm, context_ptr); - LLVMValueRef num_consts_ptr = lp_jit_context_num_constants(gallivm, - context_ptr); LLVMValueRef ssbo_ptr = lp_jit_context_ssbos(gallivm, context_ptr); - LLVMValueRef num_ssbo_ptr = lp_jit_context_num_ssbos(gallivm, context_ptr); LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][TGSI_NUM_CHANNELS]; memset(outputs, 0, sizeof outputs); @@ -1024,7 +1021,6 @@ generate_fs_loop(struct gallivm_state *gallivm, params.mask = &mask; params.fs_iface = &fs_iface.base; params.consts_ptr = consts_ptr; - params.const_sizes_ptr = num_consts_ptr; params.system_values = &system_values; params.inputs = interp->inputs; params.context_ptr = context_ptr; @@ -1032,7 +1028,6 @@ generate_fs_loop(struct gallivm_state *gallivm, params.sampler = sampler; params.info = &shader->info.base; params.ssbo_ptr = ssbo_ptr; - params.ssbo_sizes_ptr = num_ssbo_ptr; params.image = image; params.aniso_filter_table = lp_jit_context_aniso_filter_table(gallivm, context_ptr);