freedreno: implements get_sample_position
authorHyunjun Ko <zzoon@igalia.com>
Wed, 7 Nov 2018 02:30:31 +0000 (11:30 +0900)
committerRob Clark <robdclark@gmail.com>
Tue, 27 Nov 2018 20:44:03 +0000 (15:44 -0500)
Since 1285f71d3e landed, it needs to provide apps with proper sample
position for MSAA.

Currently no way to query this to hw, these are taken from blob driver.

Fixes: dEQP-GLES31.functional.texture.multisample.samples_#.sample_position
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/freedreno_resource.c

index bd7be94c859130329a0b27c1650dee3b6b428c47..252fd84b4561eecb1a66fdb1ad38c67da1fef0f3 100644 (file)
@@ -1194,6 +1194,50 @@ fd_resource_screen_init(struct pipe_screen *pscreen)
                screen->setup_slices = fd_setup_slices;
 }
 
+static void
+fd_get_sample_position(struct pipe_context *context,
+                         unsigned sample_count, unsigned sample_index,
+                         float *pos_out)
+{
+       /* The following is copied from nouveau/nv50 except for position
+        * values, which are taken from blob driver */
+       static const uint8_t pos1[1][2] = { { 0x8, 0x8 } };
+       static const uint8_t pos2[2][2] = {
+               { 0xc, 0xc }, { 0x4, 0x4 } };
+       static const uint8_t pos4[4][2] = {
+               { 0x6, 0x2 }, { 0xe, 0x6 },
+               { 0x2, 0xa }, { 0xa, 0xe } };
+       /* TODO needs to be verified on supported hw */
+       static const uint8_t pos8[8][2] = {
+               { 0x9, 0x5 }, { 0x7, 0xb },
+               { 0xd, 0x9 }, { 0x5, 0x3 },
+               { 0x3, 0xd }, { 0x1, 0x7 },
+               { 0xb, 0xf }, { 0xf, 0x1 } };
+
+       const uint8_t (*ptr)[2];
+
+       switch (sample_count) {
+       case 1:
+               ptr = pos1;
+               break;
+       case 2:
+               ptr = pos2;
+               break;
+       case 4:
+               ptr = pos4;
+               break;
+       case 8:
+               ptr = pos8;
+               break;
+       default:
+               assert(0);
+               return;
+       }
+
+       pos_out[0] = ptr[sample_index][0] / 16.0f;
+       pos_out[1] = ptr[sample_index][1] / 16.0f;
+}
+
 void
 fd_resource_context_init(struct pipe_context *pctx)
 {
@@ -1208,4 +1252,5 @@ fd_resource_context_init(struct pipe_context *pctx)
        pctx->blit = fd_blit;
        pctx->flush_resource = fd_flush_resource;
        pctx->invalidate_resource = fd_invalidate_resource;
+       pctx->get_sample_position = fd_get_sample_position;
 }