Skip to content

Commit

Permalink
Decoded position format is always the same
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 6, 2023
1 parent 0cd02ab commit d4703e9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
14 changes: 5 additions & 9 deletions GPU/Common/VertexDecoderCommon.cpp
Expand Up @@ -60,7 +60,7 @@ int TranslateNumBones(int bones) {
return bones;
}

int DecFmtSize(u8 fmt) {
static int DecFmtSize(u8 fmt) {
switch (fmt) {
case DEC_NONE: return 0;
case DEC_FLOAT_1: return 4;
Expand All @@ -83,7 +83,7 @@ int DecFmtSize(u8 fmt) {
}

void DecVtxFormat::ComputeID() {
id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20) | (posfmt << 24);
id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20);
}

void DecVtxFormat::InitializeFromID(uint32_t id) {
Expand All @@ -94,15 +94,14 @@ void DecVtxFormat::InitializeFromID(uint32_t id) {
c0fmt = ((id >> 12) & 0xF);
c1fmt = ((id >> 16) & 0xF);
nrmfmt = ((id >> 20) & 0xF);
posfmt = ((id >> 24) & 0xF);
w0off = 0;
w1off = w0off + DecFmtSize(w0fmt);
uvoff = w1off + DecFmtSize(w1fmt);
c0off = uvoff + DecFmtSize(uvfmt);
c1off = c0off + DecFmtSize(c0fmt);
nrmoff = c1off + DecFmtSize(c1fmt);
posoff = nrmoff + DecFmtSize(nrmfmt);
stride = posoff + DecFmtSize(posfmt);
stride = posoff + DecFmtSize(PosFmt());
}

void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound) {
Expand Down Expand Up @@ -1248,20 +1247,18 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options,
if (posalign[pos] > biggest)
biggest = posalign[pos];

// We don't set posfmt because it's always DEC_FLOAT_3.
if (throughmode) {
steps_[numSteps_++] = posstep_through[pos];
decFmt.posfmt = DEC_FLOAT_3;
} else {
if (skinInDecode) {
steps_[numSteps_++] = morphcount == 1 ? posstep_skin[pos] : posstep_morph_skin[pos];
decFmt.posfmt = DEC_FLOAT_3;
} else {
steps_[numSteps_++] = morphcount == 1 ? posstep[pos] : posstep_morph[pos];
decFmt.posfmt = DEC_FLOAT_3;
}
}
decFmt.posoff = decOff;
decOff += DecFmtSize(decFmt.posfmt);
decOff += DecFmtSize(DecVtxFormat::PosFmt());
}

decFmt.stride = options.alignOutputToWord ? align(decOff, 4) : decOff;
Expand All @@ -1279,7 +1276,6 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options,
ERROR_LOG_REPORT(G3D, "Vertices without position found: (%08x) %s", fmt_, temp);
}

_assert_msg_(decFmt.posfmt == DEC_FLOAT_3, "Reader only supports float pos");
_assert_msg_(decFmt.uvfmt == DEC_FLOAT_2 || decFmt.uvfmt == DEC_NONE, "Reader only supports float UV");

// Attempt to JIT as well. But only do that if the main CPU JIT is enabled, in order to aid
Expand Down
6 changes: 3 additions & 3 deletions GPU/Common/VertexDecoderCommon.h
Expand Up @@ -67,21 +67,21 @@ enum {
DEC_U16_4,
};

int DecFmtSize(u8 fmt);

struct DecVtxFormat {
u8 w0fmt; u8 w0off; // first 4 weights
u8 w1fmt; u8 w1off; // second 4 weights
u8 uvfmt; u8 uvoff;
u8 c0fmt; u8 c0off; // First color
u8 c1fmt; u8 c1off;
u8 nrmfmt; u8 nrmoff;
u8 posfmt; u8 posoff;
u8 posoff; // Output position format is always DEC_FLOAT_3.
u8 stride;

uint32_t id;
void ComputeID();
void InitializeFromID(uint32_t id);

static u8 PosFmt() { return DEC_FLOAT_3; }
};

void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound);
Expand Down
2 changes: 1 addition & 1 deletion GPU/D3D11/DrawEngineD3D11.cpp
Expand Up @@ -243,7 +243,7 @@ ID3D11InputLayout *DrawEngineD3D11::SetupDecFmtForDraw(D3D11VertexShader *vshade

// POSITION
// Always
VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, "POSITION", 0);
VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, "POSITION", 0);
VertexElement++;

// Create declaration
Expand Down
2 changes: 1 addition & 1 deletion GPU/Directx9/DrawEngineDX9.cpp
Expand Up @@ -206,7 +206,7 @@ IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(const DecVtxForma

// POSITION
// Always
VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, D3DDECLUSAGE_POSITION, 0);
VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, D3DDECLUSAGE_POSITION, 0);
VertexElement++;

// End
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/DrawEngineGLES.cpp
Expand Up @@ -218,7 +218,7 @@ GLRInputLayout *DrawEngineGLES::SetupDecFmtForDraw(const DecVtxFormat &decFmt) {
VertexAttribSetup(ATTR_COLOR0, decFmt.c0fmt, decFmt.stride, decFmt.c0off, entries);
VertexAttribSetup(ATTR_COLOR1, decFmt.c1fmt, decFmt.stride, decFmt.c1off, entries);
VertexAttribSetup(ATTR_NORMAL, decFmt.nrmfmt, decFmt.stride, decFmt.nrmoff, entries);
VertexAttribSetup(ATTR_POSITION, decFmt.posfmt, decFmt.stride, decFmt.posoff, entries);
VertexAttribSetup(ATTR_POSITION, DecVtxFormat::PosFmt(), decFmt.stride, decFmt.posoff, entries);

inputLayout = render_->CreateInputLayout(entries);
inputLayoutMap_.Insert(key, inputLayout);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Vulkan/PipelineManagerVulkan.cpp
Expand Up @@ -134,7 +134,7 @@ static int SetupVertexAttribs(VkVertexInputAttributeDescription attrs[], const D
VertexAttribSetup(&attrs[count++], decFmt.nrmfmt, decFmt.nrmoff, PspAttributeLocation::NORMAL);
}
// Position is always there.
VertexAttribSetup(&attrs[count++], decFmt.posfmt, decFmt.posoff, PspAttributeLocation::POSITION);
VertexAttribSetup(&attrs[count++], DecVtxFormat::PosFmt(), decFmt.posoff, PspAttributeLocation::POSITION);
return count;
}

Expand Down

0 comments on commit d4703e9

Please sign in to comment.