Skip to content

Commit

Permalink
[spline/bezier]Improve HW tess on Opengl to combine 3 textures into a…
Browse files Browse the repository at this point in the history
… single texture and use it.
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 3add123 commit 1b076f8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
31 changes: 9 additions & 22 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,41 +661,28 @@ void DrawEngineGLES::TessellationDataTransferGLES::SendDataToShader(const Simple
int sizeColor = hasColor ? size : 1;

float *pos = new float[size * 4];
float *tex = nullptr;
if (hasTexCoord)
tex = new float[size * 4];
float *tex = hasTexCoord ? new float[size * 4] : nullptr;
float *col = new float[sizeColor * 4];
int stride = 4;

CopyControlPoints(pos, tex, col, stride, stride, stride, points, size, vertType);

// Removed the 1D texture support, it's unlikely to be relevant for performance.

// Position
// Control Points
if (data_tex[0])
renderManager_->DeleteTexture(data_tex[0]);
data_tex[0] = renderManager_->CreateTexture(GL_TEXTURE_2D);
renderManager_->TextureImage(data_tex[0], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, (u8 *)pos, GLRAllocType::NEW, false);
renderManager_->TextureImage(data_tex[0], 0, size, 3, GL_RGBA32F, GL_RGBA, GL_FLOAT, (u8 *)nullptr, GLRAllocType::NONE, false);
renderManager_->FinalizeTexture(data_tex[0], 0, false);
renderManager_->BindTexture(TEX_SLOT_SPLINE_POS, data_tex[0]);
renderManager_->BindTexture(TEX_SLOT_SPLINE_POINTS, data_tex[0]);

// Position
renderManager_->TextureSubImage(data_tex[0], 0, 0, 0, size, 1, GL_RGBA, GL_FLOAT, (u8 *)pos, GLRAllocType::NEW);
// Texcoord
if (hasTexCoord) {
if (data_tex[1])
renderManager_->DeleteTexture(data_tex[1]);
data_tex[1] = renderManager_->CreateTexture(GL_TEXTURE_2D);
renderManager_->TextureImage(data_tex[1], 0, size, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, (u8 *)tex, GLRAllocType::NEW, false);
renderManager_->FinalizeTexture(data_tex[1], 0, false);
renderManager_->BindTexture(TEX_SLOT_SPLINE_TEX, data_tex[1]);
}

if (hasTexCoord)
renderManager_->TextureSubImage(data_tex[0], 0, 0, 1, size, 1, GL_RGBA, GL_FLOAT, (u8 *)tex, GLRAllocType::NEW);
// Color
if (data_tex[2])
renderManager_->DeleteTexture(data_tex[2]);
data_tex[2] = renderManager_->CreateTexture(GL_TEXTURE_2D);
renderManager_->TextureImage(data_tex[2], 0, sizeColor, 1, GL_RGBA32F, GL_RGBA, GL_FLOAT, (u8 *)col, GLRAllocType::NEW, false);
renderManager_->FinalizeTexture(data_tex[2], 0, false);
renderManager_->BindTexture(TEX_SLOT_SPLINE_COL, data_tex[2]);
renderManager_->TextureSubImage(data_tex[0], 0, 0, 2, sizeColor, 1, GL_RGBA, GL_FLOAT, (u8 *)col, GLRAllocType::NEW);
}

