llvmpipe/draw: wire up indirect offset
authorDave Airlie <airlied@redhat.com>
Mon, 15 Jun 2020 07:21:27 +0000 (17:21 +1000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Jul 2020 04:12:17 +0000 (04:12 +0000)
This bounds checks and adds to the llvm index.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3778>

src/gallium/auxiliary/draw/draw_llvm_sample.c
src/gallium/drivers/llvmpipe/lp_tex_sample.c

index 76b83730004ab341792129f9c17c3d8ac88a076b..faffe42a0d1cc89cc1f00f4c9cd697eb85e72ed0 100644 (file)
@@ -119,6 +119,11 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
    /* context[0].textures[unit] */
    indices[2] = lp_build_const_int32(gallivm, texture_unit);
+   if (texture_unit_offset) {
+      indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], texture_unit_offset, "");
+      LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, indices[2], lp_build_const_int32(gallivm, PIPE_MAX_SHADER_SAMPLER_VIEWS), "");
+      indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], lp_build_const_int32(gallivm, texture_unit), "");
+   }
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
@@ -211,6 +216,11 @@ draw_llvm_image_member(const struct lp_sampler_dynamic_state *base,
    indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_IMAGES);
    /* context[0].textures[unit] */
    indices[2] = lp_build_const_int32(gallivm, image_unit);
+   if (image_unit_offset) {
+      indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], image_unit_offset, "");
+      LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, indices[2], lp_build_const_int32(gallivm, PIPE_MAX_SHADER_IMAGES), "");
+      indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], lp_build_const_int32(gallivm, image_unit), "");
+   }
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
index a8d18d772d92552bbb6520812ffb35d200ffed9f..ea44970d0b76ff36aba2b5f9b83b793945955043 100644 (file)
@@ -128,6 +128,11 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
    indices[1] = lp_build_const_int32(gallivm, LP_JIT_CTX_TEXTURES);
    /* context[0].textures[unit] */
    indices[2] = lp_build_const_int32(gallivm, texture_unit);
+   if (texture_unit_offset) {
+      indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], texture_unit_offset, "");
+      LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, indices[2], lp_build_const_int32(gallivm, PIPE_MAX_SHADER_SAMPLER_VIEWS), "");
+      indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], lp_build_const_int32(gallivm, texture_unit), "");
+   }
    /* context[0].textures[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);
 
@@ -275,6 +280,11 @@ lp_llvm_image_member(const struct lp_sampler_dynamic_state *base,
    indices[1] = lp_build_const_int32(gallivm, LP_JIT_CTX_IMAGES);
    /* context[0].images[unit] */
    indices[2] = lp_build_const_int32(gallivm, image_unit);
+   if (image_unit_offset) {
+      indices[2] = LLVMBuildAdd(gallivm->builder, indices[2], image_unit_offset, "");
+      LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntULT, indices[2], lp_build_const_int32(gallivm, PIPE_MAX_SHADER_IMAGES), "");
+      indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2], lp_build_const_int32(gallivm, image_unit), "");
+   }
    /* context[0].images[unit].member */
    indices[3] = lp_build_const_int32(gallivm, member_index);