2017-10-07 22:33:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
2018-04-01 21:49:48 +01:00
|
|
|
* All Rights Reserved.
|
2017-10-07 22:33:44 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-04-01 23:42:33 +01:00
|
|
|
#include "si_build_pm4.h"
|
2017-10-07 22:33:44 +01:00
|
|
|
|
|
|
|
/* For MSAA sample positions. */
|
|
|
|
#define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \
|
2018-04-27 02:53:33 +01:00
|
|
|
((((unsigned)(s0x) & 0xf) << 0) | (((unsigned)(s0y) & 0xf) << 4) | \
|
|
|
|
(((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \
|
|
|
|
(((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \
|
2017-10-07 22:33:44 +01:00
|
|
|
(((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))
|
|
|
|
|
2018-04-28 03:02:04 +01:00
|
|
|
/* For obtaining location coordinates from registers */
|
|
|
|
#define SEXT4(x) ((int)((x) | ((x) & 0x8 ? 0xfffffff0 : 0)))
|
|
|
|
#define GET_SFIELD(reg, index) SEXT4(((reg) >> ((index) * 4)) & 0xf)
|
|
|
|
#define GET_SX(reg, index) GET_SFIELD((reg)[(index) / 4], ((index) % 4) * 2)
|
|
|
|
#define GET_SY(reg, index) GET_SFIELD((reg)[(index) / 4], ((index) % 4) * 2 + 1)
|
|
|
|
|
|
|
|
/* 1x MSAA */
|
|
|
|
static const uint32_t sample_locs_1x =
|
|
|
|
FILL_SREG( 0, 0, 0, 0, 0, 0, 0, 0); /* S1, S2, S3 fields are not used by 1x */
|
|
|
|
|
|
|
|
/* 2x MSAA */
|
2018-04-27 02:53:33 +01:00
|
|
|
static const uint32_t sample_locs_2x =
|
|
|
|
FILL_SREG(4, 4, -4, -4, 0, 0, 0, 0); /* S2 & S3 fields are not used by 2x MSAA */
|
|
|
|
|
2017-10-07 22:33:44 +01:00
|
|
|
/* 4xMSAA
|
|
|
|
* There are 4 locations: (-2, -6), (6, -2), (-6, 2), (2, 6). */
|
2018-04-27 02:53:33 +01:00
|
|
|
static const uint32_t sample_locs_4x =
|
|
|
|
FILL_SREG(-2, -6, 6, -2, -6, 2, 2, 6);
|
2017-10-07 22:33:44 +01:00
|
|
|
|
|
|
|
/* Cayman 8xMSAA */
|
|
|
|
static const uint32_t sample_locs_8x[] = {
|
|
|
|
FILL_SREG( 1, -3, -1, 3, 5, 1, -3, -5),
|
|
|
|
FILL_SREG(-5, 5, -7, -1, 3, 7, 7, -7),
|
|
|
|
};
|
|
|
|
/* Cayman 16xMSAA */
|
|
|
|
static const uint32_t sample_locs_16x[] = {
|
|
|
|
FILL_SREG( 1, 1, -1, -3, -3, 2, 4, -1),
|
|
|
|
FILL_SREG(-5, -2, 2, 5, 5, 3, 3, -5),
|
|
|
|
FILL_SREG(-2, 6, 0, -7, -4, -6, -6, 4),
|
|
|
|
FILL_SREG(-8, 0, 7, -4, 6, 7, -7, -8),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void si_get_sample_position(struct pipe_context *ctx, unsigned sample_count,
|
|
|
|
unsigned sample_index, float *out_value)
|
|
|
|
{
|
2018-04-28 03:02:04 +01:00
|
|
|
const uint32_t *sample_locs;
|
2017-10-07 22:33:44 +01:00
|
|
|
|
|
|
|
switch (sample_count) {
|
|
|
|
case 1:
|
|
|
|
default:
|
2018-04-28 03:02:04 +01:00
|
|
|
sample_locs = &sample_locs_1x;
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-04-28 03:02:04 +01:00
|
|
|
sample_locs = &sample_locs_2x;
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-04-28 03:02:04 +01:00
|
|
|
sample_locs = &sample_locs_4x;
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-04-28 03:02:04 +01:00
|
|
|
sample_locs = sample_locs_8x;
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
2018-04-28 03:02:04 +01:00
|
|
|
sample_locs = sample_locs_16x;
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-04-28 03:02:04 +01:00
|
|
|
|
|
|
|
out_value[0] = (GET_SX(sample_locs, sample_index) + 8) / 16.0f;
|
|
|
|
out_value[1] = (GET_SY(sample_locs, sample_index) + 8) / 16.0f;
|
2017-10-07 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void si_emit_sample_locations(struct radeon_winsys_cs *cs, int nr_samples)
|
|
|
|
{
|
|
|
|
switch (nr_samples) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2017-10-07 23:03:10 +01:00
|
|
|
radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 0);
|
|
|
|
radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, 0);
|
|
|
|
radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, 0);
|
|
|
|
radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, 0);
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, sample_locs_2x);
|
|
|
|
radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, sample_locs_2x);
|
|
|
|
radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, sample_locs_2x);
|
|
|
|
radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, sample_locs_2x);
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_set_context_reg(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, sample_locs_4x);
|
|
|
|
radeon_set_context_reg(cs, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0, sample_locs_4x);
|
|
|
|
radeon_set_context_reg(cs, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0, sample_locs_4x);
|
|
|
|
radeon_set_context_reg(cs, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0, sample_locs_4x);
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2017-10-07 23:03:10 +01:00
|
|
|
radeon_set_context_reg_seq(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 14);
|
2017-10-07 22:33:44 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[0]);
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[1]);
|
2017-10-07 22:33:44 +01:00
|
|
|
radeon_emit(cs, 0);
|
|
|
|
radeon_emit(cs, 0);
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[0]);
|
2017-10-07 22:33:44 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[1]);
|
|
|
|
radeon_emit(cs, 0);
|
|
|
|
radeon_emit(cs, 0);
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_8x[1]);
|
2017-10-07 22:33:44 +01:00
|
|
|
radeon_emit(cs, 0);
|
|
|
|
radeon_emit(cs, 0);
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_emit(cs, sample_locs_8x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_8x[1]);
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
case 16:
|
2017-10-07 23:03:10 +01:00
|
|
|
radeon_set_context_reg_seq(cs, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 16);
|
2017-10-07 22:33:44 +01:00
|
|
|
radeon_emit(cs, sample_locs_16x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[1]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[2]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[3]);
|
2018-04-27 02:53:33 +01:00
|
|
|
radeon_emit(cs, sample_locs_16x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[1]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[2]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[3]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[1]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[2]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[3]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[0]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[1]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[2]);
|
|
|
|
radeon_emit(cs, sample_locs_16x[3]);
|
2017-10-07 22:33:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void si_init_msaa_functions(struct si_context *sctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-04-02 00:44:25 +01:00
|
|
|
sctx->b.get_sample_position = si_get_sample_position;
|
2017-10-07 22:33:44 +01:00
|
|
|
|
2018-04-02 00:44:25 +01:00
|
|
|
si_get_sample_position(&sctx->b, 1, 0, sctx->sample_locations_1x[0]);
|
2017-10-07 22:33:44 +01:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
2018-04-02 00:44:25 +01:00
|
|
|
si_get_sample_position(&sctx->b, 2, i, sctx->sample_locations_2x[i]);
|
2017-10-07 22:33:44 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
2018-04-02 00:44:25 +01:00
|
|
|
si_get_sample_position(&sctx->b, 4, i, sctx->sample_locations_4x[i]);
|
2017-10-07 22:33:44 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
2018-04-02 00:44:25 +01:00
|
|
|
si_get_sample_position(&sctx->b, 8, i, sctx->sample_locations_8x[i]);
|
2017-10-07 22:33:44 +01:00
|
|
|
for (i = 0; i < 16; i++)
|
2018-04-02 00:44:25 +01:00
|
|
|
si_get_sample_position(&sctx->b, 16, i, sctx->sample_locations_16x[i]);
|
2017-10-07 22:33:44 +01:00
|
|
|
}
|