From: Dave Airlie Date: Tue, 27 Aug 2019 04:32:46 +0000 (+1000) Subject: gallivm: add compute jit interface. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=25f46ae9aa3b8f114082a1957b5a3f3759d7c123;p=mesa.git gallivm: add compute jit interface. This adds the jit interface for compute shaders, it's based on the fragment shader one. Reviewed-by: Roland Scheidegger --- diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 36062ac56c2..dc99cc4d961 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -316,3 +316,102 @@ lp_jit_init_types(struct lp_fragment_shader_variant *lp) if (!lp->jit_context_ptr_type) lp_jit_create_types(lp); } + +static void +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; + + texture_type = create_jit_texture_type(gallivm); + sampler_type = create_jit_sampler_type(gallivm); + image_type = create_jit_image_type(gallivm); + + /* struct lp_jit_cs_thread_data */ + { + LLVMTypeRef elem_types[LP_JIT_CS_THREAD_DATA_COUNT]; + LLVMTypeRef thread_data_type; + + elem_types[LP_JIT_CS_THREAD_DATA_CACHE] = + LLVMPointerType(lp_build_format_cache_type(gallivm), 0); + + elem_types[LP_JIT_CS_THREAD_DATA_SHARED] = LLVMPointerType(LLVMInt32TypeInContext(lc), 0); + thread_data_type = LLVMStructTypeInContext(lc, elem_types, + ARRAY_SIZE(elem_types), 0); + + lp->jit_cs_thread_data_ptr_type = LLVMPointerType(thread_data_type, 0); + } + + /* struct lp_jit_cs_context */ + { + LLVMTypeRef elem_types[LP_JIT_CS_CTX_COUNT]; + 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); + 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, + PIPE_MAX_SAMPLERS); + 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); + + elem_types[LP_JIT_CS_CTX_SHARED_SIZE] = LLVMInt32TypeInContext(lc); + + cs_context_type = LLVMStructTypeInContext(lc, elem_types, + ARRAY_SIZE(elem_types), 0); + + 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); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, samplers, + gallivm->target, cs_context_type, + LP_JIT_CS_CTX_SAMPLERS); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, images, + gallivm->target, cs_context_type, + LP_JIT_CS_CTX_IMAGES); + 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); + LP_CHECK_STRUCT_SIZE(struct lp_jit_cs_context, + gallivm->target, cs_context_type); + + lp->jit_cs_context_ptr_type = LLVMPointerType(cs_context_type, 0); + } + + if (gallivm_debug & GALLIVM_DEBUG_IR) { +#if HAVE_LLVM >= 0x304 + char *str = LLVMPrintModuleToString(gallivm->module); + fprintf(stderr, "%s", str); + LLVMDisposeMessage(str); +#else + LLVMDumpModule(gallivm->module); +#endif + } +} + +void +lp_jit_init_cs_types(struct lp_compute_shader_variant *lp) +{ + if (!lp->jit_cs_context_ptr_type) + lp_jit_create_cs_types(lp); +} diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index f8d350eea44..8c89cad2939 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -45,6 +45,7 @@ struct lp_build_format_cache; struct lp_fragment_shader_variant; +struct lp_compute_shader_variant; struct llvmpipe_screen; @@ -292,6 +293,94 @@ typedef void unsigned depth_stride); +struct lp_jit_cs_thread_data +{ + struct lp_build_format_cache *cache; + void *shared; +}; + +enum { + LP_JIT_CS_THREAD_DATA_CACHE = 0, + LP_JIT_CS_THREAD_DATA_SHARED = 1, + LP_JIT_CS_THREAD_DATA_COUNT +}; + + +#define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache") + +#define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared") + +struct lp_jit_cs_context +{ + const float *constants[LP_MAX_TGSI_CONST_BUFFERS]; + int num_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]; + + uint32_t shared_size; +}; + +/** + * These enum values must match the position of the fields in the + * lp_jit_context struct above. + */ +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_SHARED_SIZE, + LP_JIT_CS_CTX_COUNT +}; + +#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") + +#define lp_jit_cs_context_samplers(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers") + +#define lp_jit_cs_context_images(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images") + +#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") + + +typedef void +(*lp_jit_cs_func)(const struct lp_jit_cs_context *context, + uint32_t x, + uint32_t y, + uint32_t z, + uint32_t grid_x, + uint32_t grid_y, + uint32_t grid_z, + uint32_t grid_size_x, + uint32_t grid_size_y, + uint32_t grid_size_z, + struct lp_jit_cs_thread_data *thread_data); + void lp_jit_screen_cleanup(struct llvmpipe_screen *screen); @@ -303,5 +392,6 @@ lp_jit_screen_init(struct llvmpipe_screen *screen); void lp_jit_init_types(struct lp_fragment_shader_variant *lp); - +void +lp_jit_init_cs_types(struct lp_compute_shader_variant *lp); #endif /* LP_JIT_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.h b/src/gallium/drivers/llvmpipe/lp_state_cs.h index b2a00a06011..a2c470460bc 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.h +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.h @@ -30,6 +30,8 @@ #include "util/u_thread.h" #include "pipe/p_state.h" +#include "gallivm/lp_bld.h" +#include "lp_jit.h" struct lp_compute_shader_variant; struct lp_compute_shader_variant_key @@ -47,6 +49,9 @@ struct lp_compute_shader_variant struct lp_compute_shader_variant_key key; struct gallivm_state *gallivm; + + LLVMTypeRef jit_cs_context_ptr_type; + LLVMTypeRef jit_cs_thread_data_ptr_type; }; struct lp_compute_shader { @@ -56,6 +61,7 @@ struct lp_compute_shader { }; struct lp_cs_exec { + struct lp_jit_cs_context jit_context; struct lp_compute_shader_variant *variant; };