diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index f0650f4..1366c87 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -77,6 +77,7 @@ struct si_shader_context LLVMValueRef *samplers; LLVMValueRef so_buffers[4]; LLVMValueRef gs_next_vertex; + LLVMValueRef sample; }; static struct si_shader_context * si_shader_context( @@ -1893,6 +1894,85 @@ static void tex_fetch_args( emit_data->args[0] = lp_build_gather_values(gallivm, address, count); } +static void handle_depth_compare_mode(const struct lp_build_tgsi_action * action, + struct lp_build_tgsi_context *bld_base, + struct lp_build_emit_data *emit_data) +{ + struct si_shader_context *si_shader_ctx = si_shader_context(bld_base); + struct gallivm_state *gallivm = bld_base->base.gallivm; + struct lp_build_context *base = &bld_base->base; + unsigned sampler_src = emit_data->inst->Instruction.NumSrcRegs - 1; + unsigned sampler_index = emit_data->inst->Src[sampler_src].Register.Index; + struct tgsi_full_instruction non_shadow_inst; + struct lp_build_if_state if_ctx; + unsigned non_shadow_target; + LLVMValueRef compare; + char intr_name[127]; + + switch (emit_data->inst->Texture.Texture) { + case TGSI_TEXTURE_SHADOW1D: + non_shadow_target = TGSI_TEXTURE_1D; + break; + case TGSI_TEXTURE_SHADOW2D: + non_shadow_target = TGSI_TEXTURE_2D; + break; + case TGSI_TEXTURE_SHADOWRECT: + non_shadow_target = TGSI_TEXTURE_RECT; + break; + case TGSI_TEXTURE_SHADOW1D_ARRAY: + non_shadow_target = TGSI_TEXTURE_1D_ARRAY; + break; + case TGSI_TEXTURE_SHADOW2D_ARRAY: + non_shadow_target = TGSI_TEXTURE_2D_ARRAY; + break; + case TGSI_TEXTURE_SHADOWCUBE: + non_shadow_target = TGSI_TEXTURE_CUBE; + break; + case TGSI_TEXTURE_SHADOWCUBE_ARRAY: + non_shadow_target = TGSI_TEXTURE_CUBE_ARRAY; + break; + default: + return; + } + + memcpy(&non_shadow_inst, emit_data->inst, sizeof(non_shadow_inst)); + non_shadow_inst.Texture.Texture = non_shadow_target; + emit_data->inst = &non_shadow_inst; + + compare = LLVMBuildICmp(gallivm->builder, LLVMIntUGE, + LLVMBuildExtractElement(gallivm->builder, + si_shader_ctx->samplers[sampler_index], + lp_build_const_int32(gallivm, 3), ""), + LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), 0x80, 0), ""); + + if (!si_shader_ctx->sample) + si_shader_ctx->sample = lp_build_alloca(gallivm, emit_data->dst_type, ""); + + lp_build_if(&if_ctx, gallivm, compare); + { + LLVMBuildStore(gallivm->builder, emit_data->output[emit_data->chan], + si_shader_ctx->sample); + } + lp_build_else(&if_ctx); + { + tex_fetch_args(bld_base, emit_data); + + sprintf(intr_name, "%sv%ui32", action->intr_name, + LLVMGetVectorSize(LLVMTypeOf(emit_data->args[0]))); + + emit_data->output[emit_data->chan] = build_intrinsic( + base->gallivm->builder, intr_name, emit_data->dst_type, + emit_data->args, emit_data->arg_count, + LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + LLVMBuildStore(gallivm->builder, emit_data->output[emit_data->chan], + si_shader_ctx->sample); + } + lp_build_endif(&if_ctx); + + emit_data->output[emit_data->chan] = + LLVMBuildLoad(gallivm->builder, si_shader_ctx->sample, ""); +} + static void build_tex_intrinsic(const struct lp_build_tgsi_action * action, struct lp_build_tgsi_context * bld_base, struct lp_build_emit_data * emit_data) @@ -1916,6 +1996,8 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action * action, base->gallivm->builder, intr_name, emit_data->dst_type, emit_data->args, emit_data->arg_count, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + + handle_depth_compare_mode(action, bld_base, emit_data); } static void build_new_tex_intrinsic(const struct lp_build_tgsi_action * action, @@ -1939,6 +2021,8 @@ static void build_new_tex_intrinsic(const struct lp_build_tgsi_action * action, base->gallivm->builder, intr_name, emit_data->dst_type, emit_data->args, emit_data->arg_count, LLVMReadNoneAttribute | LLVMNoUnwindAttribute); + + handle_depth_compare_mode(action, bld_base, emit_data); } static void txq_fetch_args( diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index cbd51ad..9559b14 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -2671,7 +2671,8 @@ static void *si_create_sampler_state(struct pipe_context *ctx, r600_tex_aniso_filter(state->max_anisotropy) << 9 | S_008F30_DEPTH_COMPARE_FUNC(si_tex_compare(state->compare_func)) | S_008F30_FORCE_UNNORMALIZED(!state->normalized_coords) | - S_008F30_DISABLE_CUBE_WRAP(!state->seamless_cube_map)); + S_008F30_DISABLE_CUBE_WRAP(!state->seamless_cube_map) | + state->compare_mode << 31); rstate->val[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 8)) | S_008F34_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 8))); rstate->val[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 8)) |