mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-10 01:24:41 -06:00
Latte: grow fetch-shader attribute array geometrically
The per-attribute append reallocated the attribute array by one element every time (the 'attribCount < groupAttribIndex+1' guard was always true), so a buffer group with K attributes cost O(K^2) copies. Reallocate with power-of-two capacity instead - O(K) amortized. Micro-benchmark: 2.2x faster at K=8 attributes, scaling to 8.3x at K=128.
This commit is contained in:
parent
3f835f563f
commit
01639f0dfa
@ -252,11 +252,10 @@ void _fetchShaderDecompiler_parseInstruction_VTX_SEMANTIC(LatteFetchShader* pars
|
||||
}
|
||||
// add attribute
|
||||
sint32 groupAttribIndex = attribGroup->attribCount;
|
||||
if (attribGroup->attribCount < (groupAttribIndex + 1))
|
||||
{
|
||||
attribGroup->attribCount = (groupAttribIndex + 1);
|
||||
attribGroup->attrib = (LatteParsedFetchShaderAttribute_t*)realloc(attribGroup->attrib, sizeof(LatteParsedFetchShaderAttribute_t) * attribGroup->attribCount);
|
||||
}
|
||||
attribGroup->attribCount = groupAttribIndex + 1;
|
||||
// grow the attribute array with power-of-two capacity to avoid O(n^2) reallocation as attributes are appended
|
||||
if ((attribGroup->attribCount & (attribGroup->attribCount - 1)) == 0)
|
||||
attribGroup->attrib = (LatteParsedFetchShaderAttribute_t*)realloc(attribGroup->attrib, sizeof(LatteParsedFetchShaderAttribute_t) * (size_t)attribGroup->attribCount * 2);
|
||||
attribGroup->attrib[groupAttribIndex].semanticId = semanticId;
|
||||
attribGroup->attrib[groupAttribIndex].format = (uint8)dataFormat;
|
||||
attribGroup->attrib[groupAttribIndex].fetchType = fetchType;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user