Skip to content

Commit

Permalink
GPU: Clean up some shader id flag usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Sep 9, 2018
1 parent 204bfc7 commit 332788d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
25 changes: 11 additions & 14 deletions GPU/Directx9/VertexShaderGeneratorDX9.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ enum DoLightComputation {


void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage lang) { void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage lang) {
char *p = buffer; char *p = buffer;
const u32 vertType = gstate.vertType;


bool isModeThrough = id.Bit(VS_BIT_IS_THROUGH); bool isModeThrough = id.Bit(VS_BIT_IS_THROUGH);
bool lmode = id.Bit(VS_BIT_LMODE); bool lmode = id.Bit(VS_BIT_LMODE);
Expand All @@ -76,7 +75,6 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform; bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform;
bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform; bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform;
bool enableFog = id.Bit(VS_BIT_ENABLE_FOG); bool enableFog = id.Bit(VS_BIT_ENABLE_FOG);
bool throughmode = id.Bit(VS_BIT_IS_THROUGH);
bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE); bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE);
int ls0 = id.Bits(VS_BIT_LS0, 2); int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2); int ls1 = id.Bits(VS_BIT_LS1, 2);
Expand All @@ -97,7 +95,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (i == shadeLight0 || i == shadeLight1) if (i == shadeLight0 || i == shadeLight1)
doLight[i] = LIGHT_SHADE; doLight[i] = LIGHT_SHADE;
if (id.Bit(VS_BIT_LIGHTING_ENABLE) && id.Bit(VS_BIT_LIGHT0_ENABLE + i)) if (enableLighting && id.Bit(VS_BIT_LIGHT0_ENABLE + i))
doLight[i] = LIGHT_FULL; doLight[i] = LIGHT_FULL;
} }
} }
Expand Down Expand Up @@ -167,9 +165,9 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
} }
if (enableLighting) { if (enableLighting) {
WRITE(p, "float4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT); WRITE(p, "float4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT);
if ((gstate.materialupdate & 2) == 0 || !hasColor) if ((matUpdate & 2) == 0 || !hasColor)
WRITE(p, "float3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE); WRITE(p, "float3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE);
// if ((gstate.materialupdate & 4) == 0) // if ((matUpdate & 4) == 0)
WRITE(p, "float4 u_matspecular : register(c%i);\n", CONST_VS_MATSPECULAR); // Specular coef is contained in alpha WRITE(p, "float4 u_matspecular : register(c%i);\n", CONST_VS_MATSPECULAR); // Specular coef is contained in alpha
WRITE(p, "float3 u_matemissive : register(c%i);\n", CONST_VS_MATEMISSIVE); WRITE(p, "float3 u_matemissive : register(c%i);\n", CONST_VS_MATEMISSIVE);
} }
Expand All @@ -184,6 +182,8 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, "cbuffer bones : register(b2) {\n%s};\n", cb_vs_bonesStr); WRITE(p, "cbuffer bones : register(b2) {\n%s};\n", cb_vs_bonesStr);
} }


bool scaleUV = !isModeThrough && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);

// And the "varyings". // And the "varyings".
bool texCoordInVec3 = false; bool texCoordInVec3 = false;
if (useHWTransform) { if (useHWTransform) {
Expand All @@ -210,7 +210,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, "struct VS_IN {\n"); WRITE(p, "struct VS_IN {\n");
WRITE(p, " float4 position : POSITION;\n"); WRITE(p, " float4 position : POSITION;\n");
if (doTexture && hasTexcoord) { if (doTexture && hasTexcoord) {
if (doTextureTransform && !throughmode) { if (doTextureTransform && !isModeThrough) {
texCoordInVec3 = true; texCoordInVec3 = true;
WRITE(p, " float3 texcoord : TEXCOORD0;\n"); WRITE(p, " float3 texcoord : TEXCOORD0;\n");
} }
Expand Down Expand Up @@ -369,7 +369,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, " Out.v_fogdepth = In.position.w;\n"); WRITE(p, " Out.v_fogdepth = In.position.w;\n");
} }
if (lang == HLSL_D3D11 || lang == HLSL_D3D11_LEVEL9) { if (lang == HLSL_D3D11 || lang == HLSL_D3D11_LEVEL9) {
if (gstate.isModeThrough()) { if (isModeThrough) {
WRITE(p, " Out.gl_Position = mul(u_proj_through, float4(In.position.xyz, 1.0));\n"); WRITE(p, " Out.gl_Position = mul(u_proj_through, float4(In.position.xyz, 1.0));\n");
} else { } else {
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) { if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
Expand All @@ -379,7 +379,7 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
} }
} }
} else { } else {
if (gstate.isModeThrough()) { if (isModeThrough) {
WRITE(p, " Out.gl_Position = mul(float4(In.position.xyz, 1.0), u_proj_through);\n"); WRITE(p, " Out.gl_Position = mul(float4(In.position.xyz, 1.0), u_proj_through);\n");
} else { } else {
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) { if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
Expand Down Expand Up @@ -592,9 +592,9 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage


// TODO: Declare variables for dots for shade mapping if needed. // TODO: Declare variables for dots for shade mapping if needed.


const char *ambientStr = (gstate.materialupdate & 1) && hasColor ? "In.color0" : "u_matambientalpha"; const char *ambientStr = (matUpdate & 1) && hasColor ? "In.color0" : "u_matambientalpha";
const char *diffuseStr = (gstate.materialupdate & 2) && hasColor ? "In.color0.rgb" : "u_matdiffuse"; const char *diffuseStr = (matUpdate & 2) && hasColor ? "In.color0.rgb" : "u_matdiffuse";
const char *specularStr = (gstate.materialupdate & 4) && hasColor ? "In.color0.rgb" : "u_matspecular.rgb"; const char *specularStr = (matUpdate & 4) && hasColor ? "In.color0.rgb" : "u_matspecular.rgb";
if (doBezier || doSpline) { if (doBezier || doSpline) {
ambientStr = (matUpdate & 1) && hasColor ? "col" : "u_matambientalpha"; ambientStr = (matUpdate & 1) && hasColor ? "col" : "u_matambientalpha";
diffuseStr = (matUpdate & 2) && hasColor ? "col.rgb" : "u_matdiffuse"; diffuseStr = (matUpdate & 2) && hasColor ? "col.rgb" : "u_matdiffuse";
Expand Down Expand Up @@ -726,9 +726,6 @@ void GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
WRITE(p, " Out.v_color1 = float3(0, 0, 0);\n"); WRITE(p, " Out.v_color1 = float3(0, 0, 0);\n");
} }


bool scaleUV = !throughmode && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);


// Step 3: UV generation // Step 3: UV generation
if (doTexture) { if (doTexture) {
switch (uvGenMode) { switch (uvGenMode) {
Expand Down
7 changes: 3 additions & 4 deletions GPU/GLES/VertexShaderGeneratorGLES.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform; bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform;
bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform; bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform;
bool enableFog = id.Bit(VS_BIT_ENABLE_FOG); bool enableFog = id.Bit(VS_BIT_ENABLE_FOG);
bool throughmode = id.Bit(VS_BIT_IS_THROUGH);
bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE); bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE);
int ls0 = id.Bits(VS_BIT_LS0, 2); int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2); int ls1 = id.Bits(VS_BIT_LS1, 2);
Expand All @@ -203,7 +202,7 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (i == shadeLight0 || i == shadeLight1) if (i == shadeLight0 || i == shadeLight1)
doLight[i] = LIGHT_SHADE; doLight[i] = LIGHT_SHADE;
if (id.Bit(VS_BIT_LIGHTING_ENABLE) && id.Bit(VS_BIT_LIGHT0_ENABLE + i)) if (enableLighting && id.Bit(VS_BIT_LIGHT0_ENABLE + i))
doLight[i] = LIGHT_FULL; doLight[i] = LIGHT_FULL;
} }
} }
Expand Down Expand Up @@ -231,7 +230,7 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,


