Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: Correct geometry shader culling #15064

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ class VKPipeline : public Pipeline {
return buf->PushAligned(ubo_, uboSize_, vulkan->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment, vkbuf);
}

int GetUniformLoc(const char *name);
int GetUBOSize() const {
return uboSize_;
}
Expand Down Expand Up @@ -1324,17 +1323,6 @@ ShaderModule *VKContext::CreateShaderModule(ShaderStage stage, ShaderLanguage la
}
}

int VKPipeline::GetUniformLoc(const char *name) {
int loc = -1;

// HACK! As we only use one uniform we hardcode it.
if (!strcmp(name, "WorldViewProj")) {
return 0;
}

return loc;
}

void VKContext::UpdateDynamicUniformBuffer(const void *ub, size_t size) {
curPipeline_->SetDynamicUniformData(ub, size);
}
Expand Down
10 changes: 6 additions & 4 deletions GPU/Common/GeometryShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
p.BeginGSMain(varyings, outVaryings);

// Apply culling
p.C(" bool anyInside = false;\n"); // TODO: 3 or gl_in.length()? which will be faster?
p.C(" bool insidePositiveZ = false, insideNegativeZ = false;\n");

p.C(" for (int i = 0; i < 3; i++) {\n"); // TODO: 3 or gl_in.length()? which will be faster?
p.C(" vec4 outPos = gl_in[i].gl_Position;\n");
Expand All @@ -94,16 +94,18 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
p.C(" }\n");
p.C(" if (u_cullRangeMin.w <= 0.0) {\n");
p.C(" if (projPos.z < u_cullRangeMin.z || projPos.z > u_cullRangeMax.z) {\n");
p.C(" return;\n"); // Cull!
// When not clamping depth, cull the triangle of Z is outside the valid range (not based on clip Z.)
p.C(" return;\n");
p.C(" }\n");
p.C(" } else {\n");
p.C(" if (projPos.z >= u_cullRangeMin.z && projPos.z <= u_cullRangeMax.z) { anyInside = true; }\n");
p.C(" if (projPos.z >= u_cullRangeMin.z) { insideNegativeZ = true; }\n");
p.C(" if (projPos.z <= u_cullRangeMax.z) { insidePositiveZ = true; }\n");
p.C(" }\n");
p.C(" } // for\n");

// Cull any triangle fully outside in the same direction when depth clamp enabled.
// Basically simulate cull distances.
p.C(" if (!anyInside) { return; }\n");
p.C(" if (!insideNegativeZ || !insidePositiveZ) { return; }\n");

const char *clip0 = compat.shaderLanguage == HLSL_D3D11 ? "" : "[0]";

Expand Down