Skip to content

Commit

Permalink
Merge pull request #18598 from hrydgard/inline-update-uvscale
Browse files Browse the repository at this point in the history
Inline UpdateUVScaleOffset
  • Loading branch information
hrydgard committed Dec 21, 2023
2 parents 5fccf64 + e488189 commit 03b8826
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
19 changes: 2 additions & 17 deletions GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ void GPUCommon::FlushImm() {
immCount_ = 0;
return;
}
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
if (vfb) {
CheckDepthUsage(vfb);
}
Expand Down Expand Up @@ -1933,7 +1933,7 @@ bool GPUCommon::PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil f
}

bool GPUCommon::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
return drawEngineCommon_->GetCurrentSimpleVertices(count, vertices, indices);
}

Expand All @@ -1942,18 +1942,3 @@ bool GPUCommon::DescribeCodePtr(const u8 *ptr, std::string &name) {
// which is owned by the drawengine.
return drawEngineCommon_->DescribeCodePtr(ptr, name);
}

void GPUCommon::UpdateUVScaleOffset() {
#if defined(_M_SSE)
__m128i values = _mm_slli_epi32(_mm_load_si128((const __m128i *)&gstate.texscaleu), 8);
_mm_storeu_si128((__m128i *)&gstate_c.uv, values);
#elif PPSSPP_ARCH(ARM_NEON)
const uint32x4_t values = vshlq_n_u32(vld1q_u32((const u32 *)&gstate.texscaleu), 8);
vst1q_u32((u32 *)&gstate_c.uv, values);
#else
gstate_c.uv.uScale = getFloat24(gstate.texscaleu);
gstate_c.uv.vScale = getFloat24(gstate.texscalev);
gstate_c.uv.uOff = getFloat24(gstate.texoffsetu);
gstate_c.uv.vOff = getFloat24(gstate.texoffsetv);
#endif
}
2 changes: 0 additions & 2 deletions GPU/GPUCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ class GPUCommon : public GPUInterface, public GPUDebugInterface {
GPUgstate GetGState() override;
void SetCmdValue(u32 op) override;

void UpdateUVScaleOffset();

DisplayList* getList(int listid) override {
return &dls[listid];
}
Expand Down
6 changes: 3 additions & 3 deletions GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
}

int bytesRead = 0;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();

// cull mode
int cullMode = gstate.getCullMode();
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void GPUCommonHW::Execute_Bezier(u32 op, u32 diff) {
}

int bytesRead = 0;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "bezier");

gstate_c.Dirty(DIRTY_RASTER_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_GEOMETRYSHADER_STATE | DIRTY_UVSCALEOFFSET);
Expand Down Expand Up @@ -1380,7 +1380,7 @@ void GPUCommonHW::Execute_Spline(u32 op, u32 diff) {
}

int bytesRead = 0;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "spline");

gstate_c.Dirty(DIRTY_RASTER_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_GEOMETRYSHADER_STATE | DIRTY_UVSCALEOFFSET);
Expand Down
31 changes: 30 additions & 1 deletion GPU/GPUState.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@

#pragma once

#include "ppsspp_config.h"

#include "Common/CommonTypes.h"
#include "Common/Swap.h"
#include "GPU/GPU.h"
#include "GPU/ge_constants.h"
#include "GPU/Common/ShaderCommon.h"

#if defined(_M_SSE)
#include <emmintrin.h>
#endif
#if PPSSPP_ARCH(ARM_NEON)
#if defined(_MSC_VER) && PPSSPP_ARCH(ARM64)
#include <arm64_neon.h>
#else
#include <arm_neon.h>
#endif
#endif

class PointerWrap;

struct GPUgstate {
Expand Down Expand Up @@ -523,6 +536,8 @@ enum class SubmitType {
HW_SPLINE,
};

extern GPUgstate gstate;

struct GPUStateCache {
bool Use(u32 flags) const { return (useFlags_ & flags) != 0; } // Return true if ANY of flags are true.
bool UseAll(u32 flags) const { return (useFlags_ & flags) == flags; } // Return true if ALL flags are true.
Expand Down Expand Up @@ -604,6 +619,21 @@ struct GPUStateCache {
return useFlags_;
}

void UpdateUVScaleOffset() {
#if defined(_M_SSE)
__m128i values = _mm_slli_epi32(_mm_load_si128((const __m128i *)&gstate.texscaleu), 8);
_mm_storeu_si128((__m128i *)&uv, values);
#elif PPSSPP_ARCH(ARM_NEON)
const uint32x4_t values = vshlq_n_u32(vld1q_u32((const u32 *)&gstate.texscaleu), 8);
vst1q_u32((u32 *)&uv, values);
#else
uv.uScale = getFloat24(gstate.texscaleu);
uv.vScale = getFloat24(gstate.texscalev);
uv.uOff = getFloat24(gstate.texoffsetu);
uv.vOff = getFloat24(gstate.texoffsetv);
#endif
}

private:
u32 useFlags_;
public:
Expand Down Expand Up @@ -690,7 +720,6 @@ struct GPUStateCache {
class GPUInterface;
class GPUDebugInterface;

extern GPUgstate gstate;
extern GPUStateCache gstate_c;

inline u32 GPUStateCache::getRelativeAddress(u32 data) const {
Expand Down
8 changes: 4 additions & 4 deletions GPU/Software/SoftGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) {

cyclesExecuted += EstimatePerVertexCost() * count;
int bytesRead;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
drawEngine_->transformUnit.SetDirty(dirtyFlags_);
drawEngine_->transformUnit.SubmitPrimitive(verts, indices, prim, count, gstate.vertType, &bytesRead, drawEngine_);
dirtyFlags_ = drawEngine_->transformUnit.GetDirty();
Expand Down Expand Up @@ -917,7 +917,7 @@ void SoftGPU::Execute_Bezier(u32 op, u32 diff) {
SetDrawType(DRAW_BEZIER, PatchPrimToPrim(surface.primType));

int bytesRead = 0;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
drawEngine_->transformUnit.SetDirty(dirtyFlags_);
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "bezier");
dirtyFlags_ = drawEngine_->transformUnit.GetDirty();
Expand Down Expand Up @@ -971,7 +971,7 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) {
SetDrawType(DRAW_SPLINE, PatchPrimToPrim(surface.primType));

int bytesRead = 0;
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
drawEngine_->transformUnit.SetDirty(dirtyFlags_);
drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "spline");
dirtyFlags_ = drawEngine_->transformUnit.GetDirty();
Expand Down Expand Up @@ -1445,7 +1445,7 @@ bool SoftGPU::GetCurrentClut(GPUDebugBuffer &buffer)
}

bool SoftGPU::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
UpdateUVScaleOffset();
gstate_c.UpdateUVScaleOffset();
return drawEngine_->transformUnit.GetCurrentSimpleVertices(count, vertices, indices);
}

Expand Down

0 comments on commit 03b8826

Please sign in to comment.