From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/VideoCommon/VertexManagerBase.cpp | 177 ++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 Source/Core/VideoCommon/VertexManagerBase.cpp (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp new file mode 100644 index 0000000000..b5285dd0e2 --- /dev/null +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -0,0 +1,177 @@ + +#include "Common.h" + +#include "Statistics.h" +#include "OpcodeDecoding.h" +#include "IndexGenerator.h" +#include "VertexShaderManager.h" +#include "PixelShaderManager.h" +#include "NativeVertexFormat.h" +#include "TextureCacheBase.h" +#include "RenderBase.h" +#include "BPStructs.h" + +#include "VertexManagerBase.h" +#include "MainBase.h" +#include "VideoConfig.h" + +VertexManager *g_vertex_manager; + +u8 *VertexManager::s_pCurBufferPointer; +u8 *VertexManager::s_pBaseBufferPointer; +u8 *VertexManager::s_pEndBufferPointer; + +VertexManager::VertexManager() +{ + LocalVBuffer.resize(MAXVBUFFERSIZE); + s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0]; + s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); + + TIBuffer.resize(MAXIBUFFERSIZE); + LIBuffer.resize(MAXIBUFFERSIZE); + PIBuffer.resize(MAXIBUFFERSIZE); + + ResetBuffer(); +} + +VertexManager::~VertexManager() +{ +} + +void VertexManager::ResetBuffer() +{ + s_pCurBufferPointer = s_pBaseBufferPointer; + IndexGenerator::Start(GetTriangleIndexBuffer(), GetLineIndexBuffer(), GetPointIndexBuffer()); +} + +u32 VertexManager::GetRemainingSize() +{ + return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); +} + +void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) +{ + u32 const needed_vertex_bytes = count * stride; + + if (count > IndexGenerator::GetRemainingIndices() || count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize()) + { + Flush(); + + if(count > IndexGenerator::GetRemainingIndices()) + ERROR_LOG(VIDEO, "Too little remaining index values. Use 32-bit or reset them on flush."); + if (count > GetRemainingIndices(primitive)) + ERROR_LOG(VIDEO, "VertexManager: Buffer not large enough for all indices! " + "Increase MAXIBUFFERSIZE or we need primitive breaking after all."); + if (needed_vertex_bytes > GetRemainingSize()) + ERROR_LOG(VIDEO, "VertexManager: Buffer not large enough for all vertices! " + "Increase MAXVBUFFERSIZE or we need primitive breaking after all."); + } +} + +bool VertexManager::IsFlushed() const +{ + return s_pBaseBufferPointer == s_pCurBufferPointer; +} + +u32 VertexManager::GetRemainingIndices(int primitive) +{ + + if(g_Config.backend_info.bSupportsPrimitiveRestart) + { + switch (primitive) + { + case GX_DRAW_QUADS: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 5 * 4; + case GX_DRAW_TRIANGLES: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 4 * 3; + case GX_DRAW_TRIANGLE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 1 - 1; + case GX_DRAW_TRIANGLE_FAN: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4 + 1; + + case GX_DRAW_LINES: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + case GX_DRAW_LINE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + + case GX_DRAW_POINTS: + return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + + default: + return 0; + } + } + else + { + switch (primitive) + { + case GX_DRAW_QUADS: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4; + case GX_DRAW_TRIANGLES: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()); + case GX_DRAW_TRIANGLE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + case GX_DRAW_TRIANGLE_FAN: + return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + + case GX_DRAW_LINES: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + case GX_DRAW_LINE_STRIP: + return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + + case GX_DRAW_POINTS: + return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + + default: + return 0; + } + } +} + +void VertexManager::AddVertices(int primitive, u32 numVertices) +{ + if (numVertices <= 0) + return; + + ADDSTAT(stats.thisFrame.numPrims, numVertices); + INCSTAT(stats.thisFrame.numPrimitiveJoins); + + IndexGenerator::AddIndices(primitive, numVertices); +} + +void VertexManager::Flush() +{ + if (g_vertex_manager->IsFlushed()) + return; + + // loading a state will invalidate BP, so check for it + g_video_backend->CheckInvalidState(); + + VideoFifo_CheckEFBAccess(); + + // TODO: need to merge more stuff into VideoCommon + g_vertex_manager->vFlush(); + + g_vertex_manager->ResetBuffer(); +} + +void VertexManager::DoState(PointerWrap& p) +{ + g_vertex_manager->vDoState(p); +} + +void VertexManager::DoStateShared(PointerWrap& p) +{ + // It seems we half-assume to be flushed here + // We update s_pCurBufferPointer yet don't worry about IndexGenerator's outdated pointers + // and maybe other things are overlooked + + p.Do(LocalVBuffer); + p.Do(TIBuffer); + p.Do(LIBuffer); + p.Do(PIBuffer); + + s_pBaseBufferPointer = &LocalVBuffer[0]; + s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); + p.DoPointer(s_pCurBufferPointer, s_pBaseBufferPointer); +} -- cgit v1.2.3 From 6b0183952564a11cd4eee42715e61ea2962caff3 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 15 Jan 2014 21:44:46 +0100 Subject: VideoCommon: merge triangle+list+point index buffers We are used to render them out of order as long as everything else matches, but rendering order does matter, so we have to flush on primitive switch. This commit implements this flush. Also as we flush on primitive switch, we don't have to create three different index buffers. All indices are now stored in one buffer. This will slow down games which switch often primitive types (eg ztp), but it should be more accurate. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 58 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index b5285dd0e2..bce4af457e 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -21,15 +21,26 @@ u8 *VertexManager::s_pCurBufferPointer; u8 *VertexManager::s_pBaseBufferPointer; u8 *VertexManager::s_pEndBufferPointer; +PrimitiveType VertexManager::current_primitive_type; + +static const PrimitiveType primitive_from_gx[8] = { + PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS + PRIMITIVE_TRIANGLES, // GX_DRAW_NONE + PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLES + PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLE_STRIP + PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLE_FAN + PRIMITIVE_LINES, // GX_DRAW_LINES + PRIMITIVE_LINES, // GX_DRAW_LINE_STRIP + PRIMITIVE_POINTS, // GX_DRAW_POINTS +}; + VertexManager::VertexManager() { LocalVBuffer.resize(MAXVBUFFERSIZE); s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0]; s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); - TIBuffer.resize(MAXIBUFFERSIZE); - LIBuffer.resize(MAXIBUFFERSIZE); - PIBuffer.resize(MAXIBUFFERSIZE); + LocalIBuffer.resize(MAXIBUFFERSIZE); ResetBuffer(); } @@ -41,7 +52,7 @@ VertexManager::~VertexManager() void VertexManager::ResetBuffer() { s_pCurBufferPointer = s_pBaseBufferPointer; - IndexGenerator::Start(GetTriangleIndexBuffer(), GetLineIndexBuffer(), GetPointIndexBuffer()); + IndexGenerator::Start(GetIndexBuffer()); } u32 VertexManager::GetRemainingSize() @@ -53,6 +64,12 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid { u32 const needed_vertex_bytes = count * stride; + // We can't merge different kinds of primitives, so we have to flush here + if (current_primitive_type != primitive_from_gx[primitive]) + Flush(); + current_primitive_type = primitive_from_gx[primitive]; + + // Check for size in buffer, if the buffer gets full, call Flush() if (count > IndexGenerator::GetRemainingIndices() || count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize()) { Flush(); @@ -75,27 +92,28 @@ bool VertexManager::IsFlushed() const u32 VertexManager::GetRemainingIndices(int primitive) { + u32 index_len = MAXIBUFFERSIZE - IndexGenerator::GetIndexLen(); if(g_Config.backend_info.bSupportsPrimitiveRestart) { switch (primitive) { case GX_DRAW_QUADS: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 5 * 4; + return index_len / 5 * 4; case GX_DRAW_TRIANGLES: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 4 * 3; + return index_len / 4 * 3; case GX_DRAW_TRIANGLE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 1 - 1; + return index_len / 1 - 1; case GX_DRAW_TRIANGLE_FAN: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4 + 1; + return index_len / 6 * 4 + 1; case GX_DRAW_LINES: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + return index_len; case GX_DRAW_LINE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + return index_len / 2 + 1; case GX_DRAW_POINTS: - return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + return index_len; default: return 0; @@ -106,21 +124,21 @@ u32 VertexManager::GetRemainingIndices(int primitive) switch (primitive) { case GX_DRAW_QUADS: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4; + return index_len / 6 * 4; case GX_DRAW_TRIANGLES: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()); + return index_len; case GX_DRAW_TRIANGLE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + return index_len / 3 + 2; case GX_DRAW_TRIANGLE_FAN: - return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2; + return index_len / 3 + 2; case GX_DRAW_LINES: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()); + return index_len; case GX_DRAW_LINE_STRIP: - return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1; + return index_len / 2 + 1; case GX_DRAW_POINTS: - return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen()); + return index_len; default: return 0; @@ -167,9 +185,7 @@ void VertexManager::DoStateShared(PointerWrap& p) // and maybe other things are overlooked p.Do(LocalVBuffer); - p.Do(TIBuffer); - p.Do(LIBuffer); - p.Do(PIBuffer); + p.Do(LocalIBuffer); s_pBaseBufferPointer = &LocalVBuffer[0]; s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); -- cgit v1.2.3 From ebbf1d392bc5a90b556d793c07b789e100f10615 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 21 Jan 2014 10:47:00 +0100 Subject: VideoCommon: merge trivial parts of VertexManager::Flush --- Source/Core/VideoCommon/VertexManagerBase.cpp | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index bce4af457e..1238aa1b31 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -167,6 +167,73 @@ void VertexManager::Flush() VideoFifo_CheckEFBAccess(); +#if defined(_DEBUG) || defined(DEBUGFAST) + PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGen.numTexGens, + xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op, + bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable); + + for (unsigned int i = 0; i < xfregs.numChan.numColorChans; ++i) + { + LitChannel* ch = &xfregs.color[i]; + PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc); + ch = &xfregs.alpha[i]; + PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc); + } + + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + { + TexMtxInfo tinfo = xfregs.texMtxInfo[i]; + if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP) tinfo.hex &= 0x7ff; + if (tinfo.texgentype != XF_TEXGEN_REGULAR) tinfo.projection = 0; + + PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d", + i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift, + xfregs.postMtxInfo[i].index, xfregs.postMtxInfo[i].normalize); + } + + PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages, + bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); +#endif + + u32 usedtextures = 0; + for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) + if (bpmem.tevorders[i / 2].getEnable(i & 1)) + usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1); + + if (bpmem.genMode.numindstages > 0) + for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) + if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) + usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt); + + for (unsigned int i = 0; i < 8; i++) + { + if (usedtextures & (1 << i)) + { + g_renderer->SetSamplerState(i & 3, i >> 2); + const FourTexUnits &tex = bpmem.tex[i >> 2]; + const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i, + (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, + tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1, + tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, + tex.texTlut[i&3].tlut_format, + ((tex.texMode0[i&3].min_filter & 3) != 0), + (tex.texMode1[i&3].max_lod + 0xf) / 0x10, + (tex.texImage1[i&3].image_type != 0)); + + if (tentry) + { + // 0s are probably for no manual wrapping needed. + PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); + } + else + ERROR_LOG(VIDEO, "error loading texture"); + } + } + + // set global constants + VertexShaderManager::SetConstants(); + PixelShaderManager::SetConstants(); + // TODO: need to merge more stuff into VideoCommon g_vertex_manager->vFlush(); -- cgit v1.2.3 From f90fe903203781d1732a706f7b84e0a5699a682f Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 21 Jan 2014 14:23:50 +0100 Subject: fix windows debug comile This is broken because of revision ebbf1d392bc5a90b556d793c07b789e100f10615 --- Source/Core/VideoCommon/VertexManagerBase.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 1238aa1b31..135d3c3899 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -10,6 +10,7 @@ #include "TextureCacheBase.h" #include "RenderBase.h" #include "BPStructs.h" +#include "XFMemory.h" #include "VertexManagerBase.h" #include "MainBase.h" -- cgit v1.2.3 From 52feed04dbf9d487138944ed834bd877620eef74 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 23 Jan 2014 13:11:38 +0100 Subject: VideoCommon: allow backends to set the buffer pointer as they want to --- Source/Core/VideoCommon/VertexManagerBase.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 135d3c3899..d7c31d5ce4 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -24,6 +24,8 @@ u8 *VertexManager::s_pEndBufferPointer; PrimitiveType VertexManager::current_primitive_type; +bool VertexManager::IsFlushed; + static const PrimitiveType primitive_from_gx[8] = { PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS PRIMITIVE_TRIANGLES, // GX_DRAW_NONE @@ -43,14 +45,14 @@ VertexManager::VertexManager() LocalIBuffer.resize(MAXIBUFFERSIZE); - ResetBuffer(); + IsFlushed = true; } VertexManager::~VertexManager() { } -void VertexManager::ResetBuffer() +void VertexManager::ResetBuffer(u32 stride) { s_pCurBufferPointer = s_pBaseBufferPointer; IndexGenerator::Start(GetIndexBuffer()); @@ -84,11 +86,13 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid ERROR_LOG(VIDEO, "VertexManager: Buffer not large enough for all vertices! " "Increase MAXVBUFFERSIZE or we need primitive breaking after all."); } -} -bool VertexManager::IsFlushed() const -{ - return s_pBaseBufferPointer == s_pCurBufferPointer; + // need to alloc new buffer + if(IsFlushed) + { + g_vertex_manager->ResetBuffer(stride); + IsFlushed = false; + } } u32 VertexManager::GetRemainingIndices(int primitive) @@ -160,8 +164,7 @@ void VertexManager::AddVertices(int primitive, u32 numVertices) void VertexManager::Flush() { - if (g_vertex_manager->IsFlushed()) - return; + if (IsFlushed) return; // loading a state will invalidate BP, so check for it g_video_backend->CheckInvalidState(); @@ -238,7 +241,7 @@ void VertexManager::Flush() // TODO: need to merge more stuff into VideoCommon g_vertex_manager->vFlush(); - g_vertex_manager->ResetBuffer(); + IsFlushed = true; } void VertexManager::DoState(PointerWrap& p) -- cgit v1.2.3 From 62f190597834f1fc9524d9161ae34747680c5252 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 23 Jan 2014 14:27:02 +0100 Subject: VideoCommon: don't save streaming fifos into savestate --- Source/Core/VideoCommon/VertexManagerBase.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index d7c31d5ce4..aac64cdcf3 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -248,17 +248,3 @@ void VertexManager::DoState(PointerWrap& p) { g_vertex_manager->vDoState(p); } - -void VertexManager::DoStateShared(PointerWrap& p) -{ - // It seems we half-assume to be flushed here - // We update s_pCurBufferPointer yet don't worry about IndexGenerator's outdated pointers - // and maybe other things are overlooked - - p.Do(LocalVBuffer); - p.Do(LocalIBuffer); - - s_pBaseBufferPointer = &LocalVBuffer[0]; - s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); - p.DoPointer(s_pCurBufferPointer, s_pBaseBufferPointer); -} -- cgit v1.2.3 From 1ff681a41284a757db9dfaa23b93c03aeb2c88f7 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 23 Jan 2014 15:27:18 +0100 Subject: D3D: move streaming buffer fallback into D3D backend Neith OGL nor VideoCommon doen't use it, so there is no need to have it in VideoCommon. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index aac64cdcf3..96d0ce3431 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -39,12 +39,6 @@ static const PrimitiveType primitive_from_gx[8] = { VertexManager::VertexManager() { - LocalVBuffer.resize(MAXVBUFFERSIZE); - s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0]; - s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size(); - - LocalIBuffer.resize(MAXIBUFFERSIZE); - IsFlushed = true; } @@ -52,12 +46,6 @@ VertexManager::~VertexManager() { } -void VertexManager::ResetBuffer(u32 stride) -{ - s_pCurBufferPointer = s_pBaseBufferPointer; - IndexGenerator::Start(GetIndexBuffer()); -} - u32 VertexManager::GetRemainingSize() { return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); -- cgit v1.2.3 From 1898524c9620eb1669aea0df1904fe459abc916d Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 23 Jan 2014 23:39:20 +0100 Subject: VideoCommon: fix "Buffer not large enough for all vertices!" --- Source/Core/VideoCommon/VertexManagerBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 96d0ce3431..18a6c81dd6 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -61,7 +61,8 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid current_primitive_type = primitive_from_gx[primitive]; // Check for size in buffer, if the buffer gets full, call Flush() - if (count > IndexGenerator::GetRemainingIndices() || count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize()) + if ( !IsFlushed && ( count > IndexGenerator::GetRemainingIndices() || + count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize() ) ) { Flush(); -- cgit v1.2.3 From 3437c7f060a63b13f0f353949a53a0be25ad4585 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 30 Jan 2014 14:48:23 +0100 Subject: VideoCommon: small VertexLoader(Manager)? refactoring --- Source/Core/VideoCommon/VertexManagerBase.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 18a6c81dd6..c4980ae190 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -140,17 +140,6 @@ u32 VertexManager::GetRemainingIndices(int primitive) } } -void VertexManager::AddVertices(int primitive, u32 numVertices) -{ - if (numVertices <= 0) - return; - - ADDSTAT(stats.thisFrame.numPrims, numVertices); - INCSTAT(stats.thisFrame.numPrimitiveJoins); - - IndexGenerator::AddIndices(primitive, numVertices); -} - void VertexManager::Flush() { if (IsFlushed) return; -- cgit v1.2.3 From e5318d262428bda1a7c5c80eae117981384a7fe5 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 3 Feb 2014 16:56:17 +0100 Subject: move shared parts from VertexManager::vFlush into VideoCommon --- Source/Core/VideoCommon/VertexManagerBase.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index c4980ae190..cd2eec39ce 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -11,6 +11,7 @@ #include "RenderBase.h" #include "BPStructs.h" #include "XFMemory.h" +#include "Debugger.h" #include "VertexManagerBase.h" #include "MainBase.h" @@ -216,8 +217,13 @@ void VertexManager::Flush() VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); + bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate + && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; + // TODO: need to merge more stuff into VideoCommon - g_vertex_manager->vFlush(); + g_vertex_manager->vFlush(useDstAlpha); + + GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); IsFlushed = true; } -- cgit v1.2.3 From 1f4219b5b4c5877efa12ac07d7647ed5285b288c Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 4 Feb 2014 20:16:03 +0100 Subject: move perfquery enable checks into videocommon (caller side) --- Source/Core/VideoCommon/VertexManagerBase.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index cd2eec39ce..0ea44d9a57 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -12,6 +12,7 @@ #include "BPStructs.h" #include "XFMemory.h" #include "Debugger.h" +#include "PerfQueryBase.h" #include "VertexManagerBase.h" #include "MainBase.h" @@ -220,8 +221,11 @@ void VertexManager::Flush() bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; - // TODO: need to merge more stuff into VideoCommon + if(PerfQueryBase::ShouldEmulate()) + g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); g_vertex_manager->vFlush(useDstAlpha); + if(PerfQueryBase::ShouldEmulate()) + g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 0ea44d9a57..62134854ec 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -1,22 +1,20 @@ - -#include "Common.h" - -#include "Statistics.h" -#include "OpcodeDecoding.h" -#include "IndexGenerator.h" -#include "VertexShaderManager.h" -#include "PixelShaderManager.h" -#include "NativeVertexFormat.h" -#include "TextureCacheBase.h" -#include "RenderBase.h" -#include "BPStructs.h" -#include "XFMemory.h" -#include "Debugger.h" -#include "PerfQueryBase.h" - -#include "VertexManagerBase.h" -#include "MainBase.h" -#include "VideoConfig.h" +#include "Common/Common.h" + +#include "VideoCommon/BPStructs.h" +#include "VideoCommon/Debugger.h" +#include "VideoCommon/IndexGenerator.h" +#include "VideoCommon/MainBase.h" +#include "VideoCommon/NativeVertexFormat.h" +#include "VideoCommon/OpcodeDecoding.h" +#include "VideoCommon/PerfQueryBase.h" +#include "VideoCommon/PixelShaderManager.h" +#include "VideoCommon/RenderBase.h" +#include "VideoCommon/Statistics.h" +#include "VideoCommon/TextureCacheBase.h" +#include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VertexShaderManager.h" +#include "VideoCommon/VideoConfig.h" +#include "VideoCommon/XFMemory.h" VertexManager *g_vertex_manager; -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 62134854ec..ee72d074cd 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -66,7 +66,7 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid { Flush(); - if(count > IndexGenerator::GetRemainingIndices()) + if (count > IndexGenerator::GetRemainingIndices()) ERROR_LOG(VIDEO, "Too little remaining index values. Use 32-bit or reset them on flush."); if (count > GetRemainingIndices(primitive)) ERROR_LOG(VIDEO, "VertexManager: Buffer not large enough for all indices! " @@ -77,7 +77,7 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid } // need to alloc new buffer - if(IsFlushed) + if (IsFlushed) { g_vertex_manager->ResetBuffer(stride); IsFlushed = false; @@ -88,7 +88,7 @@ u32 VertexManager::GetRemainingIndices(int primitive) { u32 index_len = MAXIBUFFERSIZE - IndexGenerator::GetIndexLen(); - if(g_Config.backend_info.bSupportsPrimitiveRestart) + if (g_Config.backend_info.bSupportsPrimitiveRestart) { switch (primitive) { @@ -216,13 +216,15 @@ void VertexManager::Flush() VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); - bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate - && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; + bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && + bpmem.dstalpha.enable && + bpmem.blendmode.alphaupdate && + bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; - if(PerfQueryBase::ShouldEmulate()) + if (PerfQueryBase::ShouldEmulate()) g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); g_vertex_manager->vFlush(useDstAlpha); - if(PerfQueryBase::ShouldEmulate()) + if (PerfQueryBase::ShouldEmulate()) g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); -- cgit v1.2.3 From 8941f19cdb01bbe8c40851240d02019ed6e13a32 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sun, 23 Mar 2014 21:44:23 +0100 Subject: BPMemory: Expose the pixel_format and zformat fields in PE_CONTROL as enumerations. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index ee72d074cd..624631b805 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -219,7 +219,7 @@ void VertexManager::Flush() bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && - bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24; + bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; if (PerfQueryBase::ShouldEmulate()) g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); -- cgit v1.2.3 From 39d439fc48ef44d0a28113a10cb796cd8989f944 Mon Sep 17 00:00:00 2001 From: magumagu Date: Thu, 8 May 2014 16:53:18 -0700 Subject: Opcode decoding: handle missing opcodes 0x88 etc. Hardware testing shows that they do the same thing as the 0x80 family of opcodes: they draw quads. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 624631b805..29feabef4b 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -28,7 +28,7 @@ bool VertexManager::IsFlushed; static const PrimitiveType primitive_from_gx[8] = { PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS - PRIMITIVE_TRIANGLES, // GX_DRAW_NONE + PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS_2 PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLES PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLE_STRIP PRIMITIVE_TRIANGLES, // GX_DRAW_TRIANGLE_FAN @@ -93,6 +93,7 @@ u32 VertexManager::GetRemainingIndices(int primitive) switch (primitive) { case GX_DRAW_QUADS: + case GX_DRAW_QUADS_2: return index_len / 5 * 4; case GX_DRAW_TRIANGLES: return index_len / 4 * 3; @@ -118,6 +119,7 @@ u32 VertexManager::GetRemainingIndices(int primitive) switch (primitive) { case GX_DRAW_QUADS: + case GX_DRAW_QUADS_2: return index_len / 6 * 4; case GX_DRAW_TRIANGLES: return index_len; -- cgit v1.2.3 From 1357277f40166683a3ac4eb9979010c3038d2db8 Mon Sep 17 00:00:00 2001 From: magumagu Date: Sun, 27 Apr 2014 11:59:04 -0700 Subject: Video backends: mass-replace "xfregs" with "xfmem". --- Source/Core/VideoCommon/VertexManagerBase.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 624631b805..029308a9f2 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -150,27 +150,27 @@ void VertexManager::Flush() VideoFifo_CheckEFBAccess(); #if defined(_DEBUG) || defined(DEBUGFAST) - PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGen.numTexGens, - xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op, + PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfmem.numTexGen.numTexGens, + xfmem.numChan.numColorChans, xfmem.dualTexTrans.enabled, bpmem.ztex2.op, bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable); - for (unsigned int i = 0; i < xfregs.numChan.numColorChans; ++i) + for (unsigned int i = 0; i < xfmem.numChan.numColorChans; ++i) { - LitChannel* ch = &xfregs.color[i]; + LitChannel* ch = &xfmem.color[i]; PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc); - ch = &xfregs.alpha[i]; + ch = &xfmem.alpha[i]; PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc); } - for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i) { - TexMtxInfo tinfo = xfregs.texMtxInfo[i]; + TexMtxInfo tinfo = xfmem.texMtxInfo[i]; if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP) tinfo.hex &= 0x7ff; if (tinfo.texgentype != XF_TEXGEN_REGULAR) tinfo.projection = 0; PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d", i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift, - xfregs.postMtxInfo[i].index, xfregs.postMtxInfo[i].normalize); + xfmem.postMtxInfo[i].index, xfmem.postMtxInfo[i].normalize); } PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages, -- cgit v1.2.3 From 78fbf2ecaa8731800dfed8034bbeb1244d68624c Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Wed, 11 Jun 2014 20:34:15 +0200 Subject: Fix a few warnings caused by using BitField with non-typesafe functions. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 5e44a5aa0e..84db7cffe8 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -154,7 +154,7 @@ void VertexManager::Flush() #if defined(_DEBUG) || defined(DEBUGFAST) PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfmem.numTexGen.numTexGens, xfmem.numChan.numColorChans, xfmem.dualTexTrans.enabled, bpmem.ztex2.op, - bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable); + (int)bpmem.blendmode.colorupdate, (int)bpmem.blendmode.alphaupdate, (int)bpmem.zmode.updateenable); for (unsigned int i = 0; i < xfmem.numChan.numColorChans; ++i) { @@ -175,8 +175,8 @@ void VertexManager::Flush() xfmem.postMtxInfo[i].index, xfmem.postMtxInfo[i].normalize); } - PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages, - bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); + PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphatest=0x%x", (int)bpmem.genMode.numtevstages+1, (int)bpmem.genMode.numindstages, + (int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); #endif u32 usedtextures = 0; -- cgit v1.2.3 From fbc64984ca7de7db10b1a8a4f49002f260c93569 Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sun, 7 Sep 2014 20:06:58 -0500 Subject: Include CommonTypes.h instead of Common.h. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 84db7cffe8..919cb0b17e 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -1,4 +1,4 @@ -#include "Common/Common.h" +#include "Common/CommonTypes.h" #include "VideoCommon/BPStructs.h" #include "VideoCommon/Debugger.h" @@ -144,7 +144,8 @@ u32 VertexManager::GetRemainingIndices(int primitive) void VertexManager::Flush() { - if (IsFlushed) return; + if (IsFlushed) + return; // loading a state will invalidate BP, so check for it g_video_backend->CheckInvalidState(); -- cgit v1.2.3 From 539f270c67c8dcd422e59dc87df4482542c82366 Mon Sep 17 00:00:00 2001 From: skidau Date: Wed, 24 Sep 2014 10:46:09 +1000 Subject: Added a xf.numtexgen != bp.numtextgen error log if there is a mismatch detected. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 919cb0b17e..d637ad9017 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -232,6 +232,9 @@ void VertexManager::Flush() GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); + if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens) + ERROR_LOG(VIDEO, "xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.", xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value()); + IsFlushed = true; } -- cgit v1.2.3 From b29e5146ec63e1b35cee45e01f54c4b69f15938e Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 21 Oct 2014 20:42:55 -0400 Subject: Convert some VideoCommon stuff to BitSet. Now with a minor performance improvement removed for no reason. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 43 +++++++++++++-------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index d637ad9017..7a18ba435b 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -180,39 +180,36 @@ void VertexManager::Flush() (int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); #endif - u32 usedtextures = 0; + BitSet32 usedtextures; for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) if (bpmem.tevorders[i / 2].getEnable(i & 1)) - usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1); + usedtextures[bpmem.tevorders[i/2].getTexMap(i & 1)] = true; if (bpmem.genMode.numindstages > 0) for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) - usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt); + usedtextures[bpmem.tevindref.getTexMap(bpmem.tevind[i].bt)] = true; - for (unsigned int i = 0; i < 8; i++) + for (unsigned int i : usedtextures) { - if (usedtextures & (1 << i)) + g_renderer->SetSamplerState(i & 3, i >> 2); + const FourTexUnits &tex = bpmem.tex[i >> 2]; + const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i, + (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, + tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1, + tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, + tex.texTlut[i&3].tlut_format, + ((tex.texMode0[i&3].min_filter & 3) != 0), + (tex.texMode1[i&3].max_lod + 0xf) / 0x10, + (tex.texImage1[i&3].image_type != 0)); + + if (tentry) { - g_renderer->SetSamplerState(i & 3, i >> 2); - const FourTexUnits &tex = bpmem.tex[i >> 2]; - const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i, - (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, - tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1, - tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, - tex.texTlut[i&3].tlut_format, - ((tex.texMode0[i&3].min_filter & 3) != 0), - (tex.texMode1[i&3].max_lod + 0xf) / 0x10, - (tex.texImage1[i&3].image_type != 0)); - - if (tentry) - { - // 0s are probably for no manual wrapping needed. - PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); - } - else - ERROR_LOG(VIDEO, "error loading texture"); + // 0s are probably for no manual wrapping needed. + PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); } + else + ERROR_LOG(VIDEO, "error loading texture"); } // set global constants -- cgit v1.2.3 From 3ddf82a318eef8091d58255c712965e3271bb296 Mon Sep 17 00:00:00 2001 From: Fiora Date: Tue, 11 Nov 2014 01:48:38 -0800 Subject: Vertex Loader: SSE implementations of more position/texcoord/normal formats ~35-45% faster NFS:HP2, possibly other vertex-bound games. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 7a18ba435b..dcd8780ede 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -53,7 +53,8 @@ u32 VertexManager::GetRemainingSize() void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) { - u32 const needed_vertex_bytes = count * stride; + // The SSE vertex loader can write up to 4 bytes past the end + u32 const needed_vertex_bytes = count * stride + 4; // We can't merge different kinds of primitives, so we have to flush here if (current_primitive_type != primitive_from_gx[primitive]) -- cgit v1.2.3 From 3fc7e55cc4623c1c49efb4c317ab0202499bb5fd Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 9 Dec 2014 08:35:04 +0100 Subject: VideoCommon: clean up VertexLoader --- Source/Core/VideoCommon/VertexManagerBase.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index dcd8780ede..84e0bb5efe 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -51,7 +51,7 @@ u32 VertexManager::GetRemainingSize() return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); } -void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) +DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) { // The SSE vertex loader can write up to 4 bytes past the end u32 const needed_vertex_bytes = count * stride + 4; @@ -83,6 +83,13 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid g_vertex_manager->ResetBuffer(stride); IsFlushed = false; } + + return DataReader(s_pCurBufferPointer, s_pEndBufferPointer); +} + +void VertexManager::FlushData(u32 count, u32 stride) +{ + s_pCurBufferPointer += count * stride; } u32 VertexManager::GetRemainingIndices(int primitive) -- cgit v1.2.3 From b406e4e1f2c696ba5f6bec04ea2e6a8cc03a02d1 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 14 Dec 2014 21:23:13 +0100 Subject: VideoCommon: Add a separate constants buffer for the geometry shader. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 84e0bb5efe..7484039137 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -2,6 +2,7 @@ #include "VideoCommon/BPStructs.h" #include "VideoCommon/Debugger.h" +#include "VideoCommon/GeometryShaderManager.h" #include "VideoCommon/IndexGenerator.h" #include "VideoCommon/MainBase.h" #include "VideoCommon/NativeVertexFormat.h" @@ -223,6 +224,7 @@ void VertexManager::Flush() // set global constants VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); + GeometryShaderManager::SetConstants(); bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && -- cgit v1.2.3 From 1af3d8447a47ea7a8be86060ca879cafe1c57824 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 17 Dec 2014 03:11:23 +0100 Subject: GeometryShaderManager: Set the constants within the callbacks. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 7484039137..b1bc049fe5 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -224,7 +224,6 @@ void VertexManager::Flush() // set global constants VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); - GeometryShaderManager::SetConstants(); bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && -- cgit v1.2.3 From d09af2dbba4f375cd4e0577124a422ffc8669398 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 20 Dec 2014 13:01:37 +0100 Subject: GeometryShaderManager: Set stereo parameters in a SetConstants() call. Doing it in SetProjectionChanged() is too early because the projection type is not set yet. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index b1bc049fe5..c6191a587f 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -223,6 +223,7 @@ void VertexManager::Flush() // set global constants VertexShaderManager::SetConstants(); + GeometryShaderManager::SetConstants(); PixelShaderManager::SetConstants(); bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && -- cgit v1.2.3 From 1261f5f7f4f15fba126119eda0d0639568e2b101 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 11 Jan 2015 12:48:04 +0100 Subject: TextureCache: inline arguments into texture cache --- Source/Core/VideoCommon/VertexManagerBase.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index c6191a587f..38cfd19630 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -202,15 +202,7 @@ void VertexManager::Flush() for (unsigned int i : usedtextures) { g_renderer->SetSamplerState(i & 3, i >> 2); - const FourTexUnits &tex = bpmem.tex[i >> 2]; - const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i, - (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, - tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1, - tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, - tex.texTlut[i&3].tlut_format, - ((tex.texMode0[i&3].min_filter & 3) != 0), - (tex.texMode1[i&3].max_lod + 0xf) / 0x10, - (tex.texImage1[i&3].image_type != 0)); + const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i); if (tentry) { -- cgit v1.2.3 From 613781c7650d3cbd494a212eacdff10ea5140894 Mon Sep 17 00:00:00 2001 From: NanoByte011 Date: Fri, 26 Dec 2014 01:25:24 -0700 Subject: Cleanup and refactor of zfreeze port Based on the feedback from pull request #1767 I have put in most of degasus's suggestions in here now. I think we have a real winner here as moving the code to VertexManagerBase for a function has allowed OGL to utilize zfreeze now :) Correct use of the vertex pointer has also corrected most of the issue found in pull request #1767 that JMC47 stated. Which also for me now has Mario Tennis working with no polygon spikes on the characters anymore! Shadows are still an issue and probably in the other games with shadow problems. Rebel Strike also seems better but random skybox glitches can show up. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 38cfd19630..80ea3b5bb9 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -241,3 +241,43 @@ void VertexManager::DoState(PointerWrap& p) { g_vertex_manager->vDoState(p); } + +void VertexManager::CalculateZSlope(u32 stride) +{ + float vtx[9]; + float out[12]; + + // Lookup vertices of the last rendered triangle and software-transform them + // This allows us to determine the depth slope, which will be used if zfreeze + // is enabled in the following flush. + for (unsigned int i = 0; i < 3; ++i) + { + u8* vtx_ptr = s_pCurBufferPointer - stride * (3 - i); + vtx[0 + i * 3] = ((float*)vtx_ptr)[0]; + vtx[1 + i * 3] = ((float*)vtx_ptr)[1]; + vtx[2 + i * 3] = ((float*)vtx_ptr)[2]; + + VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]); + + // viewport offset ignored because we only look at coordinate differences. + out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd; + out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht; + out[2 + i * 4] = out[2 + i * 4] / out[3 + i * 4] * xfmem.viewport.zRange + xfmem.viewport.farZ; + } + float dx31 = out[8] - out[0]; + float dx12 = out[0] - out[4]; + float dy12 = out[1] - out[5]; + float dy31 = out[9] - out[1]; + + float DF31 = out[10] - out[2]; + float DF21 = out[6] - out[2]; + float a = DF31 * -dy12 - DF21 * dy31; + float b = dx31 * DF21 + dx12 * DF31; + float c = -dx12 * dy31 - dx31 * -dy12; + + float slope_dfdx = -a / c; + float slope_dfdy = -b / c; + float slope_f0 = out[2]; + + PixelShaderManager::SetZSlope(slope_dfdx, slope_dfdy, slope_f0); +} -- cgit v1.2.3 From 418296961cba39e4ae5bc441b3f52bf1459ad2bb Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Fri, 2 Jan 2015 23:55:41 +1300 Subject: Fix various issues with zfreeze implemntation. Results are still not correct, but things are getting closer. * Don't cull CULLALL primitives so early so they can be used as reference planes. * Convert CalculateZSlope to screenspace coordinates. * Convert Pixelshader to screenspace coordinates (instead of worldspace xy coordinates, which is totally wrong) * Divide depth by 2^24 instead of clamping to 0.0-1.0 as was done before. Progress: * Rouge Squadron 2/3 appear correct in game (videos in rs2 save file selection are missing) * Shadows draw 100% correctly in NHL 2003. * Mario golf menu renders correctly. * NFS: HP2, shadows sometimes render on top of car or below the road. * Mario Tennis, courts and shadows render correctly, but at wrong depth * Blood Omen 2, doesn't work. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 80ea3b5bb9..bcdaf466a4 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -259,11 +259,12 @@ void VertexManager::CalculateZSlope(u32 stride) VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]); - // viewport offset ignored because we only look at coordinate differences. - out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd; - out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht; + // Transform to Screenspace + out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd + (xfmem.viewport.xOrig - 342); + out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht + (xfmem.viewport.yOrig - 342); out[2 + i * 4] = out[2 + i * 4] / out[3 + i * 4] * xfmem.viewport.zRange + xfmem.viewport.farZ; } + float dx31 = out[8] - out[0]; float dx12 = out[0] - out[4]; float dy12 = out[1] - out[5]; @@ -277,7 +278,7 @@ void VertexManager::CalculateZSlope(u32 stride) float slope_dfdx = -a / c; float slope_dfdy = -b / c; - float slope_f0 = out[2]; + float slope_f0 = out[2] - (out[0] * slope_dfdx + out[1] * slope_dfdy); PixelShaderManager::SetZSlope(slope_dfdx, slope_dfdy, slope_f0); } -- cgit v1.2.3 From add59b3bea032e331363dcf28361f8e0de65e43d Mon Sep 17 00:00:00 2001 From: NanoByte011 Date: Tue, 13 Jan 2015 02:55:25 -0700 Subject: Fixes Mario Tennis Gimmick Courts and adds support for FastDepthCalc - Calculate ZSlope every flush but only set PixelShader Constant on Reset Buffer when zfreeze - Fixed another Pixel Shader bug in D3D that was giving me grief --- Source/Core/VideoCommon/VertexManagerBase.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index bcdaf466a4..23eb770c6d 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -25,6 +25,8 @@ u8 *VertexManager::s_pEndBufferPointer; PrimitiveType VertexManager::current_primitive_type; +Slope VertexManager::ZSlope; + bool VertexManager::IsFlushed; static const PrimitiveType primitive_from_gx[8] = { @@ -246,6 +248,8 @@ void VertexManager::CalculateZSlope(u32 stride) { float vtx[9]; float out[12]; + float viewOffset[2] = { xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2, + xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; // Lookup vertices of the last rendered triangle and software-transform them // This allows us to determine the depth slope, which will be used if zfreeze @@ -260,9 +264,11 @@ void VertexManager::CalculateZSlope(u32 stride) VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]); // Transform to Screenspace - out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd + (xfmem.viewport.xOrig - 342); - out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht + (xfmem.viewport.yOrig - 342); - out[2 + i * 4] = out[2 + i * 4] / out[3 + i * 4] * xfmem.viewport.zRange + xfmem.viewport.farZ; + float w = out[3 + i * 4]; + + out[0 + i * 4] = out[0 + i * 4] / w * xfmem.viewport.wd + viewOffset[0]; + out[1 + i * 4] = out[1 + i * 4] / w * xfmem.viewport.ht + viewOffset[1]; + out[2 + i * 4] = out[2 + i * 4] / w * xfmem.viewport.zRange + xfmem.viewport.farZ; } float dx31 = out[8] - out[0]; @@ -276,9 +282,11 @@ void VertexManager::CalculateZSlope(u32 stride) float b = dx31 * DF21 + dx12 * DF31; float c = -dx12 * dy31 - dx31 * -dy12; - float slope_dfdx = -a / c; - float slope_dfdy = -b / c; - float slope_f0 = out[2] - (out[0] * slope_dfdx + out[1] * slope_dfdy); + // Stop divide by zero + if (c == 0) + return; - PixelShaderManager::SetZSlope(slope_dfdx, slope_dfdy, slope_f0); + ZSlope.dfdx = -a / c; + ZSlope.dfdy = -b / c; + ZSlope.f0 = out[2] - (out[0] * ZSlope.dfdx + out[1] * ZSlope.dfdy); } -- cgit v1.2.3 From 128d3036564e99fd3c8d7e6ae45eb17e43d0c95f Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Fri, 16 Jan 2015 04:01:00 +1300 Subject: Reduce number of divisions in screenspace transform. This is closer to what the hardware does anyway. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 23eb770c6d..c9f5e2c714 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -264,11 +264,11 @@ void VertexManager::CalculateZSlope(u32 stride) VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]); // Transform to Screenspace - float w = out[3 + i * 4]; + float inv_w = 1.0f / out[3 + i * 4]; - out[0 + i * 4] = out[0 + i * 4] / w * xfmem.viewport.wd + viewOffset[0]; - out[1 + i * 4] = out[1 + i * 4] / w * xfmem.viewport.ht + viewOffset[1]; - out[2 + i * 4] = out[2 + i * 4] / w * xfmem.viewport.zRange + xfmem.viewport.farZ; + out[0 + i * 4] = out[0 + i * 4] * inv_w * xfmem.viewport.wd + viewOffset[0]; + out[1 + i * 4] = out[1 + i * 4] * inv_w * xfmem.viewport.ht + viewOffset[1]; + out[2 + i * 4] = out[2 + i * 4] * inv_w * xfmem.viewport.zRange + xfmem.viewport.farZ; } float dx31 = out[8] - out[0]; -- cgit v1.2.3 From e88c02dece0e5e8d3b019fd0137eab790d6d2036 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Fri, 16 Jan 2015 05:29:39 +1300 Subject: Ensure that ZSlopes save/restore state correctly. Had to re-do *ShaderManager so they saved their constant arrays instead of completly rebuilding them on restore state. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index c9f5e2c714..3f6c672c65 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -241,6 +241,7 @@ void VertexManager::Flush() void VertexManager::DoState(PointerWrap& p) { + p.Do(ZSlope); g_vertex_manager->vDoState(p); } -- cgit v1.2.3 From daf760b20245c2e397a98da94e80c15be9090657 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Fri, 23 Jan 2015 04:38:36 +1300 Subject: A few small cleanups based on code review. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 3f6c672c65..4c13a26736 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -250,7 +250,7 @@ void VertexManager::CalculateZSlope(u32 stride) float vtx[9]; float out[12]; float viewOffset[2] = { xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2, - xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; + xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; // Lookup vertices of the last rendered triangle and software-transform them // This allows us to determine the depth slope, which will be used if zfreeze -- cgit v1.2.3 From 5510c86b8133ec734ba490b700d4f432d98f71a7 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 24 Jan 2015 03:15:09 +1300 Subject: Move Zfreeze code out individual backends into videoCommon Also: * Implement support for per-vertex PosMatrixIndex * Only update zslope constant once when zfreeze is activated. * Added a bunch of comments. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 52 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 4c13a26736..75f6de97f8 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -12,6 +12,7 @@ #include "VideoCommon/RenderBase.h" #include "VideoCommon/Statistics.h" #include "VideoCommon/TextureCacheBase.h" +#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoConfig.h" @@ -220,6 +221,30 @@ void VertexManager::Flush() GeometryShaderManager::SetConstants(); PixelShaderManager::SetConstants(); + // Calculate ZSlope for zfreeze + if (!bpmem.genMode.zfreeze) + { + // Must be done after VertexShaderManager::SetConstants() + CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat()); + } + else if (ZSlope.dirty) // or apply any dirty ZSlopes + { + PixelShaderManager::SetZSlope(ZSlope.dfdx, ZSlope.dfdy, ZSlope.f0); + ZSlope.dirty = false; + } + + // If cull mode is CULL_ALL, we shouldn't render any triangles/quads (points and lines don't get culled) + // vertex loader has already converted any quads into triangles, so we just check for triangles. + // TODO: These culled primites need to get this far through the pipeline to be used as zfreeze refrence + // planes. But currently we apply excessive processing and store the vertices in buffers on the + // video card, which is a waste of bandwidth. + if (bpmem.genMode.cullmode == GenMode::CULL_ALL && current_primitive_type == PRIMITIVE_TRIANGLES) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); + IsFlushed = true; + return; + } + bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && @@ -245,24 +270,34 @@ void VertexManager::DoState(PointerWrap& p) g_vertex_manager->vDoState(p); } -void VertexManager::CalculateZSlope(u32 stride) +void VertexManager::CalculateZSlope(NativeVertexFormat *format) { float vtx[9]; float out[12]; float viewOffset[2] = { xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2, xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; + // Global matrix ID. + u32 mtxIdx = g_main_cp_state.matrix_index_a.PosNormalMtxIdx; + PortableVertexDeclaration vert_decl = format->GetVertexDeclaration(); + size_t posOff = vert_decl.position.offset; + size_t mtxOff = vert_decl.posmtx.offset; + // Lookup vertices of the last rendered triangle and software-transform them - // This allows us to determine the depth slope, which will be used if zfreeze + // This allows us to determine the depth slope, which will be used if z--freeze // is enabled in the following flush. for (unsigned int i = 0; i < 3; ++i) { - u8* vtx_ptr = s_pCurBufferPointer - stride * (3 - i); - vtx[0 + i * 3] = ((float*)vtx_ptr)[0]; - vtx[1 + i * 3] = ((float*)vtx_ptr)[1]; - vtx[2 + i * 3] = ((float*)vtx_ptr)[2]; + u8* vtx_ptr = s_pCurBufferPointer - vert_decl.stride * (3 - i); + vtx[0 + i * 3] = ((float*)(vtx_ptr + posOff))[0]; + vtx[1 + i * 3] = ((float*)(vtx_ptr + posOff))[1]; + vtx[2 + i * 3] = ((float*)(vtx_ptr + posOff))[2]; + + // If this vertex format has per-vertex position matrix IDs, look it up. + if(vert_decl.posmtx.enable) + mtxIdx = *((u32*)(vtx_ptr + mtxOff)); - VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]); + VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4], mtxIdx); // Transform to Screenspace float inv_w = 1.0f / out[3 + i * 4]; @@ -283,11 +318,12 @@ void VertexManager::CalculateZSlope(u32 stride) float b = dx31 * DF21 + dx12 * DF31; float c = -dx12 * dy31 - dx31 * -dy12; - // Stop divide by zero + // Sometimes we process de-generate triangles. Stop any divide by zeros if (c == 0) return; ZSlope.dfdx = -a / c; ZSlope.dfdy = -b / c; ZSlope.f0 = out[2] - (out[0] * ZSlope.dfdx + out[1] * ZSlope.dfdy); + ZSlope.dirty = true; } -- cgit v1.2.3 From 14baf038e70a598a6af1ce71719bb557425941f9 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sat, 24 Jan 2015 14:37:20 +1300 Subject: Stop doing nastly shit to OpenGL stream buffers. Instead we keep the loaded vertices in CPU memory. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 90 ++++++++++++++------------- 1 file changed, 46 insertions(+), 44 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 75f6de97f8..0c5ccdd10d 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -29,6 +29,7 @@ PrimitiveType VertexManager::current_primitive_type; Slope VertexManager::ZSlope; bool VertexManager::IsFlushed; +bool VertexManager::CullAll; static const PrimitiveType primitive_from_gx[8] = { PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS @@ -44,6 +45,7 @@ static const PrimitiveType primitive_from_gx[8] = { VertexManager::VertexManager() { IsFlushed = true; + CullAll = false; } VertexManager::~VertexManager() @@ -55,7 +57,7 @@ u32 VertexManager::GetRemainingSize() return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); } -DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) +DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall) { // The SSE vertex loader can write up to 4 bytes past the end u32 const needed_vertex_bytes = count * stride + 4; @@ -81,6 +83,8 @@ DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 "Increase MAXVBUFFERSIZE or we need primitive breaking after all."); } + CullAll = cullall; + // need to alloc new buffer if (IsFlushed) { @@ -192,34 +196,36 @@ void VertexManager::Flush() (int)bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alpha_test.hex>>16)&0xff); #endif - BitSet32 usedtextures; - for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) - if (bpmem.tevorders[i / 2].getEnable(i & 1)) - usedtextures[bpmem.tevorders[i/2].getTexMap(i & 1)] = true; - - if (bpmem.genMode.numindstages > 0) - for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) - if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) - usedtextures[bpmem.tevindref.getTexMap(bpmem.tevind[i].bt)] = true; - - for (unsigned int i : usedtextures) + // If the primitave is marked CullAll. All we need to do is update the vertex constants and calculate the zfreeze refrence slope + if (!CullAll) { - g_renderer->SetSamplerState(i & 3, i >> 2); - const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i); + BitSet32 usedtextures; + for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) + if (bpmem.tevorders[i / 2].getEnable(i & 1)) + usedtextures[bpmem.tevorders[i/2].getTexMap(i & 1)] = true; + + if (bpmem.genMode.numindstages > 0) + for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) + if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) + usedtextures[bpmem.tevindref.getTexMap(bpmem.tevind[i].bt)] = true; - if (tentry) + for (unsigned int i : usedtextures) { - // 0s are probably for no manual wrapping needed. - PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); + g_renderer->SetSamplerState(i & 3, i >> 2); + const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i); + + if (tentry) + { + // 0s are probably for no manual wrapping needed. + PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); + } + else + ERROR_LOG(VIDEO, "error loading texture"); } - else - ERROR_LOG(VIDEO, "error loading texture"); } - // set global constants + // set global vertex constants VertexShaderManager::SetConstants(); - GeometryShaderManager::SetConstants(); - PixelShaderManager::SetConstants(); // Calculate ZSlope for zfreeze if (!bpmem.genMode.zfreeze) @@ -227,41 +233,37 @@ void VertexManager::Flush() // Must be done after VertexShaderManager::SetConstants() CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat()); } - else if (ZSlope.dirty) // or apply any dirty ZSlopes + else if (ZSlope.dirty && !CullAll) // or apply any dirty ZSlopes { PixelShaderManager::SetZSlope(ZSlope.dfdx, ZSlope.dfdy, ZSlope.f0); ZSlope.dirty = false; } - // If cull mode is CULL_ALL, we shouldn't render any triangles/quads (points and lines don't get culled) - // vertex loader has already converted any quads into triangles, so we just check for triangles. - // TODO: These culled primites need to get this far through the pipeline to be used as zfreeze refrence - // planes. But currently we apply excessive processing and store the vertices in buffers on the - // video card, which is a waste of bandwidth. - if (bpmem.genMode.cullmode == GenMode::CULL_ALL && current_primitive_type == PRIMITIVE_TRIANGLES) + if (!CullAll) { - GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); - IsFlushed = true; - return; + // set the rest of the global constants + GeometryShaderManager::SetConstants(); + PixelShaderManager::SetConstants(); + + bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && + bpmem.dstalpha.enable && + bpmem.blendmode.alphaupdate && + bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; + + if (PerfQueryBase::ShouldEmulate()) + g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); + g_vertex_manager->vFlush(useDstAlpha); + if (PerfQueryBase::ShouldEmulate()) + g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); } - bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && - bpmem.dstalpha.enable && - bpmem.blendmode.alphaupdate && - bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; - - if (PerfQueryBase::ShouldEmulate()) - g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); - g_vertex_manager->vFlush(useDstAlpha); - if (PerfQueryBase::ShouldEmulate()) - g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP); - GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true); if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens) ERROR_LOG(VIDEO, "xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.", xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value()); IsFlushed = true; + CullAll = false; } void VertexManager::DoState(PointerWrap& p) @@ -279,7 +281,7 @@ void VertexManager::CalculateZSlope(NativeVertexFormat *format) // Global matrix ID. u32 mtxIdx = g_main_cp_state.matrix_index_a.PosNormalMtxIdx; - PortableVertexDeclaration vert_decl = format->GetVertexDeclaration(); + const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration(); size_t posOff = vert_decl.position.offset; size_t mtxOff = vert_decl.posmtx.offset; -- cgit v1.2.3 From 9cdfe889af54303dbeef305a26d13d4285ef1b5d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 24 Jan 2015 15:12:52 -0500 Subject: Coding style cleanup from the zfreeze merge --- Source/Core/VideoCommon/VertexManagerBase.cpp | 50 ++++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 0c5ccdd10d..e34af09bfc 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -26,10 +26,10 @@ u8 *VertexManager::s_pEndBufferPointer; PrimitiveType VertexManager::current_primitive_type; -Slope VertexManager::ZSlope; +Slope VertexManager::s_zslope; -bool VertexManager::IsFlushed; -bool VertexManager::CullAll; +bool VertexManager::s_is_flushed; +bool VertexManager::s_cull_all; static const PrimitiveType primitive_from_gx[8] = { PRIMITIVE_TRIANGLES, // GX_DRAW_QUADS @@ -44,8 +44,8 @@ static const PrimitiveType primitive_from_gx[8] = { VertexManager::VertexManager() { - IsFlushed = true; - CullAll = false; + s_is_flushed = true; + s_cull_all = false; } VertexManager::~VertexManager() @@ -68,8 +68,8 @@ DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 current_primitive_type = primitive_from_gx[primitive]; // Check for size in buffer, if the buffer gets full, call Flush() - if ( !IsFlushed && ( count > IndexGenerator::GetRemainingIndices() || - count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize() ) ) + if (!s_is_flushed && ( count > IndexGenerator::GetRemainingIndices() || + count > GetRemainingIndices(primitive) || needed_vertex_bytes > GetRemainingSize())) { Flush(); @@ -83,13 +83,13 @@ DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 "Increase MAXVBUFFERSIZE or we need primitive breaking after all."); } - CullAll = cullall; + s_cull_all = cullall; // need to alloc new buffer - if (IsFlushed) + if (s_is_flushed) { g_vertex_manager->ResetBuffer(stride); - IsFlushed = false; + s_is_flushed = false; } return DataReader(s_pCurBufferPointer, s_pEndBufferPointer); @@ -160,7 +160,7 @@ u32 VertexManager::GetRemainingIndices(int primitive) void VertexManager::Flush() { - if (IsFlushed) + if (s_is_flushed) return; // loading a state will invalidate BP, so check for it @@ -197,7 +197,7 @@ void VertexManager::Flush() #endif // If the primitave is marked CullAll. All we need to do is update the vertex constants and calculate the zfreeze refrence slope - if (!CullAll) + if (!s_cull_all) { BitSet32 usedtextures; for (u32 i = 0; i < bpmem.genMode.numtevstages + 1u; ++i) @@ -220,7 +220,9 @@ void VertexManager::Flush() PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); } else + { ERROR_LOG(VIDEO, "error loading texture"); + } } } @@ -233,13 +235,13 @@ void VertexManager::Flush() // Must be done after VertexShaderManager::SetConstants() CalculateZSlope(VertexLoaderManager::GetCurrentVertexFormat()); } - else if (ZSlope.dirty && !CullAll) // or apply any dirty ZSlopes + else if (s_zslope.dirty && !s_cull_all) // or apply any dirty ZSlopes { - PixelShaderManager::SetZSlope(ZSlope.dfdx, ZSlope.dfdy, ZSlope.f0); - ZSlope.dirty = false; + PixelShaderManager::SetZSlope(s_zslope.dfdx, s_zslope.dfdy, s_zslope.f0); + s_zslope.dirty = false; } - if (!CullAll) + if (!s_cull_all) { // set the rest of the global constants GeometryShaderManager::SetConstants(); @@ -262,17 +264,17 @@ void VertexManager::Flush() if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens) ERROR_LOG(VIDEO, "xf.numtexgens (%d) does not match bp.numtexgens (%d). Error in command stream.", xfmem.numTexGen.numTexGens, bpmem.genMode.numtexgens.Value()); - IsFlushed = true; - CullAll = false; + s_is_flushed = true; + s_cull_all = false; } void VertexManager::DoState(PointerWrap& p) { - p.Do(ZSlope); + p.Do(s_zslope); g_vertex_manager->vDoState(p); } -void VertexManager::CalculateZSlope(NativeVertexFormat *format) +void VertexManager::CalculateZSlope(NativeVertexFormat* format) { float vtx[9]; float out[12]; @@ -324,8 +326,8 @@ void VertexManager::CalculateZSlope(NativeVertexFormat *format) if (c == 0) return; - ZSlope.dfdx = -a / c; - ZSlope.dfdy = -b / c; - ZSlope.f0 = out[2] - (out[0] * ZSlope.dfdx + out[1] * ZSlope.dfdy); - ZSlope.dirty = true; + s_zslope.dfdx = -a / c; + s_zslope.dfdy = -b / c; + s_zslope.f0 = out[2] - (out[0] * s_zslope.dfdx + out[1] * s_zslope.dfdy); + s_zslope.dirty = true; } -- cgit v1.2.3 From 61215e718028de2d4b0e302f2226e43d0051876f Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Sun, 25 Jan 2015 20:31:20 +1300 Subject: Fix a buffer underrun in CalculateZSlope. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index e34af09bfc..2ebb42122f 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -287,6 +287,10 @@ void VertexManager::CalculateZSlope(NativeVertexFormat* format) size_t posOff = vert_decl.position.offset; size_t mtxOff = vert_decl.posmtx.offset; + // Make sure the buffer contains at lest 3 vertices. + if ((s_pCurBufferPointer - s_pBaseBufferPointer) < (vert_decl.stride * 3)) + return; + // Lookup vertices of the last rendered triangle and software-transform them // This allows us to determine the depth slope, which will be used if z--freeze // is enabled in the following flush. -- cgit v1.2.3 From c0a4760f0efbb99274c33f30154a7f43aab70494 Mon Sep 17 00:00:00 2001 From: magumagu Date: Mon, 26 Jan 2015 15:33:23 -0800 Subject: Decode EFB copies used as paletted textures. A number of games make an EFB copy in I4/I8 format, then use it as a texture in C4/C8 format. Detect when this happens, and decode the copy on the GPU using the specified palette. This has a few advantages: it allows using EFB2Tex for a few more games, it, it preserves the resolution of scaled EFB copies, and it's probably a bit faster. D3D only at the moment, but porting to OpenGL should be straightforward.. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 2ebb42122f..bf7800cc9a 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -209,6 +209,7 @@ void VertexManager::Flush() if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) usedtextures[bpmem.tevindref.getTexMap(bpmem.tevind[i].bt)] = true; + TextureCache::UnbindTextures(); for (unsigned int i : usedtextures) { g_renderer->SetSamplerState(i & 3, i >> 2); @@ -224,6 +225,7 @@ void VertexManager::Flush() ERROR_LOG(VIDEO, "error loading texture"); } } + TextureCache::BindTextures(); } // set global vertex constants -- cgit v1.2.3 From bc248f8941ae5f24e651d5bf029740bc96c3df89 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 31 Jan 2015 11:38:23 +0100 Subject: VideoCommon: use a new async event system for efb access --- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index bf7800cc9a..520654448f 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -166,8 +166,6 @@ void VertexManager::Flush() // loading a state will invalidate BP, so check for it g_video_backend->CheckInvalidState(); - VideoFifo_CheckEFBAccess(); - #if defined(_DEBUG) || defined(DEBUGFAST) PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfmem.numTexGen.numTexGens, xfmem.numChan.numColorChans, xfmem.dualTexTrans.enabled, bpmem.ztex2.op, -- cgit v1.2.3 From 35373c5185d586602a44c51544f85fb6acde10f1 Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 1 Mar 2015 13:04:48 +0100 Subject: TextureCache: load all mipmap levels from custom textures This drops the "feature" to load level 0 from the custom texture and all other levels from the native one if the size matches. But in my opinion, when a custom texture only provide one level, no more should be used at all. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 520654448f..0eebc05663 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -210,13 +210,12 @@ void VertexManager::Flush() TextureCache::UnbindTextures(); for (unsigned int i : usedtextures) { - g_renderer->SetSamplerState(i & 3, i >> 2); const TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i); if (tentry) { - // 0s are probably for no manual wrapping needed. - PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0); + g_renderer->SetSamplerState(i & 3, i >> 2, tentry->is_custom_tex); + PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height); } else { -- cgit v1.2.3 From 268f52e05479dc8e0f2cbf550472ca8d4867cf22 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:32:32 +0200 Subject: Add missing license headers --- Source/Core/VideoCommon/VertexManagerBase.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 0eebc05663..e414b0ecec 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -1,3 +1,7 @@ +// Copyright 2010 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + #include "Common/CommonTypes.h" #include "VideoCommon/BPStructs.h" -- cgit v1.2.3 From 4943b362595a00585b407e97da30b295952349c2 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Fri, 29 May 2015 13:43:12 +0200 Subject: zfreeze: fix 2-component positions --- Source/Core/VideoCommon/VertexManagerBase.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index e414b0ecec..dcef793cec 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -284,13 +284,16 @@ void VertexManager::CalculateZSlope(NativeVertexFormat* format) float viewOffset[2] = { xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2, xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; + if (current_primitive_type != PRIMITIVE_TRIANGLES) + return; + // Global matrix ID. u32 mtxIdx = g_main_cp_state.matrix_index_a.PosNormalMtxIdx; const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration(); size_t posOff = vert_decl.position.offset; size_t mtxOff = vert_decl.posmtx.offset; - // Make sure the buffer contains at lest 3 vertices. + // Make sure the buffer contains at least 3 vertices. if ((s_pCurBufferPointer - s_pBaseBufferPointer) < (vert_decl.stride * 3)) return; @@ -302,10 +305,13 @@ void VertexManager::CalculateZSlope(NativeVertexFormat* format) u8* vtx_ptr = s_pCurBufferPointer - vert_decl.stride * (3 - i); vtx[0 + i * 3] = ((float*)(vtx_ptr + posOff))[0]; vtx[1 + i * 3] = ((float*)(vtx_ptr + posOff))[1]; - vtx[2 + i * 3] = ((float*)(vtx_ptr + posOff))[2]; + if (vert_decl.position.components == 3) + vtx[2 + i * 3] = ((float*)(vtx_ptr + posOff))[2]; + else + vtx[2 + i * 3] = 0; // If this vertex format has per-vertex position matrix IDs, look it up. - if(vert_decl.posmtx.enable) + if (vert_decl.posmtx.enable) mtxIdx = *((u32*)(vtx_ptr + mtxOff)); VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4], mtxIdx); -- cgit v1.2.3 From 5ddd2cef6c5cc8e5414636d73365691de726b3d0 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 1 Jun 2015 19:58:27 +0200 Subject: zfreeze: cache vertex positions Suggested by degasus. --- Source/Core/VideoCommon/VertexManagerBase.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'Source/Core/VideoCommon/VertexManagerBase.cpp') diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index dcef793cec..e9e8ebf901 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -279,7 +279,6 @@ void VertexManager::DoState(PointerWrap& p) void VertexManager::CalculateZSlope(NativeVertexFormat* format) { - float vtx[9]; float out[12]; float viewOffset[2] = { xfmem.viewport.xOrig - bpmem.scissorOffset.x * 2, xfmem.viewport.yOrig - bpmem.scissorOffset.y * 2}; @@ -290,31 +289,24 @@ void VertexManager::CalculateZSlope(NativeVertexFormat* format) // Global matrix ID. u32 mtxIdx = g_main_cp_state.matrix_index_a.PosNormalMtxIdx; const PortableVertexDeclaration vert_decl = format->GetVertexDeclaration(); - size_t posOff = vert_decl.position.offset; - size_t mtxOff = vert_decl.posmtx.offset; // Make sure the buffer contains at least 3 vertices. if ((s_pCurBufferPointer - s_pBaseBufferPointer) < (vert_decl.stride * 3)) return; // Lookup vertices of the last rendered triangle and software-transform them - // This allows us to determine the depth slope, which will be used if z--freeze + // This allows us to determine the depth slope, which will be used if z-freeze // is enabled in the following flush. for (unsigned int i = 0; i < 3; ++i) { - u8* vtx_ptr = s_pCurBufferPointer - vert_decl.stride * (3 - i); - vtx[0 + i * 3] = ((float*)(vtx_ptr + posOff))[0]; - vtx[1 + i * 3] = ((float*)(vtx_ptr + posOff))[1]; - if (vert_decl.position.components == 3) - vtx[2 + i * 3] = ((float*)(vtx_ptr + posOff))[2]; - else - vtx[2 + i * 3] = 0; - // If this vertex format has per-vertex position matrix IDs, look it up. if (vert_decl.posmtx.enable) - mtxIdx = *((u32*)(vtx_ptr + mtxOff)); + mtxIdx = VertexLoaderManager::position_matrix_index[2 - i]; + + if (vert_decl.position.components == 2) + VertexLoaderManager::position_cache[2 - i][2] = 0; - VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4], mtxIdx); + VertexShaderManager::TransformToClipSpace(&VertexLoaderManager::position_cache[2 - i][0], &out[i * 4], mtxIdx); // Transform to Screenspace float inv_w = 1.0f / out[3 + i * 4]; -- cgit v1.2.3