st/nine: Implement AMD alpha to coverage
authorAxel Davy <axel.davy@ens.fr>
Wed, 14 Jan 2015 11:33:21 +0000 (12:33 +0100)
committerAxel Davy <axel.davy@ens.fr>
Thu, 5 Feb 2015 23:07:19 +0000 (00:07 +0100)
This D3D hack is supposed to be supported
by all AMD SM2+ cards. Apps use it without
checking if they are on AMD.

Reviewed-by: Tiziano Bacocco <tizbac2@gmail.com>
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 a446c8f233c197d4d0b28e1adc78765ccad1748c..63f9f16586e440d53726c2058c5ea9e65f3d3ae6 100644 (file)
@@ -2049,6 +2049,9 @@ NineDevice9_ResolveZ( struct NineDevice9 *This )
     return D3D_OK;
 }
 
+#define ALPHA_TO_COVERAGE_ENABLE   MAKEFOURCC('A', '2', 'M', '1')
+#define ALPHA_TO_COVERAGE_DISABLE  MAKEFOURCC('A', '2', 'M', '0')
+
 HRESULT WINAPI
 NineDevice9_SetRenderState( struct NineDevice9 *This,
                             D3DRENDERSTATETYPE State,
@@ -2059,8 +2062,18 @@ NineDevice9_SetRenderState( struct NineDevice9 *This,
     DBG("This=%p State=%u(%s) Value=%08x\n", This,
         State, nine_d3drs_to_string(State), Value);
 
-    if (State == D3DRS_POINTSIZE && Value == RESZ_CODE)
-        return NineDevice9_ResolveZ(This);
+    /* Amd hacks (equivalent to GL extensions) */
+    if (State == D3DRS_POINTSIZE) {
+        if (Value == RESZ_CODE)
+            return NineDevice9_ResolveZ(This);
+
+        if (Value == ALPHA_TO_COVERAGE_ENABLE ||
+            Value == ALPHA_TO_COVERAGE_DISABLE) {
+            state->rs[NINED3DRS_ALPHACOVERAGE] = (Value == ALPHA_TO_COVERAGE_ENABLE);
+            state->changed.group |= NINE_STATE_BLEND;
+            return D3D_OK;
+        }
+    }
 
     user_assert(State < Elements(state->rs), D3DERR_INVALIDCALL);
 
index 8543b27b838e7ecf440037cc5614b85b2c72de20..0da0b20263dea464157a3da08d57aa274d3ea454 100644 (file)
@@ -146,7 +146,7 @@ nine_convert_blend_state(struct cso_context *ctx, const DWORD *rs)
     blend.dither = !!rs[D3DRS_DITHERENABLE];
 
  /* blend.alpha_to_one = 0; */
- /* blend.alpha_to_coverage = 0; */ /* XXX */
+    blend.alpha_to_coverage = !!rs[NINED3DRS_ALPHACOVERAGE];
 
     blend.rt[0].blend_enable = !!rs[D3DRS_ALPHABLENDENABLE];
     if (blend.rt[0].blend_enable) {
index 972ed1f40be128a2d352ecf4d3fc84d5388b9a2b..1e533354d64b065ac7b0216575292803ca487861 100644 (file)
@@ -957,7 +957,8 @@ static const DWORD nine_render_state_defaults[NINED3DRS_LAST + 1] =
     [D3DRS_DESTBLENDALPHA] = D3DBLEND_ZERO,
     [D3DRS_BLENDOPALPHA] = D3DBLENDOP_ADD,
     [NINED3DRS_VSPOINTSIZE] = FALSE,
-    [NINED3DRS_RTMASK] = 0xf
+    [NINED3DRS_RTMASK] = 0xf,
+    [NINED3DRS_ALPHACOVERAGE] = FALSE
 };
 static const DWORD nine_tex_stage_state_defaults[NINED3DTSS_LAST + 1] =
 {
index 6e94e68ef1ed8dc69dec671d7c4ff102b1a06613..0cb293396d69680e0dadaf73957c6cd36a9ac30f 100644 (file)
 #define NINED3DRS_VSPOINTSIZE (D3DRS_BLENDOPALPHA + 1)
 #define NINED3DRS_RTMASK      (D3DRS_BLENDOPALPHA + 2)
 #define NINED3DRS_ZBIASSCALE  (D3DRS_BLENDOPALPHA + 3)
+#define NINED3DRS_ALPHACOVERAGE  (D3DRS_BLENDOPALPHA + 4)
 
 #define D3DRS_LAST       D3DRS_BLENDOPALPHA
-#define NINED3DRS_LAST   NINED3DRS_ZBIASSCALE /* 212 */
+#define NINED3DRS_LAST   NINED3DRS_ALPHACOVERAGE /* 213 */
 #define NINED3DSAMP_LAST NINED3DSAMP_SHADOW /* 15 */
 #define NINED3DTSS_LAST  D3DTSS_CONSTANT
 #define NINED3DTS_LAST   D3DTS_WORLDMATRIX(255)