diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c index 1e7cedaecd9..6a453207193 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c @@ -457,27 +457,14 @@ lp_build_llvm_texture_residency(struct gallivm_state *gallivm, { LLVMBuilderRef builder = gallivm->builder; - static_assert(offsetof(struct lp_descriptor, texture) == 0, "Invalid texture offset"); - LLVMValueRef texture_ptr = gallivm->texture_descriptor; - - LLVMTypeRef texture_ptr_type = LLVMStructGetTypeAtIndex(resources_type, LP_JIT_RES_TEXTURES); - LLVMTypeRef texture_type = LLVMGetElementType(texture_ptr_type); - texture_ptr_type = LLVMPointerType(texture_type, 0); - - texture_ptr = LLVMBuildIntToPtr(builder, texture_ptr, texture_ptr_type, ""); - - static_assert(offsetof(struct lp_jit_texture, row_stride) == offsetof(struct lp_jit_texture, residency), - "Invalid texture descriptor layout"); - LLVMValueRef indices[2] = { - lp_build_const_int32(gallivm, 0), - lp_build_const_int32(gallivm, LP_JIT_TEXTURE_ROW_STRIDE), - }; - LLVMValueRef ptr = LLVMBuildGEP2(builder, texture_type, texture_ptr, indices, ARRAY_SIZE(indices), ""); + LLVMValueRef residency_ptr_ptr = gallivm->texture_descriptor; + residency_ptr_ptr = LLVMBuildAdd(builder, residency_ptr_ptr, + lp_build_const_int64(gallivm, offsetof(struct lp_descriptor, texture.residency)), ""); LLVMTypeRef residency_type = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); - ptr = LLVMBuildBitCast(builder, ptr, LLVMPointerType(residency_type, 0), ""); + residency_ptr_ptr = LLVMBuildIntToPtr(builder, residency_ptr_ptr, LLVMPointerType(residency_type, 0), ""); - return LLVMBuildLoad2(builder, residency_type, ptr, ""); + return LLVMBuildLoad2(builder, residency_type, residency_ptr_ptr, ""); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h index 86771c53545..2c3a4756a40 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h @@ -235,10 +235,17 @@ struct lp_texture_handle { uint32_t sampler_index; }; +struct lp_jit_bindless_texture +{ + const void *base; + const void *residency; + uint32_t sampler_index; +}; + struct lp_descriptor { union { struct { - struct lp_jit_texture texture; + struct lp_jit_bindless_texture texture; struct lp_jit_sampler sampler; }; struct { diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index ae193b6d408..b29cf1a6603 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -499,6 +499,39 @@ lp_jit_texture_from_pipe(struct lp_jit_texture *jit, const struct pipe_sampler_v } } +void +lp_jit_bindless_texture_from_pipe(struct lp_jit_bindless_texture *jit, const struct pipe_sampler_view *view) +{ + struct pipe_resource *res = view->texture; + struct llvmpipe_resource *lp_tex = llvmpipe_resource(res); + assert(!lp_tex->dt); + + if (llvmpipe_resource_is_texture(res)) { + jit->base = lp_tex->tex_data; + + if (res->flags & PIPE_RESOURCE_FLAG_SPARSE) + jit->residency = lp_tex->residency; + } else { + jit->base = lp_tex->data; + + /* + * For tex2d_from_buf, adjust width and height with application + * values. If is_tex2d_from_buf is false (1D images), + * adjust using size value (stored as width). + */ + unsigned view_blocksize = util_format_get_blocksize(view->format); + + /* If it's not a 2D texture view of a buffer, adjust using size. */ + if (!view->is_tex2d_from_buf) { + /* Adjust base pointer with offset. */ + jit->base = (uint8_t *)jit->base + view->u.buf.offset; + } else { + jit->base = (uint8_t *)jit->base + + view->u.tex2d_from_buf.offset * view_blocksize; + } + } +} + void lp_jit_texture_buffer_from_bda(struct lp_jit_texture *jit, void *mem, size_t size, enum pipe_format format) { @@ -536,6 +569,12 @@ lp_jit_texture_buffer_from_bda(struct lp_jit_texture *jit, void *mem, size_t siz } } +void +lp_jit_bindless_texture_buffer_from_bda(struct lp_jit_bindless_texture *jit, void *mem) +{ + jit->base = mem; +} + void lp_jit_sampler_from_pipe(struct lp_jit_sampler *jit, const struct pipe_sampler_state *sampler) { diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index b672ad9b080..97c09f6b750 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -387,7 +387,9 @@ void lp_jit_buffer_from_bda(struct lp_jit_buffer *jit, void *mem, size_t size); void lp_jit_buffer_from_pipe(struct lp_jit_buffer *jit, const struct pipe_shader_buffer *buffer); void lp_jit_buffer_from_pipe_const(struct lp_jit_buffer *jit, const struct pipe_constant_buffer *buffer, struct pipe_screen *screen); void lp_jit_texture_from_pipe(struct lp_jit_texture *jit, const struct pipe_sampler_view *view); +void lp_jit_bindless_texture_from_pipe(struct lp_jit_bindless_texture *jit, const struct pipe_sampler_view *view); void lp_jit_texture_buffer_from_bda(struct lp_jit_texture *jit, void *mem, size_t size, enum pipe_format format); +void lp_jit_bindless_texture_buffer_from_bda(struct lp_jit_bindless_texture *jit, void *mem); void lp_jit_sampler_from_pipe(struct lp_jit_sampler *jit, const struct pipe_sampler_state *sampler); void lp_jit_image_from_pipe(struct lp_jit_image *jit, const struct pipe_image_view *view); void lp_jit_image_buffer_from_bda(struct lp_jit_image *jit, void *mem, size_t size, enum pipe_format format); diff --git a/src/gallium/frontends/lavapipe/lvp_descriptor_set.c b/src/gallium/frontends/lavapipe/lvp_descriptor_set.c index 98b7d8700ea..0a2cea4c410 100644 --- a/src/gallium/frontends/lavapipe/lvp_descriptor_set.c +++ b/src/gallium/frontends/lavapipe/lvp_descriptor_set.c @@ -491,7 +491,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets( unsigned plane_count = iview->plane_count; for (unsigned p = 0; p < plane_count; p++) { - lp_jit_texture_from_pipe(&desc[didx + p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[didx + p].texture, iview->planes[p].sv); desc[didx + p].functions = iview->planes[p].texture_handle->functions; } @@ -522,7 +522,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets( unsigned plane_count = iview->plane_count; for (unsigned p = 0; p < plane_count; p++) { - lp_jit_texture_from_pipe(&desc[didx + p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[didx + p].texture, iview->planes[p].sv); desc[didx + p].functions = iview->planes[p].texture_handle->functions; } } else { @@ -559,7 +559,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets( write->pTexelBufferView[j]); assert(bind_layout->stride == 1); if (bview) { - lp_jit_texture_from_pipe(&desc[j].texture, bview->sv); + lp_jit_bindless_texture_from_pipe(&desc[j].texture, bview->sv); desc[j].functions = bview->texture_handle->functions; } else { desc[j].functions = device->null_texture_handle->functions; @@ -798,7 +798,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descri if (iview) { for (unsigned p = 0; p < iview->plane_count; p++) { - lp_jit_texture_from_pipe(&desc[idx + p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[idx + p].texture, iview->planes[p].sv); desc[idx + p].functions = iview->planes[p].texture_handle->functions; } @@ -824,7 +824,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descri if (iview) { for (unsigned p = 0; p < iview->plane_count; p++) { - lp_jit_texture_from_pipe(&desc[idx + p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[idx + p].texture, iview->planes[p].sv); desc[idx + p].functions = iview->planes[p].texture_handle->functions; } } else { @@ -856,7 +856,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descri *(VkBufferView *)pSrc); assert(bind_layout->stride == 1); if (bview) { - lp_jit_texture_from_pipe(&desc[idx].texture, bview->sv); + lp_jit_bindless_texture_from_pipe(&desc[idx].texture, bview->sv); desc[idx].functions = bview->texture_handle->functions; } else { desc[j].functions = device->null_texture_handle->functions; @@ -1015,7 +1015,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT( unsigned plane_count = iview->plane_count; for (unsigned p = 0; p < plane_count; p++) { - lp_jit_texture_from_pipe(&desc[p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[p].texture, iview->planes[p].sv); desc[p].functions = iview->planes[p].texture_handle->functions; if (info->sampler) { @@ -1046,7 +1046,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT( unsigned plane_count = iview->plane_count; for (unsigned p = 0; p < plane_count; p++) { - lp_jit_texture_from_pipe(&desc[p].texture, iview->planes[p].sv); + lp_jit_bindless_texture_from_pipe(&desc[p].texture, iview->planes[p].sv); desc[p].functions = iview->planes[p].texture_handle->functions; } } else { @@ -1084,7 +1084,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT( const VkDescriptorAddressInfoEXT *bda = pCreateInfo->data.pUniformTexelBuffer; if (bda && bda->address) { enum pipe_format pformat = vk_format_to_pipe_format(bda->format); - lp_jit_texture_buffer_from_bda(&desc->texture, (void*)(uintptr_t)bda->address, bda->range, pformat); + lp_jit_bindless_texture_buffer_from_bda(&desc->texture, (void*)(uintptr_t)bda->address); desc->functions = get_texture_handle_bda(device, bda->address, bda->range, pformat).functions; } else { desc->functions = device->null_texture_handle->functions;