Skip to content

Commit

Permalink
Vulkan: Attempt at fixing dual source blending. Should work but doesn't.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 6, 2016
1 parent d32bffb commit 3b57f1a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
13 changes: 8 additions & 5 deletions GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"

static const char *vulkan_glsl_preamble =
"#version 400\n"
"#extension GL_ARB_separate_shader_objects : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n\n";

#define WRITE p+=sprintf

// Missing: Z depth range
Expand All @@ -49,9 +54,7 @@ bool GenerateVulkanGLSLFragmentShader(const ShaderID &id, char *buffer) {

const char *lastFragData = nullptr;

WRITE(p, "#version 140\n"); // GLSL ES
WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
WRITE(p, "%s", vulkan_glsl_preamble);

bool lmode = id.Bit(FS_BIT_LMODE);
bool doTexture = id.Bit(FS_BIT_DO_TEXTURE);
Expand Down Expand Up @@ -116,9 +119,9 @@ bool GenerateVulkanGLSLFragmentShader(const ShaderID &id, char *buffer) {
WRITE(p, "ivec3 roundAndScaleTo255iv(in vec3 x) { return ivec3(floor(x * 255.0 + 0.5)); }\n");
}

WRITE(p, "layout (location = 0) out vec4 fragColor0;\n");
WRITE(p, "layout (location = 0, index = 0) out vec4 fragColor0;\n");
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
WRITE(p, "layout (location = 1) out vec4 fragColor1;\n");
WRITE(p, "layout (location = 0, index = 1) out vec4 fragColor1;\n");
}

// PowerVR needs a custom modulo function. For some reason, this has far higher precision than the builtin one.
Expand Down
15 changes: 8 additions & 7 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ int SetupVertexAttribs(VkVertexInputAttributeDescription attrs[], const DecVtxFo
return count;
}

int SetupVertexAttribsPretransformed(VkVertexInputAttributeDescription attrs[]) {
VertexAttribSetup(&attrs[0], DEC_FLOAT_4, 0, PspAttributeLocation::POSITION);
VertexAttribSetup(&attrs[1], DEC_FLOAT_3, 16, PspAttributeLocation::TEXCOORD);
VertexAttribSetup(&attrs[2], DEC_U8_4, 28, PspAttributeLocation::COLOR0);
VertexAttribSetup(&attrs[3], DEC_U8_4, 32, PspAttributeLocation::COLOR1);
return 4;
int SetupVertexAttribsPretransformed(VkVertexInputAttributeDescription attrs[], const DecVtxFormat &decFmt) {
int count = 0;
VertexAttribSetup(&attrs[count++], DEC_FLOAT_4, 0, PspAttributeLocation::POSITION);
VertexAttribSetup(&attrs[count++], DEC_FLOAT_3, 16, PspAttributeLocation::TEXCOORD);
VertexAttribSetup(&attrs[count++], DEC_U8_4, 28, PspAttributeLocation::COLOR0);
VertexAttribSetup(&attrs[count++], DEC_U8_4, 32, PspAttributeLocation::COLOR1);
return count;
}

static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pipelineCache, VkPipelineLayout layout, VkRenderPass renderPass, const VulkanPipelineRasterStateKey &key, const VertexDecoder *vtxDec, VulkanVertexShader *vs, VulkanFragmentShader *fs, bool useHwTransform) {
Expand Down Expand Up @@ -212,7 +213,7 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip
attributeCount = SetupVertexAttribs(attrs, vtxDec->decFmt);
vertexStride = vtxDec->decFmt.stride;
} else {
attributeCount = SetupVertexAttribsPretransformed(attrs);
attributeCount = SetupVertexAttribsPretransformed(attrs, vtxDec->decFmt);
vertexStride = 36;
}

Expand Down
2 changes: 2 additions & 0 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,8 @@ void TextureCacheVulkan::SetTexture() {
gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN;
}
gstate_c.curTextureWidth = w;
gstate_c.curTextureHeight = h;
nextTexture_ = entry;
VERBOSE_LOG(G3D, "Texture at %08x Found in Cache, applying", texaddr);
return; //Done!
Expand Down
17 changes: 10 additions & 7 deletions GPU/Vulkan/VertexShaderGeneratorVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#include "GPU/Vulkan/PipelineManagerVulkan.h"
#include "GPU/Vulkan/ShaderManagerVulkan.h"

static const char *vulkan_glsl_preamble =
"#version 400\n"
"#extension GL_ARB_separate_shader_objects : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n\n";

// "Varying" layout - must match fragment shader
// color0 = 0
// color1 = 1
Expand Down Expand Up @@ -102,9 +107,7 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {

// #define USE_FOR_LOOP

WRITE(p, "#version 140\n"); // GLSL ES
WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
WRITE(p, "%s", vulkan_glsl_preamble);

bool highpFog = false;
bool highpTexcoord = false;
Expand Down Expand Up @@ -184,7 +187,7 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
if (hasColor) {
WRITE(p, "layout (location = %d) in vec4 color0;\n", PspAttributeLocation::COLOR0);
if (lmode && !useHWTransform) // only software transform supplies color1 as vertex data
WRITE(p, "layout (location = %d) in vec3 color1;\n", PspAttributeLocation::COLOR0);
WRITE(p, "layout (location = %d) in vec3 color1;\n", PspAttributeLocation::COLOR1);
}

bool prescale = false;
Expand Down Expand Up @@ -302,9 +305,9 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {

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

const char *ambientStr = (matUpdate & 1) && hasColor ? "color0" : "base.matambientalpha";
const char *diffuseStr = (matUpdate & 2) && hasColor ? "color0.rgb" : "light.matdiffuse";
const char *specularStr = (matUpdate & 4) && hasColor ? "color0.rgb" : "light.matspecular.rgb";
const char *ambientStr = ((matUpdate & 1) && hasColor) ? "color0" : "base.matambientalpha";
const char *diffuseStr = ((matUpdate & 2) && hasColor) ? "color0.rgb" : "light.matdiffuse";
const char *specularStr = ((matUpdate & 4) && hasColor) ? "color0.rgb" : "light.matspecular.rgb";

bool diffuseIsZero = true;
bool specularIsZero = true;
Expand Down
5 changes: 2 additions & 3 deletions Windows/GPU/WindowsVulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ static VkBool32 VKAPI_CALL Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, VkDebugRep
} else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
message << "DEBUG: ";
}
message << "[" << pLayerPrefix << "] " << ObjTypeToString(objType) << " Code " << msgCode << " : " << pMsg;
message << "[" << pLayerPrefix << "] " << ObjTypeToString(objType) << " Code " << msgCode << " : " << pMsg << "\n";

#ifdef _WIN32
OutputDebugStringA(message.str().c_str());
OutputDebugStringA("\n");
if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
if (options->breakOnError) {
DebugBreak();
Expand All @@ -132,7 +131,7 @@ static VkBool32 VKAPI_CALL Vulkan_Dbg(VkDebugReportFlagsEXT msgFlags, VkDebugRep
}
}
#else
std::cout << message << std::endl;
std::cout << message;
#endif

// false indicates that layer should not bail-out of an
Expand Down

0 comments on commit 3b57f1a

Please sign in to comment.