oit: poly number/vertex id overflow

Use 17 bits for vertex id but substract first vtx index
Use 13 bits for poly number instead of 12
Panzer Front uses more than 4095 tr polys.
Issue #616
This commit is contained in:
Flyinghead 2022-05-01 12:33:53 +02:00
parent c348f4ccad
commit 3cc991fa4f
10 changed files with 22 additions and 14 deletions

View File

@ -129,7 +129,7 @@ VertexOut main(in VertexIn vin)
if (envMapping0 == 1)
computeEnvMap(vo.uv.xy, vnorm);
#endif
vo.index = (uint(polyNumber) << 18) + vin.vertexId;
vo.index = uint(polyNumber) + vin.vertexId;
#endif
vo.pos = mul(projMat, vo.pos);

View File

@ -315,6 +315,7 @@ struct DX11OITRenderer : public DX11Renderer
PolyParam* params = &gply.head()[first];
u32 firstVertexIdx = Type == ListType_Translucent ? pvrrc.idx.head()[gply.head()->first] : 0;
while (count-- > 0)
{
if (params->count > 2)
@ -325,7 +326,7 @@ struct DX11OITRenderer : public DX11Renderer
params++;
continue;
}
setRenderState<Type, SortingEnabled, pass>(params, (int)(params - gply.head()));
setRenderState<Type, SortingEnabled, pass>(params, (int)((params - gply.head()) << 17) - firstVertexIdx);
deviceContext->DrawIndexed(params->count, params->first, 0);
}

View File

@ -85,7 +85,7 @@ VertexOut main(in VertexIn vin)
#endif
vo.uv = float4(vin.uv * vo.pos.z, 0.f, vo.pos.z);
vo.uv1 = vin.uv1 * vo.pos.z;
vo.index = (uint(polyNumber) << 18) + vin.vertexId;
vo.index = uint(polyNumber) + vin.vertexId;
vo.pos.w = 1.f;
vo.pos.z = 0.f;
@ -212,7 +212,7 @@ uint getPolyIndex(in Pixel pixel)
uint getPolyNumber(in Pixel pixel)
{
return (pixel.seq_num & 0x3FFFFFFFu) >> 18;
return (pixel.seq_num & 0x3FFFFFFFu) >> 17;
}
#define SHADOW_STENCIL 0x40000000u

View File

@ -294,6 +294,7 @@ static void DrawList(const List<PolyParam>& gply, int first, int count)
{
PolyParam* params = &gply.head()[first];
u32 firstVertexIdx = Type == ListType_Translucent ? pvrrc.idx.head()[gply.head()->first] : 0;
while (count-- > 0)
{
if (params->count > 2)
@ -310,7 +311,7 @@ static void DrawList(const List<PolyParam>& gply, int first, int count)
params++;
continue;
}
gl4ShaderUniforms.poly_number = params - gply.head();
gl4ShaderUniforms.poly_number = ((params - gply.head()) << 17) - firstVertexIdx;
SetGPState<Type, SortingEnabled, pass>(params);
glDrawElements(GL_TRIANGLE_STRIP, params->count, GL_UNSIGNED_INT, (GLvoid*)(sizeof(u32) * params->first)); glCheck();
}

View File

@ -89,7 +89,7 @@ void main()
vtx_base1 = in_base1;
vtx_offs1 = in_offs1;
vtx_uv1 = in_uv1 * vpos.z;
vtx_index = (uint(pp_Number) << 18) + uint(gl_VertexID);
vtx_index = uint(pp_Number) + uint(gl_VertexID);
#if pp_Gouraud == 1
vtx_base *= vpos.z;
vtx_offs *= vpos.z;

View File

@ -73,7 +73,7 @@ struct PolyParam { \n\
\n\
#define getShadowEnable(pp) (((pp).tsp_isp_pcw & 1) != 0) \n\
\n\
#define getPolyNumber(pixel) (((pixel).seq_num & 0x3FFFFFFFu) >> 18) \n\
#define getPolyNumber(pixel) (((pixel).seq_num & 0x3FFFFFFFu) >> 17) \n\
\n\
#define getPolyIndex(pixel) ((pixel).seq_num & 0x3FFFFFFFu) \n\
\n\

View File

@ -126,7 +126,7 @@ void main()
wDivide(vpos);
#ifdef OIT_RENDER
vtx_index = (uint(pp_Number) << 18) + uint(gl_VertexID);
vtx_index = uint(pp_Number) + uint(gl_VertexID);
#endif
gl_Position = vpos;

View File

@ -105,8 +105,12 @@ protected:
for (const PolyParam& pp : pvrrc.global_param_pt)
addUniform(pp, 0);
size_t trOffset = bufIdx;
for (const PolyParam& pp : pvrrc.global_param_tr)
addUniform(pp, &pp - pvrrc.global_param_tr.head());
if (pvrrc.global_param_tr.used() > 0)
{
u32 firstVertexIdx = pvrrc.idx.head()[pvrrc.global_param_tr.head()->first];
for (const PolyParam& pp : pvrrc.global_param_tr)
addUniform(pp, ((&pp - pvrrc.global_param_tr.head()) << 17) - firstVertexIdx);
}
size_t mvOffset = bufIdx;
for (const ModifierVolumeParam& mvp : pvrrc.global_param_mvo)
{

View File

@ -78,8 +78,10 @@ void OITDrawer::DrawPoly(const vk::CommandBuffer& cmdBuffer, u32 listType, bool
cmdBuffer.pushConstants<OITDescriptorSets::PushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
if (!poly.isNaomi2())
{
OITDescriptorSets::VtxPushConstants vtxPushConstants = {
listType == ListType_Translucent ? (int)(&poly - pvrrc.global_param_tr.head()) : 0
OITDescriptorSets::VtxPushConstants vtxPushConstants {};
if (listType == ListType_Translucent) {
u32 firstVertexIdx = pvrrc.idx.head()[pvrrc.global_param_tr.head()->first];
vtxPushConstants.polyNumber = (int)((&poly - pvrrc.global_param_tr.head()) << 17) - firstVertexIdx;
};
cmdBuffer.pushConstants<OITDescriptorSets::VtxPushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eVertex,
sizeof(OITDescriptorSets::PushConstants), vtxPushConstants);

View File

@ -64,7 +64,7 @@ void main()
vtx_base1 *= vpos.z;
vtx_offs1 *= vpos.z;
#endif
vtx_index = (uint(pushConstants.polyNumber) << 18) + uint(gl_VertexIndex);
vtx_index = uint(pushConstants.polyNumber) + uint(gl_VertexIndex);
vpos.w = 1.0;
vpos.z = 0.0;
gl_Position = vpos;
@ -766,7 +766,7 @@ void main()
vpos = n2Uniform.projMat * vpos;
wDivide(vpos);
vtx_index = (uint(n2Uniform.polyNumber) << 18) + uint(gl_VertexIndex);
vtx_index = uint(n2Uniform.polyNumber) + uint(gl_VertexIndex);
gl_Position = vpos;
}