st/nine: Fix usage of rasterizer multisample bit.
authorAxel Davy <axel.davy@ens.fr>
Sun, 3 Apr 2016 11:04:39 +0000 (13:04 +0200)
committerAxel Davy <axel.davy@ens.fr>
Wed, 18 May 2016 21:37:14 +0000 (23:37 +0200)
pipe_rasterizer multisample bit should be enabled only when really
wanting to do multisampling, thus we should disable when not having
msaa render target.
This fixes some depth calculation precision issues on radeon.
Also disable it when depth and stencil tests are disabled, since in that
case multisampling is same as not multisampled.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/device9.c
src/gallium/state_trackers/nine/nine_pipe.c
src/gallium/state_trackers/nine/nine_state.c
src/gallium/state_trackers/nine/nine_state.h

index ed5d17a6e071f4616d4a095fe940ba32f1132a2f..b29e161869ca1d8e486b10b2e0a6030ff33fe137 100644 (file)
@@ -1833,7 +1833,7 @@ NineDevice9_SetRenderTarget( struct NineDevice9 *This,
         This->state.scissor.maxx = rt->desc.Width;
         This->state.scissor.maxy = rt->desc.Height;
 
-        This->state.changed.group |= NINE_STATE_VIEWPORT | NINE_STATE_SCISSOR;
+        This->state.changed.group |= NINE_STATE_VIEWPORT | NINE_STATE_SCISSOR | NINE_STATE_MULTISAMPLE;
     }
 
     if (This->state.rt[i] != NineSurface9(pRenderTarget)) {
index fc708c29d38561e5b1d69265f81d41830a1c3d60..79b910c482fba7bd309e39315930496b2da7ff31 100644 (file)
@@ -94,7 +94,7 @@ nine_convert_rasterizer_state(struct pipe_rasterizer_state *rast_state, const DW
     rast.sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
     rast.point_quad_rasterization = 1;
     rast.point_size_per_vertex = rs[NINED3DRS_VSPOINTSIZE];
-    rast.multisample = !!rs[D3DRS_MULTISAMPLEANTIALIAS];
+    rast.multisample = rs[NINED3DRS_MULTISAMPLE];
     rast.line_smooth = !!rs[D3DRS_ANTIALIASEDLINEENABLE];
  /* rast.line_stipple_enable = 0; */
     rast.line_last_pixel = !!rs[D3DRS_LASTPIXEL];
index 5013b582df7275d62b82a2945d012e02abc84db4..095c998876d950f3695494c2491efa1cf2d76110 100644 (file)
 
 #define DBG_CHANNEL DBG_DEVICE
 
+/* Check if some states need to be set dirty */
+
+static inline DWORD
+check_multisample(struct NineDevice9 *device)
+{
+    DWORD *rs = device->state.rs;
+    DWORD new_value = (rs[D3DRS_ZENABLE] || rs[D3DRS_STENCILENABLE]) &&
+                      device->state.rt[0]->desc.MultiSampleType >= 1 &&
+                      rs[D3DRS_MULTISAMPLEANTIALIAS];
+    if (rs[NINED3DRS_MULTISAMPLE] != new_value) {
+        rs[NINED3DRS_MULTISAMPLE] = new_value;
+        return NINE_STATE_RASTERIZER;
+    }
+    return 0;
+}
+
 /* State preparation only */
 
 static inline void
@@ -908,7 +924,8 @@ commit_ps(struct NineDevice9 *device)
     NINE_STATE_TEXTURE |    \
     NINE_STATE_SAMPLER |    \
     NINE_STATE_VS_CONST |   \
-    NINE_STATE_PS_CONST)
+    NINE_STATE_PS_CONST |   \
+    NINE_STATE_MULTISAMPLE)
 
 #define NINE_STATE_COMMON \
    (NINE_STATE_FB |       \
@@ -1004,6 +1021,8 @@ nine_update_state(struct NineDevice9 *device)
     }
 
     if (likely(group & (NINE_STATE_FREQUENT | NINE_STATE_VS | NINE_STATE_PS))) {
+        if (group & NINE_STATE_MULTISAMPLE)
+            group |= check_multisample(device);
         if (group & NINE_STATE_RASTERIZER)
             prepare_rasterizer(device);
         if (group & (NINE_STATE_TEXTURE | NINE_STATE_SAMPLER))
@@ -1188,7 +1207,8 @@ static const DWORD nine_render_state_defaults[NINED3DRS_LAST + 1] =
     [D3DRS_BLENDOPALPHA] = D3DBLENDOP_ADD,
     [NINED3DRS_VSPOINTSIZE] = FALSE,
     [NINED3DRS_RTMASK] = 0xf,
-    [NINED3DRS_ALPHACOVERAGE] = FALSE
+    [NINED3DRS_ALPHACOVERAGE] = FALSE,
+    [NINED3DRS_MULTISAMPLE] = FALSE
 };
 static const DWORD nine_tex_stage_state_defaults[NINED3DTSS_LAST + 1] =
 {
@@ -1472,7 +1492,7 @@ const uint32_t nine_render_states_vertex[(NINED3DRS_LAST + 31) / 32] =
 /* TODO: put in the right values */
 const uint32_t nine_render_state_group[NINED3DRS_LAST + 1] =
 {
-    [D3DRS_ZENABLE] = NINE_STATE_DSA,
+    [D3DRS_ZENABLE] = NINE_STATE_DSA | NINE_STATE_MULTISAMPLE,
     [D3DRS_FILLMODE] = NINE_STATE_RASTERIZER,
     [D3DRS_SHADEMODE] = NINE_STATE_RASTERIZER,
     [D3DRS_ZWRITEENABLE] = NINE_STATE_DSA,
@@ -1494,7 +1514,7 @@ const uint32_t nine_render_state_group[NINED3DRS_LAST + 1] =
     [D3DRS_FOGEND] = NINE_STATE_FF_OTHER | NINE_STATE_PS_CONST,
     [D3DRS_FOGDENSITY] = NINE_STATE_FF_OTHER | NINE_STATE_PS_CONST,
     [D3DRS_RANGEFOGENABLE] = NINE_STATE_FF_OTHER,
-    [D3DRS_STENCILENABLE] = NINE_STATE_DSA,
+    [D3DRS_STENCILENABLE] = NINE_STATE_DSA | NINE_STATE_MULTISAMPLE,
     [D3DRS_STENCILFAIL] = NINE_STATE_DSA,
     [D3DRS_STENCILZFAIL] = NINE_STATE_DSA,
     [D3DRS_STENCILPASS] = NINE_STATE_DSA,
@@ -1531,7 +1551,7 @@ const uint32_t nine_render_state_group[NINED3DRS_LAST + 1] =
     [D3DRS_POINTSCALE_A] = NINE_STATE_FF_OTHER,
     [D3DRS_POINTSCALE_B] = NINE_STATE_FF_OTHER,
     [D3DRS_POINTSCALE_C] = NINE_STATE_FF_OTHER,
-    [D3DRS_MULTISAMPLEANTIALIAS] = NINE_STATE_RASTERIZER,
+    [D3DRS_MULTISAMPLEANTIALIAS] = NINE_STATE_MULTISAMPLE,
     [D3DRS_MULTISAMPLEMASK] = NINE_STATE_SAMPLE_MASK,
     [D3DRS_PATCHEDGESTYLE] = NINE_STATE_UNHANDLED,
     [D3DRS_DEBUGMONITORTOKEN] = NINE_STATE_UNHANDLED,
index 7e7a8996c917f5d339477d26442e3135d15f9a43..d3c36f84eab1e24e5c970c5dc8beceeb1ff961f4 100644 (file)
  * bit 1: ATOC is on
  */
 #define NINED3DRS_ALPHACOVERAGE  (D3DRS_BLENDOPALPHA + 3)
+#define NINED3DRS_MULTISAMPLE  (D3DRS_BLENDOPALPHA + 4)
 
 #define D3DRS_LAST       D3DRS_BLENDOPALPHA
-#define NINED3DRS_LAST   NINED3DRS_ALPHACOVERAGE /* 213 */
+#define NINED3DRS_LAST   NINED3DRS_MULTISAMPLE /* 214 */
 #define NINED3DSAMP_LAST NINED3DSAMP_SHADOW /* 15 */
 #define NINED3DTSS_LAST  D3DTSS_CONSTANT
 #define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)
@@ -82,8 +83,9 @@
 #define NINE_STATE_FOG_SHADER  (1 << 25)
 #define NINE_STATE_PS1X_SHADER (1 << 26)
 #define NINE_STATE_POINTSIZE_SHADER (1 << 27)
-#define NINE_STATE_ALL          0xfffffff
-#define NINE_STATE_UNHANDLED   (1 << 28)
+#define NINE_STATE_MULTISAMPLE (1 << 28)
+#define NINE_STATE_ALL          0x1fffffff
+#define NINE_STATE_UNHANDLED   (1 << 29)
 
 #define NINE_STATE_COMMIT_DSA  (1 << 0)
 #define NINE_STATE_COMMIT_RASTERIZER (1 << 1)