bool texcoordVec3In = false; bool texcoordVec3In = false;
if (doTexture && hasTexcoord) { if (doTexture && hasTexcoord) {
if (!useHWTransform && doTextureProjection && !throughmode) { if (!useHWTransform && doTextureProjection && !isModeThrough) {
WRITE(p, "%s vec3 texcoord;\n", attribute); WRITE(p, "%s vec3 texcoord;\n", attribute);
texcoordVec3In = true; texcoordVec3In = true;
} else { } else {
Expand All @@ -257,7 +256,7 @@ void GenerateVertexShader(const VShaderID &id, char *buffer, uint32_t *attrMask,
// Add all the uniforms we'll need to transform properly. // Add all the uniforms we'll need to transform properly.
} }


bool scaleUV = !throughmode && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN); bool scaleUV = !isModeThrough && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);


if (useHWTransform) { if (useHWTransform) {
// When transforming by hardware, we need a great deal more uniforms... // When transforming by hardware, we need a great deal more uniforms...
Expand Down
5 changes: 2 additions & 3 deletions GPU/Vulkan/VertexShaderGeneratorVulkan.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform; bool hasNormal = id.Bit(VS_BIT_HAS_NORMAL) && useHWTransform;
bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform; bool hasTexcoord = id.Bit(VS_BIT_HAS_TEXCOORD) || !useHWTransform;
bool enableFog = id.Bit(VS_BIT_ENABLE_FOG); bool enableFog = id.Bit(VS_BIT_ENABLE_FOG);
bool throughmode = id.Bit(VS_BIT_IS_THROUGH);
bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE); bool flipNormal = id.Bit(VS_BIT_NORM_REVERSE);
int ls0 = id.Bits(VS_BIT_LS0, 2); int ls0 = id.Bits(VS_BIT_LS0, 2);
int ls1 = id.Bits(VS_BIT_LS1, 2); int ls1 = id.Bits(VS_BIT_LS1, 2);
Expand Down Expand Up @@ -175,7 +174,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {


bool texcoordInVec3 = false; bool texcoordInVec3 = false;
if (doTexture && hasTexcoord) { if (doTexture && hasTexcoord) {
if (!useHWTransform && doTextureTransform && !throughmode) { if (!useHWTransform && doTextureTransform && !isModeThrough) {
WRITE(p, "layout (location = %d) in vec3 texcoord;\n", (int)PspAttributeLocation::TEXCOORD); WRITE(p, "layout (location = %d) in vec3 texcoord;\n", (int)PspAttributeLocation::TEXCOORD);
texcoordInVec3 = true; texcoordInVec3 = true;
} }
Expand Down Expand Up @@ -618,7 +617,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
} }
} }


bool scaleUV = !throughmode && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN); bool scaleUV = !isModeThrough && (uvGenMode == GE_TEXMAP_TEXTURE_COORDS || uvGenMode == GE_TEXMAP_UNKNOWN);


// Step 3: UV generation // Step 3: UV generation
if (doTexture) { if (doTexture) {
Expand Down

0 comments on commit 332788d

Please sign in to comment.