void DrawEngineGLES::TessellationDataTransferGLES::EndFrame() {
Expand Down
6 changes: 3 additions & 3 deletions GPU/GLES/DrawEngineGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ enum {
TEX_SLOT_SHADERBLEND_SRC = 1,
TEX_SLOT_ALPHATEST = 2,
TEX_SLOT_CLUT = 3,
TEX_SLOT_SPLINE_POS = 4,
TEX_SLOT_SPLINE_TEX = 5,
TEX_SLOT_SPLINE_COL = 6,
TEX_SLOT_SPLINE_POINTS = 4,
TEX_SLOT_SPLINE_WEIGHTS_U = 5,
TEX_SLOT_SPLINE_WEIGHTS_V = 6,
};


Expand Down
12 changes: 6 additions & 6 deletions GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs,

// We need to fetch these unconditionally, gstate_c.spline or bezier will not be set if we
// create this shader at load time from the shader cache.
queries.push_back({ &u_tess_pos_tex, "u_tess_pos_tex" });
queries.push_back({ &u_tess_tex_tex, "u_tess_tex_tex" });
queries.push_back({ &u_tess_col_tex, "u_tess_col_tex" });
queries.push_back({ &u_tess_points, "u_tess_points" });
queries.push_back({ &u_tess_weights_u, "u_tess_weights_u" });
queries.push_back({ &u_tess_weights_v, "u_tess_weights_v" });
queries.push_back({ &u_spline_count_u, "u_spline_count_u" });
queries.push_back({ &u_spline_count_v, "u_spline_count_v" });
queries.push_back({ &u_spline_type_u, "u_spline_type_u" });
Expand All @@ -176,9 +176,9 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs,
initialize.push_back({ &u_fbotex, 0, 1 });
initialize.push_back({ &u_testtex, 0, 2 });
initialize.push_back({ &u_pal, 0, 3 }); // CLUT
initialize.push_back({ &u_tess_pos_tex, 0, 4 }); // Texture unit 4
initialize.push_back({ &u_tess_tex_tex, 0, 5 }); // Texture unit 5
initialize.push_back({ &u_tess_col_tex, 0, 6 }); // Texture unit 6
initialize.push_back({ &u_tess_points, 0, 4 }); // Control Points
initialize.push_back({ &u_tess_weights_u, 0, 5 });
initialize.push_back({ &u_tess_weights_v, 0, 6 });

program = render->CreateProgram(shaders, semantics, queries, initialize, gstate_c.featureFlags & GPU_SUPPORTS_DUALSOURCE_BLEND);

Expand Down
7 changes: 4 additions & 3 deletions GPU/GLES/ShaderManagerGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ class LinkedShader {
int u_lightspecular[4]; // attenuation
int u_lightambient[4]; // attenuation

int u_tess_pos_tex;
int u_tess_tex_tex;
int u_tess_col_tex;
// Spline Tessellation
int u_tess_points; // Control Points
int u_tess_weights_u;
int u_tess_weights_v;
int u_spline_count_u;
int u_spline_count_v;
int u_spline_type_u;
Expand Down
14 changes: 7 additions & 7 deletions GPU/GLES/VertexShaderGeneratorGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
if (doBezier || doSpline) {
*uniformMask |= DIRTY_BEZIERSPLINE;

WRITE(p, "uniform sampler2D u_tess_pos_tex;\n");
WRITE(p, "uniform sampler2D u_tess_tex_tex;\n");
WRITE(p, "uniform sampler2D u_tess_col_tex;\n");
WRITE(p, "uniform sampler2D u_tess_points;\n"); // Control Points
WRITE(p, "uniform sampler2D u_tess_weights_u;\n");
WRITE(p, "uniform sampler2D u_tess_weights_v;\n");

WRITE(p, "uniform int u_spline_count_u;\n");

Expand Down Expand Up @@ -506,11 +506,11 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
WRITE(p, " for (int i = 0; i < 4; i++) {\n");
WRITE(p, " for (int j = 0; j < 4; j++) {\n");
WRITE(p, " int index = (i + v%s) * u_spline_count_u + (j + u%s);\n", doBezier ? " * 3" : "", doBezier ? " * 3" : "");
WRITE(p, " _pos[i * 4 + j] = %s(u_tess_pos_tex, ivec2(index, 0), 0).xyz;\n", texelFetch);
WRITE(p, " _pos[i * 4 + j] = %s(u_tess_points, ivec2(index, 0), 0).xyz;\n", texelFetch);
if (doTexture && hasTexcoord && hasTexcoordTess)
WRITE(p, " _tex[i * 4 + j] = %s(u_tess_tex_tex, ivec2(index, 0), 0).xy;\n", texelFetch);
WRITE(p, " _tex[i * 4 + j] = %s(u_tess_points, ivec2(index, 1), 0).xy;\n", texelFetch);
if (hasColor && hasColorTess)
WRITE(p, " _col[i * 4 + j] = %s(u_tess_col_tex, ivec2(index, 0), 0).rgba;\n", texelFetch);
WRITE(p, " _col[i * 4 + j] = %s(u_tess_points, ivec2(index, 2), 0).rgba;\n", texelFetch);
WRITE(p, " }\n");
WRITE(p, " }\n");
WRITE(p, " vec2 tess_pos = position.xy;\n");
Expand Down Expand Up @@ -539,7 +539,7 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
if (hasColorTess)
WRITE(p, " vec4 col = tess_sample(_col, weights);\n");
else
WRITE(p, " vec4 col = %s(u_tess_col_tex, ivec2(0, 0), 0).rgba;\n", texelFetch);
WRITE(p, " vec4 col = %s(u_tess_points, ivec2(0, 2), 0).rgba;\n", texelFetch);
}
if (hasNormal) {
// Curved surface is probably always need to compute normal(not sampling from control points)
Expand Down

0 comments on commit 1b076f8

Please sign in to comment.