From d32aa2686c84632b7c03fcbbffa33d7299b8e919 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 26 Aug 2022 16:47:26 +1000 Subject: [PATCH] gallium: consolidate jit image types between draw/llvmpipe Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/draw/draw_llvm.c | 67 ++----------------- src/gallium/auxiliary/draw/draw_llvm.h | 32 ++------- src/gallium/auxiliary/draw/draw_llvm_sample.c | 16 ++--- .../auxiliary/gallivm/lp_bld_jit_types.c | 44 ++++++++++++ .../auxiliary/gallivm/lp_bld_jit_types.h | 27 ++++++++ src/gallium/drivers/llvmpipe/lp_jit.c | 48 +------------ src/gallium/drivers/llvmpipe/lp_jit.h | 25 ------- 7 files changed, 90 insertions(+), 169 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 3af278f7b11..cd9c583b41b 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -143,63 +143,6 @@ create_jit_dvbuffer_type(struct gallivm_state *gallivm, return dvbuffer_type; } - -/** - * Create LLVM type for struct draw_jit_texture - */ -static LLVMTypeRef -create_jit_image_type(struct gallivm_state *gallivm, const char *struct_name) -{ - LLVMTargetDataRef target = gallivm->target; - LLVMTypeRef image_type; - LLVMTypeRef elem_types[DRAW_JIT_IMAGE_NUM_FIELDS]; - LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); - - elem_types[DRAW_JIT_IMAGE_WIDTH] = - elem_types[DRAW_JIT_IMAGE_HEIGHT] = - elem_types[DRAW_JIT_IMAGE_DEPTH] = - elem_types[DRAW_JIT_IMAGE_ROW_STRIDE] = - elem_types[DRAW_JIT_IMAGE_IMG_STRIDE] = - elem_types[DRAW_JIT_IMAGE_NUM_SAMPLES] = - elem_types[DRAW_JIT_IMAGE_SAMPLE_STRIDE] = int32_type; - elem_types[DRAW_JIT_IMAGE_BASE] = - LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); - - image_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_image, width, - target, image_type, - DRAW_JIT_IMAGE_WIDTH); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, height, - target, image_type, - DRAW_JIT_IMAGE_HEIGHT); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, depth, - target, image_type, - DRAW_JIT_IMAGE_DEPTH); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, base, - target, image_type, - DRAW_JIT_IMAGE_BASE); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, row_stride, - target, image_type, - DRAW_JIT_IMAGE_ROW_STRIDE); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, img_stride, - target, image_type, - DRAW_JIT_IMAGE_IMG_STRIDE); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, num_samples, - target, image_type, - DRAW_JIT_IMAGE_NUM_SAMPLES); - LP_CHECK_MEMBER_OFFSET(struct draw_jit_image, sample_stride, - target, image_type, - DRAW_JIT_IMAGE_SAMPLE_STRIDE); - - LP_CHECK_STRUCT_SIZE(struct draw_jit_image, target, image_type); - - return image_type; -} - - /** * Create LLVM type for struct draw_jit_context */ @@ -209,7 +152,7 @@ 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 = lp_build_create_jit_texture_type(gallivm); LLVMTypeRef sampler_type = lp_build_create_jit_sampler_type(gallivm); - LLVMTypeRef image_type = create_jit_image_type(gallivm, "image"); + LLVMTypeRef image_type = lp_build_create_jit_image_type(gallivm); LLVMTargetDataRef target = gallivm->target; LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); @@ -2448,7 +2391,7 @@ draw_llvm_set_mapped_image(struct draw_context *draw, uint32_t num_samples, uint32_t sample_stride) { - struct draw_jit_image *jit_image; + struct lp_jit_image *jit_image; switch (shader_stage) { case PIPE_SHADER_VERTEX: @@ -2587,7 +2530,7 @@ create_gs_jit_types(struct draw_gs_llvm_variant *var) texture_type = lp_build_create_jit_texture_type(gallivm); sampler_type = lp_build_create_jit_sampler_type(gallivm); - image_type = create_jit_image_type(gallivm, "image"); + image_type = lp_build_create_jit_image_type(gallivm); buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_gs_jit_context_type(gallivm, @@ -2973,7 +2916,7 @@ create_tcs_jit_types(struct draw_tcs_llvm_variant *var) texture_type = lp_build_create_jit_texture_type(gallivm); sampler_type = lp_build_create_jit_sampler_type(gallivm); - image_type = create_jit_image_type(gallivm, "image"); + image_type = lp_build_create_jit_image_type(gallivm); buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_tcs_jit_context_type(gallivm, @@ -3632,7 +3575,7 @@ create_tes_jit_types(struct draw_tes_llvm_variant *var) texture_type = lp_build_create_jit_texture_type(gallivm); sampler_type = lp_build_create_jit_sampler_type(gallivm); - image_type = create_jit_image_type(gallivm, "image"); + image_type = lp_build_create_jit_image_type(gallivm); buffer_type = lp_build_create_jit_buffer_type(gallivm); var->context_type = create_tes_jit_context_type(gallivm, diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index 81f5c0d30c5..f1042667f50 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -64,36 +64,12 @@ struct draw_image_static_state struct lp_static_texture_state image_state; }; -struct draw_jit_image -{ - uint32_t width; - uint32_t height; - uint32_t depth; - const void *base; - uint32_t row_stride; - uint32_t img_stride; - uint32_t num_samples; - uint32_t sample_stride; -}; - enum { DRAW_JIT_VERTEX_VERTEX_ID = 0, DRAW_JIT_VERTEX_CLIP_POS, DRAW_JIT_VERTEX_DATA }; -enum { - DRAW_JIT_IMAGE_WIDTH = 0, - DRAW_JIT_IMAGE_HEIGHT, - DRAW_JIT_IMAGE_DEPTH, - DRAW_JIT_IMAGE_BASE, - DRAW_JIT_IMAGE_ROW_STRIDE, - DRAW_JIT_IMAGE_IMG_STRIDE, - DRAW_JIT_IMAGE_NUM_SAMPLES, - DRAW_JIT_IMAGE_SAMPLE_STRIDE, - DRAW_JIT_IMAGE_NUM_FIELDS /* number of fields above */ -}; - /** * This structure is passed directly to the generated vertex shader. * @@ -113,7 +89,7 @@ struct draw_jit_context struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; - struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; + struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; @@ -198,7 +174,7 @@ struct draw_gs_jit_context * DRAW_JIT_CTX_SAMPLERS positions in the struct */ struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; - struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; + struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; int **prim_lengths; int *emitted_vertices; @@ -254,7 +230,7 @@ struct draw_tcs_jit_context { * DRAW_JIT_CTX_SAMPLERS positions in the struct */ struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; - struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; + struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; @@ -291,7 +267,7 @@ struct draw_tes_jit_context { * DRAW_JIT_CTX_SAMPLERS positions in the struct */ struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS]; struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS]; - struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES]; + struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES]; struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS]; diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c index 5e6d8c8b3b7..d031bbe9cda 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_sample.c +++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c @@ -345,14 +345,14 @@ DRAW_LLVM_SAMPLER_MEMBER(max_aniso, LP_JIT_SAMPLER_MAX_ANISO, TRUE) } -DRAW_LLVM_IMAGE_MEMBER(width, DRAW_JIT_IMAGE_WIDTH, TRUE) -DRAW_LLVM_IMAGE_MEMBER(height, DRAW_JIT_IMAGE_HEIGHT, TRUE) -DRAW_LLVM_IMAGE_MEMBER(depth, DRAW_JIT_IMAGE_DEPTH, TRUE) -DRAW_LLVM_IMAGE_MEMBER(base_ptr, DRAW_JIT_IMAGE_BASE, TRUE) -DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(row_stride, DRAW_JIT_IMAGE_ROW_STRIDE, TRUE) -DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(img_stride, DRAW_JIT_IMAGE_IMG_STRIDE, TRUE) -DRAW_LLVM_IMAGE_MEMBER(num_samples, DRAW_JIT_IMAGE_NUM_SAMPLES, TRUE) -DRAW_LLVM_IMAGE_MEMBER(sample_stride, DRAW_JIT_IMAGE_SAMPLE_STRIDE, TRUE) +DRAW_LLVM_IMAGE_MEMBER(width, LP_JIT_IMAGE_WIDTH, TRUE) +DRAW_LLVM_IMAGE_MEMBER(height, LP_JIT_IMAGE_HEIGHT, TRUE) +DRAW_LLVM_IMAGE_MEMBER(depth, LP_JIT_IMAGE_DEPTH, TRUE) +DRAW_LLVM_IMAGE_MEMBER(base_ptr, LP_JIT_IMAGE_BASE, TRUE) +DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(row_stride, LP_JIT_IMAGE_ROW_STRIDE, TRUE) +DRAW_LLVM_IMAGE_MEMBER_OUTTYPE(img_stride, LP_JIT_IMAGE_IMG_STRIDE, TRUE) +DRAW_LLVM_IMAGE_MEMBER(num_samples, LP_JIT_IMAGE_NUM_SAMPLES, TRUE) +DRAW_LLVM_IMAGE_MEMBER(sample_stride, LP_JIT_IMAGE_SAMPLE_STRIDE, TRUE) /** diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c index dd89bf37687..c5d297eb8a0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c @@ -193,3 +193,47 @@ lp_build_create_jit_sampler_type(struct gallivm_state *gallivm) gallivm->target, sampler_type); return sampler_type; } + +LLVMTypeRef +lp_build_create_jit_image_type(struct gallivm_state *gallivm) +{ + LLVMContextRef lc = gallivm->context; + LLVMTypeRef image_type; + LLVMTypeRef elem_types[LP_JIT_IMAGE_NUM_FIELDS]; + elem_types[LP_JIT_IMAGE_WIDTH] = + elem_types[LP_JIT_IMAGE_HEIGHT] = + elem_types[LP_JIT_IMAGE_DEPTH] = LLVMInt32TypeInContext(lc); + elem_types[LP_JIT_IMAGE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0); + elem_types[LP_JIT_IMAGE_ROW_STRIDE] = + elem_types[LP_JIT_IMAGE_IMG_STRIDE] = + elem_types[LP_JIT_IMAGE_NUM_SAMPLES] = + elem_types[LP_JIT_IMAGE_SAMPLE_STRIDE] = LLVMInt32TypeInContext(lc); + + image_type = LLVMStructTypeInContext(lc, elem_types, + ARRAY_SIZE(elem_types), 0); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, width, + gallivm->target, image_type, + LP_JIT_IMAGE_WIDTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, height, + gallivm->target, image_type, + LP_JIT_IMAGE_HEIGHT); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, depth, + gallivm->target, image_type, + LP_JIT_IMAGE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, base, + gallivm->target, image_type, + LP_JIT_IMAGE_BASE); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, row_stride, + gallivm->target, image_type, + LP_JIT_IMAGE_ROW_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, img_stride, + gallivm->target, image_type, + LP_JIT_IMAGE_IMG_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, num_samples, + gallivm->target, image_type, + LP_JIT_IMAGE_NUM_SAMPLES); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, sample_stride, + gallivm->target, image_type, + LP_JIT_IMAGE_SAMPLE_STRIDE); + return image_type; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h index 5fe671818de..bbe25d70e03 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h @@ -106,4 +106,31 @@ enum { LLVMTypeRef lp_build_create_jit_sampler_type(struct gallivm_state *gallivm); +struct lp_jit_image +{ + uint32_t width; /* same as number of elements */ + uint32_t height; + uint32_t depth; + const void *base; + uint32_t row_stride; + uint32_t img_stride; + uint32_t num_samples; + uint32_t sample_stride; +}; + +enum { + LP_JIT_IMAGE_WIDTH = 0, + LP_JIT_IMAGE_HEIGHT, + LP_JIT_IMAGE_DEPTH, + LP_JIT_IMAGE_BASE, + LP_JIT_IMAGE_ROW_STRIDE, + LP_JIT_IMAGE_IMG_STRIDE, + LP_JIT_IMAGE_NUM_SAMPLES, + LP_JIT_IMAGE_SAMPLE_STRIDE, + LP_JIT_IMAGE_NUM_FIELDS /* number of fields above */ +}; + +LLVMTypeRef +lp_build_create_jit_image_type(struct gallivm_state *gallivm); + #endif diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index e38a10c75f5..0ed8725eb46 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -42,50 +42,6 @@ #include "lp_screen.h" #include "lp_jit.h" -static LLVMTypeRef -create_jit_image_type(struct gallivm_state *gallivm) -{ - LLVMContextRef lc = gallivm->context; - LLVMTypeRef image_type; - LLVMTypeRef elem_types[LP_JIT_IMAGE_NUM_FIELDS]; - elem_types[LP_JIT_IMAGE_WIDTH] = - elem_types[LP_JIT_IMAGE_HEIGHT] = - elem_types[LP_JIT_IMAGE_DEPTH] = LLVMInt32TypeInContext(lc); - elem_types[LP_JIT_IMAGE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0); - elem_types[LP_JIT_IMAGE_ROW_STRIDE] = - elem_types[LP_JIT_IMAGE_IMG_STRIDE] = - elem_types[LP_JIT_IMAGE_NUM_SAMPLES] = - elem_types[LP_JIT_IMAGE_SAMPLE_STRIDE] = LLVMInt32TypeInContext(lc); - - image_type = LLVMStructTypeInContext(lc, elem_types, - ARRAY_SIZE(elem_types), 0); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, width, - gallivm->target, image_type, - LP_JIT_IMAGE_WIDTH); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, height, - gallivm->target, image_type, - LP_JIT_IMAGE_HEIGHT); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, depth, - gallivm->target, image_type, - LP_JIT_IMAGE_DEPTH); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, base, - gallivm->target, image_type, - LP_JIT_IMAGE_BASE); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, row_stride, - gallivm->target, image_type, - LP_JIT_IMAGE_ROW_STRIDE); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, img_stride, - gallivm->target, image_type, - LP_JIT_IMAGE_IMG_STRIDE); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, num_samples, - gallivm->target, image_type, - LP_JIT_IMAGE_NUM_SAMPLES); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, sample_stride, - gallivm->target, image_type, - LP_JIT_IMAGE_SAMPLE_STRIDE); - return image_type; -} - static void lp_jit_create_types(struct lp_fragment_shader_variant *lp) { @@ -117,7 +73,7 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp) buffer_type = lp_build_create_jit_buffer_type(gallivm); texture_type = lp_build_create_jit_texture_type(gallivm); sampler_type = lp_build_create_jit_sampler_type(gallivm); - image_type = create_jit_image_type(gallivm); + image_type = lp_build_create_jit_image_type(gallivm); /* struct lp_jit_context */ { @@ -323,7 +279,7 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp) buffer_type = lp_build_create_jit_buffer_type(gallivm); texture_type = lp_build_create_jit_texture_type(gallivm); sampler_type = lp_build_create_jit_sampler_type(gallivm); - image_type = create_jit_image_type(gallivm); + image_type = lp_build_create_jit_image_type(gallivm); /* struct lp_jit_cs_thread_data */ { diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index a0f61e0e6df..12336fff538 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -56,37 +56,12 @@ struct lp_jit_viewport float max_depth; }; -struct lp_jit_image -{ - uint32_t width; /* same as number of elements */ - uint32_t height; - uint32_t depth; - const void *base; - uint32_t row_stride; - uint32_t img_stride; - uint32_t num_samples; - uint32_t sample_stride; -}; - enum { LP_JIT_VIEWPORT_MIN_DEPTH, LP_JIT_VIEWPORT_MAX_DEPTH, LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */ }; -enum { - LP_JIT_IMAGE_WIDTH = 0, - LP_JIT_IMAGE_HEIGHT, - LP_JIT_IMAGE_DEPTH, - LP_JIT_IMAGE_BASE, - LP_JIT_IMAGE_ROW_STRIDE, - LP_JIT_IMAGE_IMG_STRIDE, - LP_JIT_IMAGE_NUM_SAMPLES, - LP_JIT_IMAGE_SAMPLE_STRIDE, - LP_JIT_IMAGE_NUM_FIELDS /* number of fields above */ -}; - - /** * This structure is passed directly to the generated fragment shader. *