summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@lse.epita.fr>2012-03-24 18:41:51 +0100
committerPierre Bourdon <delroth@lse.epita.fr>2012-03-24 18:41:51 +0100
commitb5ba2eb030a3c314a7b43e79d41f3c6f78ad54d0 (patch)
tree1dbad88fa125b559799273502e94bdc91cfbcf3f /Source/Core/VideoCommon
parent339ee98e6258024622ef509aafe25ff46ad19341 (diff)
parent7a1744575d7569dd52739836685b6e6643ace61a (diff)
Merge branch 'master' into zcomploc-support
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Src/BPStructs.cpp9
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp14
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.h19
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderManager.cpp42
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderManager.h6
-rw-r--r--Source/Core/VideoCommon/Src/RenderBase.cpp2
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.cpp7
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.h2
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderManager.cpp6
9 files changed, 40 insertions, 67 deletions
diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp
index 6cb102555b..01b09e351b 100644
--- a/Source/Core/VideoCommon/Src/BPStructs.cpp
+++ b/Source/Core/VideoCommon/Src/BPStructs.cpp
@@ -476,10 +476,15 @@ void BPWritten(const BPCmd& bp)
// if this is different from 0, manual TMEM management is used.
if (bp.newvalue != 0)
{
- // NOTE(neobrain): Apparently tmemodd doesn't affect hardware behavior at all (libogc uses it just as a buffer and switches its contents with tmemeven whenever this is called)
BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5);
- u32 tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
+ u32 tmem_addr = 0;
+
+ if (bp.newvalue >> 16)
+ tmem_addr = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE;
+ else
+ tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
+
u32 size = tmem_cfg.preload_tile_info.count * 32;
memcpy(texMem + tmem_addr, ram_ptr, size);
}
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index 79afc45974..89032c67ea 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -560,10 +560,6 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "uniform float4 "I_KCOLORS"[4] : register(c%d);\n", C_KCOLORS);
WRITE(p, "uniform float4 "I_ALPHA"[1] : register(c%d);\n", C_ALPHA);
WRITE(p, "uniform float4 "I_TEXDIMS"[8] : register(c%d);\n", C_TEXDIMS);
- if (ApiType & API_D3D9)
- {
- WRITE(p, "uniform float4 "I_VTEXSCALE"[4] : register(c%d);\n", C_VTEXSCALE);
- }
WRITE(p, "uniform float4 "I_ZBIAS"[2] : register(c%d);\n", C_ZBIAS);
WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE);
WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX);
@@ -1103,15 +1099,9 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType)
{
if (ApiType == API_D3D11)
- WRITE(p, "%s=Tex%d.Sample(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap);
- else if (ApiType & API_D3D9)
- {
- // D3D9 uses different pixel to texel mapping, so we need to offset our sampling address by half a pixel (assuming native and virtual texture dimensions match each other, otherwise some math is involved).
- // Read the MSDN article "Directly Mapping Texels to Pixels (Direct3D 9)" for further info.
- WRITE(p, "%s=tex2D(samp%d, (%s.xy + 0.5f*"I_VTEXSCALE"[%d].%s) * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap/2, (texmap&1)?"zw":"xy", texmap, texswap);
- }
+ WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap);
else
- WRITE(p, "%s=tex2D(samp%d, %s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap);
+ WRITE(p, "%s=tex2D(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap);
}
static const char *tevAlphaFuncsTable[] =
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h
index 7374251c96..31242a916e 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h
@@ -24,27 +24,26 @@
#define I_KCOLORS "k"
#define I_ALPHA "alphaRef"
#define I_TEXDIMS "texdim"
-#define I_VTEXSCALE "vtexscale"
#define I_ZBIAS "czbias"
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOG "cfog"
#define I_PLIGHTS "cLights"
-#define I_PMATERIALS "cmtrl"
+#define I_PMATERIALS "cmtrl"
#define C_COLORMATRIX 0 // 0
#define C_COLORS 0 // 0
#define C_KCOLORS (C_COLORS + 4) // 4
#define C_ALPHA (C_KCOLORS + 4) // 8
#define C_TEXDIMS (C_ALPHA + 1) // 9
-#define C_VTEXSCALE (C_TEXDIMS + 8) //17 - virtual texture scaling factor (e.g. custom textures, scaled EFB copies)
-#define C_ZBIAS (C_VTEXSCALE + 4) //21
-#define C_INDTEXSCALE (C_ZBIAS + 2) //23
-#define C_INDTEXMTX (C_INDTEXSCALE + 2) //25
-#define C_FOG (C_INDTEXMTX + 6) //31
-#define C_PLIGHTS (C_FOG + 3) //34
-#define C_PMATERIALS (C_PLIGHTS + 40) //74
-#define C_PENVCONST_END (C_PMATERIALS + 4) //78
+#define C_ZBIAS (C_TEXDIMS + 8) //17
+#define C_INDTEXSCALE (C_ZBIAS + 2) //19
+#define C_INDTEXMTX (C_INDTEXSCALE + 2) //21
+#define C_FOG (C_INDTEXMTX + 6) //27
+
+#define C_PLIGHTS (C_FOG + 3)
+#define C_PMATERIALS (C_PLIGHTS + 40)
+#define C_PENVCONST_END (C_PMATERIALS + 4)
#define PIXELSHADERUID_MAX_VALUES 70
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
index 3e0f6d73c4..2521f80500 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp
@@ -36,11 +36,9 @@ static bool s_bFogRangeAdjustChanged;
static int nLightsChanged[2]; // min,max
static float lastRGBAfull[2][4][4];
static u8 s_nTexDimsChanged;
-static u8 s_nVirtualTexScalesChanged;
static u8 s_nIndTexScaleChanged;
static u32 lastAlpha;
static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30
-static float lastVirtualTexScales[16]; // even fields: width ratio; odd fields: height ratio
static u32 lastZBias;
static int nMaterialsChanged;
@@ -63,7 +61,6 @@ void PixelShaderManager::Init()
{
lastAlpha = 0;
memset(lastTexDims, 0, sizeof(lastTexDims));
- memset(lastVirtualTexScales, 0, sizeof(lastVirtualTexScales));
lastZBias = 0;
memset(lastRGBAfull, 0, sizeof(lastRGBAfull));
Dirty();
@@ -73,7 +70,6 @@ void PixelShaderManager::Dirty()
{
s_nColorsChanged[0] = s_nColorsChanged[1] = 15;
s_nTexDimsChanged = 0xFF;
- s_nVirtualTexScalesChanged = 0xFF;
s_nIndTexScaleChanged = 0xFF;
s_nIndTexMtxChanged = 15;
s_bAlphaChanged = s_bZBiasChanged = s_bZTextureTypeChanged = s_bDepthRangeChanged = true;
@@ -87,7 +83,7 @@ void PixelShaderManager::Shutdown()
}
-void PixelShaderManager::SetConstants(API_TYPE api_type)
+void PixelShaderManager::SetConstants()
{
for (int i = 0; i < 2; ++i)
{
@@ -113,16 +109,6 @@ void PixelShaderManager::SetConstants(API_TYPE api_type)
s_nTexDimsChanged = 0;
}
- if ((api_type & API_D3D9) && s_nVirtualTexScalesChanged)
- {
- for (int i = 0; i < 8; i += 2)
- {
- if (s_nVirtualTexScalesChanged & (3<<i))
- SetPSVirtualTexScalePair(i/2);
- }
- s_nVirtualTexScalesChanged = 0;
- }
-
if (s_bAlphaChanged)
{
SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f);
@@ -352,13 +338,6 @@ void PixelShaderManager::SetPSTextureDims(int texid)
SetPSConstant4fv(C_TEXDIMS + texid, fdims);
}
-void PixelShaderManager::SetPSVirtualTexScalePair(int texpairid)
-{
- PRIM_LOG("vtexscale%d: %f %f %f %f\n", texpairid, lastVirtualTexScales[texpairid*4], lastVirtualTexScales[texpairid*4+1],
- lastVirtualTexScales[texpairid*4+2], lastVirtualTexScales[texpairid*4+3]);
- SetPSConstant4fv(C_VTEXSCALE + texpairid, &lastVirtualTexScales[texpairid*4]);
-}
-
// This one is high in profiles (0.5%). TODO: Move conversion out, only store the raw color value
// and update it when the shader constant is set, only.
void PixelShaderManager::SetColorChanged(int type, int num, bool high)
@@ -397,25 +376,14 @@ void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha)
}
}
-void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 virtual_width, u32 virtual_height, u32 wraps, u32 wrapt, API_TYPE api_type)
+void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
{
u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30);
-
- bool refresh = lastTexDims[texmapid] != wh;
- if (api_type & API_D3D9)
+ if (lastTexDims[texmapid] != wh)
{
- refresh |= (lastVirtualTexScales[texmapid*2] != (float)width / (float)virtual_width);
- refresh |= (lastVirtualTexScales[texmapid*2+1] != (float)height / (float)virtual_height);
- }
-
- if (refresh)
- {
- lastTexDims[texmapid] = wh;
- lastVirtualTexScales[texmapid*2] = (float)width / (float)virtual_width;
- lastVirtualTexScales[texmapid*2+1] = (float)height / (float)virtual_height;
+ lastTexDims[texmapid] = wh;
s_nTexDimsChanged |= 1 << texmapid;
- s_nVirtualTexScalesChanged |= 1 << texmapid;
- }
+ }
}
void PixelShaderManager::SetZTextureBias(u32 bias)
diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.h b/Source/Core/VideoCommon/Src/PixelShaderManager.h
index 5cbe86cae4..2d1c01cad6 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderManager.h
+++ b/Source/Core/VideoCommon/Src/PixelShaderManager.h
@@ -26,20 +26,18 @@
class PixelShaderManager
{
static void SetPSTextureDims(int texid);
- static void SetPSVirtualTexScalePair(int texpairid);
-
public:
static void Init();
static void Dirty();
static void Shutdown();
- static void SetConstants(API_TYPE api_type); // sets pixel shader constants
+ static void SetConstants(); // sets pixel shader constants
// constant management, should be called after memory is committed
static void SetColorChanged(int type, int index, bool high);
static void SetAlpha(const AlphaFunc& alpha);
static void SetDestAlpha(const ConstantAlpha& alpha);
- static void SetTexDims(int texmapid, u32 width, u32 height, u32 virtual_width, u32 virtual_height, u32 wraps, u32 wrapt, API_TYPE api_type);
+ static void SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt);
static void SetZTextureBias(u32 bias);
static void SetViewportChanged();
static void SetIndMatrixChanged(int matrixidx);
diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp
index 3b06bbb1c0..ef0fff57f7 100644
--- a/Source/Core/VideoCommon/Src/RenderBase.cpp
+++ b/Source/Core/VideoCommon/Src/RenderBase.cpp
@@ -43,6 +43,7 @@
#include "XFMemory.h"
#include "FifoPlayer/FifoRecorder.h"
#include "AVIDump.h"
+#include "VertexShaderManager.h"
#include <cmath>
#include <string>
@@ -193,6 +194,7 @@ bool Renderer::CalculateTargetSize(int multiplier)
{
s_target_width = newEFBWidth;
s_target_height = newEFBHeight;
+ VertexShaderManager::SetViewportChanged();
return true;
}
return false;
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index 5076f9f044..3df779a7ba 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -493,6 +493,13 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
//seems to get rather complicated
}
+ if (api_type & API_D3D9)
+ {
+ // D3D9 is addressing pixel centers instead of pixel boundaries in clip space.
+ // Thus we need to offset the final position by half a pixel
+ WRITE(p, "o.pos = o.pos + float4("I_DEPTHPARAMS".z, "I_DEPTHPARAMS".w, 0.f, 0.f);\n");
+ }
+
WRITE(p, "return o;\n}\n");
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h
index 0c522286b1..cb253a9b6c 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.h
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h
@@ -35,7 +35,7 @@
#define I_TRANSFORMMATRICES "ctrmtx"
#define I_NORMALMATRICES "cnmtx"
#define I_POSTTRANSFORMMATRICES "cpostmtx"
-#define I_DEPTHPARAMS "cDepth"
+#define I_DEPTHPARAMS "cDepth" // farZ, zRange, scaled viewport width, scaled viewport height
#define C_POSNORMALMATRIX 0
#define C_PROJECTION (C_POSNORMALMATRIX + 6)
diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp
index d7d25c5c85..b6afbc61c6 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp
@@ -306,7 +306,11 @@ void VertexShaderManager::SetConstants()
if (bViewportChanged)
{
bViewportChanged = false;
- SetVSConstant4f(C_DEPTHPARAMS,xfregs.viewport.farZ / 16777216.0f,xfregs.viewport.zRange / 16777216.0f,0.0f,0.0f);
+ SetVSConstant4f(C_DEPTHPARAMS,
+ xfregs.viewport.farZ / 16777216.0f,
+ xfregs.viewport.zRange / 16777216.0f,
+ -1.f / (float)g_renderer->EFBToScaledX((int)ceil(2.0f * xfregs.viewport.wd)),
+ 1.f / (float)g_renderer->EFBToScaledY((int)ceil(-2.0f * xfregs.viewport.ht)));
// This is so implementation-dependent that we can't have it here.
UpdateViewport(s_viewportCorrection);
bProjectionChanged = true;