mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-08-26 07:25:14 +02:00
Delete the Vulkan implementation of DrawActiveTexture, fixups to shader gen
This commit is contained in:
+26
-18
@@ -6,7 +6,7 @@
|
||||
#include "Common/GPU/ShaderWriter.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
const char *vulkan_glsl_preamble_fs =
|
||||
const char * const vulkan_glsl_preamble_fs =
|
||||
"#version 450\n"
|
||||
"#extension GL_ARB_separate_shader_objects : enable\n"
|
||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||
@@ -18,7 +18,7 @@ const char *vulkan_glsl_preamble_fs =
|
||||
"precision highp int;\n"
|
||||
"\n";
|
||||
|
||||
const char *hlsl_preamble_fs =
|
||||
const char * const hlsl_preamble_fs =
|
||||
"#define vec2 float2\n"
|
||||
"#define vec3 float3\n"
|
||||
"#define vec4 float4\n"
|
||||
@@ -35,14 +35,14 @@ const char *hlsl_preamble_fs =
|
||||
"#define highp\n"
|
||||
"#define mod(x, y) fmod(x, y)\n";
|
||||
|
||||
const char *hlsl_d3d11_preamble_fs =
|
||||
static const char * const hlsl_d3d11_preamble_fs =
|
||||
"#define DISCARD discard\n"
|
||||
"#define DISCARD_BELOW(x) clip(x);\n";
|
||||
const char *hlsl_d3d9_preamble_fs =
|
||||
static const char * const hlsl_d3d9_preamble_fs =
|
||||
"#define DISCARD clip(-1)\n"
|
||||
"#define DISCARD_BELOW(x) clip(x)\n";
|
||||
|
||||
const char *vulkan_glsl_preamble_vs =
|
||||
static const char * const vulkan_glsl_preamble_vs =
|
||||
"#version 450\n"
|
||||
"#extension GL_ARB_separate_shader_objects : enable\n"
|
||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||
@@ -51,7 +51,7 @@ const char *vulkan_glsl_preamble_vs =
|
||||
"precision highp float;\n"
|
||||
"\n";
|
||||
|
||||
const char *hlsl_preamble_vs =
|
||||
static const char * const hlsl_preamble_vs =
|
||||
"#define vec2 float2\n"
|
||||
"#define vec3 float3\n"
|
||||
"#define vec4 float4\n"
|
||||
@@ -66,6 +66,16 @@ const char *hlsl_preamble_vs =
|
||||
"#define highp\n"
|
||||
"\n";
|
||||
|
||||
static const char * const semanticNames[8] = {
|
||||
"POSITION",
|
||||
"COLOR0",
|
||||
"TEXCOORD0",
|
||||
"TEXCOORD1",
|
||||
"NORMAL",
|
||||
"TANGENT",
|
||||
"BINORMAL",
|
||||
};
|
||||
|
||||
// Unsafe. But doesn't matter, we'll use big buffers for shader gen.
|
||||
ShaderWriter & ShaderWriter::F(const char *format, ...) {
|
||||
va_list args;
|
||||
@@ -153,7 +163,7 @@ void ShaderWriter::BeginVSMain(Slice<InputDef> inputs, Slice<UniformDef> uniform
|
||||
{
|
||||
C("struct VS_OUTPUT {\n");
|
||||
for (auto &varying : varyings) {
|
||||
F(" %s %s : %s;\n", varying.type, varying.name, varying.semantic);
|
||||
F(" %s %s : %s;\n", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
F(" vec4 pos : %s;\n", lang_.shaderLanguage == HLSL_D3D11 ? "SV_Position" : "POSITION");
|
||||
C("};\n");
|
||||
@@ -164,27 +174,25 @@ void ShaderWriter::BeginVSMain(Slice<InputDef> inputs, Slice<UniformDef> uniform
|
||||
}
|
||||
// List the inputs.
|
||||
for (auto &input : inputs) {
|
||||
F("in %s %s : %s, ", input.type, input.name, input.semantic);
|
||||
F("in %s %s : %s, ", input.type, input.name, semanticNames[input.semantic]);
|
||||
}
|
||||
|
||||
Rewind(2); // Get rid of the last comma.
|
||||
C(") {\n");
|
||||
C(" vec4 gl_Position;\n");
|
||||
for (auto &varying : varyings) {
|
||||
F(" %s %s;\n", varying.type, varying.name);
|
||||
F(" %s %s; // %s\n", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GLSL_VULKAN:
|
||||
{
|
||||
int i = 0;
|
||||
for (auto &input : inputs) {
|
||||
F("layout(location = %d) in %s %s;\n", i, input.type, input.name);
|
||||
i++;
|
||||
F("layout(location = %d) in %s %s;\n", input.semantic /*index*/, input.type, input.name);
|
||||
}
|
||||
for (auto &varying : varyings) {
|
||||
F("layout(location = %d) %s out %s %s; // %s\n",
|
||||
varying.index, varying.precision ? varying.precision : "", varying.type, varying.name, varying.semantic);
|
||||
varying.index, varying.precision ? varying.precision : "", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
C("void main() {\n");
|
||||
break;
|
||||
@@ -194,7 +202,7 @@ void ShaderWriter::BeginVSMain(Slice<InputDef> inputs, Slice<UniformDef> uniform
|
||||
F("in %s %s;\n", input.type, input.name);
|
||||
}
|
||||
for (auto &varying : varyings) {
|
||||
F("%s %s %s %s; // %s (%d)\n", lang_.varying_vs, varying.precision ? varying.precision : "", varying.type, varying.name, varying.semantic, varying.index);
|
||||
F("%s %s %s %s; // %s (%d)\n", lang_.varying_vs, varying.precision ? varying.precision : "", varying.type, varying.name, semanticNames[varying.semantic], varying.index);
|
||||
}
|
||||
C("void main() {\n");
|
||||
break;
|
||||
@@ -218,7 +226,7 @@ void ShaderWriter::BeginFSMain(Slice<UniformDef> uniforms, Slice<VaryingDef> var
|
||||
// Let's do the varyings as parameters to main, no struct.
|
||||
C("vec4 main(");
|
||||
for (auto &varying : varyings) {
|
||||
F(" %s %s : %s, ", varying.type, varying.name, varying.semantic);
|
||||
F(" %s %s : %s, ", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
// Erase the last comma
|
||||
Rewind(2);
|
||||
@@ -232,7 +240,7 @@ void ShaderWriter::BeginFSMain(Slice<UniformDef> uniforms, Slice<VaryingDef> var
|
||||
// Let's do the varyings as parameters to main, no struct.
|
||||
C("vec4 main(");
|
||||
for (auto &varying : varyings) {
|
||||
F(" %s %s : %s, ", varying.type, varying.name, varying.semantic);
|
||||
F(" %s %s : %s, ", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
// Erase the last comma
|
||||
Rewind(2);
|
||||
@@ -241,7 +249,7 @@ void ShaderWriter::BeginFSMain(Slice<UniformDef> uniforms, Slice<VaryingDef> var
|
||||
break;
|
||||
case GLSL_VULKAN:
|
||||
for (auto &varying : varyings) {
|
||||
F("layout(location = %d) %s in %s %s; // %s\n", varying.index, varying.precision ? varying.precision : "", varying.type, varying.name, varying.semantic);
|
||||
F("layout(location = %d) %s in %s %s; // %s\n", varying.index, varying.precision ? varying.precision : "", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
C("layout(location = 0, index = 0) out vec4 fragColor0;\n");
|
||||
if (!uniforms.is_empty()) {
|
||||
@@ -256,7 +264,7 @@ void ShaderWriter::BeginFSMain(Slice<UniformDef> uniforms, Slice<VaryingDef> var
|
||||
|
||||
default: // GLSL OpenGL
|
||||
for (auto &varying : varyings) {
|
||||
F("%s %s %s %s; // %s\n", lang_.varying_fs, varying.precision ? varying.precision : "", varying.type, varying.name, varying.semantic);
|
||||
F("%s %s %s %s; // %s\n", lang_.varying_fs, varying.precision ? varying.precision : "", varying.type, varying.name, semanticNames[varying.semantic]);
|
||||
}
|
||||
for (auto &uniform : uniforms) {
|
||||
F("uniform %s %s;\n", uniform.type, uniform.name);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
struct InputDef {
|
||||
const char *type;
|
||||
const char *name;
|
||||
const char *semantic;
|
||||
int semantic;
|
||||
};
|
||||
|
||||
struct UniformDef {
|
||||
@@ -31,7 +31,7 @@ struct UniformDef {
|
||||
struct VaryingDef {
|
||||
const char *type;
|
||||
const char *name;
|
||||
const char *semantic;
|
||||
int semantic;
|
||||
int index;
|
||||
const char *precision;
|
||||
};
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#include "GPU/Common/TextureCacheCommon.h"
|
||||
|
||||
static const InputDef inputs[2] = {
|
||||
{ "vec2", "a_position", "POSITION" },
|
||||
{ "vec2", "a_texcoord", "TEXCOORD0" },
|
||||
{ "vec2", "a_position", Draw::SEM_POSITION },
|
||||
{ "vec2", "a_texcoord", Draw::SEM_TEXCOORD0 },
|
||||
};
|
||||
|
||||
static const VaryingDef varyings[1] = {
|
||||
{ "vec2", "v_texcoord", "TEXCOORD0", 0, "highp" },
|
||||
{ "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" },
|
||||
};
|
||||
|
||||
void GenerateDraw2DFs(char *buffer, const ShaderLanguageDesc &lang, const Draw::Bugs &bugs) {
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#include "Common/GPU/Shader.h"
|
||||
#include "Common/GPU/ShaderWriter.h"
|
||||
#include "Common/Log.h"
|
||||
#include "Common/GPU/thin3d.h"
|
||||
#include "GPU/Common/ReinterpretFramebuffer.h"
|
||||
|
||||
static const VaryingDef varyings[1] = {
|
||||
{ "vec2", "v_texcoord", "TEXCOORD0", 0, "highp" },
|
||||
{ "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" },
|
||||
};
|
||||
|
||||
// TODO: We could possibly have an option to preserve any extra color precision? But gonna start without it.
|
||||
|
||||
@@ -72,11 +72,11 @@ static const UniformDef uniforms[1] = {
|
||||
};
|
||||
|
||||
static const InputDef inputs[1] = {
|
||||
{ "vec2", "a_position", "POSITION", }
|
||||
{ "vec2", "a_position", Draw::SEM_POSITION, }
|
||||
};
|
||||
|
||||
static const VaryingDef varyings[1] = {
|
||||
{ "vec2", "v_texcoord", "TEXCOORD0", 0, "highp" },
|
||||
{ "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" },
|
||||
};
|
||||
|
||||
void GenerateStencilFs(char *buffer, const ShaderLanguageDesc &lang, const Draw::Bugs &bugs) {
|
||||
|
||||
@@ -170,66 +170,6 @@ void FramebufferManagerVulkan::NotifyClear(bool clearColor, bool clearAlpha, boo
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) {
|
||||
float texCoords[8] = {
|
||||
u0,v0,
|
||||
u1,v0,
|
||||
u1,v1,
|
||||
u0,v1,
|
||||
};
|
||||
|
||||
if (uvRotation != ROTATION_LOCKED_HORIZONTAL) {
|
||||
float temp[8];
|
||||
int rotation = 0;
|
||||
switch (uvRotation) {
|
||||
case ROTATION_LOCKED_HORIZONTAL180: rotation = 4; break;
|
||||
case ROTATION_LOCKED_VERTICAL: rotation = 2; break;
|
||||
case ROTATION_LOCKED_VERTICAL180: rotation = 6; break;
|
||||
}
|
||||
for (int i = 0; i < 8; i++) {
|
||||
temp[i] = texCoords[(i + rotation) & 7];
|
||||
}
|
||||
memcpy(texCoords, temp, sizeof(temp));
|
||||
}
|
||||
|
||||
Vulkan2D::Vertex vtx[4] = {
|
||||
{x, y, 0, texCoords[0], texCoords[1]},
|
||||
{x + w, y, 0, texCoords[2], texCoords[3]},
|
||||
{x, y + h, 0, texCoords[6], texCoords[7]},
|
||||
{x + w, y + h, 0, texCoords[4], texCoords[5]},
|
||||
};
|
||||
|
||||
float invDestW = 1.0f / (destW * 0.5f);
|
||||
float invDestH = 1.0f / (destH * 0.5f);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
vtx[i].x = vtx[i].x * invDestW - 1.0f;
|
||||
vtx[i].y = vtx[i].y * invDestH - 1.0f;
|
||||
}
|
||||
|
||||
if ((flags & DRAWTEX_TO_BACKBUFFER) && g_display_rotation != DisplayRotation::ROTATE_0) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Lin::Vec3 v(vtx[i].x, vtx[i].y, 0.0f);
|
||||
// backwards notation, should fix that...
|
||||
v = v * g_display_rot_matrix;
|
||||
vtx[i].x = v.x;
|
||||
vtx[i].y = v.y;
|
||||
}
|
||||
}
|
||||
|
||||
draw_->FlushState();
|
||||
|
||||
// TODO: Should probably use draw_ directly and not go low level
|
||||
|
||||
VulkanRenderManager *renderManager = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
||||
|
||||
VkImageView view = (VkImageView)draw_->GetNativeObject(Draw::NativeObject::BOUND_TEXTURE0_IMAGEVIEW);
|
||||
VkDescriptorSet descSet = vulkan2D_->GetDescriptorSet(view, (flags & DRAWTEX_LINEAR) ? linearSampler_ : nearestSampler_, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
VkBuffer vbuffer;
|
||||
VkDeviceSize offset = push_->Push(vtx, sizeof(vtx), &vbuffer);
|
||||
renderManager->BindPipeline(cur2DPipeline_, (PipelineFlags)0);
|
||||
renderManager->Draw(vulkan2D_->GetPipelineLayout(), descSet, 0, nullptr, vbuffer, offset, 4);
|
||||
}
|
||||
|
||||
void FramebufferManagerVulkan::Bind2DShader() {
|
||||
VkRenderPass rp = (VkRenderPass)draw_->GetNativeObject(Draw::NativeObject::COMPATIBLE_RENDERPASS);
|
||||
cur2DPipeline_ = vulkan2D_->GetPipeline(rp, vsBasicTex_, fsBasicTex_);
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
void SetVulkan2D(Vulkan2D *vk2d) { vulkan2D_ = vk2d; }
|
||||
void SetPushBuffer(VulkanPushBuffer *push) { push_ = push; }
|
||||
|
||||
// x,y,w,h are relative to destW, destH which fill out the target completely.
|
||||
void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) override;
|
||||
|
||||
void BeginFrameVulkan(); // there's a BeginFrame in the base class, which this calls
|
||||
void EndFrame();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user