[Mesa-dev] [PATCH 5/5] radeonsi: add preloading for all samplers

Christian König deathsimple at vodafone.de
Fri Mar 22 02:54:40 PDT 2013


Am 21.03.2013 17:20, schrieb Alex Deucher:
> On Thu, Mar 21, 2013 at 12:09 PM, Christian König
> <deathsimple at vodafone.de> wrote:
>> Am 21.03.2013 15:10, schrieb Alex Deucher:
>>
>>> On Thu, Mar 21, 2013 at 7:38 AM, Christian König
>>> <deathsimple at vodafone.de> wrote:
>>>> From: Christian König <christian.koenig at amd.com>
>>>>
>>>> Signed-off-by: Christian König <christian.koenig at amd.com>
>>>> ---
>>>>    src/gallium/drivers/radeonsi/radeonsi_shader.c |   57
>>>> +++++++++++++++++++-----
>>>>    1 file changed, 45 insertions(+), 12 deletions(-)
>>>>
>>>> diff --git a/src/gallium/drivers/radeonsi/radeonsi_shader.c
>>>> b/src/gallium/drivers/radeonsi/radeonsi_shader.c
>>>> index 33f79e7..840537a 100644
>>>> --- a/src/gallium/drivers/radeonsi/radeonsi_shader.c
>>>> +++ b/src/gallium/drivers/radeonsi/radeonsi_shader.c
>>>> @@ -63,6 +63,8 @@ struct si_shader_context
>>>>           LLVMValueRef const_md;
>>>>           LLVMValueRef const_resource;
>>>>           LLVMValueRef *constants;
>>>> +       LLVMValueRef *resources;
>>>> +       LLVMValueRef *samplers;
>>>>    };
>>>>
>>>>    static struct si_shader_context * si_shader_context(
>>>> @@ -740,8 +742,6 @@ static void tex_fetch_args(
>>>>           const struct tgsi_full_instruction * inst = emit_data->inst;
>>>>           unsigned opcode = inst->Instruction.Opcode;
>>>>           unsigned target = inst->Texture.Texture;
>>>> -       LLVMValueRef ptr;
>>>> -       LLVMValueRef offset;
>>>>           LLVMValueRef coords[4];
>>>>           LLVMValueRef address[16];
>>>>           unsigned count = 0;
>>>> @@ -859,18 +859,10 @@ static void tex_fetch_args(
>>>>           emit_data->args[1] = lp_build_gather_values(gallivm, address,
>>>> count);
>>>>
>>>>           /* Resource */
>>>> -       ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn,
>>>> SI_PARAM_RESOURCE);
>>>> -       offset = lp_build_const_int32(bld_base->base.gallivm,
>>>> -
>>>> emit_data->inst->Src[1].Register.Index);
>>>> -       emit_data->args[2] = build_indexed_load(si_shader_ctx,
>>>> -                                               ptr, offset);
>>>> +       emit_data->args[2] =
>>>> si_shader_ctx->resources[emit_data->inst->Src[1].Register.Index];
>>>>
>>>>           /* Sampler */
>>>> -       ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn,
>>>> SI_PARAM_SAMPLER);
>>>> -       offset = lp_build_const_int32(bld_base->base.gallivm,
>>>> -
>>>> emit_data->inst->Src[1].Register.Index);
>>>> -       emit_data->args[3] = build_indexed_load(si_shader_ctx,
>>>> -                                               ptr, offset);
>>>> +       emit_data->args[3] =
>>>> si_shader_ctx->samplers[emit_data->inst->Src[1].Register.Index];
>>>>
>>>>           /* Dimensions */
>>>>           emit_data->args[4] =
>>>> lp_build_const_int32(bld_base->base.gallivm, target);
>>>> @@ -1009,6 +1001,40 @@ static void preload_constants(struct
>>>> si_shader_context *si_shader_ctx)
>>>>           }
>>>>    }
>>>>
>>>> +static void preload_samplers(struct si_shader_context *si_shader_ctx)
>>>> +{
>>>> +       struct lp_build_tgsi_context * bld_base =
>>>> &si_shader_ctx->radeon_bld.soa.bld_base;
>>>> +       struct gallivm_state * gallivm = bld_base->base.gallivm;
>>>> +       const struct tgsi_shader_info * info = bld_base->info;
>>>> +
>>>> +       unsigned i, num_samplers = info->file_max[TGSI_FILE_SAMPLER] + 1;
>>>> +
>>>> +       LLVMValueRef res_ptr, samp_ptr;
>>>> +       LLVMValueRef offset;
>>>> +
>>>> +       if (num_samplers == 0)
>>>> +               return;
>>>> +
>>>> +       /* Allocate space for the values */
>>>> +       si_shader_ctx->resources = CALLOC(num_samplers,
>>>> sizeof(LLVMValueRef));
>>>> +       si_shader_ctx->samplers = CALLOC(num_samplers,
>>>> sizeof(LLVMValueRef));
>>>> +
>>>> +       res_ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn,
>>>> SI_PARAM_RESOURCE);
>>>> +       samp_ptr = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn,
>>>> SI_PARAM_SAMPLER);
>>>> +
>>>> +       /* Load the resources and samplers, we rely on the code sinking
>>>> to do the rest */
>>>> +       for (i = 0; i < num_samplers; ++i) {
>>>> +
>>>> +               /* Resource */
>>>> +               offset = lp_build_const_int32(gallivm, i);
>>>> +               si_shader_ctx->resources[i] =
>>>> build_indexed_load(si_shader_ctx, res_ptr, offset);
>>>> +
>>>> +               /* Sampler */
>>>> +               offset = lp_build_const_int32(gallivm, i);
>>>> +               si_shader_ctx->samplers[i] =
>>>> build_indexed_load(si_shader_ctx, samp_ptr, offset);
>>>> +       }
>>>> +}
>>>> +
>>>
>>> Is there ever a case when num_samplers != num_resources?
>>
>> Currently not, so it would be possible to put it into one structure, but I
>> like to keep that separate, just in case we get separate sampler/resources.
>>
> I was thinking there may be cases with more samplers than resources.

Not that I know about any, or do you have anything specific in mind?

Christian.


More information about the mesa-dev mailing list