radeonsi: fix instanced arrays with non-zero start instance
authorMarek Olšák <marek.olsak@amd.com>
Sat, 31 Jan 2015 18:00:44 +0000 (19:00 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 4 Feb 2015 13:34:13 +0000 (14:34 +0100)
Fixes piglit ARB_base_instance/arb_base_instance-drawarrays.

Cc: 10.3 10.4 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeonsi/si_shader.c

index fb1419ddb4d5181c5315ca81d6ba8adcf811daa0..4b1279cc26b70d73f7fdfab94ce1722264312749 100644 (file)
@@ -236,14 +236,14 @@ static LLVMValueRef get_instance_index_for_fetch(
 
        LLVMValueRef result = LLVMGetParam(radeon_bld->main_fn,
                                           si_shader_ctx->param_instance_id);
-       result = LLVMBuildAdd(gallivm->builder, result, LLVMGetParam(
-                       radeon_bld->main_fn, SI_PARAM_START_INSTANCE), "");
 
+       /* The division must be done before START_INSTANCE is added. */
        if (divisor > 1)
                result = LLVMBuildUDiv(gallivm->builder, result,
                                lp_build_const_int32(gallivm, divisor), "");
 
-       return result;
+       return LLVMBuildAdd(gallivm->builder, result, LLVMGetParam(
+                       radeon_bld->main_fn, SI_PARAM_START_INSTANCE), "");
 }
 
 static void declare_input_vs(