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

Draw points using triangles #15075

Merged
merged 3 commits into from
Oct 31, 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
2 changes: 0 additions & 2 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,8 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
#ifndef USING_GLES2
if (g_Config.iInternalResolution == 0) {
glLineWidth(std::max(1, (int)(renderWidth_ / 480)));
glPointSize(std::max(1.0f, (float)(renderWidth_ / 480.f)));
} else {
glLineWidth(g_Config.iInternalResolution);
glPointSize((float)g_Config.iInternalResolution);
}
#endif
*/
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/Vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ void VulkanContext::ChooseDevice(int physical_device) {
deviceFeatures_.enabled = {};
// Enable a few safe ones if they are available.
deviceFeatures_.enabled.dualSrcBlend = deviceFeatures_.available.dualSrcBlend;
deviceFeatures_.enabled.largePoints = deviceFeatures_.available.largePoints;
deviceFeatures_.enabled.wideLines = deviceFeatures_.available.wideLines;
deviceFeatures_.enabled.logicOp = deviceFeatures_.available.logicOp;
deviceFeatures_.enabled.depthClamp = deviceFeatures_.available.depthClamp;
Expand Down
1 change: 0 additions & 1 deletion Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ std::vector<std::string> VKContext::GetFeatureList() const {
AddFeature(features, "depthBounds", available.depthBounds, enabled.depthBounds);
AddFeature(features, "depthClamp", available.depthClamp, enabled.depthClamp);
AddFeature(features, "fillModeNonSolid", available.fillModeNonSolid, enabled.fillModeNonSolid);
AddFeature(features, "largePoints", available.largePoints, enabled.largePoints);
AddFeature(features, "wideLines", available.wideLines, enabled.wideLines);
AddFeature(features, "pipelineStatisticsQuery", available.pipelineStatisticsQuery, enabled.pipelineStatisticsQuery);
AddFeature(features, "samplerAnisotropy", available.samplerAnisotropy, enabled.samplerAnisotropy);
Expand Down
73 changes: 73 additions & 0 deletions GPU/Common/SoftwareTransformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
vert.u = 0.0f;
vert.v = 0.0f;
}
vert.uv_w = 1.0f;

// Ignore color1 and fog, never used in throughmode anyway.
// The w of uv is also never used (hardcoded to 1.0.)
Expand Down Expand Up @@ -589,6 +590,10 @@ void SoftwareTransform::BuildDrawingParams(int prim, int vertexCount, u32 vertTy
result->stencilValue = 0;
}
}
} else if (prim == GE_PRIM_POINTS) {
ExpandPoints(vertexCount, maxIndex, inds, transformed, transformedExpanded, numTrans, throughmode);
result->drawBuffer = transformedExpanded;
result->drawIndexed = true;
} else {
// We can simply draw the unexpanded buffer.
numTrans = vertexCount;
Expand Down Expand Up @@ -787,3 +792,71 @@ void SoftwareTransform::ExpandRectangles(int vertexCount, int &maxIndex, u16 *&i
}
inds = newInds;
}

