mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-24 05:49:58 +00:00
Vulkan/D3D11: Make some space in the base uniform buffer by consolidating the spline parameters into one variable.
This commit is contained in:
parent
f4d8bfdf18
commit
163350bbcd
@ -198,10 +198,7 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
|
||||
}
|
||||
|
||||
if (dirtyUniforms & DIRTY_BEZIERSPLINE) {
|
||||
ub->spline_count_u = gstate_c.spline_count_u;
|
||||
ub->spline_count_v = gstate_c.spline_count_v;
|
||||
ub->spline_type_u = gstate_c.spline_type_u;
|
||||
ub->spline_type_v = gstate_c.spline_type_v;
|
||||
ub->spline_counts = BytesToUint32(gstate_c.spline_count_u, gstate_c.spline_count_v, gstate_c.spline_type_u, gstate_c.spline_type_v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ struct UB_VS_FS_Base {
|
||||
float depthRange[4];
|
||||
float fogCoef[2]; float stencil; float pad0;
|
||||
float matAmbient[4];
|
||||
int spline_count_u; int spline_count_v; int spline_type_u; int spline_type_v;
|
||||
uint32_t spline_counts; int pad1; int pad2; int pad3;
|
||||
// Fragment data
|
||||
float fogColor[4];
|
||||
float texEnvColor[4];
|
||||
@ -53,10 +53,10 @@ R"( mat4 proj_mtx;
|
||||
vec2 fogcoef;
|
||||
float stencilReplace;
|
||||
vec4 matambientalpha;
|
||||
int spline_count_u;
|
||||
int spline_count_v;
|
||||
int spline_type_u;
|
||||
int spline_type_v;
|
||||
uint spline_counts;
|
||||
int pad1;
|
||||
int pad2;
|
||||
int pad3;
|
||||
vec3 fogcolor;
|
||||
vec3 texenv;
|
||||
ivec4 alphacolorref;
|
||||
@ -79,10 +79,10 @@ R"( float4x4 u_proj;
|
||||
float2 u_fogcoef;
|
||||
float u_stencilReplaceValue;
|
||||
float4 u_matambientalpha;
|
||||
int u_spline_count_u;
|
||||
int u_spline_count_v;
|
||||
int u_spline_type_u;
|
||||
int u_spline_type_v;
|
||||
uint u_spline_counts;
|
||||
int pad1;
|
||||
int pad2;
|
||||
int pad3;
|
||||
float3 u_fogcolor;
|
||||
float3 u_texenv;
|
||||
uint4 u_alphacolorref;
|
||||
|
@ -390,6 +390,8 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
||||
if (!enableBones) {
|
||||
// Hardware tessellation
|
||||
if (doSpline || doBezier) {
|
||||
WRITE(p, " uint u_spline_count_u = u_spline_counts & 0xFF;\n");
|
||||
WRITE(p, " uint u_spline_count_v = (u_spline_counts >> 8) & 0xFF;\n");
|
||||
WRITE(p, " uint num_patches_u = %s;\n", doBezier ? "(u_spline_count_u - 1) / 3u" : "u_spline_count_u - 3");
|
||||
WRITE(p, " float2 tess_pos = In.position.xy;\n");
|
||||
WRITE(p, " int u = In.instanceId %% num_patches_u;\n");
|
||||
@ -420,6 +422,8 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
||||
WRITE(p, " weights[3] = tess_pos * tess_pos * tess_pos;\n");
|
||||
} else if (doSpline) {
|
||||
WRITE(p, " int2 spline_num_patches = int2(u_spline_count_u - 3, u_spline_count_v - 3);\n");
|
||||
WRITE(p, " int u_spline_type_u = (u_spline_counts >> 16) & 0xFF;\n");
|
||||
WRITE(p, " int u_spline_type_v = (u_spline_counts >> 24) & 0xFF;\n");
|
||||
WRITE(p, " int2 spline_type = int2(u_spline_type_u, u_spline_type_v);\n");
|
||||
WRITE(p, " float2 knots[6];\n");
|
||||
WRITE(p, " spline_knot(spline_num_patches, spline_type, knots, patch_pos);\n");
|
||||
|
@ -20,6 +20,7 @@
|
||||
#endif
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stringutil.h"
|
||||
#include "math/lin/matrix4x4.h"
|
||||
#include "math/math_util.h"
|
||||
#include "math/dataconv.h"
|
||||
@ -48,7 +49,7 @@ VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id,
|
||||
std::string errorMessage;
|
||||
std::vector<uint32_t> spirv;
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA(code);
|
||||
OutputDebugStringA(LineNumberString(code).c_str());
|
||||
#endif
|
||||
|
||||
bool success = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, code, spirv, &errorMessage);
|
||||
@ -63,7 +64,6 @@ VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id,
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA("Messages:\n");
|
||||
OutputDebugStringA(errorMessage.c_str());
|
||||
OutputDebugStringA(code);
|
||||
#endif
|
||||
Reporting::ReportMessage("Vulkan error in shader compilation: info: %s / code: %s", errorMessage.c_str(), code);
|
||||
} else {
|
||||
@ -105,7 +105,7 @@ VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, cons
|
||||
std::string errorMessage;
|
||||
std::vector<uint32_t> spirv;
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA(code);
|
||||
OutputDebugStringA(LineNumberString(code).c_str());
|
||||
#endif
|
||||
bool success = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, code, spirv, &errorMessage);
|
||||
if (!errorMessage.empty()) {
|
||||
|
@ -216,14 +216,14 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
|
||||
WRITE(p, "out gl_PerVertex { vec4 gl_Position; };\n");
|
||||
|
||||
if (doBezier || doSpline) {
|
||||
WRITE(p, "layout (std430) struct TessData {\n");
|
||||
WRITE(p, "struct TessData {\n");
|
||||
WRITE(p, " vec4 pos;\n");
|
||||
WRITE(p, " vec4 uv;\n");
|
||||
WRITE(p, " vec4 color;\n");
|
||||
WRITE(p, "};");
|
||||
WRITE(p, "layout (std430, set = 0, binding = 5) buffer s_tess_data {\n");
|
||||
WRITE(p, " TessData data[];");
|
||||
WRITE(p, "} tess_data;");
|
||||
WRITE(p, "} tess_data;\n");
|
||||
|
||||
for (int i = 2; i <= 4; i++) {
|
||||
// Define 3 types vec2, vec3, vec4
|
||||
@ -334,13 +334,15 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
|
||||
WRITE(p, " vec3 _pos[16];\n");
|
||||
WRITE(p, " vec2 _tex[16];\n");
|
||||
WRITE(p, " vec4 _col[16];\n");
|
||||
WRITE(p, " int num_patches_u = %s;\n", doBezier ? "(base.spline_count_u - 1) / 3" : "base.spline_count_u - 3");
|
||||
WRITE(p, " int spline_count_u = int(base.spline_counts & 0xff);\n");
|
||||
WRITE(p, " int spline_count_v = int((base.spline_counts >> 8) & 0xff);\n");
|
||||
WRITE(p, " int num_patches_u = %s;\n", doBezier ? "(spline_count_u - 1) / 3" : "spline_count_u - 3");
|
||||
WRITE(p, " int u = int(mod(gl_InstanceIndex, num_patches_u));\n");
|
||||
WRITE(p, " int v = gl_InstanceIndex / num_patches_u;\n");
|
||||
WRITE(p, " ivec2 patch_pos = ivec2(u, v);\n");
|
||||
WRITE(p, " for (int i = 0; i < 4; i++) {\n");
|
||||
WRITE(p, " for (int j = 0; j < 4; j++) {\n");
|
||||
WRITE(p, " int idx = (i + v%s) * base.spline_count_u + (j + u%s);\n", doBezier ? " * 3" : "", doBezier ? " * 3" : "");
|
||||
WRITE(p, " int idx = (i + v%s) * spline_count_u + (j + u%s);\n", doBezier ? " * 3" : "", doBezier ? " * 3" : "");
|
||||
WRITE(p, " _pos[i * 4 + j] = tess_data.data[idx].pos.xyz;\n");
|
||||
if (doTexture && hasTexcoord && hasTexcoordTess)
|
||||
WRITE(p, " _tex[i * 4 + j] = tess_data.data[idx].uv.xy;\n");
|
||||
@ -357,8 +359,10 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
|
||||
WRITE(p, " weights[2] = 3 * tess_pos * tess_pos * (1 - tess_pos);\n");
|
||||
WRITE(p, " weights[3] = tess_pos * tess_pos * tess_pos;\n");
|
||||
} else { // Spline
|
||||
WRITE(p, " ivec2 spline_num_patches = ivec2(base.spline_count_u - 3, base.spline_count_v - 3);\n");
|
||||
WRITE(p, " ivec2 spline_type = ivec2(base.spline_type_u, base.spline_type_v);\n");
|
||||
WRITE(p, " ivec2 spline_num_patches = ivec2(spline_count_u - 3, spline_count_v - 3);\n");
|
||||
WRITE(p, " int spline_type_u = int((base.spline_counts >> 16) & 0xff);\n");
|
||||
WRITE(p, " int spline_type_v = int((base.spline_counts >> 24) & 0xff);\n");
|
||||
WRITE(p, " ivec2 spline_type = ivec2(spline_type_u, spline_type_v);\n");
|
||||
WRITE(p, " vec2 knots[6];\n");
|
||||
WRITE(p, " spline_knot(spline_num_patches, spline_type, knots, patch_pos);\n");
|
||||
WRITE(p, " spline_weight(tess_pos + patch_pos, knots, weights);\n");
|
||||
|
@ -157,3 +157,7 @@ inline void ExpandFloat24x3ToFloat4(float dest[4], const uint32_t src[3]) {
|
||||
memcpy(dest, temp, sizeof(float) * 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint32_t BytesToUint32(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
|
||||
return (a) | (b << 8) | (c << 16) | (d << 24);
|
||||
}
|
Loading…
Reference in New Issue
Block a user