Merge pull request #15782 from hrydgard/unify-draw-rect

Unify DrawActiveTexture
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-08-03 15:18:17 +02:00
commit 4d519b49a0
23 files changed
+264 -305

No files matched your search

+2
View File
@@ -1529,6 +1529,8 @@ endif()
set(GPU_SOURCES
${GPU_IMPLS}
${GPU_NEON}
GPU/Common/Draw2D.cpp
GPU/Common/Draw2D.h
GPU/Common/DepalettizeShaderCommon.cpp
GPU/Common/DepalettizeShaderCommon.h
GPU/Common/FragmentShaderGenerator.cpp
+26 -18
View File
@@ -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);
+2 -2
View File
@@ -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;
};
+131
View File
@@ -0,0 +1,131 @@
// Copyright (c) 2014- 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 "Common/GPU/Shader.h"
#include "Common/GPU/ShaderWriter.h"
#include "Common/GPU/thin3d.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/Reporting.h"
#include "GPU/Common/Draw2D.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "GPU/Common/FramebufferManagerCommon.h"
#include "GPU/Common/TextureCacheCommon.h"
static const InputDef inputs[2] = {
{ "vec2", "a_position", Draw::SEM_POSITION },
{ "vec2", "a_texcoord", Draw::SEM_TEXCOORD0 },
};
static const VaryingDef varyings[1] = {
{ "vec2", "v_texcoord", Draw::SEM_TEXCOORD0, 0, "highp" },
};
void GenerateDraw2DFs(char *buffer, const ShaderLanguageDesc &lang, const Draw::Bugs &bugs) {
ShaderWriter writer(buffer, lang, ShaderStage::Fragment, nullptr, 0);
writer.DeclareSampler2D("samp", 0);
writer.DeclareTexture2D("tex", 0);
writer.BeginFSMain(Slice<UniformDef>::empty(), varyings);
writer.C(" vec4 outColor = ").SampleTexture2D("tex", "samp", "v_texcoord.xy").C(";\n");
writer.EndFSMain("outColor");
}
void GenerateDraw2DVS(char *buffer, const ShaderLanguageDesc &lang) {
ShaderWriter writer(buffer, lang, ShaderStage::Vertex, nullptr, 0);
writer.BeginVSMain(inputs, Slice<UniformDef>::empty(), varyings);
writer.C(" v_texcoord = a_texcoord;\n"); // yes, this should be right. Should be 2.0 in the far corners.
writer.C(" gl_Position = vec4(a_position, 0.0, 1.0);\n");
writer.F(" gl_Position.y *= %s1.0;\n", lang.viewportYSign);
writer.EndVSMain(varyings);
}
// verts have positions in clip coordinates.
void FramebufferManagerCommon::DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter) {
using namespace Draw;
if (!draw2DPipelineLinear_) {
const ShaderLanguageDesc &shaderLanguageDesc = draw_->GetShaderLanguageDesc();
char *fsCode = new char[4000];
char *vsCode = new char[4000];
GenerateDraw2DFs(fsCode, shaderLanguageDesc, draw_->GetBugs());
GenerateDraw2DVS(vsCode, shaderLanguageDesc);
draw2DFs_ = draw_->CreateShaderModule(ShaderStage::Fragment, shaderLanguageDesc.shaderLanguage, (const uint8_t *)fsCode, strlen(fsCode), "draw2d_fs");
draw2DVs_ = draw_->CreateShaderModule(ShaderStage::Vertex, shaderLanguageDesc.shaderLanguage, (const uint8_t *)vsCode, strlen(vsCode), "draw2d_vs");
_assert_(draw2DFs_ && draw2DVs_);
InputLayoutDesc desc = {
{
{ 16, false },
},
{
{ 0, SEM_POSITION, DataFormat::R32G32_FLOAT, 0 },
{ 0, SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 8 },
},
};
InputLayout *inputLayout = draw_->CreateInputLayout(desc);
BlendState *blendOff = draw_->CreateBlendState({ false, 0xF });
DepthStencilStateDesc dsDesc{};
DepthStencilState *noDepthStencil = draw_->CreateDepthStencilState(dsDesc);
RasterState *rasterNoCull = draw_->CreateRasterState({});
PipelineDesc stencilWriteDesc{
Primitive::TRIANGLE_STRIP,
{ draw2DVs_, draw2DFs_ },
inputLayout, noDepthStencil, blendOff, rasterNoCull, nullptr,
};
draw2DPipelineLinear_ = draw_->CreateGraphicsPipeline(stencilWriteDesc);
_assert_(draw2DPipelineLinear_);
delete[] fsCode;
delete[] vsCode;
rasterNoCull->Release();
blendOff->Release();
noDepthStencil->Release();
inputLayout->Release();
SamplerStateDesc descLinear{};
descLinear.magFilter = TextureFilter::LINEAR;
descLinear.minFilter = TextureFilter::LINEAR;
descLinear.mipFilter = TextureFilter::LINEAR;
descLinear.wrapU = TextureAddressMode::CLAMP_TO_EDGE;
descLinear.wrapV = TextureAddressMode::CLAMP_TO_EDGE;
draw2DSamplerLinear_= draw_->CreateSamplerState(descLinear);
SamplerStateDesc descNearest{};
descLinear.magFilter = TextureFilter::NEAREST;
descLinear.minFilter = TextureFilter::NEAREST;
descLinear.mipFilter = TextureFilter::NEAREST;
descLinear.wrapU = TextureAddressMode::CLAMP_TO_EDGE;
descLinear.wrapV = TextureAddressMode::CLAMP_TO_EDGE;
draw2DSamplerNearest_ = draw_->CreateSamplerState(descNearest);
}
draw_->BindPipeline(draw2DPipelineLinear_);
if (tex) {
draw_->BindTextures(TEX_SLOT_PSP_TEXTURE, 1, &tex);
}
draw_->BindSamplerStates(TEX_SLOT_PSP_TEXTURE, 1, linearFilter ? &draw2DSamplerLinear_ : &draw2DSamplerNearest_);
draw_->DrawUP(verts, vertexCount);
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
// For framebuffer copies and similar things that just require passthrough.
struct Draw2DVertex {
float x;
float y;
float u;
float v;
};
+62 -2
View File
@@ -23,6 +23,9 @@
#include "Common/GPU/OpenGL/GLFeatures.h"
#include "Common/Data/Convert/ColorConv.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Math/lin/matrix4x4.h"
#include "Common/Math/math_util.h"
#include "Common/System/Display.h"
#include "Common/CommonTypes.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
@@ -44,8 +47,7 @@
#include "GPU/GPUState.h"
FramebufferManagerCommon::FramebufferManagerCommon(Draw::DrawContext *draw)
: draw_(draw),
displayFormat_(GE_FORMAT_565) {
: draw_(draw), displayFormat_(GE_FORMAT_565) {
presentation_ = new PresentationCommon(draw);
}
@@ -2492,6 +2494,11 @@ void FramebufferManagerCommon::DeviceLost() {
DoRelease(stencilUploadVs_);
DoRelease(stencilUploadSampler_);
DoRelease(stencilUploadPipeline_);
DoRelease(draw2DPipelineLinear_);
DoRelease(draw2DSamplerNearest_);
DoRelease(draw2DSamplerLinear_);
DoRelease(draw2DVs_);
DoRelease(draw2DFs_);
presentation_->DeviceLost();
draw_ = nullptr;
}
@@ -2500,3 +2507,56 @@ void FramebufferManagerCommon::DeviceRestore(Draw::DrawContext *draw) {
draw_ = draw;
presentation_->DeviceRestore(draw);
}
void FramebufferManagerCommon::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) {
// Will be drawn as a strip.
Draw2DVertex coord[4] = {
{x, y, u0, v0},
{x + w, y, u1, v0},
{x + w, y + h, u1, v1},
{x, y + h, u0, v1},
};
if (uvRotation != ROTATION_LOCKED_HORIZONTAL) {
float temp[8];
int rotation = 0;
switch (uvRotation) {
case ROTATION_LOCKED_HORIZONTAL180: rotation = 2; break;
case ROTATION_LOCKED_VERTICAL: rotation = 1; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 3; break;
}
for (int i = 0; i < 4; i++) {
temp[i * 2] = coord[((i + rotation) & 3)].u;
temp[i * 2 + 1] = coord[((i + rotation) & 3)].v;
}
for (int i = 0; i < 4; i++) {
coord[i].u = temp[i * 2];
coord[i].v = temp[i * 2 + 1];
}
}
const float invDestW = 2.0f / destW;
const float invDestH = 2.0f / destH;
for (int i = 0; i < 4; i++) {
coord[i].x = coord[i].x * invDestW - 1.0f;
coord[i].y = coord[i].y * invDestH - 1.0f;
}
if ((flags & DRAWTEX_TO_BACKBUFFER) && g_display_rotation != DisplayRotation::ROTATE_0) {
for (int i = 0; i < 4; i++) {
// backwards notation, should fix that...
Lin::Vec3 pos = Lin::Vec3(coord[i].x, coord[i].y, 0.0);
pos = pos * g_display_rot_matrix;
coord[i].x = pos.x;
coord[i].y = pos.y;
}
}
// Rearrange to strip form.
std::swap(coord[2], coord[3]);
DrawStrip2D(nullptr, coord, 4, (flags & DRAWTEX_LINEAR) != 0);
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE);
}
+12 -4
View File
@@ -29,11 +29,11 @@
#include "Common/CommonTypes.h"
#include "Common/Log.h"
#include "Core/MemMap.h"
#include "Common/GPU/thin3d.h"
#include "GPU/GPU.h"
#include "GPU/ge_constants.h"
#include "GPU/GPUInterface.h"
#include "Common/GPU/thin3d.h"
#include "GPU/Common/Draw2D.h"
enum {
FB_USAGE_DISPLAYED_FRAMEBUFFER = 1,
@@ -164,7 +164,6 @@ enum BindFramebufferColorFlags {
enum DrawTextureFlags {
DRAWTEX_NEAREST = 0,
DRAWTEX_LINEAR = 1,
DRAWTEX_KEEP_STENCIL_ALPHA = 4,
DRAWTEX_TO_BACKBUFFER = 8,
};
@@ -354,9 +353,11 @@ protected:
virtual void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
void SetViewport2D(int x, int y, int w, int h);
Draw::Texture *MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
virtual 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) = 0;
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);
virtual void Bind2DShader() = 0;
void DrawStrip2D(Draw::Texture *tex, Draw2DVertex *verts, int vertexCount, bool linearFilter);
bool UpdateSize();
void FlushBeforeCopy();
@@ -473,4 +474,11 @@ protected:
Draw::ShaderModule *stencilUploadVs_ = nullptr;
Draw::ShaderModule *stencilUploadFs_ = nullptr;
Draw::SamplerState *stencilUploadSampler_ = nullptr;
// Draw2D pipelines
Draw::Pipeline *draw2DPipelineLinear_ = nullptr;
Draw::SamplerState *draw2DSamplerLinear_ = nullptr;
Draw::SamplerState *draw2DSamplerNearest_ = nullptr;
Draw::ShaderModule *draw2DVs_ = nullptr;
Draw::ShaderModule *draw2DFs_ = nullptr;
};
+2 -1
View File
@@ -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.
+2 -2
View File
@@ -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) {
-69
View File
@@ -21,9 +21,6 @@
#include "Common/Common.h"
#include "Common/Data/Convert/ColorConv.h"
#include "Common/System/Display.h"
#include "Common/Math/lin/matrix4x4.h"
#include "Common/Math/math_util.h"
#include "Common/GPU/thin3d.h"
#include "Core/MemMap.h"
@@ -170,72 +167,6 @@ void FramebufferManagerD3D11::SetDrawEngine(DrawEngineD3D11 *td) {
drawEngine_ = td;
}
void FramebufferManagerD3D11::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) {
struct Coord {
Lin::Vec3 pos; float u, v;
};
Coord coord[4] = {
{{x, y, 0}, u0, v0},
{{x + w, y, 0}, u1, v0},
{{x + w, y + h,0}, u1, v1},
{{x, y + h, 0}, u0, v1},
};
if (uvRotation != ROTATION_LOCKED_HORIZONTAL) {
float temp[8];
int rotation = 0;
switch (uvRotation) {
case ROTATION_LOCKED_HORIZONTAL180: rotation = 2; break;
case ROTATION_LOCKED_VERTICAL: rotation = 1; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 3; break;
}
for (int i = 0; i < 4; i++) {
temp[i * 2] = coord[((i + rotation) & 3)].u;
temp[i * 2 + 1] = coord[((i + rotation) & 3)].v;
}
for (int i = 0; i < 4; i++) {
coord[i].u = temp[i * 2];
coord[i].v = temp[i * 2 + 1];
}
}
float invDestW = 1.0f / (destW * 0.5f);
float invDestH = 1.0f / (destH * 0.5f);
for (int i = 0; i < 4; i++) {
coord[i].pos.x = coord[i].pos.x * invDestW - 1.0f;
coord[i].pos.y = -(coord[i].pos.y * invDestH - 1.0f);
}
if ((flags & DRAWTEX_TO_BACKBUFFER) && g_display_rotation != DisplayRotation::ROTATE_0) {
for (int i = 0; i < 4; i++) {
// backwards notation, should fix that...
coord[i].pos = coord[i].pos * g_display_rot_matrix;
}
}
// The above code is for FAN geometry but we can only do STRIP. So rearrange it a little.
D3D11_MAPPED_SUBRESOURCE map;
context_->Map(quadBuffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
float *dest = (float *)map.pData;
memcpy(dest, coord, sizeof(Coord));
memcpy(dest + 5, coord + 1, sizeof(Coord));
memcpy(dest + 10, coord + 3, sizeof(Coord));
memcpy(dest + 15, coord + 2, sizeof(Coord));
context_->Unmap(quadBuffer_, 0);
context_->RSSetState(stockD3D11.rasterStateNoCull);
context_->OMSetBlendState(stockD3D11.blendStateDisabledWithColorMask[0xF], nullptr, 0xFFFFFFFF);
context_->OMSetDepthStencilState(stockD3D11.depthStencilDisabled, 0);
context_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
context_->PSSetSamplers(0, 1, (flags & DRAWTEX_LINEAR) ? &stockD3D11.samplerLinear2DClamp : &stockD3D11.samplerPoint2DClamp);
UINT stride = 20;
UINT offset = 0;
context_->IASetVertexBuffers(0, 1, &quadBuffer_, &stride, &offset);
context_->Draw(4, 0);
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE);
}
void FramebufferManagerD3D11::Bind2DShader() {
context_->IASetInputLayout(quadInputLayout_);
context_->PSSetShader(quadPixelShader_, 0, 0);
-1
View File
@@ -39,7 +39,6 @@ public:
void SetTextureCache(TextureCacheD3D11 *tc);
void SetShaderManager(ShaderManagerD3D11 *sm);
void SetDrawEngine(DrawEngineD3D11 *td);
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 EndFrame();
-60
View File
@@ -152,66 +152,6 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
drawEngine_ = td;
}
void FramebufferManagerDX9::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) {
// TODO: StretchRect instead when possible?
float coord[20] = {
x,y,0, u0,v0,
x+w,y,0, u1,v0,
x+w,y+h,0, u1,v1,
x,y+h,0, u0,v1,
};
if (uvRotation != ROTATION_LOCKED_HORIZONTAL) {
float temp[8];
int rotation = 0;
switch (uvRotation) {
case ROTATION_LOCKED_HORIZONTAL180: rotation = 2; break;
case ROTATION_LOCKED_VERTICAL: rotation = 1; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 3; break;
}
for (int i = 0; i < 4; i++) {
temp[i * 2] = coord[((i + rotation) & 3) * 5 + 3];
temp[i * 2 + 1] = coord[((i + rotation) & 3) * 5 + 4];
}
for (int i = 0; i < 4; i++) {
coord[i * 5 + 3] = temp[i * 2];
coord[i * 5 + 4] = temp[i * 2 + 1];
}
}
float invDestW = 1.0f / (destW * 0.5f);
float invDestH = 1.0f / (destH * 0.5f);
float halfPixelX = invDestW * 0.5f;
float halfPixelY = invDestH * 0.5f;
for (int i = 0; i < 4; i++) {
coord[i * 5] = coord[i * 5] * invDestW - 1.0f - halfPixelX;
coord[i * 5 + 1] = -(coord[i * 5 + 1] * invDestH - 1.0f - halfPixelY);
}
if (flags & DRAWTEX_LINEAR) {
dxstate.texMagFilter.set(D3DTEXF_LINEAR);
dxstate.texMinFilter.set(D3DTEXF_LINEAR);
} else {
dxstate.texMagFilter.set(D3DTEXF_POINT);
dxstate.texMinFilter.set(D3DTEXF_POINT);
}
dxstate.texMipLodBias.set(0.0f);
dxstate.texMaxMipLevel.set(0);
dxstate.blend.disable();
dxstate.cullMode.set(D3DCULL_NONE);
dxstate.depthTest.disable();
dxstate.scissorTest.disable();
dxstate.stencilTest.disable();
dxstate.colorMask.set(0xF);
dxstate.stencilWriteMask.set(0xFF);
HRESULT hr = device_->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float));
if (FAILED(hr)) {
ERROR_LOG_REPORT(G3D, "DrawActiveTexture() failed: %08x", (uint32_t)hr);
}
}
void FramebufferManagerDX9::Bind2DShader() {
device_->SetVertexDeclaration(pFramebufferVertexDecl);
device_->SetPixelShader(pFramebufferPixelShader);
-1
View File
@@ -42,7 +42,6 @@ public:
void SetTextureCache(TextureCacheDX9 *tc);
void SetShaderManager(ShaderManagerDX9 *sm);
void SetDrawEngine(DrawEngineDX9 *td);
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 DestroyAllFBOs() override;
-77
View File
@@ -162,83 +162,6 @@ FramebufferManagerGLES::~FramebufferManagerGLES() {
delete [] convBuf_;
}
// x, y, w, h are relative coordinates against destW/destH, which is not very intuitive.
// TODO: This could totally use fbo_blit in many cases.
void FramebufferManagerGLES::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;
// Vertical and Vertical180 needed swapping after we changed the coordinate system.
switch (uvRotation) {
case ROTATION_LOCKED_HORIZONTAL180: rotation = 4; break;
case ROTATION_LOCKED_VERTICAL: rotation = 6; break;
case ROTATION_LOCKED_VERTICAL180: rotation = 2; break;
}
for (int i = 0; i < 8; i++) {
temp[i] = texCoords[(i + rotation) & 7];
}
memcpy(texCoords, temp, sizeof(temp));
}
float pos[12] = {
x,y,0,
x + w,y,0,
x + w,y + h,0,
x,y + h,0
};
float invDestW = 1.0f / (destW * 0.5f);
float invDestH = 1.0f / (destH * 0.5f);
for (int i = 0; i < 4; i++) {
pos[i * 3] = pos[i * 3] * invDestW - 1.0f;
pos[i * 3 + 1] = pos[i * 3 + 1] * invDestH - 1.0f;
}
// We always want a plain state here, well, except for when it's used by the stencil stuff...
render_->SetDepth(false, false, GL_ALWAYS);
render_->SetRaster(false, GL_CCW, GL_FRONT, GL_FALSE, GL_FALSE);
if (!(flags & DRAWTEX_KEEP_STENCIL_ALPHA)) {
render_->SetNoBlendAndMask(0xF);
render_->SetStencilDisabled();
}
// Upscaling postshaders don't look well with linear
if (flags & DRAWTEX_LINEAR) {
render_->SetTextureSampler(0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_LINEAR, GL_LINEAR, 0.0f);
} else {
render_->SetTextureSampler(0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f);
}
Simple2DVertex verts[4];
memcpy(verts[0].pos, &pos[0], 12);
memcpy(verts[1].pos, &pos[3], 12);
memcpy(verts[3].pos, &pos[6], 12);
memcpy(verts[2].pos, &pos[9], 12);
memcpy(verts[0].uv, &texCoords[0], 8);
memcpy(verts[1].uv, &texCoords[2], 8);
memcpy(verts[3].uv, &texCoords[4], 8);
memcpy(verts[2].uv, &texCoords[6], 8);
uint32_t bindOffset;
GLRBuffer *buffer;
// Workaround: This might accidentally get called from ReportScreen screenshot-taking, and in that case
// the push buffer is not mapped. This only happens if framebuffer blit support is not available.
if (drawEngineGL_->GetPushVertexBuffer()->IsReady()) {
void *dest = drawEngineGL_->GetPushVertexBuffer()->Push(sizeof(verts), &bindOffset, &buffer);
memcpy(dest, verts, sizeof(verts));
render_->BindVertexBuffer(simple2DInputLayout_, buffer, bindOffset);
render_->Draw(GL_TRIANGLE_STRIP, 0, 4);
}
}
void FramebufferManagerGLES::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {
_assert_msg_(nvfb->fbo, "Expecting a valid nvfb in UpdateDownloadTempBuffer");
-3
View File
@@ -40,9 +40,6 @@ public:
void SetShaderManager(ShaderManagerGLES *sm);
void SetDrawEngine(DrawEngineGLES *td);
// 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;
virtual void Init() override;
void EndFrame();
void Resized() override;
+3 -1
View File
@@ -338,6 +338,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\ext\xbrz\xbrz.h" />
<ClInclude Include="Common\Draw2D.h" />
<ClInclude Include="Common\ReinterpretFramebuffer.h" />
<ClInclude Include="Common\DepalettizeShaderCommon.h" />
<ClInclude Include="Common\DrawEngineCommon.h" />
@@ -459,6 +460,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\ext\xbrz\xbrz.cpp" />
<ClCompile Include="Common\Draw2D.cpp" />
<ClCompile Include="Common\ReinterpretFramebuffer.cpp" />
<ClCompile Include="Common\DepalettizeShaderCommon.cpp" />
<ClCompile Include="Common\DrawEngineCommon.cpp" />
@@ -666,4 +668,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
+7 -1
View File
@@ -264,6 +264,9 @@
<ClInclude Include="Software\BinManager.h">
<Filter>Software</Filter>
</ClInclude>
<ClInclude Include="Common\Draw2D.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Math3D.cpp">
@@ -518,6 +521,9 @@
<ClCompile Include="Software\BinManager.cpp">
<Filter>Software</Filter>
</ClCompile>
<ClCompile Include="Common\Draw2D.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="..\assets\shaders\tex_4xbrz.csh">
@@ -535,4 +541,4 @@
<Filter>Shaders</Filter>
</None>
</ItemGroup>
</Project>
</Project>
-60
View File
@@ -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_);
-3
View File
@@ -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();
+2
View File
@@ -380,6 +380,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
<ClInclude Include="..\..\GPU\Common\Draw2D.h" />
<ClInclude Include="..\..\GPU\Common\DrawEngineCommon.h" />
<ClInclude Include="..\..\GPU\Common\FragmentShaderGenerator.h" />
<ClInclude Include="..\..\GPU\Common\FramebufferManagerCommon.h" />
@@ -439,6 +440,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\GPU\Common\DepalettizeShaderCommon.cpp" />
<ClCompile Include="..\..\GPU\Common\Draw2D.cpp" />
<ClCompile Include="..\..\GPU\Common\DrawEngineCommon.cpp" />
<ClCompile Include="..\..\GPU\Common\FragmentShaderGenerator.cpp" />
<ClCompile Include="..\..\GPU\Common\FramebufferManagerCommon.cpp" />
+2
View File
@@ -57,6 +57,7 @@
<ClCompile Include="..\..\GPU\Common\FragmentShaderGenerator.cpp" />
<ClCompile Include="..\..\GPU\Common\VertexShaderGenerator.cpp" />
<ClCompile Include="..\..\GPU\Common\ReinterpretFramebuffer.cpp" />
<ClCompile Include="..\..\GPU\Common\Draw2D.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
@@ -116,5 +117,6 @@
<ClInclude Include="..\..\GPU\Common\FragmentShaderGenerator.h" />
<ClInclude Include="..\..\GPU\Common\VertexShaderGenerator.h" />
<ClInclude Include="..\..\GPU\Common\ReinterpretFramebuffer.h" />
<ClInclude Include="..\..\GPU\Common\Draw2D.h" />
</ItemGroup>
</Project>
+1
View File
@@ -319,6 +319,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/GPU/GPUState.cpp \
$(SRC)/GPU/GeConstants.cpp \
$(SRC)/GPU/GeDisasm.cpp \
$(SRC)/GPU/Common/Draw2D.cpp \
$(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \
$(SRC)/GPU/Common/FragmentShaderGenerator.cpp \
$(SRC)/GPU/Common/FramebufferManagerCommon.cpp \
+1
View File
@@ -315,6 +315,7 @@ SOURCES_C +=\
$(COMMONDIR)/GPU/OpenGL/gl3stub.c
SOURCES_CXX += \
$(GPUCOMMONDIR)/Draw2D.cpp \
$(GPUCOMMONDIR)/VertexDecoderCommon.cpp \
$(GPUCOMMONDIR)/GPUStateUtils.cpp \
$(GPUCOMMONDIR)/DrawEngineCommon.cpp \