void SoftwareTransform::ExpandPoints(int vertexCount, int &maxIndex, u16 *&inds, TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) {
numTrans = 0;
TransformedVertex *trans = &transformedExpanded[0];

const u16 *indsIn = (const u16 *)inds;
u16 *newInds = inds + vertexCount;
u16 *indsOut = newInds;

float dx = 1.0f * gstate_c.vpWidthScale * (1.0f / gstate.getViewportXScale());
float dy = 1.0f * gstate_c.vpHeightScale * (1.0f / gstate.getViewportYScale());
float du = 1.0f / gstate_c.curTextureWidth;
float dv = 1.0f / gstate_c.curTextureHeight;

if (throughmode) {
dx = 1.0f;
dy = 1.0f;
}

maxIndex = 4 * vertexCount;
for (int i = 0; i < vertexCount; ++i) {
const TransformedVertex &transVtxTL = transformed[indsIn[i]];

// Create the bottom right version.
TransformedVertex transVtxBR = transVtxTL;
transVtxBR.x += dx * transVtxTL.pos_w;
transVtxBR.y += dy * transVtxTL.pos_w;
transVtxBR.u += du * transVtxTL.uv_w;
transVtxBR.v += dv * transVtxTL.uv_w;

// We have to turn the rectangle into two triangles, so 6 points.
// This is 4 verts + 6 indices.

// bottom right
trans[0] = transVtxBR;

// top right
trans[1] = transVtxBR;
trans[1].y = transVtxTL.y;
trans[1].v = transVtxTL.v;

// top left
trans[2] = transVtxBR;
trans[2].x = transVtxTL.x;
trans[2].y = transVtxTL.y;
trans[2].u = transVtxTL.u;
trans[2].v = transVtxTL.v;

// bottom left
trans[3] = transVtxBR;
trans[3].x = transVtxTL.x;
trans[3].u = transVtxTL.u;

// Triangle: BR-TR-TL
indsOut[0] = i * 4 + 0;
indsOut[1] = i * 4 + 1;
indsOut[2] = i * 4 + 2;
// Triangle: BL-BR-TL
indsOut[3] = i * 4 + 3;
indsOut[4] = i * 4 + 0;
indsOut[5] = i * 4 + 2;
trans += 4;
indsOut += 6;

numTrans += 6;
}
inds = newInds;
}
1 change: 1 addition & 0 deletions GPU/Common/SoftwareTransformCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SoftwareTransform {
protected:
void CalcCullParams(float &minZValue, float &maxZValue);
void ExpandRectangles(int vertexCount, int &maxIndex, u16 *&inds, TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode);
void ExpandPoints(int vertexCount, int &maxIndex, u16 *&inds, TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode);

const SoftwareTransformParams &params_;
Lin::Matrix4x4 projMatrix_;
Expand Down
3 changes: 0 additions & 3 deletions GPU/Common/VertexShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,9 +1178,6 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
compat.vsOutPrefix, compat.vsOutPrefix, compat.vsOutPrefix);
}

if (compat.shaderLanguage == GLSL_VULKAN) {
WRITE(p, " gl_PointSize = 1.0;\n");
}
if (compat.shaderLanguage == HLSL_D3D11 || compat.shaderLanguage == HLSL_D3D9) {
WRITE(p, " return Out;\n");
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/D3D11/DrawEngineD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "GPU/D3D11/GPU_D3D11.h"

const D3D11_PRIMITIVE_TOPOLOGY d3d11prim[8] = {
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Points are expanded to triangles.
D3D11_PRIMITIVE_TOPOLOGY_LINELIST,
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
Expand Down
4 changes: 2 additions & 2 deletions GPU/D3D11/StateMappingD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ static const D3D11_STENCIL_OP stencilOps[] = {
};

static const D3D11_PRIMITIVE_TOPOLOGY primToD3D11[8] = {
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Points are expanded to triangles.
D3D11_PRIMITIVE_TOPOLOGY_LINELIST,
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, // D3D11 doesn't do triangle fans.
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Rectangles are expanded to triangles.
};

static const D3D11_LOGIC_OP logicOps[] = {
Expand Down
4 changes: 3 additions & 1 deletion GPU/Directx9/DrawEngineDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
namespace DX9 {

static const D3DPRIMITIVETYPE d3d_prim[8] = {
D3DPT_POINTLIST,
// Points, which are expanded to triangles.
D3DPT_TRIANGLELIST,
D3DPT_LINELIST,
D3DPT_LINESTRIP,
D3DPT_TRIANGLELIST,
D3DPT_TRIANGLESTRIP,
D3DPT_TRIANGLEFAN,
// Rectangles, which are expanded to triangles.
D3DPT_TRIANGLELIST,
};

Expand Down
5 changes: 3 additions & 2 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
#include "GPU/GLES/GPU_GLES.h"

const GLuint glprim[8] = {
GL_POINTS,
// Points, which are expanded to triangles.
GL_TRIANGLES,
GL_LINES,
GL_LINE_STRIP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN,
// Rectangles, which are expanded to triangles.
GL_TRIANGLES,
// Rectangles need to be expanded into triangles.
};

enum {
Expand Down
1 change: 0 additions & 1 deletion GPU/Vulkan/GPU_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ void GPU_Vulkan::BuildReportingInfo() {
CHECK_BOOL_FEATURE(fillModeNonSolid);
CHECK_BOOL_FEATURE(depthBounds);
CHECK_BOOL_FEATURE(wideLines);
CHECK_BOOL_FEATURE(largePoints);
CHECK_BOOL_FEATURE(alphaToOne);
CHECK_BOOL_FEATURE(multiViewport);
CHECK_BOOL_FEATURE(samplerAnisotropy);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Vulkan/StateMappingVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static const VkStencilOp stencilOps[] = {
};

static const VkPrimitiveTopology primToVulkan[8] = {
VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // We convert points to triangles.
VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
VK_PRIMITIVE_TOPOLOGY_LINE_STRIP,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
Expand Down