More progress

This commit is contained in:
Henrik Rydgard committed 2016-03-20 19:26:41 +01:00
1 parent 4ddca8607f
commit cfbecf5071
18 files changed
+320 -426

No files matched your search

-2
View File
@@ -249,7 +249,6 @@
<ClInclude Include="Vulkan\FramebufferVulkan.h" />
<ClInclude Include="Vulkan\GPU_Vulkan.h" />
<ClInclude Include="Vulkan\PipelineManagerVulkan.h" />
<ClInclude Include="Vulkan\ShaderCompiler.h" />
<ClInclude Include="Vulkan\ShaderManagerVulkan.h" />
<ClInclude Include="Vulkan\TextureCacheVulkan.h" />
<ClInclude Include="Vulkan\VertexShaderGeneratorVulkan.h" />
@@ -337,7 +336,6 @@
<ClCompile Include="Vulkan\FramebufferVulkan.cpp" />
<ClCompile Include="Vulkan\GPU_Vulkan.cpp" />
<ClCompile Include="Vulkan\PipelineManagerVulkan.cpp" />
<ClCompile Include="Vulkan\ShaderCompiler.cpp" />
<ClCompile Include="Vulkan\ShaderManagerVulkan.cpp" />
<ClCompile Include="Vulkan\StateMappingVulkan.cpp" />
<ClCompile Include="Vulkan\VertexShaderGeneratorVulkan.cpp" />
-2
View File
@@ -210,7 +210,6 @@
<ClInclude Include="Vulkan\VertexShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\FragmentShaderGeneratorVulkan.h" />
<ClInclude Include="Vulkan\ShaderManagerVulkan.h" />
<ClInclude Include="Vulkan\ShaderCompiler.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Math3D.cpp">
@@ -404,6 +403,5 @@
<ClCompile Include="Vulkan\FramebufferVulkan.cpp" />
<ClCompile Include="Vulkan\FragmentShaderGeneratorVulkan.cpp" />
<ClCompile Include="Vulkan\ShaderManagerVulkan.cpp" />
<ClCompile Include="Vulkan\ShaderCompiler.cpp" />
</ItemGroup>
</Project>
-23
View File
@@ -1,23 +0,0 @@
// Copyright (c) 2015- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "GPU/Vulkan/VulkanUtil.h"
#include "GPU/Vulkan/ShaderCompiler.h"
bool CompileGLSLVulkan(const char *code, std::vector<uint32_t> &spirv, std::string &errorMessage) {
return false;
}
-27
View File
@@ -1,27 +0,0 @@
// Copyright (c) 2015- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <vector>
#include "GPU/Vulkan/VulkanUtil.h"
// Wrapper around the GLSL compiler library. Compiles GLSL into SPIR-V consumable by Vulkan.
bool CompileGLSLVulkan(const char *code, std::vector<uint32_t> &spirv, std::string &errorMessage);
// TODO: Compute shaders
+9 -32
View File
@@ -37,7 +37,6 @@
#include "GPU/Vulkan/ShaderManagerVulkan.h"
#include "GPU/Vulkan/DrawEngineVulkan.h"
#include "GPU/Vulkan/FramebufferVulkan.h"
#include "GPU/Vulkan/ShaderCompiler.h"
#include "GPU/Vulkan/FragmentShaderGeneratorVulkan.h"
#include "GPU/Vulkan/VertexShaderGeneratorVulkan.h"
#include "UI/OnScreenDisplay.h"
@@ -51,7 +50,8 @@ VulkanFragmentShader::VulkanFragmentShader(VkDevice device, ShaderID id, const c
std::string errorMessage;
std::vector<uint32_t> spirv;
bool success = CompileGLSLVulkan(code, spirv, errorMessage);
bool success = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, code, spirv, &errorMessage);
if (!errorMessage.empty()) {
if (success) {
ERROR_LOG(G3D, "Warnings in shader compilation!");
@@ -100,7 +100,7 @@ VulkanVertexShader::VulkanVertexShader(VkDevice device, ShaderID id, const char
#endif
std::string errorMessage;
std::vector<uint32_t> spirv;
bool success = CompileGLSLVulkan(code, spirv, errorMessage);
bool success = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, code, spirv, &errorMessage);
if (!errorMessage.empty()) {
if (success) {
ERROR_LOG(G3D, "Warnings in shader compilation!");
@@ -142,33 +142,12 @@ std::string VulkanVertexShader::GetShaderString(DebugShaderStringType type) cons
}
}
/*
// Utility
void ShaderManagerVulkan::VSSetMatrix4x3(int creg, const float *m4x3) {
float m4x4[16];
ConvertMatrix4x3To4x4Transposed(m4x4, m4x3);
pD3Ddevice->SetVertexShaderConstantF(creg, m4x4, 4);
}
void ShaderManagerVulkan::VSSetMatrix4x3_3(int creg, const float *m4x3) {
float m3x4[16];
ConvertMatrix4x3To3x4Transposed(m3x4, m4x3);
pD3Ddevice->SetVertexShaderConstantF(creg, m3x4, 3);
}
void ShaderManagerVulkan::VSSetMatrix(int creg, const float* pMatrix) {
float transp[16];
Transpose4x4(transp, pMatrix);
pD3Ddevice->SetVertexShaderConstantF(creg, transp, 4);
}
*/
// Depth in ogl is between -1;1 we need between 0;1 and optionally reverse it
static void ConvertProjMatrixToVulkan(Matrix4x4 &in, bool invertedX, bool invertedY, bool invertedZ) {
// Half pixel offset hack
float xoff = 0.5f / gstate_c.curRTRenderWidth;
xoff = gstate_c.vpXOffset + (invertedX ? xoff : -xoff);
float yoff = -0.5f / gstate_c.curRTRenderHeight;
float yoff = 0.5f / gstate_c.curRTRenderHeight;
yoff = gstate_c.vpYOffset + (invertedY ? yoff : -yoff);
if (invertedX)
@@ -180,9 +159,7 @@ static void ConvertProjMatrixToVulkan(Matrix4x4 &in, bool invertedX, bool invert
}
static void ConvertProjMatrixToVulkanThrough(Matrix4x4 &in) {
float xoff = -0.5f / gstate_c.curRTRenderWidth;
float yoff = 0.5f / gstate_c.curRTRenderHeight;
in.translateAndScale(Vec3(xoff, yoff, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
in.translateAndScale(Vec3(0.0f, 0.0f, 0.5f), Vec3(1.0f, 1.0f, 0.5f));
}
void ShaderManagerVulkan::PSUpdateUniforms(int dirtyUniforms) {
@@ -402,20 +379,20 @@ void ShaderManagerVulkan::VSUpdateUniforms(int dirtyUniforms) {
// Lighting
if (dirtyUniforms & DIRTY_AMBIENT) {
Uint8x3ToFloat4_AlphaUint8(ub_lightGlobal.ambientColor, gstate.ambientcolor, gstate.getAmbientA());
Uint8x3ToFloat4_AlphaUint8(ub_lights.ambientColor, gstate.ambientcolor, gstate.getAmbientA());
}
if (dirtyUniforms & DIRTY_MATAMBIENTALPHA) {
// Note - this one is not in lighting but in transformCommon as it has uses beyond lighting
Uint8x3ToFloat4_AlphaUint8(ub_transformCommon.matAmbient, gstate.materialambient, gstate.getMaterialAmbientA());
}
if (dirtyUniforms & DIRTY_MATDIFFUSE) {
Uint8x3ToFloat4(ub_lightGlobal.materialDiffuse, gstate.materialdiffuse);
Uint8x3ToFloat4(ub_lights.materialDiffuse, gstate.materialdiffuse);
}
if (dirtyUniforms & DIRTY_MATEMISSIVE) {
Uint8x3ToFloat4(ub_lightGlobal.materialEmissive, gstate.materialemissive);
Uint8x3ToFloat4(ub_lights.materialEmissive, gstate.materialemissive);
}
if (dirtyUniforms & DIRTY_MATSPECULAR) {
Uint8x3ToFloat4_Alpha(ub_lightGlobal.materialEmissive, gstate.materialspecular, getFloat24(gstate.materialspecularcoef));
Uint8x3ToFloat4_Alpha(ub_lights.materialEmissive, gstate.materialspecular, getFloat24(gstate.materialspecularcoef));
}
for (int i = 0; i < 4; i++) {
+10 -17
View File
@@ -96,6 +96,10 @@ R"(matrix4x4 proj;
)";
struct UB_VS_Lights {
float ambientColor[4];
float materialDiffuse[4];
float materialSpecular[4];
float materialEmissive[4];
float lpos[4][4];
float ldir[4][4];
float latt[4][4];
@@ -107,7 +111,11 @@ struct UB_VS_Lights {
};
static const char *ub_vs_lightsStr =
R"(vec3 lpos[4];
R"(vec3 ambientColor;
vec3 materialDiffuse;
vec4 materialSpecular;
vec3 materialEmissive;
vec3 lpos[4];
vec3 ldir[4];
vec3 latt[4];
float lightAngle[4];
@@ -117,26 +125,12 @@ R"(vec3 lpos[4];
vec3 lightSpecular[4];
)";
struct UB_VS_LightGlobal {
float ambientColor[4];
float materialDiffuse[4];
float materialSpecular[4];
float materialEmissive[4];
};
static const char *ub_vs_lightsGlobalStr =
R"(vec3 ambientColor;
vec3 materialDiffuse;
vec4 materialSpecular;
vec3 materialEmissive;
)";
struct UB_VS_Bones {
float bones[8][16];
};
static const char *ub_vs_bonesStr =
R"(matrix4x4 bone[8];
R"(matrix4x4 m[8];
)";
// Let's not bother splitting this, we'll just upload the lot for every draw call.
@@ -242,7 +236,6 @@ private:
// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.
UB_VS_TransformCommon ub_transformCommon;
UB_VS_LightGlobal ub_lightGlobal;
UB_VS_Lights ub_lights;
UB_VS_Bones ub_bones;
UB_FS_All ub_fragment;
+12 -10
View File
@@ -176,22 +176,24 @@ void ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManager, int prim, Vulk
bool alphaMask = gstate.isClearModeAlphaMask();
key.colorWriteMask = (colorMask ? (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_A_BIT) : 0) | (alphaMask ? VK_COLOR_COMPONENT_A_BIT : 0);
GenericStencilFuncState stencilState;
ConvertStencilFuncState(stencilState);
// Stencil Test
if (alphaMask) {
if (stencilState.enabled) {
key.stencilTestEnable = true;
key.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
key.stencilPassOp = VK_STENCIL_OP_REPLACE;
key.stencilFailOp = VK_STENCIL_OP_REPLACE;
key.stencilDepthFailOp = VK_STENCIL_OP_REPLACE;
// TODO: Are these right?
key.stencilCompareOp = compareOps[stencilState.testFunc];
key.stencilPassOp = stencilOps[stencilState.zPass];
key.stencilFailOp = stencilOps[stencilState.sFail];
key.stencilDepthFailOp = stencilOps[stencilState.zFail];
dynState.useStencil = true;
dynState.stencilRef = 0xFF;
dynState.stencilCompareMask = 0xFF;
dynState.stencilWriteMask = 0xFF;
dynState.stencilRef = stencilState.testRef;
dynState.stencilCompareMask = stencilState.testMask;
dynState.stencilWriteMask = stencilState.writeMask;
} else {
key.stencilTestEnable = false;
dynState.useStencil = false;
}
} else {
// Set cull
bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
+11 -47
View File
@@ -32,6 +32,7 @@
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Vulkan/VertexShaderGeneratorVulkan.h"
#include "GPU/Vulkan/PipelineManagerVulkan.h"
#include "GPU/Vulkan/ShaderManagerVulkan.h"
// "Varying" layout - must match fragment shader
// color0 = 0
@@ -70,42 +71,6 @@ enum DoLightComputation {
LIGHT_FULL,
};
const char *vulkan_base_uniforms = R"(
layout(set=0, binding=4) uniform base {
mat4 proj;
mat4 world;
mat4 view;
mat4 texmtx;
vec4 uvscaleoffset;
vec2 fogcoef;
vec4 depthRange;
vec4 matambientalpha;
};
)";
const char *vulkan_light_uniforms = R"(
layout(set=0, binding=5) uniform light {
vec4 ambient;
vec3 matdiffuse;
vec4 matspecular;
vec3 matemissive;
vec3 pos[4];
// TODO: Make lighttype/comp uniforms too
vec3 att[4];
vec3 dir[4];
float angle[4];
float spotCoef[4];
vec3 ambient[4];
vec3 diffuse[4];
vec3 specular[4];
)";
const char *vulkan_bone_uniforms = R"(
layout(set=0, binding=6) uniform bone {
mat4 m[8];
)";
// Depth range and viewport
//
// After the multiplication with the projection matrix, we have a 4D vector in clip space.
@@ -213,12 +178,11 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
// We will memcpy the parts into place in a big buffer so we can be quite dynamic about what parts
// are present and what parts aren't, but we will not be ultra detailed about it.
WRITE(p, "%s", vulkan_base_uniforms);
WRITE(p, "layout (binding=3) uniform base {\n%s\n}\n", ub_vs_transformCommonStr);
if (enableLighting)
WRITE(p, "%s", vulkan_light_uniforms);
WRITE(p, "layout (binding=4) uniform light {\n%s\n}\n", ub_vs_lightsStr);
if (enableBones)
WRITE(p, "%s", vulkan_bone_uniforms);
WRITE(p, "layout (binding=5) uniform bone {\n%s\n}\n", ub_vs_bonesStr);
bool prescale = false;
@@ -409,10 +373,10 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
if (poweredDiffuse) {
// pow(0.0, 0.0) may be undefined, but the PSP seems to treat it as 1.0.
// Seen in Tales of the World: Radiant Mythology (#2424.)
WRITE(p, " if (dot%i == 0.0 && u_matspecular.a == 0.0) {\n", i);
WRITE(p, " if (dot%i == 0.0 && light.matspecular.a == 0.0) {\n", i);
WRITE(p, " dot%i = 1.0;\n", i);
WRITE(p, " } else {\n");
WRITE(p, " dot%i = pow(dot[%i], u_matspecular.a);\n", i, i);
WRITE(p, " dot%i = pow(dot[%i], light.matspecular.a);\n", i, i);
WRITE(p, " }\n");
}
@@ -444,7 +408,7 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
if (doSpecular) {
WRITE(p, " dot[%i] = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n", i);
WRITE(p, " if (dot[%i] > 0.0)\n", i);
WRITE(p, " lightSum1 += light.specular[%i] * %s * (pow(dot[%i], u_matspecular.a) %s);\n", i, specularStr, i, timesLightScale);
WRITE(p, " lightSum1 += light.specular[%i] * %s * (pow(dot[%i], light.matspecular.a) %s);\n", i, specularStr, i, timesLightScale);
}
WRITE(p, " lightSum0.rgb += (light.ambient[%i] * %s.rgb + diffuse)%s;\n", i, ambientStr, timesLightScale);
}
@@ -471,7 +435,7 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
if (hasColor) {
WRITE(p, " v_color0 = color0;\n");
} else {
WRITE(p, " v_color0 = u_matambientalpha;\n");
WRITE(p, " v_color0 = base.matambientalpha;\n");
}
if (lmode)
WRITE(p, " v_color1 = vec3(0.0);\n");
@@ -490,9 +454,9 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
}
} else {
if (hasTexcoord) {
WRITE(p, " v_texcoord = texcoord * u_uvscaleoffset.xy + u_uvscaleoffset.zw;\n");
WRITE(p, " v_texcoord = texcoord * base.uvscaleoffset.xy + base.uvscaleoffset.zw;\n");
} else {
WRITE(p, " v_texcoord = u_uvscaleoffset.zw;\n");
WRITE(p, " v_texcoord = base.uvscaleoffset.zw;\n");
}
}
break;
@@ -546,7 +510,7 @@ bool GenerateVulkanGLSLVertexShader(const ShaderID &id, char *buffer) {
// Compute fogdepth
if (enableFog)
WRITE(p, " v_fogdepth = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n");
WRITE(p, " v_fogdepth = (viewPos.z + base.fogcoef.x) * base.fogcoef.y;\n");
}
WRITE(p, "}\n");
return true;
+1
View File
@@ -2,4 +2,5 @@
#define VK_PROTOTYPES
#include "ext/vulkan/vulkan.h"
#include "thin3d/vulkan_utils.h"