mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 11:03:45 +01:00
[dx9] don't do alpha test in pixel shader, use state mapping
hrydgard: Cleaned up a bit, disabled by default Conflicts: GPU/Directx9/TextureCacheDX9.cpp
This commit is contained in:
1 parent
5d836bfa5a
commit
d4adc3abb8
7 files changed
+30
-16
No files matched your search
@@ -25,8 +25,6 @@
|
||||
|
||||
// #define DEBUG_SHADER
|
||||
|
||||
// GL_NV_shader_framebuffer_fetch looks interesting....
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
static bool IsAlphaTestTriviallyTrue() {
|
||||
@@ -253,19 +251,16 @@ void GenerateFragmentShaderDX9(char *buffer) {
|
||||
WRITE(p, " float4 v = In.v_color0 %s;\n", secondary);
|
||||
}
|
||||
|
||||
#if !defined(DX9_USE_HW_ALPHA_TEST)
|
||||
if (enableAlphaTest) {
|
||||
GEComparison alphaTestFunc = gstate.getAlphaTestFunction();
|
||||
const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; // never/always don't make sense
|
||||
if (alphaTestFuncs[alphaTestFunc][0] != '#') {
|
||||
// WRITE(p, " if (roundAndScaleTo255f(v.a) %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]);
|
||||
//WRITE(p, "clip((roundAndScaleTo255f(v.rgb) %s u_alphacolorref.a)? -1:1);\n", alphaTestFuncs[alphaTestFunc]);
|
||||
|
||||
//WRITE(p, " if (roundAndScaleTo255f(v.a) %s u_alphacolorref.a) clip(-1);\n", alphaTestFuncs[alphaTestFunc]);
|
||||
// TODO: Rewrite this to use clip() appropriately (like, clip(v.a - u_alphacolorref.a))
|
||||
WRITE(p, " if (roundTo255th(v.a) %s u_alphacolorref.a) clip(-1);\n", alphaTestFuncs[alphaTestFunc]);
|
||||
//WRITE(p, " if (roundTo255th(v.a) %s u_alphacolorref.a) v.r=1;\n", alphaTestFuncs[alphaTestFunc]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
// TODO: Before or after the color test?
|
||||
if (enableColorDoubling && enableAlphaDoubling) {
|
||||
WRITE(p, " v = v * 2.0;\n");
|
||||
@@ -280,15 +275,9 @@ void GenerateFragmentShaderDX9(char *buffer) {
|
||||
const char *colorTestFuncs[] = { "#", "#", " != ", " == " }; // never/always don't make sense
|
||||
u32 colorTestMask = gstate.getColorTestMask();
|
||||
if (colorTestFuncs[colorTestFunc][0] != '#') {
|
||||
//WRITE(p, "clip((roundAndScaleTo255v(v.rgb) %s u_alphacolorref.rgb)? -1:1);\n", colorTestFuncs[colorTestFunc]);
|
||||
//WRITE(p, "if (roundAndScaleTo255v(v.rgb) %s u_alphacolorref.rgb) clip(-1);\n", colorTestFuncs[colorTestFunc]);
|
||||
|
||||
// cleanup ?
|
||||
const char * test = colorTestFuncs[colorTestFunc];
|
||||
//WRITE(p, "float3 colortest = roundAndScaleTo255v(v.rgb);\n");
|
||||
WRITE(p, "float3 colortest = roundTo255thv(v.rgb);\n");
|
||||
WRITE(p, "if ((colortest.r %s u_alphacolorref.r) && (colortest.g %s u_alphacolorref.g) && (colortest.b %s u_alphacolorref.b )) clip(-1);\n", test, test, test);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
// TODO: Bench both ways. Result may be different on old vs new hardware though..
|
||||
// #define DX9_USE_HW_ALPHA_TEST 1
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
struct FragmentShaderIDDX9
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "GPU/Directx9/ShaderManagerDX9.h"
|
||||
#include "GPU/Directx9/TextureCacheDX9.h"
|
||||
#include "GPU/Directx9/FramebufferDX9.h"
|
||||
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
@@ -268,6 +269,19 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DX9_USE_HW_ALPHA_TEST)
|
||||
// Older hardware (our target for DX9) often has separate alpha testing hardware that
|
||||
// is generally faster than using discard/clip. Let's use it.
|
||||
if (gstate.alphaTestEnable) {
|
||||
dxstate.alphaTest.enable();
|
||||
GEComparison alphaTestFunc = gstate.getAlphaTestFunction();
|
||||
dxstate.alphaTestFunc.set(ztests[alphaTestFunc]);
|
||||
dxstate.alphaTestRef.set(gstate.getAlphaTestRef());
|
||||
} else {
|
||||
dxstate.alphaTest.disable();
|
||||
}
|
||||
#endif
|
||||
|
||||
float renderWidthFactor, renderHeightFactor;
|
||||
float renderWidth, renderHeight;
|
||||
float renderX, renderY;
|
||||
|
||||
@@ -1343,13 +1343,11 @@ void TextureCacheDX9::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, u32 dstFm
|
||||
}
|
||||
|
||||
static inline void copyTexture(int xoffset, int yoffset, int w, int h, int pitch, int srcfmt, int fmt, void * pSrc, void * pDst) {
|
||||
// Swap color
|
||||
int y;
|
||||
switch(fmt) {
|
||||
case D3DFMT_R5G6B5:
|
||||
case D3DFMT_A4R4G4B4:
|
||||
case D3DFMT_A1R5G5B5:
|
||||
// Really needed ?
|
||||
for(y = 0; y < h; y++) {
|
||||
const u16 *src = (const u16 *)((u8*)pSrc + (w*2) * y);
|
||||
u16 *dst = (u16*)((u8*)pDst + pitch * y);
|
||||
|
||||
@@ -41,6 +41,10 @@ void DirectxState::Restore() {
|
||||
|
||||
// viewport.restore(); count++;
|
||||
|
||||
alphaTest.restore(); count++;
|
||||
alphaTestFunc.restore(); count++;
|
||||
alphaTestRef.restore(); count++;
|
||||
|
||||
stencilTest.restore(); count++;
|
||||
stencilOp.restore(); count++;
|
||||
stencilFunc.restore(); count++;
|
||||
|
||||
@@ -303,6 +303,10 @@ public:
|
||||
|
||||
BoolState<D3DRS_ZENABLE, false> depthTest;
|
||||
|
||||
DxState1<D3DRS_ALPHAFUNC, D3DCMP_ALWAYS> alphaTestFunc;
|
||||
DxState1<D3DRS_ALPHAREF, 0> alphaTestRef;
|
||||
BoolState<D3DRS_ALPHATESTENABLE, false> alphaTest;
|
||||
|
||||
DxState1<D3DRS_ZFUNC, D3DCMP_LESSEQUAL> depthFunc;
|
||||
DxState1<D3DRS_ZWRITEENABLE, TRUE> depthWrite;
|
||||
|
||||
|
||||
@@ -392,11 +392,13 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
|
||||
}
|
||||
|
||||
id0 |= (lmode & 1) << 11;
|
||||
#if !defined(DX9_USE_HW_ALPHA_TEST)
|
||||
if (enableAlphaTest) {
|
||||
// 4 bits total.
|
||||
id0 |= 1 << 12;
|
||||
id0 |= gstate.getAlphaTestFunction() << 13;
|
||||
}
|
||||
#endif
|
||||
if (enableColorTest) {
|
||||
// 3 bits total.
|
||||
id0 |= 1 << 16;
|
||||
|
||||
Reference in new issue
Block a user