radv: fix sample_mask_in loading. (v3.1)
authorDave Airlie <airlied@redhat.com>
Tue, 23 Jan 2018 01:07:26 +0000 (11:07 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 24 Jan 2018 04:25:11 +0000 (14:25 +1000)
This is ported from radeonsi and fixes:
dEQP-VK.pipeline.multisample_shader_builtin.sample_mask.bit_*

v2: don't call this path for radeonsi, it does it in the epilog.
use the radeonsi code path.
v3: handle NULL pCreateInfo->pMultisampleState properly (Samuel)
v3.1: set ps_iter_samples default to 1 (Bas)

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Fixes: bdcbe7c76 (radv: add sample mask input support)
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/common/ac_nir_to_llvm.c
src/amd/common/ac_nir_to_llvm.h
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_private.h

index cc3af77386369fcfcd2005968ef0966028763288..8ae8650a7bf5cad53f40ec1108303c05d22885f4 100644 (file)
@@ -4049,6 +4049,30 @@ static LLVMValueRef load_sample_pos(struct ac_nir_context *ctx)
        return ac_build_gather_values(&ctx->ac, values, 2);
 }
 
+static LLVMValueRef load_sample_mask_in(struct ac_nir_context *ctx)
+{
+       uint8_t log2_ps_iter_samples = ctx->nctx->shader_info->info.ps.force_persample ? ctx->nctx->options->key.fs.log2_num_samples : ctx->nctx->options->key.fs.log2_ps_iter_samples;
+
+       /* The bit pattern matches that used by fixed function fragment
+        * processing. */
+       static const uint16_t ps_iter_masks[] = {
+               0xffff, /* not used */
+               0x5555,
+               0x1111,
+               0x0101,
+               0x0001,
+       };
+       assert(log2_ps_iter_samples < ARRAY_SIZE(ps_iter_masks));
+
+       uint32_t ps_iter_mask = ps_iter_masks[log2_ps_iter_samples];
+
+       LLVMValueRef result, sample_id;
+       sample_id = unpack_param(&ctx->ac, ctx->abi->ancillary, 8, 4);
+       sample_id = LLVMBuildShl(ctx->ac.builder, LLVMConstInt(ctx->ac.i32, ps_iter_mask, false), sample_id, "");
+       result = LLVMBuildAnd(ctx->ac.builder, sample_id, ctx->abi->sample_coverage, "");
+       return result;
+}
+
 static LLVMValueRef visit_interp(struct nir_to_llvm_context *ctx,
                                 const nir_intrinsic_instr *instr)
 {
@@ -4353,7 +4377,10 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
                result = load_sample_pos(ctx);
                break;
        case nir_intrinsic_load_sample_mask_in:
-               result = ctx->abi->sample_coverage;
+               if (ctx->nctx)
+                       result = load_sample_mask_in(ctx);
+               else
+                       result = ctx->abi->sample_coverage;
                break;
        case nir_intrinsic_load_frag_coord: {
                LLVMValueRef values[4] = {
index 62ea38be373bfc75ffd8a08df54f52a34032df7b..1656289e06eb78382fed4b0d4f6ca6c5460487a1 100644 (file)
@@ -60,6 +60,8 @@ struct ac_tcs_variant_key {
 
 struct ac_fs_variant_key {
        uint32_t col_format;
+       uint8_t log2_ps_iter_samples;
+       uint8_t log2_num_samples;
        uint32_t is_int8;
        uint32_t is_int10;
        uint32_t multisample : 1;
index a49fe05993472983a875176717f3dd9cdb8ef995..21333b808abf8f3233047d2f1ab8840784d63217 100644 (file)
@@ -798,6 +798,18 @@ radv_pipeline_init_raster_state(struct radv_pipeline *pipeline,
 
 }
 
+static uint8_t radv_pipeline_get_ps_iter_samples(const VkPipelineMultisampleStateCreateInfo *vkms)
+{
+       uint32_t num_samples = vkms->rasterizationSamples;
+       uint32_t ps_iter_samples = 1;
+
+       if (vkms->sampleShadingEnable) {
+               ps_iter_samples = ceil(vkms->minSampleShading * num_samples);
+               ps_iter_samples = util_next_power_of_two(ps_iter_samples);
+       }
+       return ps_iter_samples;
+}
+
 static void
 radv_pipeline_init_multisample_state(struct radv_pipeline *pipeline,
                                     const VkGraphicsPipelineCreateInfo *pCreateInfo)
@@ -813,9 +825,9 @@ radv_pipeline_init_multisample_state(struct radv_pipeline *pipeline,
        else
                ms->num_samples = 1;
 
-       if (vkms && vkms->sampleShadingEnable) {
-               ps_iter_samples = ceil(vkms->minSampleShading * ms->num_samples);
-       } else if (pipeline->shaders[MESA_SHADER_FRAGMENT]->info.info.ps.force_persample) {
+       if (vkms)
+               ps_iter_samples = radv_pipeline_get_ps_iter_samples(vkms);
+       if (vkms && !vkms->sampleShadingEnable && pipeline->shaders[MESA_SHADER_FRAGMENT]->info.info.ps.force_persample) {
                ps_iter_samples = ms->num_samples;
        }
 
@@ -838,7 +850,7 @@ radv_pipeline_init_multisample_state(struct radv_pipeline *pipeline,
 
        if (ms->num_samples > 1) {
                unsigned log_samples = util_logbase2(ms->num_samples);
-               unsigned log_ps_iter_samples = util_logbase2(util_next_power_of_two(ps_iter_samples));
+               unsigned log_ps_iter_samples = util_logbase2(ps_iter_samples);
                ms->pa_sc_mode_cntl_0 |= S_028A48_MSAA_ENABLE(1);
                ms->pa_sc_line_cntl |= S_028BDC_EXPAND_LINE_WIDTH(1); /* CM_R_028BDC_PA_SC_LINE_CNTL */
                ms->db_eqaa |= S_028804_MAX_ANCHOR_SAMPLES(log_samples) |
@@ -1745,8 +1757,13 @@ radv_generate_graphics_pipeline_key(struct radv_pipeline *pipeline,
 
 
        if (pCreateInfo->pMultisampleState &&
-           pCreateInfo->pMultisampleState->rasterizationSamples > 1)
+           pCreateInfo->pMultisampleState->rasterizationSamples > 1) {
+               uint32_t num_samples = pCreateInfo->pMultisampleState->rasterizationSamples;
+               uint32_t ps_iter_samples = radv_pipeline_get_ps_iter_samples(pCreateInfo->pMultisampleState);
                key.multisample = true;
+               key.log2_num_samples = util_logbase2(num_samples);
+               key.log2_ps_iter_samples = util_logbase2(ps_iter_samples);
+       }
 
        key.col_format = pipeline->graphics.blend.spi_shader_col_format;
        if (pipeline->device->physical_device->rad_info.chip_class < VI)
@@ -1784,6 +1801,8 @@ radv_fill_shader_keys(struct ac_shader_variant_key *keys,
        keys[MESA_SHADER_FRAGMENT].fs.col_format = key->col_format;
        keys[MESA_SHADER_FRAGMENT].fs.is_int8 = key->is_int8;
        keys[MESA_SHADER_FRAGMENT].fs.is_int10 = key->is_int10;
+       keys[MESA_SHADER_FRAGMENT].fs.log2_ps_iter_samples = key->log2_ps_iter_samples;
+       keys[MESA_SHADER_FRAGMENT].fs.log2_num_samples = key->log2_num_samples;
 }
 
 static void
index 808db0007dc96586468df3689988c95dde02eeb4..711ae7192662ccd02146f3f3032a164ca1926a89 100644 (file)
@@ -331,6 +331,8 @@ struct radv_pipeline_key {
        uint32_t col_format;
        uint32_t is_int8;
        uint32_t is_int10;
+       uint8_t log2_ps_iter_samples;
+       uint8_t log2_num_samples;
        uint32_t multisample : 1;
        uint32_t has_multiview_view_index : 1;
 };