Bridge more vertex shader differences

This commit is contained in:
Henrik Rydgård committed 2020-10-25 08:34:35 +01:00
1 parent 22b26ffc09
commit 057fd9f8a3
8 files changed
+22 -16

No files matched your search

+1
View File
@@ -117,4 +117,5 @@ void GLSLShaderCompat::SetupForVulkan() {
texture = "texture";
texelFetch = "texelFetch";
vulkan = true;
forceMatrix4x4 = false;
}
+1
View File
@@ -156,6 +156,7 @@ struct GLSLShaderCompat {
const char *framebufferFetchExtension;
bool glslES30;
bool bitwiseOps;
bool forceMatrix4x4;
void SetupForVulkan();
};
+2 -2
View File
@@ -50,7 +50,7 @@ R"( mat4 u_proj;
mat4 u_proj_through;
mat3x4 u_view;
mat3x4 u_world;
mat3x4 u_tex;
mat3x4 u_texmtx;
vec4 u_uvscaleoffset;
vec4 u_depthRange;
vec2 u_fogcoef;
@@ -78,7 +78,7 @@ R"( float4x4 u_proj;
float4x4 u_proj_through;
float4x3 u_view;
float4x3 u_world;
float4x3 u_tex;
float4x3 u_texmtx;
float4 u_uvscaleoffset;
float4 u_depthRange;
float2 u_fogcoef;
+2 -2
View File
@@ -121,7 +121,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, "float4x3 u_world : register(c%i);\n", CONST_VS_WORLD);
WRITE(p, "float4x3 u_view : register(c%i);\n", CONST_VS_VIEW);
if (doTextureTransform)
WRITE(p, "float4x3 u_tex : register(c%i);\n", CONST_VS_TEXMTX);
WRITE(p, "float4x3 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX);
if (enableBones) {
#ifdef USE_BONE_ARRAY
WRITE(p, "float4x3 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0);
@@ -687,7 +687,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
break;
}
// Transform by texture matrix. XYZ as we are doing projection mapping.
WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_tex) * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_texmtx) * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
}
break;
+1
View File
@@ -595,6 +595,7 @@ void ShaderManagerGLES::DetectShaderLanguage() {
compat.bitwiseOps = false;
compat.lastFragData = nullptr;
compat.gles = gl_extensions.IsGLES;
compat.forceMatrix4x4 = true;
if (compat.gles) {
if (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300)) {
+7 -5
View File
@@ -197,7 +197,6 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
int numBoneWeights = 0;
int boneWeightScale = id.Bits(VS_BIT_WEIGHT_FMTSCALE, 2);
bool texcoordVec3In = false;
bool scaleUV = false;
if (compat.vulkan) {
if (enableBones) {
@@ -292,8 +291,6 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
// Add all the uniforms we'll need to transform properly.
}
scaleUV = !isModeThrough && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);
if (useHWTransform) {
// When transforming by hardware, we need a great deal more uniforms...
// TODO: Use 4x3 matrices where possible. Though probably doesn't matter much.
@@ -625,7 +622,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
WRITE(p, " mediump vec3 worldnormal = normalize((u_world * vec4(skinnednormal, 0.0)).xyz);\n");
}
WRITE(p, " vec4 viewPos = vec4(worldpos, 1.0) * u_view;\n");
WRITE(p, " vec4 viewPos = vec4((vec4(worldpos, 1.0) * u_view).xyz, 1.0);\n");
// Final view and projection transforms.
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
@@ -787,6 +784,8 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
WRITE(p, " v_color1 = vec3(0.0);\n");
}
bool scaleUV = !isModeThrough && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);
// Step 3: UV generation
if (doTexture) {
switch (uvGenMode) {
@@ -795,7 +794,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
if (scaleUV) {
if (hasTexcoord) {
if (doBezier || doSpline)
WRITE(p, " v_texcoord = vec3(tess.tex * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
WRITE(p, " v_texcoord = vec3(tess.tex.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
else
WRITE(p, " v_texcoord = vec3(texcoord.xy * u_uvscaleoffset.xy, 0.0);\n");
} else {
@@ -876,6 +875,9 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
WRITE(p, " }\n");
}
WRITE(p, " gl_Position = outPos;\n");
if (compat.vulkan) {
WRITE(p, " gl_PointSize = 1.0;\n");
}
WRITE(p, "}\n");
return true;
+4 -4
View File
@@ -346,9 +346,9 @@ bool GenerateVertexShaderVulkanGLSL(const VShaderID &id, char *buffer, std::stri
}
} else {
// No skinning, just standard T&L.
WRITE(p, " vec3 worldpos = vec4(position.xyz, 1.0) * u_world;\n");
WRITE(p, " vec3 worldpos = (vec4(position.xyz, 1.0) * u_world).xyz;\n");
if (hasNormal)
WRITE(p, " mediump vec3 worldnormal = normalize(vec4(%snormal, 0.0) * u_world);\n", flipNormal ? "-" : "");
WRITE(p, " mediump vec3 worldnormal = normalize((vec4(%snormal, 0.0) * u_world).xyz);\n", flipNormal ? "-" : "");
else
WRITE(p, " mediump vec3 worldnormal = vec3(0.0, 0.0, 1.0);\n");
}
@@ -382,7 +382,7 @@ bool GenerateVertexShaderVulkanGLSL(const VShaderID &id, char *buffer, std::stri
WRITE(p, " mediump vec3 worldnormal = normalize(vec4(skinnednormal, 0.0) * u_world);\n");
}
WRITE(p, " vec4 viewPos = vec4(vec4(worldpos, 1.0) * u_view, 1.0);\n");
WRITE(p, " vec4 viewPos = vec4((vec4(worldpos, 1.0) * u_view).xyz, 1.0);\n");
// Final view and projection transforms.
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
@@ -595,7 +595,7 @@ bool GenerateVertexShaderVulkanGLSL(const VShaderID &id, char *buffer, std::stri
break;
}
// Transform by texture matrix. XYZ as we are doing projection mapping.
WRITE(p, " v_texcoord = (%s * u_tex).xyz * vec3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
WRITE(p, " v_texcoord = (%s * u_texmtx).xyz * vec3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
}
break;
+4 -3
View File
@@ -95,7 +95,8 @@ bool TestCompileShader(const char *buffer, ShaderLanguage lang, bool vertex) {
return false;
case ShaderLanguage::GLSL_300:
return false;
case ShaderLanguage::TEST_GLSL_VULKAN:
return true;
default:
return false;
}
@@ -117,7 +118,7 @@ void PrintDiff(const char *a, const char *b) {
printf("a: %s\n", a_lines[i].c_str());
printf("b: %s\n", b_lines[i].c_str());
printf("...continues...\n");
for (size_t j = i; j < i + 4 && j < a_lines.size(); j++) {
for (size_t j = i + 1; j < i + 5 && j < a_lines.size(); j++) {
printf("a: %s\n", a_lines[j].c_str());
printf("b: %s\n", b_lines[j].c_str());
}
@@ -182,7 +183,7 @@ bool TestShaderGenerators() {
return 1;
}
if (generateSuccess[0] && strcmp(buffer[0], buffer[1])) {
printf("mismatching shaders!\n");
printf("mismatching shaders! a=glsl b=vulkan\n");
PrintDiff(buffer[0], buffer[1]);
return 1;
}