mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 03:14:34 +01:00
sync dx9 gpu with gles
This commit is contained in:
1 parent
71e64938a6
commit
16f68fec5c
7 files changed
+48
-69
No files matched your search
@@ -35,17 +35,16 @@ static bool IsAlphaTestTriviallyTrue() {
|
||||
case GE_COMP_ALWAYS:
|
||||
return true;
|
||||
case GE_COMP_GEQUAL:
|
||||
if (alphaTestRef == 0)
|
||||
return true;
|
||||
return alphaTestRef == 0;
|
||||
|
||||
// This breaks the trees in MotoGP, for example.
|
||||
// case GE_COMP_GREATER:
|
||||
//if (alphaTestRef == 0 && (gstate.alphaBlendEnable & 1) && gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA && gstate.getBlendFuncB() == GE_SRCBLEND_INVSRCALPHA)
|
||||
//if (alphaTestRef == 0 && (gstate.isAlphaBlendEnabled() & 1) && gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA && gstate.getBlendFuncB() == GE_SRCBLEND_INVSRCALPHA)
|
||||
// return true;
|
||||
|
||||
case GE_COMP_LEQUAL:
|
||||
if (alphaTestRef == 255)
|
||||
return true;
|
||||
return alphaTestRef == 255;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -104,8 +103,8 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
|
||||
bool enableColorDoubling = gstate.isColorDoublingEnabled();
|
||||
// This isn't really correct, but it's a hack to get doubled blend modes to work more correctly.
|
||||
bool enableAlphaDoubling = CanDoubleSrcBlendMode();
|
||||
bool doTextureProjection = gstate.getUVGenMode() == 1;
|
||||
bool doTextureAlpha = (gstate.texfunc & 0x100) != 0;
|
||||
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
|
||||
bool doTextureAlpha = gstate.isTextureAlphaUsed();
|
||||
|
||||
// All texfuncs except replace are the same for RGB as for RGBA with full alpha.
|
||||
if (gstate_c.textureFullAlpha && gstate.getTextureFunction() != GE_TEXFUNC_REPLACE)
|
||||
@@ -133,34 +132,10 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
|
||||
|
||||
// Missing: Z depth range
|
||||
// Also, logic ops etc, of course. Urgh.
|
||||
#if 0
|
||||
void GenerateFragmentShader(char *buffer) {
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Pixel shader
|
||||
//--------------------------------------------------------------------------------------
|
||||
const char * pscode =
|
||||
" sampler s: register(s0); "
|
||||
" struct PS_IN "
|
||||
" { "
|
||||
" float3 Uv : TEXCOORD0; "
|
||||
" float4 C1 : COLOR0; " // Vertex color
|
||||
" float4 C2 : COLOR1; " // Vertex color
|
||||
" }; "
|
||||
" "
|
||||
" float4 main( PS_IN In ) : COLOR "
|
||||
" { "
|
||||
//" float4 c = In.C1; "
|
||||
" float4 c = tex2D(s, In.Uv.xy); "
|
||||
" return c; "
|
||||
" } ";
|
||||
|
||||
strcpy(buffer, pscode);
|
||||
}
|
||||
#else
|
||||
void GenerateFragmentShader(char *buffer) {
|
||||
char *p = buffer;
|
||||
|
||||
int lmode = (gstate.lmode & 1) && gstate.isLightingEnabled();
|
||||
int lmode = lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
int doTexture = gstate.isTextureMapEnabled() && !gstate.isModeClear();
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !gstate.isModeClear();
|
||||
@@ -168,8 +143,8 @@ void GenerateFragmentShader(char *buffer) {
|
||||
bool enableColorDoubling = gstate.isColorDoublingEnabled();
|
||||
// This isn't really correct, but it's a hack to get doubled blend modes to work more correctly.
|
||||
bool enableAlphaDoubling = CanDoubleSrcBlendMode();
|
||||
bool doTextureProjection = gstate.getUVGenMode() == 1;
|
||||
bool doTextureAlpha = (gstate.texfunc & 0x100) != 0;
|
||||
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
|
||||
bool doTextureAlpha = gstate.isTextureAlphaUsed();
|
||||
|
||||
if (gstate_c.textureFullAlpha && gstate.getTextureFunction() != GE_TEXFUNC_REPLACE)
|
||||
doTextureAlpha = false;
|
||||
@@ -179,7 +154,7 @@ void GenerateFragmentShader(char *buffer) {
|
||||
|
||||
if (enableAlphaTest || enableColorTest) {
|
||||
WRITE(p, "float4 u_alphacolorref;\n");
|
||||
WRITE(p, "float3 u_colormask;\n");
|
||||
WRITE(p, "float4 u_colormask;\n");
|
||||
}
|
||||
if (gstate.isTextureMapEnabled())
|
||||
WRITE(p, "float3 u_texenv;\n");
|
||||
@@ -324,4 +299,3 @@ void GenerateFragmentShader(char *buffer) {
|
||||
}
|
||||
WRITE(p, "}\n");
|
||||
}
|
||||
#endif
|
||||
@@ -37,7 +37,7 @@ enum {
|
||||
};
|
||||
|
||||
static bool MaskedEqual(u32 addr1, u32 addr2) {
|
||||
return (addr1 & 0x3FFFFFF) == (addr2 & 0x3FFFFFF);
|
||||
return (addr1 & 0x03FFFFFF) == (addr2 & 0x03FFFFFF);
|
||||
}
|
||||
|
||||
inline u16 RGBA8888toRGB565(u32 px) {
|
||||
@@ -876,7 +876,7 @@ void FramebufferManager::DecimateFBOs() {
|
||||
VirtualFramebuffer *vfb = vfbs_[i];
|
||||
int age = frameLastFramebufUsed - vfb->last_frame_used;
|
||||
|
||||
if(useMem && !age && !vfb->memoryUpdated) {
|
||||
if(useMem && age == 0 && !vfb->memoryUpdated) {
|
||||
ReadFramebufferToMemory(vfb);
|
||||
}
|
||||
|
||||
|
||||
@@ -373,7 +373,8 @@ void LinkedShader::updateUniforms() {
|
||||
int h = gstate.getTextureHeight(0);
|
||||
float widthFactor = (float)w / (float)gstate_c.curTextureWidth;
|
||||
float heightFactor = (float)h / (float)gstate_c.curTextureHeight;
|
||||
if (gstate.getUVGenMode() == 0) {
|
||||
// Not sure what GE_TEXMAP_UNKNOWN is, but seen in Riviera. Treating the same as GE_TEXMAP_TEXTURE_COORDS works.
|
||||
if (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_COORDS || gstate.getUVGenMode() == GE_TEXMAP_UNKNOWN) {
|
||||
static const float rescale[4] = {1.0f, 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f};
|
||||
float factor = rescale[(gstate.vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT];
|
||||
uvscaleoff[0] = gstate_c.uv.uScale * factor * widthFactor;
|
||||
|
||||
@@ -208,10 +208,9 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
|
||||
dxstate.cullMode.set(false, false);
|
||||
|
||||
// Depth Test
|
||||
bool depthMask = (gstate.clearmode >> 10) & 1;
|
||||
dxstate.depthTest.enable();
|
||||
dxstate.depthFunc.set(D3DCMP_ALWAYS);
|
||||
dxstate.depthWrite.set(depthMask);
|
||||
dxstate.depthWrite.set(gstate.isClearModeDepthWriteEnabled());
|
||||
|
||||
// Color Test
|
||||
bool colorMask = (gstate.clearmode >> 8) & 1;
|
||||
@@ -288,13 +287,13 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
|
||||
// Scissor
|
||||
int scissorX1 = gstate.getScissorX1();
|
||||
int scissorY1 = gstate.getScissorY1();
|
||||
int scissorX2 = gstate.getScissorX2();
|
||||
int scissorY2 = gstate.getScissorY2();
|
||||
int scissorX2 = gstate.getScissorX2() + 1;
|
||||
int scissorY2 = gstate.getScissorY2() + 1;
|
||||
|
||||
// This is a bit of a hack as the render buffer isn't always that size
|
||||
if (scissorX1 == 0 && scissorY1 == 0
|
||||
&& scissorX2 >= (int) (gstate_c.curRTWidth - 1)
|
||||
&& scissorY2 >= (int) (gstate_c.curRTHeight - 1)) {
|
||||
&& scissorX2 >= (int) gstate_c.curRTWidth
|
||||
&& scissorY2 >= (int) gstate_c.curRTHeight) {
|
||||
dxstate.scissorTest.disable();
|
||||
} else {
|
||||
dxstate.scissorTest.enable();
|
||||
|
||||
@@ -129,7 +129,7 @@ void TextureCache::Decimate() {
|
||||
}
|
||||
|
||||
void TextureCache::Invalidate(u32 addr, int size, GPUInvalidationType type) {
|
||||
addr &= 0xFFFFFFF;
|
||||
addr &= 0x0FFFFFFF;
|
||||
u32 addr_end = addr + size;
|
||||
|
||||
// They could invalidate inside the texture, let's just give a bit of leeway.
|
||||
@@ -194,11 +194,10 @@ inline void TextureCache::AttachFramebuffer(TexCacheEntry *entry, u32 address, V
|
||||
if (entry->format != framebuffer->format) {
|
||||
WARN_LOG_REPORT_ONCE(diffFormat1, HLE, "Render to texture with different formats %d != %d", entry->format, framebuffer->format);
|
||||
// If it already has one, let's hope that one is correct.
|
||||
// Try to not bind FB now as it seems to be attached some strange stuff on top of the original FB.
|
||||
//AttachFramebufferInvalid(entry, framebuffer);
|
||||
AttachFramebufferInvalid(entry, framebuffer);
|
||||
} else {
|
||||
AttachFramebufferValid(entry, framebuffer);
|
||||
}
|
||||
}
|
||||
// TODO: Delete the original non-fbo texture too.
|
||||
}
|
||||
} else if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE || g_Config.iRenderingMode == FB_BUFFERED_MODE) {
|
||||
@@ -212,11 +211,11 @@ inline void TextureCache::AttachFramebuffer(TexCacheEntry *entry, u32 address, V
|
||||
if (framebuffer->format != entry->format) {
|
||||
WARN_LOG_REPORT_ONCE(diffFormat2, HLE, "Render to texture with different formats %d != %d at %08x", entry->format, framebuffer->format, address);
|
||||
// TODO: Use an FBO to translate the palette?
|
||||
AttachFramebufferValid(entry, framebuffer);
|
||||
AttachFramebufferValid(entry, framebuffer);
|
||||
} else if ((entry->addr - address) / entry->bufw < framebuffer->height) {
|
||||
WARN_LOG_REPORT_ONCE(subarea, HLE, "Render to area containing texture at %08x", address);
|
||||
// TODO: Keep track of the y offset.
|
||||
AttachFramebufferInvalid(entry, framebuffer);
|
||||
AttachFramebufferValid(entry, framebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,22 +241,18 @@ void TextureCache::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffe
|
||||
case NOTIFY_FB_CREATED:
|
||||
case NOTIFY_FB_UPDATED:
|
||||
for (auto it = cache.lower_bound(cacheKey), end = cache.upper_bound(cacheKeyEnd); it != end; ++it) {
|
||||
AttachFramebuffer(&it->second, address, framebuffer, it->first == cacheKey);
|
||||
AttachFramebuffer(&it->second, address | 0x04000000, framebuffer, it->first == cacheKey);
|
||||
}
|
||||
break;
|
||||
|
||||
case NOTIFY_FB_DESTROYED:
|
||||
for (auto it = cache.lower_bound(cacheKey), end = cache.upper_bound(cacheKeyEnd); it != end; ++it) {
|
||||
DetachFramebuffer(&it->second, address, framebuffer);
|
||||
DetachFramebuffer(&it->second, address | 0x04000000, framebuffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static u32 GetClutAddr() {
|
||||
return ((gstate.clutaddr & 0xFFFFFF) | ((gstate.clutaddrupper << 8) & 0x0F000000));
|
||||
}
|
||||
|
||||
static u32 GetClutIndex(u32 index) {
|
||||
const u32 clutBase = gstate.getClutIndexStartPos();
|
||||
const u32 clutMask = gstate.getClutIndexMask();
|
||||
@@ -1297,6 +1292,9 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
case GE_TFMT_CLUT4:
|
||||
{
|
||||
dstFmt = getClutDestFormat(clutformat);
|
||||
// Don't allow this to be less than 16 bytes (32 * 4 / 8 = 16.)
|
||||
if (bufw < 32)
|
||||
bufw = 32;
|
||||
|
||||
const bool mipmapShareClut = (gstate.texmode & 0x100) == 0;
|
||||
const int clutSharingOffset = mipmapShareClut ? 0 : level * 16;
|
||||
@@ -1355,18 +1353,24 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT8:
|
||||
if (bufw < 8)
|
||||
bufw = 8;
|
||||
dstFmt = getClutDestFormat(gstate.getClutPaletteFormat());
|
||||
texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()];
|
||||
finalBuf = readIndexedTex(level, texaddr, 1, dstFmt);
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT16:
|
||||
if (bufw < 8)
|
||||
bufw = 8;
|
||||
dstFmt = getClutDestFormat(gstate.getClutPaletteFormat());
|
||||
texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()];
|
||||
finalBuf = readIndexedTex(level, texaddr, 2, dstFmt);
|
||||
break;
|
||||
|
||||
case GE_TFMT_CLUT32:
|
||||
if (bufw < 4)
|
||||
bufw = 4;
|
||||
dstFmt = getClutDestFormat(gstate.getClutPaletteFormat());
|
||||
texByteAlign = texByteAlignMap[gstate.getClutPaletteFormat()];
|
||||
finalBuf = readIndexedTex(level, texaddr, 4, dstFmt);
|
||||
@@ -1375,6 +1379,8 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
case GE_TFMT_4444:
|
||||
case GE_TFMT_5551:
|
||||
case GE_TFMT_5650:
|
||||
if (bufw < 8)
|
||||
bufw = 8;
|
||||
if (format == GE_TFMT_4444)
|
||||
dstFmt = D3DFMT_A4R4G4B4;
|
||||
else if (format == GE_TFMT_5551)
|
||||
@@ -1398,6 +1404,8 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
break;
|
||||
|
||||
case GE_TFMT_8888:
|
||||
if (bufw < 4)
|
||||
bufw = 4;
|
||||
dstFmt = D3DFMT_A8R8G8B8;
|
||||
if (!(gstate.texmode & 1)) {
|
||||
// Special case: if we don't need to deal with packing, we don't need to copy.
|
||||
@@ -1459,7 +1467,6 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
//TextureConvertColors(finalBuf, finalBuf, dstFmt, bufw * h);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1481,7 +1488,6 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
||||
}
|
||||
w = (w + 3) & ~3;
|
||||
finalBuf = tmpTexBuf32.data();
|
||||
//TextureConvertColors(finalBuf, finalBuf, dstFmt, bufw * h);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
u32 InjectUVs(u8 *decoded, const void *verts, float *customuv, int count) const;
|
||||
|
||||
bool hasColor() const { return col != 0; }
|
||||
int VertexSize() const { return size; }
|
||||
int VertexSize() const { return size; } // PSP format size
|
||||
|
||||
void Step_WeightsU8() const;
|
||||
void Step_WeightsU16() const;
|
||||
|
||||
@@ -50,7 +50,7 @@ int TranslateNumBones(int bones) {
|
||||
void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
||||
const u32 vertType = gstate.vertType;
|
||||
int doTexture = gstate.isTextureMapEnabled() && !gstate.isModeClear();
|
||||
bool doTextureProjection = gstate.getUVGenMode() == 1;
|
||||
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
|
||||
|
||||
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
|
||||
bool hasNormal = (vertType & GE_VTYPE_NRM_MASK) != 0;
|
||||
@@ -77,9 +77,9 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
||||
id->d[0] |= gstate.getUVGenMode() << 16;
|
||||
|
||||
// The next bits are used differently depending on UVgen mode
|
||||
if (gstate.getUVGenMode() == 1) {
|
||||
if (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX) {
|
||||
id->d[0] |= gstate.getUVProjMode() << 18;
|
||||
} else if (gstate.getUVGenMode() == 2) {
|
||||
} else if (gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
|
||||
id->d[0] |= gstate.getUVLS0() << 18;
|
||||
id->d[0] |= gstate.getUVLS1() << 20;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
||||
|
||||
// Okay, d[1] coming up. ==============
|
||||
|
||||
if (gstate.isLightingEnabled() || gstate.getUVGenMode() == 2) {
|
||||
if (gstate.isLightingEnabled() || gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP) {
|
||||
// Light bits
|
||||
for (int i = 0; i < 4; i++) {
|
||||
id->d[1] |= gstate.getLightComputation(i) << (i * 4);
|
||||
@@ -136,12 +136,12 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool throughmode = (vertType & GE_VTYPE_THROUGH_MASK) != 0;
|
||||
bool flipV = gstate_c.flipTexture;
|
||||
bool doTextureProjection = gstate.getUVGenMode() == 1;
|
||||
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
|
||||
|
||||
DoLightComputation doLight[4] = {LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF};
|
||||
if (useHWTransform) {
|
||||
int shadeLight0 = gstate.getUVGenMode() == 2 ? gstate.getUVLS0() : -1;
|
||||
int shadeLight1 = gstate.getUVGenMode() == 2 ? gstate.getUVLS1() : -1;
|
||||
int shadeLight0 = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP ? gstate.getUVLS0() : -1;
|
||||
int shadeLight1 = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP ? gstate.getUVLS1() : -1;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i == shadeLight0 || i == shadeLight1)
|
||||
doLight[i] = LIGHT_SHADE;
|
||||
@@ -194,7 +194,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
WRITE(p, "float3 u_lightatt%i;\n", i);
|
||||
|
||||
if (type == GE_LIGHTTYPE_SPOT) {
|
||||
if (type == GE_LIGHTTYPE_SPOT || type == GE_LIGHTTYPE_UNKNOWN) {
|
||||
WRITE(p, "float u_lightangle%i;\n", i);
|
||||
WRITE(p, "float u_lightspotCoef%i;\n", i);
|
||||
}
|
||||
@@ -529,7 +529,6 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
temp_tc = "float4(0.0, 0.0, 1.0, 1.0)";
|
||||
break;
|
||||
}
|
||||
//WRITE(p, " Out.Uv.xyz = (u_texmtx * %s).xyz * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
|
||||
WRITE(p, " Out.Uv.xyz = mul(%s,u_texmtx).xyz * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
|
||||
}
|
||||
// Transform by texture matrix. XYZ as we are doing projection mapping.
|
||||
|
||||
Reference in new issue
Block a user