mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-26 03:35:27 +00:00
Initial stab at porting the DX9 backend to D3D11. Not working yet.
This commit is contained in:
parent
01e11c6437
commit
ba95e0f4d9
@ -29,7 +29,12 @@
|
||||
// Uses integer instructions available since OpenGL 3.0. Suitable for ES 3.0 as well.
|
||||
void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage language) {
|
||||
char *p = buffer;
|
||||
if (language == GLSL_VULKAN) {
|
||||
if (language == HLSL_D3D11) {
|
||||
WRITE(p, "SamplerState texSamp : register(s0);\n");
|
||||
WRITE(p, "Texture2D<float4> tex : register(t0);\n");
|
||||
WRITE(p, "SamplerState palSamp : register(s1);\n");
|
||||
WRITE(p, "Texture2D<float4> pal : register(t1);\n");
|
||||
} else if (language == GLSL_VULKAN) {
|
||||
WRITE(p, "#version 140\n");
|
||||
WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
|
||||
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
|
||||
@ -50,9 +55,14 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang
|
||||
WRITE(p, "uniform sampler2D pal;\n");
|
||||
}
|
||||
|
||||
// TODO: Add support for integer textures. Though it hardly matters.
|
||||
WRITE(p, "void main() {\n");
|
||||
WRITE(p, " vec4 color = texture(tex, v_texcoord0);\n");
|
||||
if (language == HLSL_D3D11) {
|
||||
WRITE(p, "float4 main(in v_texcoord0 : TEXCOORD0) : SV_Target {\n");
|
||||
WRITE(p, " float4 color = texSamp.Sample(tex, v_texcoord0);\n");
|
||||
} else {
|
||||
// TODO: Add support for integer textures. Though it hardly matters.
|
||||
WRITE(p, "void main() {\n");
|
||||
WRITE(p, " vec4 color = texture(tex, v_texcoord0);\n");
|
||||
}
|
||||
|
||||
int mask = gstate.getClutIndexMask();
|
||||
int shift = gstate.getClutIndexShift();
|
||||
@ -110,7 +120,11 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang
|
||||
WRITE(p, ";\n");
|
||||
}
|
||||
|
||||
WRITE(p, " fragColor0 = texture(pal, vec2((float(index) + 0.5) * (1.0 / %f), 0.0));\n", texturePixels);
|
||||
if (language == HLSL_D3D11) {
|
||||
WRITE(p, " fragColor0 = texSamp.Sample(pal, float2((float(index) + 0.5) * (1.0 / %f), 0.0));\n", texturePixels);
|
||||
} else {
|
||||
WRITE(p, " fragColor0 = texture(pal, vec2((float(index) + 0.5) * (1.0 / %f), 0.0));\n", texturePixels);
|
||||
}
|
||||
WRITE(p, "}\n");
|
||||
}
|
||||
|
||||
@ -262,6 +276,7 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguag
|
||||
break;
|
||||
case GLSL_300:
|
||||
case GLSL_VULKAN:
|
||||
case HLSL_D3D11:
|
||||
GenerateDepalShader300(buffer, pixelFormat, language);
|
||||
break;
|
||||
case HLSL_DX9:
|
||||
|
@ -18,12 +18,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "GPU/ge_constants.h"
|
||||
|
||||
enum ShaderLanguage {
|
||||
GLSL_140,
|
||||
GLSL_300,
|
||||
GLSL_VULKAN,
|
||||
HLSL_DX9,
|
||||
};
|
||||
#include "GPU/Common/ShaderCommon.h"
|
||||
|
||||
void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage language);
|
||||
|
@ -17,6 +17,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum ShaderLanguage {
|
||||
GLSL_140,
|
||||
GLSL_300,
|
||||
GLSL_VULKAN,
|
||||
HLSL_DX9,
|
||||
HLSL_D3D11,
|
||||
};
|
||||
|
||||
enum DebugShaderType {
|
||||
SHADER_TYPE_VERTEX = 0,
|
||||
SHADER_TYPE_FRAGMENT = 1,
|
||||
|
@ -52,6 +52,30 @@ namespace Draw {
|
||||
class DrawContext;
|
||||
}
|
||||
|
||||
// Used by D3D11 and Vulkan, could be used by modern GL
|
||||
struct SamplerCacheKey {
|
||||
SamplerCacheKey() : fullKey(0) {}
|
||||
|
||||
union {
|
||||
u32 fullKey;
|
||||
struct {
|
||||
bool mipEnable : 1;
|
||||
bool minFilt : 1;
|
||||
bool mipFilt : 1;
|
||||
bool magFilt : 1;
|
||||
bool sClamp : 1;
|
||||
bool tClamp : 1;
|
||||
int lodBias : 4;
|
||||
int maxLevel : 4;
|
||||
};
|
||||
};
|
||||
|
||||
bool operator < (const SamplerCacheKey &other) const {
|
||||
return fullKey < other.fullKey;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FramebufferManagerCommon;
|
||||
|
||||
class TextureCacheCommon {
|
||||
@ -123,6 +147,9 @@ public:
|
||||
void *texturePtr;
|
||||
CachedTextureVulkan *vkTex;
|
||||
};
|
||||
#ifdef _WIN32
|
||||
void *textureView; // Used by D3D11 only for the shader resource view.
|
||||
#endif
|
||||
int invalidHint;
|
||||
u32 fullhash;
|
||||
u32 cluthash;
|
||||
|
91
GPU/D3D11/D3D11Util.cpp
Normal file
91
GPU/D3D11/D3D11Util.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <d3d11.h>
|
||||
#include <D3Dcompiler.h>
|
||||
#include "thin3d/d3d11_loader.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
#include "D3D11Util.h"
|
||||
|
||||
static std::vector<uint8_t> CompileShaderToBytecode(const char *code, size_t codeSize, const char *target) {
|
||||
ID3DBlob *compiledCode = nullptr;
|
||||
ID3DBlob *errorMsgs = nullptr;
|
||||
HRESULT result = ptr_D3DCompile(code, codeSize, nullptr, nullptr, nullptr, "main", target, 0, 0, &compiledCode, &errorMsgs);
|
||||
if (errorMsgs) {
|
||||
std::string errors = std::string((const char *)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize());
|
||||
ELOG("%s: %s\n%s", SUCCEEDED(result) ? "warnings" : "errors", code, errors.c_str());
|
||||
errorMsgs->Release();
|
||||
}
|
||||
if (compiledCode) {
|
||||
const uint8_t *buf = (const uint8_t *)compiledCode->GetBufferPointer();
|
||||
std::vector<uint8_t> compiled = std::vector<uint8_t>(buf, buf + compiledCode->GetBufferSize());
|
||||
compiledCode->Release();
|
||||
return compiled;
|
||||
}
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
|
||||
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut) {
|
||||
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "vs_5_0");
|
||||
if (byteCode.empty())
|
||||
return nullptr;
|
||||
ID3D11VertexShader *vs;
|
||||
device->CreateVertexShader(byteCode.data(), byteCode.size(), nullptr, &vs);
|
||||
if (byteCodeOut)
|
||||
*byteCodeOut = byteCode;
|
||||
return vs;
|
||||
}
|
||||
|
||||
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize) {
|
||||
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "ps_5_0");
|
||||
if (byteCode.empty())
|
||||
return nullptr;
|
||||
|
||||
ID3D11PixelShader *ps;
|
||||
device->CreatePixelShader(byteCode.data(), byteCode.size(), nullptr, &ps);
|
||||
return ps;
|
||||
}
|
||||
|
||||
void StockObjectsD3D11::Create(ID3D11Device *device) {
|
||||
D3D11_BLEND_DESC blend_desc{};
|
||||
for (int i = 0; i < 16; i++) {
|
||||
blend_desc.RenderTarget[0].RenderTargetWriteMask = i;
|
||||
device->CreateBlendState(&blend_desc, &blendStateDisabledWithColorMask[i]);
|
||||
}
|
||||
D3D11_DEPTH_STENCIL_DESC depth_desc{};
|
||||
device->CreateDepthStencilState(&depth_desc, &depthStencilDisabled);
|
||||
depth_desc.StencilEnable = TRUE;
|
||||
depth_desc.StencilReadMask = 0xFF;
|
||||
depth_desc.StencilWriteMask = 0xFF;
|
||||
depth_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
|
||||
depth_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
|
||||
depth_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
depth_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
device->CreateDepthStencilState(&depth_desc, &depthDisabledStencilWrite);
|
||||
D3D11_RASTERIZER_DESC raster_desc{};
|
||||
raster_desc.FillMode = D3D11_FILL_SOLID;
|
||||
raster_desc.CullMode = D3D11_CULL_NONE;
|
||||
raster_desc.ScissorEnable = FALSE;
|
||||
device->CreateRasterizerState(&raster_desc, &rasterStateNoCull);
|
||||
D3D11_SAMPLER_DESC sampler_desc{};
|
||||
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
device->CreateSamplerState(&sampler_desc, &samplerPoint2DWrap);
|
||||
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
device->CreateSamplerState(&sampler_desc, &samplerLinear2DWrap);
|
||||
}
|
||||
|
||||
void StockObjectsD3D11::Destroy() {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
blendStateDisabledWithColorMask[i]->Release();
|
||||
}
|
||||
depthStencilDisabled->Release();
|
||||
depthDisabledStencilWrite->Release();
|
||||
rasterStateNoCull->Release();
|
||||
samplerPoint2DWrap->Release();
|
||||
samplerLinear2DWrap->Release();
|
||||
}
|
||||
|
||||
StockObjectsD3D11 stockD3D11;
|
81
GPU/D3D11/D3D11Util.h
Normal file
81
GPU/D3D11/D3D11Util.h
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2017- 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 <cstdint>
|
||||
#include <d3d11.h>
|
||||
|
||||
class PushBufferD3D11 {
|
||||
public:
|
||||
PushBufferD3D11(ID3D11Device *device, size_t size, D3D11_BIND_FLAG bindFlags) {
|
||||
D3D11_BUFFER_DESC desc{};
|
||||
desc.BindFlags = bindFlags;
|
||||
desc.ByteWidth = (UINT)size;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
device->CreateBuffer(&desc, nullptr, &buffer_);
|
||||
}
|
||||
~PushBufferD3D11() {
|
||||
buffer_->Release();
|
||||
}
|
||||
ID3D11Buffer *Buf() const {
|
||||
return buffer_;
|
||||
}
|
||||
|
||||
// Should be done each frame
|
||||
void Reset() {
|
||||
pos_ = 0;
|
||||
nextMapDiscard_ = true;
|
||||
}
|
||||
|
||||
uint8_t *BeginPush(ID3D11DeviceContext *context, int &offset, size_t size) {
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
context->Map(buffer_, 0, nextMapDiscard_ ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
nextMapDiscard_ = false;
|
||||
offset = (int)pos_;
|
||||
uint8_t *retval = (uint8_t *)map.pData + pos_;
|
||||
pos_ += size;
|
||||
return retval;
|
||||
}
|
||||
void EndPush(ID3D11DeviceContext *context) {
|
||||
context->Unmap(buffer_, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
ID3D11Buffer *buffer_ = nullptr;
|
||||
size_t pos_ = 0;
|
||||
bool nextMapDiscard_ = false;
|
||||
};
|
||||
|
||||
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut);
|
||||
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize);
|
||||
|
||||
class StockObjectsD3D11 {
|
||||
public:
|
||||
void Create(ID3D11Device *device);
|
||||
void Destroy();
|
||||
|
||||
ID3D11DepthStencilState *depthStencilDisabled;
|
||||
ID3D11DepthStencilState *depthDisabledStencilWrite;
|
||||
ID3D11BlendState *blendStateDisabledWithColorMask[16];
|
||||
ID3D11RasterizerState *rasterStateNoCull;
|
||||
ID3D11SamplerState *samplerPoint2DWrap;
|
||||
ID3D11SamplerState *samplerLinear2DWrap;
|
||||
};
|
||||
|
||||
extern StockObjectsD3D11 stockD3D11;
|
@ -0,0 +1,175 @@
|
||||
// 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 <map>
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/logging.h"
|
||||
#include "Common/Log.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "GPU/D3D11/TextureCacheD3D11.h"
|
||||
#include "GPU/D3D11/DepalettizeShaderD3D11.h"
|
||||
#include "GPU/D3D11/D3D11Util.h"
|
||||
#include "GPU/Common/DepalettizeShaderCommon.h"
|
||||
//#include "gfx/d3d9_shader.h"
|
||||
|
||||
static const int DEPAL_TEXTURE_OLD_AGE = 120;
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SHADERLOG
|
||||
#endif
|
||||
|
||||
static const char *depalVShaderHLSL =
|
||||
"struct VS_IN {\n"
|
||||
" float3 a_position : POSITION;\n"
|
||||
" float2 a_texcoord0 : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"struct VS_OUT {\n"
|
||||
" float4 Position : SV_Position;\n"
|
||||
" float2 Texcoord : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"VS_OUT main(VS_IN input) {\n"
|
||||
" VS_OUT output;\n"
|
||||
" output.Texcoord = input.a_texcoord0;\n"
|
||||
" output.Position = float4(input.a_position, 1.0);\n"
|
||||
" return output;\n"
|
||||
"}\n";
|
||||
|
||||
static const D3D11_INPUT_ELEMENT_DESC g_DepalVertexElements[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, },
|
||||
};
|
||||
|
||||
DepalShaderCacheD3D11::DepalShaderCacheD3D11(ID3D11Device *device, ID3D11DeviceContext *context)
|
||||
: device_(device), context_(context) {
|
||||
std::string errorMessage;
|
||||
std::vector<uint8_t> vsByteCode;
|
||||
vertexShader_ = CreateVertexShaderD3D11(device, depalVShaderHLSL, strlen(depalVShaderHLSL), &vsByteCode);
|
||||
device_->CreateInputLayout(g_DepalVertexElements, ARRAY_SIZE(g_DepalVertexElements), vsByteCode.data(), vsByteCode.size(), &inputLayout_);
|
||||
|
||||
D3D11_SAMPLER_DESC sampDesc{};
|
||||
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampDesc.Filter = D3D11_FILTER_MINIMUM_MIN_MAG_MIP_POINT;
|
||||
device_->CreateSamplerState(&sampDesc, &clutSampler);
|
||||
}
|
||||
|
||||
DepalShaderCacheD3D11::~DepalShaderCacheD3D11() {
|
||||
Clear();
|
||||
if (vertexShader_) {
|
||||
vertexShader_->Release();
|
||||
}
|
||||
clutSampler->Release();
|
||||
}
|
||||
|
||||
u32 DepalShaderCacheD3D11::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
|
||||
return (clutFormat & 0xFFFFFF) | (pixelFormat << 24);
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView *DepalShaderCacheD3D11::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) {
|
||||
const u32 realClutID = clutID ^ clutFormat;
|
||||
|
||||
auto oldtex = texCache_.find(realClutID);
|
||||
if (oldtex != texCache_.end()) {
|
||||
oldtex->second->lastFrame = gpuStats.numFlips;
|
||||
return oldtex->second->view;
|
||||
}
|
||||
|
||||
DXGI_FORMAT dstFmt = getClutDestFormatD3D11(clutFormat);
|
||||
int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512;
|
||||
|
||||
DepalTextureD3D11 *tex = new DepalTextureD3D11();
|
||||
// TODO: Look into 1D textures
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc{};
|
||||
desc.Width = texturePixels;
|
||||
desc.Height = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = dstFmt;
|
||||
desc.Usage = D3D11_USAGE_IMMUTABLE;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data{};
|
||||
data.pSysMem = rawClut;
|
||||
// Regardless of format, the CLUT should always be 1024 bytes.
|
||||
data.SysMemPitch = 1024;
|
||||
HRESULT hr = device_->CreateTexture2D(&desc, &data, &tex->texture);
|
||||
if (FAILED(hr)) {
|
||||
ERROR_LOG(G3D, "Failed to create D3D texture for depal");
|
||||
delete tex;
|
||||
return nullptr;
|
||||
}
|
||||
device_->CreateShaderResourceView(tex->texture, nullptr, &tex->view);
|
||||
tex->lastFrame = gpuStats.numFlips;
|
||||
texCache_[realClutID] = tex;
|
||||
return tex->view;
|
||||
}
|
||||
|
||||
void DepalShaderCacheD3D11::Clear() {
|
||||
for (auto shader = cache_.begin(); shader != cache_.end(); ++shader) {
|
||||
shader->second->pixelShader->Release();
|
||||
delete shader->second;
|
||||
}
|
||||
cache_.clear();
|
||||
|
||||
for (auto tex = texCache_.begin(); tex != texCache_.end(); ++tex) {
|
||||
delete tex->second;
|
||||
}
|
||||
texCache_.clear();
|
||||
}
|
||||
|
||||
void DepalShaderCacheD3D11::Decimate() {
|
||||
for (auto tex = texCache_.begin(); tex != texCache_.end();) {
|
||||
if (tex->second->lastFrame + DEPAL_TEXTURE_OLD_AGE < gpuStats.numFlips) {
|
||||
delete tex->second;
|
||||
texCache_.erase(tex++);
|
||||
} else {
|
||||
++tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11PixelShader *DepalShaderCacheD3D11::GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) {
|
||||
u32 id = GenerateShaderID(clutFormat, pixelFormat);
|
||||
|
||||
auto shader = cache_.find(id);
|
||||
if (shader != cache_.end()) {
|
||||
return shader->second->pixelShader;
|
||||
}
|
||||
|
||||
char *buffer = new char[2048];
|
||||
|
||||
GenerateDepalShader(buffer, pixelFormat, HLSL_D3D11);
|
||||
|
||||
ID3D11PixelShader *pshader = CreatePixelShaderD3D11(device_, buffer, strlen(buffer));
|
||||
|
||||
if (!pshader) {
|
||||
ERROR_LOG(G3D, "Failed to compile depal pixel shader");
|
||||
delete[] buffer;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DepalShaderD3D11 *depal = new DepalShaderD3D11();
|
||||
depal->pixelShader = pshader;
|
||||
|
||||
cache_[id] = depal;
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
return depal->pixelShader;
|
||||
}
|
@ -15,6 +15,55 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <d3d11.h>
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
|
||||
class DepalShaderCacheD3D11 {};
|
||||
class DepalShaderD3D11 {
|
||||
public:
|
||||
ID3D11PixelShader *pixelShader;
|
||||
};
|
||||
|
||||
class DepalTextureD3D11 {
|
||||
public:
|
||||
~DepalTextureD3D11() {
|
||||
if (texture)
|
||||
texture->Release();
|
||||
if (view)
|
||||
view->Release();
|
||||
}
|
||||
ID3D11Texture2D *texture;
|
||||
ID3D11ShaderResourceView *view;
|
||||
int lastFrame;
|
||||
};
|
||||
|
||||
// Caches both shaders and palette textures.
|
||||
class DepalShaderCacheD3D11 {
|
||||
public:
|
||||
DepalShaderCacheD3D11(ID3D11Device *device, ID3D11DeviceContext *context);
|
||||
~DepalShaderCacheD3D11();
|
||||
|
||||
// This also uploads the palette and binds the correct texture.
|
||||
ID3D11PixelShader *GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
|
||||
ID3D11VertexShader *GetDepalettizeVertexShader() { return vertexShader_; }
|
||||
ID3D11InputLayout *GetInputLayout() { return inputLayout_; }
|
||||
ID3D11ShaderResourceView *GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut);
|
||||
ID3D11SamplerState *GetClutSampler() { return clutSampler; }
|
||||
void Clear();
|
||||
void Decimate();
|
||||
|
||||
private:
|
||||
u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat);
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
ID3D11VertexShader *vertexShader_ = nullptr;
|
||||
ID3D11InputLayout *inputLayout_ = nullptr;
|
||||
ID3D11SamplerState *clutSampler = nullptr;
|
||||
|
||||
std::map<u32, DepalShaderD3D11 *> cache_;
|
||||
std::map<u32, DepalTextureD3D11 *> texCache_;
|
||||
};
|
||||
|
@ -0,0 +1,926 @@
|
||||
// Copyright (c) 2012- 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 "base/logging.h"
|
||||
#include "base/timeutil.h"
|
||||
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "Core/MemMap.h"
|
||||
#include "Core/Host.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
|
||||
#include "GPU/Math3D.h"
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
|
||||
#include "GPU/Common/TextureDecoder.h"
|
||||
#include "GPU/Common/SplineCommon.h"
|
||||
#include "GPU/Common/TransformCommon.h"
|
||||
#include "GPU/Common/VertexDecoderCommon.h"
|
||||
#include "GPU/Common/SoftwareTransformCommon.h"
|
||||
#include "GPU/D3D11/TextureCacheD3D11.h"
|
||||
#include "GPU/D3D11/DrawEngineD3D11.h"
|
||||
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
||||
#include "GPU/D3D11/GPU_D3D11.h"
|
||||
|
||||
const D3D11_PRIMITIVE_TOPOLOGY glprim[8] = {
|
||||
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
|
||||
D3D11_PRIMITIVE_TOPOLOGY_LINELIST,
|
||||
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
|
||||
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
|
||||
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
|
||||
D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, // Fans not supported
|
||||
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, // Need expansion - though we could do it with geom shaders in most cases
|
||||
};
|
||||
|
||||
enum {
|
||||
TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex)
|
||||
};
|
||||
|
||||
#define VERTEXCACHE_DECIMATION_INTERVAL 17
|
||||
|
||||
enum { VAI_KILL_AGE = 120, VAI_UNRELIABLE_KILL_AGE = 240, VAI_UNRELIABLE_KILL_MAX = 4 };
|
||||
|
||||
static const D3D11_INPUT_ELEMENT_DESC TransformedVertexElements[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
DrawEngineD3D11::DrawEngineD3D11(ID3D11Device *device, ID3D11DeviceContext *context)
|
||||
: device_(device),
|
||||
context_(context),
|
||||
decodedVerts_(0),
|
||||
prevPrim_(GE_PRIM_INVALID),
|
||||
lastVType_(-1),
|
||||
shaderManager_(0),
|
||||
textureCache_(0),
|
||||
framebufferManager_(0),
|
||||
numDrawCalls(0),
|
||||
vertexCountInDrawCalls(0),
|
||||
decodeCounter_(0),
|
||||
dcid_(0),
|
||||
fboTexNeedBind_(false),
|
||||
fboTexBound_(false) {
|
||||
decOptions_.expandAllWeightsToFloat = true;
|
||||
decOptions_.expand8BitNormalsToFloat = true;
|
||||
|
||||
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
|
||||
// Allocate nicely aligned memory. Maybe graphics drivers will
|
||||
// appreciate it.
|
||||
// All this is a LOT of memory, need to see if we can cut down somehow.
|
||||
decoded = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
|
||||
decIndex = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
|
||||
splineBuffer = (u8 *)AllocateMemoryPages(SPLINE_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
|
||||
transformed = (TransformedVertex *)AllocateMemoryPages(TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
|
||||
transformedExpanded = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
|
||||
|
||||
indexGen.Setup(decIndex);
|
||||
|
||||
InitDeviceObjects();
|
||||
|
||||
tessDataTransfer = new TessellationDataTransferD3D11();
|
||||
transformedVertexDecl_ = nullptr;
|
||||
}
|
||||
|
||||
DrawEngineD3D11::~DrawEngineD3D11() {
|
||||
if (transformedVertexDecl_) {
|
||||
transformedVertexDecl_->Release();
|
||||
}
|
||||
|
||||
DestroyDeviceObjects();
|
||||
FreeMemoryPages(decoded, DECODED_VERTEX_BUFFER_SIZE);
|
||||
FreeMemoryPages(decIndex, DECODED_INDEX_BUFFER_SIZE);
|
||||
FreeMemoryPages(splineBuffer, SPLINE_BUFFER_SIZE);
|
||||
FreeMemoryPages(transformed, TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
FreeMemoryPages(transformedExpanded, 3 * TRANSFORMED_VERTEX_BUFFER_SIZE);
|
||||
for (auto decl = vertexDeclMap_.begin(); decl != vertexDeclMap_.end(); ++decl) {
|
||||
if (decl->second) {
|
||||
decl->second->Release();
|
||||
}
|
||||
}
|
||||
|
||||
delete tessDataTransfer;
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::InitDeviceObjects() {
|
||||
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::DestroyDeviceObjects() {
|
||||
ClearTrackedVertexArrays();
|
||||
}
|
||||
|
||||
struct DeclTypeInfo {
|
||||
DXGI_FORMAT type;
|
||||
const char * name;
|
||||
};
|
||||
|
||||
static const DeclTypeInfo VComp[] = {
|
||||
{ DXGI_FORMAT_UNKNOWN, "NULL" }, // DEC_NONE,
|
||||
{ DXGI_FORMAT_R32_FLOAT, "D3DDECLTYPE_FLOAT1 " }, // DEC_FLOAT_1,
|
||||
{ DXGI_FORMAT_R32G32_FLOAT, "D3DDECLTYPE_FLOAT2 " }, // DEC_FLOAT_2,
|
||||
{ DXGI_FORMAT_R32G32B32_FLOAT, "D3DDECLTYPE_FLOAT3 " }, // DEC_FLOAT_3,
|
||||
{ DXGI_FORMAT_R32G32B32A32_FLOAT, "D3DDECLTYPE_FLOAT4 " }, // DEC_FLOAT_4,
|
||||
|
||||
{ DXGI_FORMAT_R8G8B8A8_SNORM, "UNUSED" }, // DEC_S8_3,
|
||||
|
||||
{ DXGI_FORMAT_R16G16B16A16_SNORM, "D3DDECLTYPE_SHORT4N " }, // DEC_S16_3,
|
||||
{ DXGI_FORMAT_R8G8B8A8_UNORM, "D3DDECLTYPE_UBYTE4N " }, // DEC_U8_1,
|
||||
{ DXGI_FORMAT_R8G8B8A8_UNORM, "D3DDECLTYPE_UBYTE4N " }, // DEC_U8_2,
|
||||
{ DXGI_FORMAT_R8G8B8A8_UNORM, "D3DDECLTYPE_UBYTE4N " }, // DEC_U8_3,
|
||||
{ DXGI_FORMAT_R8G8B8A8_UNORM, "D3DDECLTYPE_UBYTE4N " }, // DEC_U8_4,
|
||||
|
||||
{ DXGI_FORMAT_UNKNOWN, "UNUSED_DEC_U16_1" }, // DEC_U16_1,
|
||||
{ DXGI_FORMAT_UNKNOWN, "UNUSED_DEC_U16_2" }, // DEC_U16_2,
|
||||
{ DXGI_FORMAT_R16G16B16A16_UNORM ,"D3DDECLTYPE_USHORT4N "}, // DEC_U16_3,
|
||||
{ DXGI_FORMAT_R16G16B16A16_UNORM ,"D3DDECLTYPE_USHORT4N "}, // DEC_U16_4,
|
||||
{ DXGI_FORMAT_UNKNOWN, "UNUSED_DEC_U8A_2"}, // DEC_U8A_2,
|
||||
{ DXGI_FORMAT_UNKNOWN, "UNUSED_DEC_U16A_2" }, // DEC_U16A_2,
|
||||
};
|
||||
|
||||
static void VertexAttribSetup(D3D11_INPUT_ELEMENT_DESC * VertexElement, u8 fmt, u8 offset, const char *semantic, u8 semantic_index = 0) {
|
||||
memset(VertexElement, 0, sizeof(D3D11_INPUT_ELEMENT_DESC));
|
||||
VertexElement->AlignedByteOffset = offset;
|
||||
VertexElement->Format = VComp[fmt].type;
|
||||
VertexElement->SemanticName = semantic;
|
||||
VertexElement->SemanticIndex = semantic_index;
|
||||
}
|
||||
|
||||
ID3D11InputLayout *DrawEngineD3D11::SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt) {
|
||||
auto vertexDeclCached = vertexDeclMap_.find(pspFmt);
|
||||
|
||||
if (vertexDeclCached == vertexDeclMap_.end()) {
|
||||
D3D11_INPUT_ELEMENT_DESC VertexElements[8];
|
||||
D3D11_INPUT_ELEMENT_DESC *VertexElement = &VertexElements[0];
|
||||
|
||||
// Vertices Elements orders
|
||||
// WEIGHT
|
||||
if (decFmt.w0fmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.w0fmt, decFmt.w0off, "TEXCOORD", 1);
|
||||
VertexElement++;
|
||||
}
|
||||
|
||||
if (decFmt.w1fmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.w1fmt, decFmt.w1off, "TEXCOORD", 2);
|
||||
VertexElement++;
|
||||
}
|
||||
|
||||
// TC
|
||||
if (decFmt.uvfmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.uvfmt, decFmt.uvoff, "TEXCOORD", 0);
|
||||
VertexElement++;
|
||||
}
|
||||
|
||||
// COLOR
|
||||
if (decFmt.c0fmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.c0fmt, decFmt.c0off, "COLOR", 0);
|
||||
VertexElement++;
|
||||
}
|
||||
// Never used ?
|
||||
if (decFmt.c1fmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.c1fmt, decFmt.c1off, "COLOR", 1);
|
||||
VertexElement++;
|
||||
}
|
||||
|
||||
// NORMAL
|
||||
if (decFmt.nrmfmt != 0) {
|
||||
VertexAttribSetup(VertexElement, decFmt.nrmfmt, decFmt.nrmoff, "NORMAL", 0);
|
||||
VertexElement++;
|
||||
}
|
||||
|
||||
// POSITION
|
||||
// Always
|
||||
VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, "POSITION", 0);
|
||||
VertexElement++;
|
||||
|
||||
// Create declaration
|
||||
ID3D11InputLayout *inputLayout = nullptr;
|
||||
HRESULT hr = device_->CreateInputLayout(VertexElements, VertexElement - VertexElements, vshader->bytecode().data(), vshader->bytecode().size(), &inputLayout);
|
||||
if (FAILED(hr)) {
|
||||
ERROR_LOG(G3D, "Failed to create input layout!");
|
||||
inputLayout = nullptr;
|
||||
}
|
||||
|
||||
// Add it to map
|
||||
vertexDeclMap_[pspFmt] = inputLayout;
|
||||
return inputLayout;
|
||||
} else {
|
||||
// Set it from map
|
||||
return vertexDeclCached->second;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::SetupVertexDecoder(u32 vertType) {
|
||||
SetupVertexDecoderInternal(vertType);
|
||||
}
|
||||
|
||||
inline void DrawEngineD3D11::SetupVertexDecoderInternal(u32 vertType) {
|
||||
// As the decoder depends on the UVGenMode when we use UV prescale, we simply mash it
|
||||
// into the top of the verttype where there are unused bits.
|
||||
const u32 vertTypeID = (vertType & 0xFFFFFF) | (gstate.getUVGenMode() << 24);
|
||||
|
||||
// If vtype has changed, setup the vertex decoder.
|
||||
if (vertTypeID != lastVType_) {
|
||||
dec_ = GetVertexDecoder(vertTypeID);
|
||||
lastVType_ = vertTypeID;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead) {
|
||||
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS || vertexCountInDrawCalls + vertexCount > VERTEX_BUFFER_MAX)
|
||||
Flush();
|
||||
|
||||
// TODO: Is this the right thing to do?
|
||||
if (prim == GE_PRIM_KEEP_PREVIOUS) {
|
||||
prim = prevPrim_ != GE_PRIM_INVALID ? prevPrim_ : GE_PRIM_POINTS;
|
||||
} else {
|
||||
prevPrim_ = prim;
|
||||
}
|
||||
|
||||
SetupVertexDecoderInternal(vertType);
|
||||
|
||||
*bytesRead = vertexCount * dec_->VertexSize();
|
||||
|
||||
if ((vertexCount < 2 && prim > 0) || (vertexCount < 3 && prim > 2 && prim != GE_PRIM_RECTANGLES))
|
||||
return;
|
||||
|
||||
DeferredDrawCall &dc = drawCalls[numDrawCalls];
|
||||
dc.verts = verts;
|
||||
dc.inds = inds;
|
||||
dc.vertType = vertType;
|
||||
dc.indexType = (vertType & GE_VTYPE_IDX_MASK) >> GE_VTYPE_IDX_SHIFT;
|
||||
dc.prim = prim;
|
||||
dc.vertexCount = vertexCount;
|
||||
|
||||
u32 dhash = dcid_;
|
||||
dhash ^= (u32)(uintptr_t)verts;
|
||||
dhash = __rotl(dhash, 13);
|
||||
dhash ^= (u32)(uintptr_t)inds;
|
||||
dhash = __rotl(dhash, 13);
|
||||
dhash ^= (u32)vertType;
|
||||
dhash = __rotl(dhash, 13);
|
||||
dhash ^= (u32)vertexCount;
|
||||
dhash = __rotl(dhash, 13);
|
||||
dhash ^= (u32)prim;
|
||||
dcid_ = dhash;
|
||||
|
||||
if (inds) {
|
||||
GetIndexBounds(inds, vertexCount, vertType, &dc.indexLowerBound, &dc.indexUpperBound);
|
||||
} else {
|
||||
dc.indexLowerBound = 0;
|
||||
dc.indexUpperBound = vertexCount - 1;
|
||||
}
|
||||
|
||||
uvScale[numDrawCalls] = gstate_c.uv;
|
||||
|
||||
numDrawCalls++;
|
||||
vertexCountInDrawCalls += vertexCount;
|
||||
|
||||
if (g_Config.bSoftwareSkinning && (vertType & GE_VTYPE_WEIGHT_MASK)) {
|
||||
DecodeVertsStep();
|
||||
decodeCounter_++;
|
||||
}
|
||||
|
||||
if (prim == GE_PRIM_RECTANGLES && (gstate.getTextureAddress(0) & 0x3FFFFFFF) == (gstate.getFrameBufAddress() & 0x3FFFFFFF)) {
|
||||
// Rendertarget == texture?
|
||||
if (!g_Config.bDisableSlowFramebufEffects) {
|
||||
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
||||
Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::DecodeVerts() {
|
||||
const UVScale origUV = gstate_c.uv;
|
||||
for (; decodeCounter_ < numDrawCalls; decodeCounter_++) {
|
||||
gstate_c.uv = uvScale[decodeCounter_];
|
||||
DecodeVertsStep();
|
||||
}
|
||||
gstate_c.uv = origUV;
|
||||
|
||||
// Sanity check
|
||||
if (indexGen.Prim() < 0) {
|
||||
ERROR_LOG_REPORT(G3D, "DecodeVerts: Failed to deduce prim: %i", indexGen.Prim());
|
||||
// Force to points (0)
|
||||
indexGen.AddPrim(GE_PRIM_POINTS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::DecodeVertsStep() {
|
||||
const int i = decodeCounter_;
|
||||
|
||||
const DeferredDrawCall &dc = drawCalls[i];
|
||||
|
||||
indexGen.SetIndex(decodedVerts_);
|
||||
int indexLowerBound = dc.indexLowerBound, indexUpperBound = dc.indexUpperBound;
|
||||
|
||||
u32 indexType = dc.indexType;
|
||||
void *inds = dc.inds;
|
||||
if (indexType == GE_VTYPE_IDX_NONE >> GE_VTYPE_IDX_SHIFT) {
|
||||
// Decode the verts and apply morphing. Simple.
|
||||
dec_->DecodeVerts(decoded + decodedVerts_ * (int)dec_->GetDecVtxFmt().stride,
|
||||
dc.verts, indexLowerBound, indexUpperBound);
|
||||
decodedVerts_ += indexUpperBound - indexLowerBound + 1;
|
||||
indexGen.AddPrim(dc.prim, dc.vertexCount);
|
||||
} else {
|
||||
// It's fairly common that games issue long sequences of PRIM calls, with differing
|
||||
// inds pointer but the same base vertex pointer. We'd like to reuse vertices between
|
||||
// these as much as possible, so we make sure here to combine as many as possible
|
||||
// into one nice big drawcall, sharing data.
|
||||
|
||||
// 1. Look ahead to find the max index, only looking as "matching" drawcalls.
|
||||
// Expand the lower and upper bounds as we go.
|
||||
int lastMatch = i;
|
||||
const int total = numDrawCalls;
|
||||
for (int j = i + 1; j < total; ++j) {
|
||||
if (drawCalls[j].verts != dc.verts)
|
||||
break;
|
||||
if (memcmp(&uvScale[j], &uvScale[i], sizeof(uvScale[0])) != 0)
|
||||
break;
|
||||
|
||||
indexLowerBound = std::min(indexLowerBound, (int)drawCalls[j].indexLowerBound);
|
||||
indexUpperBound = std::max(indexUpperBound, (int)drawCalls[j].indexUpperBound);
|
||||
lastMatch = j;
|
||||
}
|
||||
|
||||
// 2. Loop through the drawcalls, translating indices as we go.
|
||||
switch (indexType) {
|
||||
case GE_VTYPE_IDX_8BIT >> GE_VTYPE_IDX_SHIFT:
|
||||
for (int j = i; j <= lastMatch; j++) {
|
||||
indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u8 *)drawCalls[j].inds, indexLowerBound);
|
||||
}
|
||||
break;
|
||||
case GE_VTYPE_IDX_16BIT >> GE_VTYPE_IDX_SHIFT:
|
||||
for (int j = i; j <= lastMatch; j++) {
|
||||
indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u16_le *)drawCalls[j].inds, indexLowerBound);
|
||||
}
|
||||
break;
|
||||
case GE_VTYPE_IDX_32BIT >> GE_VTYPE_IDX_SHIFT:
|
||||
for (int j = i; j <= lastMatch; j++) {
|
||||
indexGen.TranslatePrim(drawCalls[j].prim, drawCalls[j].vertexCount, (const u32_le *)drawCalls[j].inds, indexLowerBound);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const int vertexCount = indexUpperBound - indexLowerBound + 1;
|
||||
|
||||
// This check is a workaround for Pangya Fantasy Golf, which sends bogus index data when switching items in "My Room" sometimes.
|
||||
if (decodedVerts_ + vertexCount > VERTEX_BUFFER_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Decode that range of vertex data.
|
||||
dec_->DecodeVerts(decoded + decodedVerts_ * (int)dec_->GetDecVtxFmt().stride,
|
||||
dc.verts, indexLowerBound, indexUpperBound);
|
||||
decodedVerts_ += vertexCount;
|
||||
|
||||
// 4. Advance indexgen vertex counter.
|
||||
indexGen.Advance(vertexCount);
|
||||
decodeCounter_ = lastMatch;
|
||||
}
|
||||
}
|
||||
|
||||
inline u32 ComputeMiniHashRange(const void *ptr, size_t sz) {
|
||||
// Switch to u32 units.
|
||||
const u32 *p = (const u32 *)ptr;
|
||||
sz >>= 2;
|
||||
|
||||
if (sz > 100) {
|
||||
size_t step = sz / 4;
|
||||
u32 hash = 0;
|
||||
for (size_t i = 0; i < sz; i += step) {
|
||||
hash += DoReliableHash32(p + i, 100, 0x3A44B9C4);
|
||||
}
|
||||
return hash;
|
||||
} else {
|
||||
return p[0] + p[sz - 1];
|
||||
}
|
||||
}
|
||||
|
||||
u32 DrawEngineD3D11::ComputeMiniHash() {
|
||||
u32 fullhash = 0;
|
||||
const int vertexSize = dec_->GetDecVtxFmt().stride;
|
||||
const int indexSize = IndexSize(dec_->VertexType());
|
||||
|
||||
int step;
|
||||
if (numDrawCalls < 3) {
|
||||
step = 1;
|
||||
} else if (numDrawCalls < 8) {
|
||||
step = 4;
|
||||
} else {
|
||||
step = numDrawCalls / 8;
|
||||
}
|
||||
for (int i = 0; i < numDrawCalls; i += step) {
|
||||
const DeferredDrawCall &dc = drawCalls[i];
|
||||
if (!dc.inds) {
|
||||
fullhash += ComputeMiniHashRange(dc.verts, vertexSize * dc.vertexCount);
|
||||
} else {
|
||||
int indexLowerBound = dc.indexLowerBound, indexUpperBound = dc.indexUpperBound;
|
||||
fullhash += ComputeMiniHashRange((const u8 *)dc.verts + vertexSize * indexLowerBound, vertexSize * (indexUpperBound - indexLowerBound));
|
||||
fullhash += ComputeMiniHashRange(dc.inds, indexSize * dc.vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
return fullhash;
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::MarkUnreliable(VertexArrayInfoD3D11 *vai) {
|
||||
vai->status = VertexArrayInfoD3D11::VAI_UNRELIABLE;
|
||||
if (vai->vbo) {
|
||||
vai->vbo->Release();
|
||||
vai->vbo = nullptr;
|
||||
}
|
||||
if (vai->ebo) {
|
||||
vai->ebo->Release();
|
||||
vai->ebo = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ReliableHashType DrawEngineD3D11::ComputeHash() {
|
||||
ReliableHashType fullhash = 0;
|
||||
const int vertexSize = dec_->GetDecVtxFmt().stride;
|
||||
const int indexSize = IndexSize(dec_->VertexType());
|
||||
|
||||
// TODO: Add some caps both for numDrawCalls and num verts to check?
|
||||
// It is really very expensive to check all the vertex data so often.
|
||||
for (int i = 0; i < numDrawCalls; i++) {
|
||||
const DeferredDrawCall &dc = drawCalls[i];
|
||||
if (!dc.inds) {
|
||||
fullhash += DoReliableHash((const char *)dc.verts, vertexSize * dc.vertexCount, 0x1DE8CAC4);
|
||||
} else {
|
||||
int indexLowerBound = dc.indexLowerBound, indexUpperBound = dc.indexUpperBound;
|
||||
int j = i + 1;
|
||||
int lastMatch = i;
|
||||
while (j < numDrawCalls) {
|
||||
if (drawCalls[j].verts != dc.verts)
|
||||
break;
|
||||
indexLowerBound = std::min(indexLowerBound, (int)dc.indexLowerBound);
|
||||
indexUpperBound = std::max(indexUpperBound, (int)dc.indexUpperBound);
|
||||
lastMatch = j;
|
||||
j++;
|
||||
}
|
||||
// This could get seriously expensive with sparse indices. Need to combine hashing ranges the same way
|
||||
// we do when drawing.
|
||||
fullhash += DoReliableHash((const char *)dc.verts + vertexSize * indexLowerBound,
|
||||
vertexSize * (indexUpperBound - indexLowerBound), 0x029F3EE1);
|
||||
// Hm, we will miss some indices when combining above, but meh, it should be fine.
|
||||
fullhash += DoReliableHash((const char *)dc.inds, indexSize * dc.vertexCount, 0x955FD1CA);
|
||||
i = lastMatch;
|
||||
}
|
||||
}
|
||||
if (uvScale) {
|
||||
fullhash += DoReliableHash(&uvScale[0], sizeof(uvScale[0]) * numDrawCalls, 0x0123e658);
|
||||
}
|
||||
|
||||
return fullhash;
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::ClearTrackedVertexArrays() {
|
||||
for (auto vai = vai_.begin(); vai != vai_.end(); vai++) {
|
||||
delete vai->second;
|
||||
}
|
||||
vai_.clear();
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::DecimateTrackedVertexArrays() {
|
||||
if (--decimationCounter_ <= 0) {
|
||||
decimationCounter_ = VERTEXCACHE_DECIMATION_INTERVAL;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
const int threshold = gpuStats.numFlips - VAI_KILL_AGE;
|
||||
const int unreliableThreshold = gpuStats.numFlips - VAI_UNRELIABLE_KILL_AGE;
|
||||
int unreliableLeft = VAI_UNRELIABLE_KILL_MAX;
|
||||
for (auto iter = vai_.begin(); iter != vai_.end(); ) {
|
||||
bool kill;
|
||||
if (iter->second->status == VertexArrayInfoD3D11::VAI_UNRELIABLE) {
|
||||
// We limit killing unreliable so we don't rehash too often.
|
||||
kill = iter->second->lastFrame < unreliableThreshold && --unreliableLeft >= 0;
|
||||
} else {
|
||||
kill = iter->second->lastFrame < threshold;
|
||||
}
|
||||
if (kill) {
|
||||
delete iter->second;
|
||||
vai_.erase(iter++);
|
||||
} else {
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable if you want to see vertex decoders in the log output. Need a better way.
|
||||
#if 0
|
||||
char buffer[16384];
|
||||
for (std::map<u32, VertexDecoder*>::iterator dec = decoderMap_.begin(); dec != decoderMap_.end(); ++dec) {
|
||||
char *ptr = buffer;
|
||||
ptr += dec->second->ToString(ptr);
|
||||
// *ptr++ = '\n';
|
||||
NOTICE_LOG(G3D, buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
VertexArrayInfoD3D11::~VertexArrayInfoD3D11() {
|
||||
if (vbo) {
|
||||
vbo->Release();
|
||||
}
|
||||
if (ebo) {
|
||||
ebo->Release();
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t SwapRB(uint32_t c) {
|
||||
return (c & 0xFF00FF00) | ((c >> 16) & 0xFF) | ((c << 16) & 0xFF0000);
|
||||
}
|
||||
|
||||
// The inline wrapper in the header checks for numDrawCalls == 0
|
||||
void DrawEngineD3D11::DoFlush() {
|
||||
gpuStats.numFlushes++;
|
||||
gpuStats.numTrackedVertexArrays = (int)vai_.size();
|
||||
|
||||
// This is not done on every drawcall, we should collect vertex data
|
||||
// until critical state changes. That's when we draw (flush).
|
||||
|
||||
GEPrimitiveType prim = prevPrim_;
|
||||
ApplyDrawState(prim);
|
||||
|
||||
bool useHWTransform = CanUseHardwareTransform(prim);
|
||||
|
||||
if (useHWTransform) {
|
||||
ID3D11Buffer *vb_ = nullptr;
|
||||
ID3D11Buffer *ib_ = nullptr;
|
||||
|
||||
int vertexCount = 0;
|
||||
int maxIndex = 0;
|
||||
bool useElements = true;
|
||||
|
||||
// Cannot cache vertex data with morph enabled.
|
||||
bool useCache = g_Config.bVertexCache && !(lastVType_ & GE_VTYPE_MORPHCOUNT_MASK);
|
||||
// Also avoid caching when software skinning.
|
||||
if (g_Config.bSoftwareSkinning && (lastVType_ & GE_VTYPE_WEIGHT_MASK))
|
||||
useCache = false;
|
||||
|
||||
if (useCache) {
|
||||
u32 id = dcid_ ^ gstate.getUVGenMode(); // This can have an effect on which UV decoder we need to use! And hence what the decoded data will look like. See #9263
|
||||
auto iter = vai_.find(id);
|
||||
VertexArrayInfoD3D11 *vai;
|
||||
if (iter != vai_.end()) {
|
||||
// We've seen this before. Could have been a cached draw.
|
||||
vai = iter->second;
|
||||
} else {
|
||||
vai = new VertexArrayInfoD3D11();
|
||||
vai_[id] = vai;
|
||||
}
|
||||
|
||||
switch (vai->status) {
|
||||
case VertexArrayInfoD3D11::VAI_NEW:
|
||||
{
|
||||
// Haven't seen this one before.
|
||||
ReliableHashType dataHash = ComputeHash();
|
||||
vai->hash = dataHash;
|
||||
vai->minihash = ComputeMiniHash();
|
||||
vai->status = VertexArrayInfoD3D11::VAI_HASHING;
|
||||
vai->drawsUntilNextFullHash = 0;
|
||||
DecodeVerts(); // writes to indexGen
|
||||
vai->numVerts = indexGen.VertexCount();
|
||||
vai->prim = indexGen.Prim();
|
||||
vai->maxIndex = indexGen.MaxIndex();
|
||||
vai->flags = gstate_c.vertexFullAlpha ? VAI11_FLAG_VERTEXFULLALPHA : 0;
|
||||
|
||||
goto rotateVBO;
|
||||
}
|
||||
|
||||
// Hashing - still gaining confidence about the buffer.
|
||||
// But if we get this far it's likely to be worth creating a vertex buffer.
|
||||
case VertexArrayInfoD3D11::VAI_HASHING:
|
||||
{
|
||||
vai->numDraws++;
|
||||
if (vai->lastFrame != gpuStats.numFlips) {
|
||||
vai->numFrames++;
|
||||
}
|
||||
if (vai->drawsUntilNextFullHash == 0) {
|
||||
// Let's try to skip a full hash if mini would fail.
|
||||
const u32 newMiniHash = ComputeMiniHash();
|
||||
ReliableHashType newHash = vai->hash;
|
||||
if (newMiniHash == vai->minihash) {
|
||||
newHash = ComputeHash();
|
||||
}
|
||||
if (newMiniHash != vai->minihash || newHash != vai->hash) {
|
||||
MarkUnreliable(vai);
|
||||
DecodeVerts();
|
||||
goto rotateVBO;
|
||||
}
|
||||
if (vai->numVerts > 64) {
|
||||
// exponential backoff up to 16 draws, then every 24
|
||||
vai->drawsUntilNextFullHash = std::min(24, vai->numFrames);
|
||||
} else {
|
||||
// Lower numbers seem much more likely to change.
|
||||
vai->drawsUntilNextFullHash = 0;
|
||||
}
|
||||
// TODO: tweak
|
||||
//if (vai->numFrames > 1000) {
|
||||
// vai->status = VertexArrayInfo::VAI_RELIABLE;
|
||||
//}
|
||||
} else {
|
||||
vai->drawsUntilNextFullHash--;
|
||||
u32 newMiniHash = ComputeMiniHash();
|
||||
if (newMiniHash != vai->minihash) {
|
||||
MarkUnreliable(vai);
|
||||
DecodeVerts();
|
||||
goto rotateVBO;
|
||||
}
|
||||
}
|
||||
|
||||
if (vai->vbo == 0) {
|
||||
DecodeVerts();
|
||||
vai->numVerts = indexGen.VertexCount();
|
||||
vai->prim = indexGen.Prim();
|
||||
vai->maxIndex = indexGen.MaxIndex();
|
||||
vai->flags = gstate_c.vertexFullAlpha ? VAI11_FLAG_VERTEXFULLALPHA : 0;
|
||||
useElements = !indexGen.SeenOnlyPurePrims();
|
||||
if (!useElements && indexGen.PureCount()) {
|
||||
vai->numVerts = indexGen.PureCount();
|
||||
}
|
||||
|
||||
_dbg_assert_msg_(G3D, gstate_c.vertBounds.minV >= gstate_c.vertBounds.maxV, "Should not have checked UVs when caching.");
|
||||
|
||||
// TODO: Combine these two into one buffer?
|
||||
void * pVb;
|
||||
u32 size = dec_->GetDecVtxFmt().stride * indexGen.MaxIndex();
|
||||
D3D11_BUFFER_DESC desc{ size, D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, D3D11_CPU_ACCESS_WRITE };
|
||||
D3D11_SUBRESOURCE_DATA data{ decoded };
|
||||
device_->CreateBuffer(&desc, &data, &vai->vbo);
|
||||
if (useElements) {
|
||||
void * pIb;
|
||||
u32 size = sizeof(short) * indexGen.VertexCount();
|
||||
D3D11_BUFFER_DESC desc{ size, D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, D3D11_CPU_ACCESS_WRITE };
|
||||
D3D11_SUBRESOURCE_DATA data{ decoded };
|
||||
device_->CreateBuffer(&desc, &data, &vai->ebo);
|
||||
} else {
|
||||
vai->ebo = 0;
|
||||
}
|
||||
} else {
|
||||
gpuStats.numCachedDrawCalls++;
|
||||
useElements = vai->ebo ? true : false;
|
||||
gpuStats.numCachedVertsDrawn += vai->numVerts;
|
||||
gstate_c.vertexFullAlpha = vai->flags & VAI11_FLAG_VERTEXFULLALPHA;
|
||||
}
|
||||
vb_ = vai->vbo;
|
||||
ib_ = vai->ebo;
|
||||
vertexCount = vai->numVerts;
|
||||
maxIndex = vai->maxIndex;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
break;
|
||||
}
|
||||
|
||||
// Reliable - we don't even bother hashing anymore. Right now we don't go here until after a very long time.
|
||||
case VertexArrayInfoD3D11::VAI_RELIABLE:
|
||||
{
|
||||
vai->numDraws++;
|
||||
if (vai->lastFrame != gpuStats.numFlips) {
|
||||
vai->numFrames++;
|
||||
}
|
||||
gpuStats.numCachedDrawCalls++;
|
||||
gpuStats.numCachedVertsDrawn += vai->numVerts;
|
||||
vb_ = vai->vbo;
|
||||
ib_ = vai->ebo;
|
||||
|
||||
vertexCount = vai->numVerts;
|
||||
|
||||
maxIndex = vai->maxIndex;
|
||||
prim = static_cast<GEPrimitiveType>(vai->prim);
|
||||
|
||||
gstate_c.vertexFullAlpha = vai->flags & VAI11_FLAG_VERTEXFULLALPHA;
|
||||
break;
|
||||
}
|
||||
|
||||
case VertexArrayInfoD3D11::VAI_UNRELIABLE:
|
||||
{
|
||||
vai->numDraws++;
|
||||
if (vai->lastFrame != gpuStats.numFlips) {
|
||||
vai->numFrames++;
|
||||
}
|
||||
DecodeVerts();
|
||||
goto rotateVBO;
|
||||
}
|
||||
}
|
||||
|
||||
vai->lastFrame = gpuStats.numFlips;
|
||||
} else {
|
||||
DecodeVerts();
|
||||
rotateVBO:
|
||||
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
|
||||
useElements = !indexGen.SeenOnlyPurePrims();
|
||||
vertexCount = indexGen.VertexCount();
|
||||
maxIndex = indexGen.MaxIndex();
|
||||
if (!useElements && indexGen.PureCount()) {
|
||||
vertexCount = indexGen.PureCount();
|
||||
}
|
||||
prim = indexGen.Prim();
|
||||
}
|
||||
|
||||
VERBOSE_LOG(G3D, "Flush prim %i! %i verts in one go", prim, vertexCount);
|
||||
bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
|
||||
if (gstate.isModeThrough()) {
|
||||
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && (hasColor || gstate.getMaterialAmbientA() == 255);
|
||||
} else {
|
||||
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255);
|
||||
}
|
||||
|
||||
ApplyDrawStateLate(false, 0);
|
||||
|
||||
D3D11VertexShader *vshader;
|
||||
D3D11FragmentShader *fshader;
|
||||
shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, useHWTransform);
|
||||
ID3D11InputLayout *pHardwareVertexDecl = SetupDecFmtForDraw(vshader, dec_->GetDecVtxFmt(), dec_->VertexType());
|
||||
|
||||
context_->IASetInputLayout(pHardwareVertexDecl);
|
||||
if (!vb_) {
|
||||
// Push!
|
||||
int vOffset;
|
||||
// pushVerts_->BeginPush(context_, offset, )
|
||||
if (useElements) {
|
||||
// context_->DrawIndexedPrimitiveUP(glprim[prim], 0, maxIndex + 1, D3DPrimCount(glprim[prim], vertexCount), decIndex, D3DFMT_INDEX16, decoded, dec_->GetDecVtxFmt().stride);
|
||||
} else {
|
||||
// context_->DrawPrimitiveUP(glprim[prim], D3DPrimCount(glprim[prim], vertexCount), decoded, dec_->GetDecVtxFmt().stride);
|
||||
}
|
||||
} else {
|
||||
UINT stride = dec_->GetDecVtxFmt().stride;
|
||||
UINT offset = 0;
|
||||
context_->IASetVertexBuffers(0, 1, &vb_, &stride, &offset);
|
||||
context_->IASetPrimitiveTopology(glprim[prim]);
|
||||
if (useElements) {
|
||||
context_->IASetIndexBuffer(ib_, DXGI_FORMAT_R16_UINT, 0);
|
||||
context_->DrawIndexed(vertexCount, 0, 0);
|
||||
} else {
|
||||
context_->Draw(vertexCount, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DecodeVerts();
|
||||
bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
|
||||
if (gstate.isModeThrough()) {
|
||||
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && (hasColor || gstate.getMaterialAmbientA() == 255);
|
||||
} else {
|
||||
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255);
|
||||
}
|
||||
|
||||
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
|
||||
prim = indexGen.Prim();
|
||||
// Undo the strip optimization, not supported by the SW code yet.
|
||||
if (prim == GE_PRIM_TRIANGLE_STRIP)
|
||||
prim = GE_PRIM_TRIANGLES;
|
||||
VERBOSE_LOG(G3D, "Flush prim %i SW! %i verts in one go", prim, indexGen.VertexCount());
|
||||
|
||||
int numTrans = 0;
|
||||
bool drawIndexed = false;
|
||||
u16 *inds = decIndex;
|
||||
TransformedVertex *drawBuffer = NULL;
|
||||
SoftwareTransformResult result;
|
||||
memset(&result, 0, sizeof(result));
|
||||
|
||||
SoftwareTransformParams params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.decoded = decoded;
|
||||
params.transformed = transformed;
|
||||
params.transformedExpanded = transformedExpanded;
|
||||
params.fbman = framebufferManager_;
|
||||
params.texCache = textureCache_;
|
||||
params.allowSeparateAlphaClear = true;
|
||||
|
||||
int maxIndex = indexGen.MaxIndex();
|
||||
SoftwareTransform(
|
||||
prim, indexGen.VertexCount(),
|
||||
dec_->VertexType(), inds, GE_VTYPE_IDX_16BIT, dec_->GetDecVtxFmt(),
|
||||
maxIndex, drawBuffer, numTrans, drawIndexed, ¶ms, &result);
|
||||
|
||||
ApplyDrawStateLate(result.setStencil, result.stencilValue);
|
||||
|
||||
D3D11VertexShader *vshader;
|
||||
D3D11FragmentShader *fshader;
|
||||
shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, false);
|
||||
|
||||
// TODO: Implement clear properly when possible. Colormask no longer applies to clearing unfortunately (though wonder if it ever did in hardware..) which makes it trickier.
|
||||
if (result.action == SW_DRAW_PRIMITIVES || result.action == SW_CLEAR) {
|
||||
// TODO: Add a post-transform cache here for multi-RECTANGLES only.
|
||||
// Might help for text drawing.
|
||||
|
||||
// these spam the gDebugger log.
|
||||
const int vertexSize = sizeof(transformed[0]);
|
||||
|
||||
// This is so weird. Why do we need the shader bytecode to create an input layout??
|
||||
// Well, at least all vshaders for pretransformed data will have one single layout so we can share it.
|
||||
if (!transformedVertexDecl_) {
|
||||
device_->CreateInputLayout(TransformedVertexElements, 4, vshader->bytecode().data(), vshader->bytecode().size(), &transformedVertexDecl_);
|
||||
}
|
||||
|
||||
context_->IASetInputLayout(transformedVertexDecl_);
|
||||
ID3D11Buffer *pushVertData = pushVerts_->Buf();
|
||||
ID3D11Buffer *pushIndexData = pushInds_->Buf();
|
||||
UINT strides = sizeof(TransformedVertex);
|
||||
context_->IASetVertexBuffers(0, 1, &pushVertData, &strides, nullptr);
|
||||
if (drawIndexed) {
|
||||
context_->IASetIndexBuffer(pushIndexData, DXGI_FORMAT_R16_UINT, 0);
|
||||
context_->DrawIndexed(numTrans, 0, 0);
|
||||
// context_->DrawIndexedPrimitiveUP(glprim[prim], 0, maxIndex, numTrans, inds, DXGI_FORMAT_R16_UINT, drawBuffer, sizeof(TransformedVertex));
|
||||
} else {
|
||||
// context_->DrawPrimitiveUP(glprim[prim], D3DPrimCount(glprim[prim], numTrans), drawBuffer, sizeof(TransformedVertex));
|
||||
context_->Draw(numTrans, 0);
|
||||
}
|
||||
} /*else if (result.action == SW_CLEAR) {
|
||||
u32 clearColor = result.color;
|
||||
float clearDepth = result.depth;
|
||||
|
||||
UINT depthClearFlag = 0;
|
||||
|
||||
bool clearColor = gstate.isClearModeColorMask();
|
||||
if (gstate.isClearModeAlphaMask()) depthClearFlag |= D3D11_CLEAR_STENCIL;
|
||||
if (gstate.isClearModeDepthMask()) depthClearFlag |= D3D11_CLEAR_DEPTH;
|
||||
|
||||
if (clearColor) {
|
||||
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);
|
||||
}
|
||||
if (depthClearFlag & D3D11_CLEAR_DEPTH) {
|
||||
framebufferManager_->SetDepthUpdated();
|
||||
}
|
||||
|
||||
int colorMask = 0;
|
||||
if (clearColor)
|
||||
colorMask |= 7;
|
||||
if (depthClearFlag & D3D11_CLEAR_STENCIL) {
|
||||
colorMask |= 8;
|
||||
}
|
||||
context_->OMSetBlendState(stockD3D11.blendStateDisabledWithColorMask[colorMask], nullptr, 0xFFFFFFFF);
|
||||
|
||||
device_->Clear(0, NULL, mask, SwapRB(clearColor), clearDepth, clearColor >> 24);
|
||||
|
||||
int scissorX1 = gstate.getScissorX1();
|
||||
int scissorY1 = gstate.getScissorY1();
|
||||
int scissorX2 = gstate.getScissorX2() + 1;
|
||||
int scissorY2 = gstate.getScissorY2() + 1;
|
||||
framebufferManager_->SetSafeSize(scissorX2, scissorY2);
|
||||
|
||||
if (g_Config.bBlockTransferGPU && (gstate_c.featureFlags & GPU_USE_CLEAR_RAM_HACK) && gstate.isClearModeColorMask() && (gstate.isClearModeAlphaMask() || gstate.FrameBufFormat() == GE_FORMAT_565)) {
|
||||
ApplyClearToMemory(scissorX1, scissorY1, scissorX2, scissorY2, clearColor);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
gpuStats.numDrawCalls += numDrawCalls;
|
||||
gpuStats.numVertsSubmitted += vertexCountInDrawCalls;
|
||||
|
||||
indexGen.Reset();
|
||||
decodedVerts_ = 0;
|
||||
numDrawCalls = 0;
|
||||
vertexCountInDrawCalls = 0;
|
||||
decodeCounter_ = 0;
|
||||
dcid_ = 0;
|
||||
prevPrim_ = GE_PRIM_INVALID;
|
||||
gstate_c.vertexFullAlpha = true;
|
||||
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);
|
||||
|
||||
// Now seems as good a time as any to reset the min/max coords, which we may examine later.
|
||||
gstate_c.vertBounds.minU = 512;
|
||||
gstate_c.vertBounds.minV = 512;
|
||||
gstate_c.vertBounds.maxU = 0;
|
||||
gstate_c.vertBounds.maxV = 0;
|
||||
|
||||
host->GPUNotifyDraw();
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::Resized() {
|
||||
decJitCache_->Clear();
|
||||
lastVType_ = -1;
|
||||
dec_ = NULL;
|
||||
for (auto iter = decoderMap_.begin(); iter != decoderMap_.end(); iter++) {
|
||||
delete iter->second;
|
||||
}
|
||||
decoderMap_.clear();
|
||||
}
|
||||
|
||||
bool DrawEngineD3D11::IsCodePtrVertexDecoder(const u8 *ptr) const {
|
||||
return decJitCache_->IsInSpace(ptr);
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::TessellationDataTransferD3D11::SendDataToShader(const float * pos, const float * tex, const float * col, int size, bool hasColor, bool hasTexCoords)
|
||||
{
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2017- PPSSPP Project.
|
||||
// Copyright (c) 2012- 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
|
||||
@ -17,7 +17,229 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class DrawEngineD3D11 {
|
||||
#include <unordered_map>
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/Common/GPUDebugInterface.h"
|
||||
#include "GPU/Common/IndexGenerator.h"
|
||||
#include "GPU/Common/VertexDecoderCommon.h"
|
||||
#include "GPU/Common/DrawEngineCommon.h"
|
||||
#include "GPU/Common/GPUStateUtils.h"
|
||||
#include "GPU/D3D11/FragmentShaderGeneratorD3D11.h"
|
||||
#include "GPU/D3D11/D3D11Util.h"
|
||||
|
||||
struct DecVtxFormat;
|
||||
struct UVScale;
|
||||
|
||||
class D3D11VertexShader;
|
||||
class ShaderManagerD3D11;
|
||||
class TextureCacheD3D11;
|
||||
class FramebufferManagerD3D11;
|
||||
|
||||
// States transitions:
|
||||
// On creation: DRAWN_NEW
|
||||
// DRAWN_NEW -> DRAWN_HASHING
|
||||
// DRAWN_HASHING -> DRAWN_RELIABLE
|
||||
// DRAWN_HASHING -> DRAWN_UNRELIABLE
|
||||
// DRAWN_ONCE -> UNRELIABLE
|
||||
// DRAWN_RELIABLE -> DRAWN_SAFE
|
||||
// UNRELIABLE -> death
|
||||
// DRAWN_ONCE -> death
|
||||
// DRAWN_RELIABLE -> death
|
||||
|
||||
enum {
|
||||
VAI11_FLAG_VERTEXFULLALPHA = 1,
|
||||
};
|
||||
|
||||
// Avoiding the full include of TextureDecoder.h.
|
||||
#if (defined(_M_SSE) && defined(_M_X64)) || defined(ARM64)
|
||||
typedef u64 ReliableHashType;
|
||||
#else
|
||||
typedef u32 ReliableHashType;
|
||||
#endif
|
||||
|
||||
// Try to keep this POD.
|
||||
class VertexArrayInfoD3D11 {
|
||||
public:
|
||||
void Flush() {}
|
||||
};
|
||||
VertexArrayInfoD3D11() {
|
||||
status = VAI_NEW;
|
||||
vbo = 0;
|
||||
ebo = 0;
|
||||
prim = GE_PRIM_INVALID;
|
||||
numDraws = 0;
|
||||
numFrames = 0;
|
||||
lastFrame = gpuStats.numFlips;
|
||||
numVerts = 0;
|
||||
drawsUntilNextFullHash = 0;
|
||||
flags = 0;
|
||||
}
|
||||
~VertexArrayInfoD3D11();
|
||||
|
||||
enum Status {
|
||||
VAI_NEW,
|
||||
VAI_HASHING,
|
||||
VAI_RELIABLE, // cache, don't hash
|
||||
VAI_UNRELIABLE, // never cache
|
||||
};
|
||||
|
||||
ReliableHashType hash;
|
||||
u32 minihash;
|
||||
|
||||
Status status;
|
||||
|
||||
ID3D11Buffer *vbo;
|
||||
ID3D11Buffer *ebo;
|
||||
|
||||
// Precalculated parameter for drawRangeElements
|
||||
u16 numVerts;
|
||||
u16 maxIndex;
|
||||
s8 prim;
|
||||
|
||||
// ID information
|
||||
int numDraws;
|
||||
int numFrames;
|
||||
int lastFrame; // So that we can forget.
|
||||
u16 drawsUntilNextFullHash;
|
||||
u8 flags;
|
||||
};
|
||||
|
||||
// Handles transform, lighting and drawing.
|
||||
class DrawEngineD3D11 : public DrawEngineCommon {
|
||||
public:
|
||||
DrawEngineD3D11(ID3D11Device *device, ID3D11DeviceContext *context);
|
||||
virtual ~DrawEngineD3D11();
|
||||
|
||||
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead);
|
||||
|
||||
void SetShaderManager(ShaderManagerD3D11 *shaderManager) {
|
||||
shaderManager_ = shaderManager;
|
||||
}
|
||||
void SetTextureCache(TextureCacheD3D11 *textureCache) {
|
||||
textureCache_ = textureCache;
|
||||
}
|
||||
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager) {
|
||||
framebufferManager_ = fbManager;
|
||||
}
|
||||
void InitDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
void GLLost() {};
|
||||
|
||||
void Resized(); // TODO: Call
|
||||
|
||||
void DecimateTrackedVertexArrays();
|
||||
void ClearTrackedVertexArrays();
|
||||
|
||||
void SetupVertexDecoder(u32 vertType);
|
||||
void SetupVertexDecoderInternal(u32 vertType);
|
||||
|
||||
// So that this can be inlined
|
||||
void Flush() {
|
||||
if (!numDrawCalls)
|
||||
return;
|
||||
DoFlush();
|
||||
}
|
||||
|
||||
void FinishDeferred() {
|
||||
if (!numDrawCalls)
|
||||
return;
|
||||
DecodeVerts();
|
||||
}
|
||||
|
||||
bool IsCodePtrVertexDecoder(const u8 *ptr) const;
|
||||
|
||||
void DispatchFlush() override { Flush(); }
|
||||
void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead) override {
|
||||
SubmitPrim(verts, inds, prim, vertexCount, vertType, bytesRead);
|
||||
}
|
||||
|
||||
private:
|
||||
void DecodeVerts();
|
||||
void DecodeVertsStep();
|
||||
void DoFlush();
|
||||
|
||||
void ApplyDrawState(int prim);
|
||||
void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef);
|
||||
bool ApplyShaderBlending();
|
||||
void ResetShaderBlending();
|
||||
|
||||
ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
|
||||
|
||||
u32 ComputeMiniHash();
|
||||
ReliableHashType ComputeHash(); // Reads deferred vertex data.
|
||||
void MarkUnreliable(VertexArrayInfoD3D11 *vai);
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
// Defer all vertex decoding to a Flush, so that we can hash and cache the
|
||||
// generated buffers without having to redecode them every time.
|
||||
struct DeferredDrawCall {
|
||||
void *verts;
|
||||
void *inds;
|
||||
u32 vertType;
|
||||
u8 indexType;
|
||||
s8 prim;
|
||||
u32 vertexCount;
|
||||
u16 indexLowerBound;
|
||||
u16 indexUpperBound;
|
||||
};
|
||||
|
||||
// Vertex collector state
|
||||
IndexGenerator indexGen;
|
||||
int decodedVerts_;
|
||||
GEPrimitiveType prevPrim_;
|
||||
|
||||
u32 lastVType_;
|
||||
|
||||
TransformedVertex *transformed;
|
||||
TransformedVertex *transformedExpanded;
|
||||
|
||||
std::unordered_map<u32, VertexArrayInfoD3D11 *> vai_;
|
||||
std::unordered_map<u32, ID3D11InputLayout *> vertexDeclMap_;
|
||||
|
||||
// SimpleVertex
|
||||
ID3D11InputLayout *transformedVertexDecl_;
|
||||
|
||||
// Other
|
||||
ShaderManagerD3D11 *shaderManager_;
|
||||
TextureCacheD3D11 *textureCache_;
|
||||
FramebufferManagerD3D11 *framebufferManager_;
|
||||
|
||||
// Pushbuffers
|
||||
PushBufferD3D11 *pushVerts_;
|
||||
PushBufferD3D11 *pushInds_;
|
||||
|
||||
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
|
||||
|
||||
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
|
||||
int numDrawCalls;
|
||||
int vertexCountInDrawCalls;
|
||||
|
||||
int decimationCounter_;
|
||||
int decodeCounter_;
|
||||
u32 dcid_;
|
||||
|
||||
UVScale uvScale[MAX_DEFERRED_DRAW_CALLS];
|
||||
|
||||
bool fboTexNeedBind_;
|
||||
bool fboTexBound_;
|
||||
|
||||
// D3D11 state object caches
|
||||
std::map<uint32_t, ID3D11BlendState *> blendCache_;
|
||||
std::map<uint32_t, ID3D11DepthStencilState *> depthStencilCache_;
|
||||
std::map<uint32_t, ID3D11RasterizerState *> rasterCache_;
|
||||
|
||||
// Hardware tessellation
|
||||
class TessellationDataTransferD3D11 : public TessellationDataTransfer {
|
||||
private:
|
||||
int data_tex[3];
|
||||
public:
|
||||
TessellationDataTransferD3D11() : TessellationDataTransfer(), data_tex() {
|
||||
}
|
||||
~TessellationDataTransferD3D11() {
|
||||
}
|
||||
void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) override;
|
||||
};
|
||||
};
|
||||
|
@ -1,5 +1,24 @@
|
||||
// Copyright (c) 2017- 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/Common/ShaderCommon.h"
|
||||
#include "GPU/D3D11/FragmentShaderGeneratorD3D11.h"
|
||||
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
|
||||
|
||||
void GenerateFragmentShaderD3D11(const ShaderID &id, char *buffer) {
|
||||
|
||||
DX9::GenerateFragmentShaderHLSL(id, buffer, HLSL_D3D11);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2017- PPSSPP Project.
|
||||
// Copyright (c) 2012- 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
|
||||
@ -17,4 +17,133 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class FramebufferManagerD3D11 {};
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
// Keeps track of allocated FBOs.
|
||||
// Also provides facilities for drawing and later converting raw
|
||||
// pixel data.
|
||||
|
||||
|
||||
#include "Globals.h"
|
||||
#include "GPU/GPUCommon.h"
|
||||
#include "GPU/Common/FramebufferCommon.h"
|
||||
#include "Core/Config.h"
|
||||
#include "ext/native/thin3d/thin3d.h"
|
||||
|
||||
class TextureCacheD3D11;
|
||||
class DrawEngineD3D11;
|
||||
class ShaderManagerD3D11;
|
||||
|
||||
class FramebufferManagerD3D11 : public FramebufferManagerCommon {
|
||||
public:
|
||||
FramebufferManagerD3D11(Draw::DrawContext *draw);
|
||||
~FramebufferManagerD3D11();
|
||||
|
||||
void SetTextureCache(TextureCacheD3D11 *tc);
|
||||
void SetShaderManager(ShaderManagerD3D11 *sm) {
|
||||
shaderManager_ = sm;
|
||||
}
|
||||
void SetDrawEngine(DrawEngineD3D11 *td) {
|
||||
drawEngine_ = td;
|
||||
}
|
||||
|
||||
virtual void DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
||||
virtual void DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, bool applyPostShader) override;
|
||||
|
||||
void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, bool linearFilter);
|
||||
|
||||
void DestroyAllFBOs(bool forceDelete);
|
||||
|
||||
void EndFrame();
|
||||
void Resized() override;
|
||||
void DeviceLost();
|
||||
void CopyDisplayToOutput();
|
||||
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) override;
|
||||
|
||||
void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) override;
|
||||
|
||||
void BindFramebufferColor(int stage, VirtualFramebuffer *framebuffer, int flags);
|
||||
|
||||
void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) override;
|
||||
void DownloadFramebufferForClut(u32 fb_address, u32 loadBytes) override;
|
||||
|
||||
std::vector<FramebufferInfo> GetFramebufferList();
|
||||
|
||||
virtual bool NotifyStencilUpload(u32 addr, int size, bool skipZero = false) override;
|
||||
|
||||
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes);
|
||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
|
||||
bool GetOutputFramebuffer(GPUDebugBuffer &buffer);
|
||||
|
||||
virtual void RebindFramebuffer() override;
|
||||
|
||||
protected:
|
||||
void DisableState() override;
|
||||
void ClearBuffer(bool keepState = false) override;
|
||||
void FlushBeforeCopy() override;
|
||||
|
||||
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
||||
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;
|
||||
|
||||
bool CreateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
||||
|
||||
private:
|
||||
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
|
||||
void CompileDraw2DProgram();
|
||||
void DestroyDraw2DProgram();
|
||||
|
||||
void PackFramebufferD3D11_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
// Used by DrawPixels
|
||||
ID3D11Texture2D *drawPixelsTex_;
|
||||
ID3D11ShaderResourceView *drawPixelsTexView_;
|
||||
int drawPixelsTexW_;
|
||||
int drawPixelsTexH_;
|
||||
|
||||
ID3D11VertexShader *pFramebufferVertexShader_;
|
||||
ID3D11PixelShader *pFramebufferPixelShader_;
|
||||
ID3D11InputLayout *pFramebufferVertexDecl_;
|
||||
|
||||
u8 *convBuf;
|
||||
|
||||
int plainColorLoc_;
|
||||
ID3D11PixelShader *stencilUploadPS_;
|
||||
ID3D11VertexShader *stencilUploadVS_;
|
||||
ID3D11InputLayout *stencilUploadInputLayout_;
|
||||
bool stencilUploadFailed_;
|
||||
|
||||
TextureCacheD3D11 *textureCacheD3D11_;
|
||||
ShaderManagerD3D11 *shaderManager_;
|
||||
DrawEngineD3D11 *drawEngine_;
|
||||
|
||||
ID3D11Buffer *vbFullScreenRect_;
|
||||
UINT vbFullScreenStride_ = 20;
|
||||
UINT vbFullScreenOffset_ = 0;
|
||||
|
||||
// Used by post-processing shader
|
||||
std::vector<Draw::Framebuffer *> extraFBOs_;
|
||||
|
||||
bool resized_;
|
||||
|
||||
struct TempFBO {
|
||||
Draw::Framebuffer *fbo;
|
||||
int last_frame_used;
|
||||
};
|
||||
|
||||
std::map<u64, TempFBO> tempFBOs_;
|
||||
|
||||
#if 0
|
||||
AsyncPBO *pixelBufObj_; //this isn't that large
|
||||
u8 currentPBO_;
|
||||
#endif
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -28,105 +28,99 @@
|
||||
#include "GPU/D3D11/DepalettizeShaderD3D11.h"
|
||||
#include "GPU/Common/VertexDecoderCommon.h"
|
||||
|
||||
namespace D3D11 {
|
||||
class ShaderManagerD3D11;
|
||||
class LinkedShaderD3D11;
|
||||
|
||||
class ShaderManagerD3D11;
|
||||
class LinkedShaderD3D11;
|
||||
class GPU_D3D11 : public GPUCommon {
|
||||
public:
|
||||
GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw);
|
||||
~GPU_D3D11();
|
||||
|
||||
class GPU_D3D11 : public GPUCommon {
|
||||
public:
|
||||
GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw);
|
||||
~GPU_D3D11();
|
||||
void CheckGPUFeatures();
|
||||
void PreExecuteOp(u32 op, u32 diff) override;
|
||||
void ExecuteOp(u32 op, u32 diff) override;
|
||||
|
||||
void CheckGPUFeatures();
|
||||
void PreExecuteOp(u32 op, u32 diff) override;
|
||||
void ExecuteOp(u32 op, u32 diff) override;
|
||||
void ReapplyGfxStateInternal() override;
|
||||
void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override;
|
||||
void BeginFrame() override;
|
||||
void GetStats(char *buffer, size_t bufsize) override;
|
||||
void ClearCacheNextFrame() override;
|
||||
void DeviceLost() override; // Only happens on Android. Drop all textures and shaders.
|
||||
void DeviceRestore() override;
|
||||
|
||||
void ReapplyGfxStateInternal() override;
|
||||
void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override;
|
||||
void BeginFrame() override;
|
||||
void GetStats(char *buffer, size_t bufsize) override;
|
||||
void ClearCacheNextFrame() override;
|
||||
void DeviceLost() override; // Only happens on Android. Drop all textures and shaders.
|
||||
void DeviceRestore() override;
|
||||
void DumpNextFrame() override;
|
||||
void DoState(PointerWrap &p) override;
|
||||
|
||||
void DumpNextFrame() override;
|
||||
void DoState(PointerWrap &p) override;
|
||||
void ClearShaderCache() override;
|
||||
bool DecodeTexture(u8 *dest, const GPUgstate &state) override {
|
||||
return false;
|
||||
}
|
||||
bool FramebufferDirty() override;
|
||||
bool FramebufferReallyDirty() override;
|
||||
|
||||
void ClearShaderCache() override;
|
||||
bool DecodeTexture(u8 *dest, const GPUgstate &state) override {
|
||||
return false;
|
||||
}
|
||||
bool FramebufferDirty() override;
|
||||
bool FramebufferReallyDirty() override;
|
||||
void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) override {
|
||||
primaryInfo = reportingPrimaryInfo_;
|
||||
fullInfo = reportingFullInfo_;
|
||||
}
|
||||
std::vector<FramebufferInfo> GetFramebufferList() override;
|
||||
|
||||
void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) override {
|
||||
primaryInfo = reportingPrimaryInfo_;
|
||||
fullInfo = reportingFullInfo_;
|
||||
}
|
||||
std::vector<FramebufferInfo> GetFramebufferList() override;
|
||||
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes = -1) override;
|
||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) override;
|
||||
bool GetCurrentClut(GPUDebugBuffer &buffer) override;
|
||||
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;
|
||||
|
||||
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes = -1) override;
|
||||
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) override;
|
||||
bool GetCurrentClut(GPUDebugBuffer &buffer) override;
|
||||
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
|
||||
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;
|
||||
|
||||
typedef void (GPU_D3D11::*CmdFunc)(u32 op, u32 diff);
|
||||
struct CommandInfo {
|
||||
uint64_t flags;
|
||||
GPU_D3D11::CmdFunc func;
|
||||
};
|
||||
|
||||
void Execute_Prim(u32 op, u32 diff);
|
||||
void Execute_Bezier(u32 op, u32 diff);
|
||||
void Execute_Spline(u32 op, u32 diff);
|
||||
void Execute_VertexType(u32 op, u32 diff);
|
||||
void Execute_VertexTypeSkinning(u32 op, u32 diff);
|
||||
void Execute_TexSize0(u32 op, u32 diff);
|
||||
void Execute_LoadClut(u32 op, u32 diff);
|
||||
|
||||
// Using string because it's generic - makes no assumptions on the size of the shader IDs of this backend.
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
|
||||
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override;
|
||||
|
||||
protected:
|
||||
void FastRunLoop(DisplayList &list) override;
|
||||
void FinishDeferred() override;
|
||||
|
||||
private:
|
||||
void UpdateCmdInfo();
|
||||
|
||||
void Flush() {
|
||||
drawEngine_.Flush();
|
||||
}
|
||||
// void ApplyDrawState(int prim);
|
||||
void CheckFlushOp(int cmd, u32 diff);
|
||||
void BuildReportingInfo();
|
||||
|
||||
void InitClearInternal() override;
|
||||
void BeginFrameInternal() override;
|
||||
void CopyDisplayToOutputInternal() override;
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
FramebufferManagerD3D11 *framebufferManagerD3D11_;
|
||||
TextureCacheD3D11 *textureCacheD3D11_;
|
||||
DepalShaderCacheD3D11 depalShaderCache_;
|
||||
DrawEngineD3D11 drawEngine_;
|
||||
ShaderManagerD3D11 *shaderManagerD3D11_;
|
||||
|
||||
static CommandInfo cmdInfo_[256];
|
||||
|
||||
int lastVsync_;
|
||||
|
||||
std::string reportingPrimaryInfo_;
|
||||
std::string reportingFullInfo_;
|
||||
typedef void (GPU_D3D11::*CmdFunc)(u32 op, u32 diff);
|
||||
struct CommandInfo {
|
||||
uint64_t flags;
|
||||
GPU_D3D11::CmdFunc func;
|
||||
};
|
||||
|
||||
} // namespace D3D11
|
||||
void Execute_Prim(u32 op, u32 diff);
|
||||
void Execute_Bezier(u32 op, u32 diff);
|
||||
void Execute_Spline(u32 op, u32 diff);
|
||||
void Execute_VertexType(u32 op, u32 diff);
|
||||
void Execute_VertexTypeSkinning(u32 op, u32 diff);
|
||||
void Execute_TexSize0(u32 op, u32 diff);
|
||||
void Execute_LoadClut(u32 op, u32 diff);
|
||||
|
||||
typedef D3D11::GPU_D3D11 D3D11_GPU;
|
||||
// Using string because it's generic - makes no assumptions on the size of the shader IDs of this backend.
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
|
||||
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override;
|
||||
|
||||
protected:
|
||||
void FastRunLoop(DisplayList &list) override;
|
||||
void FinishDeferred() override;
|
||||
|
||||
private:
|
||||
void UpdateCmdInfo();
|
||||
|
||||
void Flush() {
|
||||
drawEngine_.Flush();
|
||||
}
|
||||
// void ApplyDrawState(int prim);
|
||||
void CheckFlushOp(int cmd, u32 diff);
|
||||
void BuildReportingInfo();
|
||||
|
||||
void InitClearInternal() override;
|
||||
void BeginFrameInternal() override;
|
||||
void CopyDisplayToOutputInternal() override;
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
FramebufferManagerD3D11 *framebufferManagerD3D11_;
|
||||
TextureCacheD3D11 *textureCacheD3D11_;
|
||||
DepalShaderCacheD3D11 *depalShaderCache_;
|
||||
DrawEngineD3D11 drawEngine_;
|
||||
ShaderManagerD3D11 *shaderManagerD3D11_;
|
||||
|
||||
static CommandInfo cmdInfo_[256];
|
||||
|
||||
int lastVsync_;
|
||||
|
||||
std::string reportingPrimaryInfo_;
|
||||
std::string reportingFullInfo_;
|
||||
};
|
@ -39,25 +39,19 @@
|
||||
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
||||
#include "GPU/D3D11/FragmentShaderGeneratorD3D11.h"
|
||||
#include "GPU/D3D11/VertexShaderGeneratorD3D11.h"
|
||||
#include "GPU/D3D11/D3D11Util.h"
|
||||
|
||||
D3D11FragmentShader::D3D11FragmentShader(ID3D11Device *device, ShaderID id, const char *code, bool useHWTransform)
|
||||
: device_(device), id_(id), failed_(false), useHWTransform_(useHWTransform), module_(0) {
|
||||
source_ = code;
|
||||
|
||||
std::string errorMessage;
|
||||
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA(code);
|
||||
#endif
|
||||
|
||||
uint8_t *bytecode;
|
||||
UINT bytecodeSize;
|
||||
|
||||
HRESULT hr = device_->CreatePixelShader(bytecode, bytecodeSize, nullptr, &module_);
|
||||
if (FAILED(hr)) {
|
||||
module_ = CreatePixelShaderD3D11(device, code, strlen(code));
|
||||
if (!module_)
|
||||
failed_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
D3D11FragmentShader::~D3D11FragmentShader() {
|
||||
@ -79,19 +73,14 @@ std::string D3D11FragmentShader::GetShaderString(DebugShaderStringType type) con
|
||||
D3D11VertexShader::D3D11VertexShader(ID3D11Device *device, ShaderID id, const char *code, int vertType, bool useHWTransform, bool usesLighting)
|
||||
: device_(device), id_(id), failed_(false), useHWTransform_(useHWTransform), module_(nullptr), usesLighting_(usesLighting) {
|
||||
source_ = code;
|
||||
std::string errorMessage;
|
||||
std::vector<uint32_t> spirv;
|
||||
|
||||
#ifdef SHADERLOG
|
||||
OutputDebugStringA(code);
|
||||
#endif
|
||||
uint8_t *bytecode;
|
||||
UINT bytecodeSize;
|
||||
|
||||
HRESULT hr = device_->CreateVertexShader(bytecode, bytecodeSize, nullptr, &module_);
|
||||
if (FAILED(hr)) {
|
||||
module_ = CreateVertexShaderD3D11(device, code, strlen(code), &bytecode_);
|
||||
if (!module_)
|
||||
failed_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
D3D11VertexShader::~D3D11VertexShader() {
|
||||
@ -120,6 +109,13 @@ ShaderManagerD3D11::ShaderManagerD3D11(ID3D11Device *device, ID3D11DeviceContext
|
||||
ILOG("sizeof(ub_base): %d", (int)sizeof(ub_base));
|
||||
ILOG("sizeof(ub_lights): %d", (int)sizeof(ub_lights));
|
||||
ILOG("sizeof(ub_bones): %d", (int)sizeof(ub_bones));
|
||||
|
||||
D3D11_BUFFER_DESC desc{sizeof(ub_base), D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, D3D11_CPU_ACCESS_WRITE };
|
||||
device_->CreateBuffer(&desc, nullptr, &push_base);
|
||||
desc.ByteWidth = sizeof(ub_lights);
|
||||
device_->CreateBuffer(&desc, nullptr, &push_lights);
|
||||
desc.ByteWidth = sizeof(ub_bones);
|
||||
device_->CreateBuffer(&desc, nullptr, &push_bones);
|
||||
}
|
||||
|
||||
ShaderManagerD3D11::~ShaderManagerD3D11() {
|
||||
@ -162,12 +158,25 @@ void ShaderManagerD3D11::DirtyLastShader() { // disables vertex arrays
|
||||
uint64_t ShaderManagerD3D11::UpdateUniforms() {
|
||||
uint64_t dirty = gstate_c.GetDirtyUniforms();
|
||||
if (dirty != 0) {
|
||||
if (dirty & DIRTY_BASE_UNIFORMS)
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
if (dirty & DIRTY_BASE_UNIFORMS) {
|
||||
BaseUpdateUniforms(&ub_base, dirty);
|
||||
if (dirty & DIRTY_LIGHT_UNIFORMS)
|
||||
context_->Map(push_base, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &ub_base, sizeof(ub_base));
|
||||
context_->Unmap(push_base, 0);
|
||||
}
|
||||
if (dirty & DIRTY_LIGHT_UNIFORMS) {
|
||||
LightUpdateUniforms(&ub_lights, dirty);
|
||||
if (dirty & DIRTY_BONE_UNIFORMS)
|
||||
context_->Map(push_lights, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &ub_lights, sizeof(ub_lights));
|
||||
context_->Unmap(push_lights, 0);
|
||||
}
|
||||
if (dirty & DIRTY_BONE_UNIFORMS) {
|
||||
BoneUpdateUniforms(&ub_bones, dirty);
|
||||
context_->Map(push_bones, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &ub_bones, sizeof(ub_bones));
|
||||
context_->Unmap(push_bones, 0);
|
||||
}
|
||||
}
|
||||
gstate_c.CleanUniforms();
|
||||
return dirty;
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
~D3D11VertexShader();
|
||||
|
||||
const std::string &source() const { return source_; }
|
||||
|
||||
const std::vector<uint8_t> &bytecode() const { return bytecode_; }
|
||||
bool Failed() const { return failed_; }
|
||||
bool UseHWTransform() const { return useHWTransform_; }
|
||||
bool HasBones() const {
|
||||
@ -80,6 +80,8 @@ protected:
|
||||
|
||||
ID3D11Device *device_;
|
||||
std::string source_;
|
||||
std::vector<uint8_t> bytecode_;
|
||||
|
||||
bool failed_;
|
||||
bool useHWTransform_;
|
||||
bool usesLighting_;
|
||||
@ -137,6 +139,11 @@ private:
|
||||
UB_VS_Lights ub_lights;
|
||||
UB_VS_Bones ub_bones;
|
||||
|
||||
// Not actual pushbuffers, requires D3D11.1, let's try to live without that first.
|
||||
ID3D11Buffer *push_base;
|
||||
ID3D11Buffer *push_lights;
|
||||
ID3D11Buffer *push_bones;
|
||||
|
||||
D3D11FragmentShader *lastFShader_;
|
||||
D3D11VertexShader *lastVShader_;
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "math/dataconv.h"
|
||||
|
||||
#include "GPU/Math3D.h"
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
@ -26,6 +28,8 @@
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "GPU/Common/FramebufferCommon.h"
|
||||
#include "GPU/D3D11/DrawEngineD3D11.h"
|
||||
#include "GPU/D3D11/FramebufferManagerD3D11.h"
|
||||
|
||||
// These tables all fit into u8s.
|
||||
static const D3D11_BLEND d3d11BlendFactorLookup[(size_t)BlendFactor::COUNT] = {
|
||||
@ -377,3 +381,60 @@ void ConvertStateToKeys(FramebufferManagerCommon *fbManager, ShaderManagerD3D11
|
||||
gstate_c.Dirty(DIRTY_DEPTHRANGE);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::ApplyDrawState(int prim) {
|
||||
D3D11StateKeys keys;
|
||||
D3D11DynamicState dynState;
|
||||
ConvertStateToKeys(framebufferManager_, shaderManager_, prim, keys, dynState);
|
||||
|
||||
uint32_t blendKey, depthKey, rasterKey;
|
||||
memcpy(&blendKey, &keys.blend, sizeof(uint32_t));
|
||||
memcpy(&depthKey, &keys.depthStencil, sizeof(uint32_t));
|
||||
memcpy(&rasterKey, &keys.raster, sizeof(uint32_t));
|
||||
|
||||
ID3D11BlendState *bs = nullptr;
|
||||
ID3D11DepthStencilState *ds = nullptr;
|
||||
ID3D11RasterizerState *rs = nullptr;
|
||||
|
||||
auto blendIter = blendCache_.find(blendKey);
|
||||
if (blendIter == blendCache_.end()) {
|
||||
D3D11_BLEND_DESC desc{};
|
||||
D3D11_RENDER_TARGET_BLEND_DESC &rt = desc.RenderTarget[0];
|
||||
rt.BlendEnable = keys.blend.blendEnable;
|
||||
rt.BlendOp = (D3D11_BLEND_OP)keys.blend.blendOpColor;
|
||||
rt.BlendOpAlpha = (D3D11_BLEND_OP)keys.blend.blendOpAlpha;
|
||||
rt.SrcBlend = (D3D11_BLEND)keys.blend.srcColor;
|
||||
rt.DestBlend = (D3D11_BLEND)keys.blend.destColor;
|
||||
rt.SrcBlendAlpha = (D3D11_BLEND)keys.blend.srcAlpha;
|
||||
rt.DestBlendAlpha = (D3D11_BLEND)keys.blend.destAlpha;
|
||||
rt.RenderTargetWriteMask = keys.blend.colorWriteMask;
|
||||
device_->CreateBlendState(&desc, &bs);
|
||||
blendCache_.insert(std::pair<uint32_t, ID3D11BlendState *>(blendKey, bs));
|
||||
} else {
|
||||
bs = blendIter->second;
|
||||
}
|
||||
|
||||
auto depthIter = depthStencilCache_.find(depthKey);
|
||||
if (depthIter == depthStencilCache_.end()) {
|
||||
D3D11_DEPTH_STENCIL_DESC desc{};
|
||||
desc.DepthEnable = keys.depthStencil.depthTestEnable;
|
||||
desc.DepthWriteMask = keys.depthStencil.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
desc.StencilEnable = keys.depthStencil.stencilTestEnable;
|
||||
// ...
|
||||
device_->CreateDepthStencilState(&desc, &ds);
|
||||
depthStencilCache_.insert(std::pair<uint32_t, ID3D11DepthStencilState *>(depthKey, ds));
|
||||
} else {
|
||||
ds = depthIter->second;
|
||||
}
|
||||
|
||||
float blendColor[4];
|
||||
Uint8x4ToFloat4(blendColor, dynState.blendColor);
|
||||
context_->OMSetBlendState(bs, blendColor, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
void DrawEngineD3D11::ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef) {
|
||||
if (applyStencilRef) {
|
||||
ID3D11DepthStencilState *state;
|
||||
context_->OMSetDepthStencilState(state, stencilRef);
|
||||
}
|
||||
}
|
261
GPU/D3D11/StencilBufferD3D11.cpp
Normal file
261
GPU/D3D11/StencilBufferD3D11.cpp
Normal file
@ -0,0 +1,261 @@
|
||||
// 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 <d3d11.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
||||
#include "gfx/d3d9_state.h"
|
||||
#include "ext/native/thin3d/thin3d.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "GPU/D3D11/FramebufferManagerD3D11.h"
|
||||
#include "GPU/D3D11/FragmentShaderGeneratorD3D11.h"
|
||||
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
||||
#include "GPU/D3D11/TextureCacheD3D11.h"
|
||||
#include "GPU/D3D11/D3D11Util.h"
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
struct StencilUB {
|
||||
float u_stencilValue[4];
|
||||
};
|
||||
|
||||
static const char *stencil_ps =
|
||||
"sampler tex: register(s0);\n"
|
||||
"cbuffer base : register(b0) {\n"
|
||||
" float4 u_stencilValue;\n"
|
||||
"};\n"
|
||||
"struct PS_IN {\n"
|
||||
" float2 v_texcoord0 : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"float roundAndScaleTo255f(in float x) { return floor(x * 255.99); }\n"
|
||||
"float4 main(PS_IN In) : COLOR {\n"
|
||||
" float4 index = tex2D(tex, In.v_texcoord0);\n"
|
||||
" float shifted = roundAndScaleTo255f(index.a) / roundAndScaleTo255f(u_stencilValue.x);\n"
|
||||
" clip(fmod(floor(shifted), 2.0) - 0.99);\n"
|
||||
" return index.aaaa;\n"
|
||||
"}\n";
|
||||
|
||||
static const char *stencil_vs =
|
||||
"struct VS_IN {\n"
|
||||
" float4 a_position : POSITION;\n"
|
||||
" float2 a_texcoord0 : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"struct VS_OUT {\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float2 v_texcoord0 : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"VS_OUT main(VS_IN In) {\n"
|
||||
" VS_OUT Out;\n"
|
||||
" Out.position = In.a_position;\n"
|
||||
" Out.v_texcoord0 = In.a_texcoord0;\n"
|
||||
" return Out;\n"
|
||||
"}\n";
|
||||
|
||||
static u8 StencilBits5551(const u8 *ptr8, u32 numPixels) {
|
||||
const u32 *ptr = (const u32 *)ptr8;
|
||||
|
||||
for (u32 i = 0; i < numPixels / 2; ++i) {
|
||||
if (ptr[i] & 0x80008000) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 StencilBits4444(const u8 *ptr8, u32 numPixels) {
|
||||
const u32 *ptr = (const u32 *)ptr8;
|
||||
u32 bits = 0;
|
||||
|
||||
for (u32 i = 0; i < numPixels / 2; ++i) {
|
||||
bits |= ptr[i];
|
||||
}
|
||||
|
||||
return ((bits >> 12) & 0xF) | (bits >> 28);
|
||||
}
|
||||
|
||||
static u8 StencilBits8888(const u8 *ptr8, u32 numPixels) {
|
||||
const u32 *ptr = (const u32 *)ptr8;
|
||||
u32 bits = 0;
|
||||
|
||||
for (u32 i = 0; i < numPixels; ++i) {
|
||||
bits |= ptr[i];
|
||||
}
|
||||
|
||||
return bits >> 24;
|
||||
}
|
||||
|
||||
// TODO : If SV_StencilRef is available (D3D11.3) then this can be done in a single pass.
|
||||
bool FramebufferManagerD3D11::NotifyStencilUpload(u32 addr, int size, bool skipZero) {
|
||||
if (!MayIntersectFramebuffer(addr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VirtualFramebuffer *dstBuffer = 0;
|
||||
for (size_t i = 0; i < vfbs_.size(); ++i) {
|
||||
VirtualFramebuffer *vfb = vfbs_[i];
|
||||
if (MaskedEqual(vfb->fb_address, addr)) {
|
||||
dstBuffer = vfb;
|
||||
}
|
||||
}
|
||||
if (!dstBuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int values = 0;
|
||||
u8 usedBits = 0;
|
||||
|
||||
const u8 *src = Memory::GetPointer(addr);
|
||||
if (!src) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (dstBuffer->format) {
|
||||
case GE_FORMAT_565:
|
||||
// Well, this doesn't make much sense.
|
||||
return false;
|
||||
case GE_FORMAT_5551:
|
||||
usedBits = StencilBits5551(src, dstBuffer->fb_stride * dstBuffer->bufferHeight);
|
||||
values = 2;
|
||||
break;
|
||||
case GE_FORMAT_4444:
|
||||
usedBits = StencilBits4444(src, dstBuffer->fb_stride * dstBuffer->bufferHeight);
|
||||
values = 16;
|
||||
break;
|
||||
case GE_FORMAT_8888:
|
||||
usedBits = StencilBits8888(src, dstBuffer->fb_stride * dstBuffer->bufferHeight);
|
||||
values = 256;
|
||||
break;
|
||||
case GE_FORMAT_INVALID:
|
||||
// Impossible.
|
||||
break;
|
||||
}
|
||||
|
||||
if (usedBits == 0) {
|
||||
if (skipZero) {
|
||||
// Common when creating buffers, it's already 0. We're done.
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: Find a fast way to clear stencil+alpha. Probably a quad.
|
||||
// Let's not bother with the shader if it's just zero.
|
||||
dxstate.scissorTest.disable();
|
||||
dxstate.colorMask.set(false, false, false, true);
|
||||
// TODO: Verify this clears only stencil/alpha.
|
||||
pD3Ddevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL, D3DCOLOR_RGBA(0, 0, 0, 0), 0.0f, 0);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stencilUploadFailed_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Helper with logging?
|
||||
if (!stencilUploadPS_) {
|
||||
std::string errorMessage;
|
||||
stencilUploadPS_ = CreatePixelShaderD3D11(device_, stencil_ps, strlen(stencil_ps));
|
||||
}
|
||||
if (!stencilUploadVS_) {
|
||||
std::string errorMessage;
|
||||
std::vector<uint8_t> byteCode;
|
||||
stencilUploadVS_ = CreateVertexShaderD3D11(device_, stencil_vs, strlen(stencil_vs), &byteCode);
|
||||
// stencilUploadInputLayout_ = device_->CreateInputLayout()
|
||||
}
|
||||
if (!stencilUploadPS_ || !stencilUploadVS_) {
|
||||
stencilUploadFailed_ = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderManager_->DirtyLastShader();
|
||||
|
||||
DisableState();
|
||||
|
||||
context_->OMSetBlendState(stockD3D11.blendStateDisabledWithColorMask[0x8], nullptr, 0xFFFFFFFF);
|
||||
context_->OMSetDepthStencilState(stockD3D11.depthDisabledStencilWrite, 0xFF);
|
||||
context_->RSSetState(stockD3D11.rasterStateNoCull);
|
||||
|
||||
u16 w = dstBuffer->renderWidth;
|
||||
u16 h = dstBuffer->renderHeight;
|
||||
|
||||
if (dstBuffer->fbo) {
|
||||
draw_->BindFramebufferAsRenderTarget(dstBuffer->fbo);
|
||||
}
|
||||
D3D11_VIEWPORT vp{ 0.0f, 0.0f, (float)w, (float)h, 0.0f, 1.0f };
|
||||
context_->RSSetViewports(1, &vp);
|
||||
|
||||
MakePixelTexture(src, dstBuffer->format, dstBuffer->fb_stride, dstBuffer->bufferWidth, dstBuffer->bufferHeight);
|
||||
|
||||
// Zero stencil
|
||||
draw_->Clear(Draw::ClearFlag::STENCIL, 0, 0, 0);
|
||||
|
||||
float fw = dstBuffer->width;
|
||||
float fh = dstBuffer->height;
|
||||
|
||||
float coord[20] = {
|
||||
0.0f,0.0f,0.0f, 0.0f,0.0f,
|
||||
fw,0.0f,0.0f, 1.0f,0.0f,
|
||||
fw,fh,0.0f, 1.0f,1.0f,
|
||||
0.0f,fh,0.0f, 0.0f,1.0f,
|
||||
};
|
||||
// I think all these calculations pretty much cancel out?
|
||||
float invDestW = 1.0f / (fw * 0.5f);
|
||||
float invDestH = 1.0f / (fh * 0.5f);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
coord[i * 5] = coord[i * 5] * invDestW - 1.0f;
|
||||
coord[i * 5 + 1] = -(coord[i * 5 + 1] * invDestH - 1.0f);
|
||||
}
|
||||
|
||||
/* TODO
|
||||
// context_->IASetInputLayout(ia);
|
||||
context_->PSSetShader(stencilUploadPS_);
|
||||
context_->VSSetSamplers(stencilUploadVS_);
|
||||
context_->pD3Ddevice->SetTexture(0, drawPixelsTex_);
|
||||
|
||||
shaderManager_->DirtyLastShader();
|
||||
textureCacheD3D11_->ForgetLastTexture();
|
||||
|
||||
for (int i = 1; i < values; i += i) {
|
||||
if (!(usedBits & i)) {
|
||||
// It's already zero, let's skip it.
|
||||
continue;
|
||||
}
|
||||
if (dstBuffer->format == GE_FORMAT_4444) {
|
||||
dxstate.stencilMask.set(i | (i << 4));
|
||||
const float f[4] = {i * (16.0f / 255.0f)};
|
||||
pD3Ddevice->SetPixelShaderConstantF(CONST_PS_STENCILVALUE, f, 1);
|
||||
} else if (dstBuffer->format == GE_FORMAT_5551) {
|
||||
dxstate.stencilMask.set(0xFF);
|
||||
const float f[4] = {i * (128.0f / 255.0f)};
|
||||
pD3Ddevice->SetPixelShaderConstantF(CONST_PS_STENCILVALUE, f, 1);
|
||||
} else {
|
||||
dxstate.stencilMask.set(i);
|
||||
const float f[4] = {i * (1.0f / 255.0f)};
|
||||
pD3Ddevice->SetPixelShaderConstantF(CONST_PS_STENCILVALUE, f, 1);
|
||||
}
|
||||
HRESULT hr = pD3Ddevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coord, 5 * sizeof(float));
|
||||
if (FAILED(hr)) {
|
||||
ERROR_LOG_REPORT(G3D, "Failed to draw stencil bit %x: %08x", i, hr);
|
||||
}
|
||||
}
|
||||
dxstate.stencilMask.set(0xFF);
|
||||
RebindFramebuffer();
|
||||
*/
|
||||
return true;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -17,4 +17,113 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class TextureCacheD3D11 {};
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "../Globals.h"
|
||||
#include "GPU/GPU.h"
|
||||
#include "GPU/GPUInterface.h"
|
||||
#include "GPU/D3D11/TextureScalerD3D11.h"
|
||||
#include "GPU/Common/TextureCacheCommon.h"
|
||||
|
||||
struct VirtualFramebuffer;
|
||||
|
||||
class FramebufferManagerD3D11;
|
||||
class DepalShaderCacheD3D11;
|
||||
class ShaderManagerD3D11;
|
||||
|
||||
class SamplerCacheD3D11 {
|
||||
public:
|
||||
SamplerCacheD3D11() {}
|
||||
~SamplerCacheD3D11();
|
||||
ID3D11SamplerState *GetOrCreateSampler(ID3D11Device *device, const SamplerCacheKey &key);
|
||||
|
||||
private:
|
||||
std::map<SamplerCacheKey, ID3D11SamplerState *> cache_;
|
||||
};
|
||||
|
||||
class TextureCacheD3D11 : public TextureCacheCommon {
|
||||
public:
|
||||
TextureCacheD3D11(Draw::DrawContext *draw);
|
||||
~TextureCacheD3D11();
|
||||
|
||||
void SetTexture(bool force = false);
|
||||
|
||||
void Clear(bool delete_them);
|
||||
void StartFrame();
|
||||
|
||||
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager);
|
||||
void SetDepalShaderCache(DepalShaderCacheD3D11 *dpCache) {
|
||||
depalShaderCache_ = dpCache;
|
||||
}
|
||||
void SetShaderManager(ShaderManagerD3D11 *sm) {
|
||||
shaderManager_ = sm;
|
||||
}
|
||||
|
||||
// Only used by Qt UI?
|
||||
bool DecodeTexture(u8 *output, const GPUgstate &state);
|
||||
|
||||
void ForgetLastTexture() override;
|
||||
|
||||
void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key);
|
||||
|
||||
void ApplyTexture();
|
||||
|
||||
protected:
|
||||
void Unbind() override;
|
||||
|
||||
private:
|
||||
void Decimate(); // Run this once per frame to get rid of old textures.
|
||||
void DeleteTexture(TexCache::iterator it);
|
||||
void UpdateSamplingParams(TexCacheEntry &entry, SamplerCacheKey &key);
|
||||
void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int maxLevel, bool replaceImages, int scaleFactor, u32 dstFmt);
|
||||
DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
|
||||
TexCacheEntry::Status CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h);
|
||||
u32 GetCurrentClutHash();
|
||||
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple);
|
||||
void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer);
|
||||
|
||||
bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete);
|
||||
bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete);
|
||||
void BuildTexture(TexCacheEntry *const entry, bool replaceImages);
|
||||
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
ID3D11Texture2D *DxTex(TexCacheEntry *entry) {
|
||||
return (ID3D11Texture2D *)entry->texturePtr;
|
||||
}
|
||||
ID3D11ShaderResourceView *DxView(TexCacheEntry *entry) {
|
||||
return (ID3D11ShaderResourceView *)entry->textureView;
|
||||
}
|
||||
void ReleaseTexture(TexCacheEntry *entry) {
|
||||
ID3D11Texture2D *texture = (ID3D11Texture2D *)entry->texturePtr;
|
||||
ID3D11ShaderResourceView *view = (ID3D11ShaderResourceView *)entry->textureView;
|
||||
if (texture) {
|
||||
texture->Release();
|
||||
entry->texturePtr = nullptr;
|
||||
}
|
||||
if (view) {
|
||||
view->Release();
|
||||
entry->textureView = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
TextureScalerD3D11 scaler;
|
||||
|
||||
SamplerCacheD3D11 samplerCache_;
|
||||
|
||||
u32 clutHash_;
|
||||
|
||||
ID3D11ShaderResourceView *lastBoundTexture;
|
||||
float maxAnisotropyLevel;
|
||||
|
||||
int decimationCounter_;
|
||||
int texelsScaledThisFrame_;
|
||||
int timesInvalidatedAllThisFrame_;
|
||||
|
||||
FramebufferManagerD3D11 *framebufferManagerD3D11_;
|
||||
DepalShaderCacheD3D11 *depalShaderCache_;
|
||||
ShaderManagerD3D11 *shaderManager_;
|
||||
};
|
||||
|
||||
DXGI_FORMAT getClutDestFormatD3D11(GEPaletteFormat format);
|
||||
|
57
GPU/D3D11/TextureScalerD3D11.cpp
Normal file
57
GPU/D3D11/TextureScalerD3D11.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2012- 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 <algorithm>
|
||||
|
||||
#include <d3d11.h>
|
||||
#include "Common/ColorConv.h"
|
||||
#include "Common/ThreadPools.h"
|
||||
#include "GPU/Common/TextureScalerCommon.h"
|
||||
#include "GPU/D3D11/TextureScalerD3D11.h"
|
||||
#include "GPU/D3D11/GPU_D3D11.h"
|
||||
|
||||
int TextureScalerD3D11::BytesPerPixel(u32 format) {
|
||||
return format == GE_FORMAT_8888 ? 4 : 2;
|
||||
}
|
||||
|
||||
u32 TextureScalerD3D11::Get8888Format() {
|
||||
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
|
||||
void TextureScalerD3D11::ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) {
|
||||
switch (format) {
|
||||
case GE_FORMAT_8888:
|
||||
dest = source; // already fine
|
||||
break;
|
||||
|
||||
case GE_FORMAT_4444:
|
||||
GlobalThreadPool::Loop(std::bind(&convert4444_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height);
|
||||
break;
|
||||
|
||||
case GE_FORMAT_565:
|
||||
GlobalThreadPool::Loop(std::bind(&convert565_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height);
|
||||
break;
|
||||
|
||||
case GE_FORMAT_5551:
|
||||
GlobalThreadPool::Loop(std::bind(&convert5551_dx9, (u16*)source, dest, width, std::placeholders::_1, std::placeholders::_2), 0, height);
|
||||
break;
|
||||
|
||||
default:
|
||||
dest = source;
|
||||
ERROR_LOG(G3D, "iXBRZTexScaling: unsupported texture format");
|
||||
}
|
||||
}
|
29
GPU/D3D11/TextureScalerD3D11.h
Normal file
29
GPU/D3D11/TextureScalerD3D11.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2012- 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 "Common/CommonTypes.h"
|
||||
#include "GPU/Common/TextureScalerCommon.h"
|
||||
|
||||
class TextureScalerD3D11 : public TextureScalerCommon {
|
||||
private:
|
||||
// NOTE: We use GE formats, D3D11 doesn't support 4444
|
||||
void ConvertTo8888(u32 format, u32* source, u32* &dest, int width, int height) override;
|
||||
int BytesPerPixel(u32 format) override;
|
||||
u32 Get8888Format() override;
|
||||
};
|
@ -1,5 +1,25 @@
|
||||
// Copyright (c) 2017- 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/Common/ShaderCommon.h"
|
||||
#include "GPU/D3D11/VertexShaderGeneratorD3D11.h"
|
||||
#include "GPU/Directx9/VertexShaderGeneratorDX9.h"
|
||||
|
||||
void GenerateVertexShaderD3D11(const ShaderID &id, char *buffer, bool *usesLighting) {
|
||||
|
||||
*usesLighting = true;
|
||||
DX9::GenerateVertexShaderHLSL(id, buffer, HLSL_D3D11);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <map>
|
||||
#include <d3d9.h>
|
||||
|
||||
#include <d3d9.h>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
@ -920,7 +920,7 @@ bool DrawEngineDX9::IsCodePtrVertexDecoder(const u8 *ptr) const {
|
||||
return decJitCache_->IsInSpace(ptr);
|
||||
}
|
||||
|
||||
void DX9::DrawEngineDX9::TessellationDataTransferDX9::SendDataToShader(const float * pos, const float * tex, const float * col, int size, bool hasColor, bool hasTexCoords)
|
||||
void DrawEngineDX9::TessellationDataTransferDX9::SendDataToShader(const float * pos, const float * tex, const float * col, int size, bool hasColor, bool hasTexCoords)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -942,8 +942,8 @@ void GPU_DX9::GetStats(char *buffer, size_t bufsize) {
|
||||
(int)textureCacheDX9_->NumLoadedTextures(),
|
||||
gpuStats.numTexturesDecoded,
|
||||
gpuStats.numTextureInvalidations,
|
||||
shaderManagerDX9_->NumVertexShaders(),
|
||||
shaderManagerDX9_->NumFragmentShaders()
|
||||
shaderManagerDX9_->GetNumVertexShaders(),
|
||||
shaderManagerDX9_->GetNumFragmentShaders()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "GPU/ge_constants.h"
|
||||
#include "GPU/Common/GPUStateUtils.h"
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/Common/ShaderUniforms.h"
|
||||
|
||||
#define WRITE p+=sprintf
|
||||
|
||||
@ -33,7 +34,7 @@ namespace DX9 {
|
||||
|
||||
// Missing: Z depth range
|
||||
// Also, logic ops etc, of course, as they are not supported in DX9.
|
||||
bool GenerateFragmentShaderDX9(const ShaderID &id, char *buffer) {
|
||||
bool GenerateFragmentShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage lang) {
|
||||
char *p = buffer;
|
||||
|
||||
bool lmode = id.Bit(FS_BIT_LMODE);
|
||||
@ -68,39 +69,43 @@ bool GenerateFragmentShaderDX9(const ShaderID &id, char *buffer) {
|
||||
|
||||
StencilValueType replaceAlphaWithStencilType = (StencilValueType)id.Bits(FS_BIT_REPLACE_ALPHA_WITH_STENCIL_TYPE, 4);
|
||||
|
||||
if (doTexture)
|
||||
WRITE(p, "sampler tex : register(s0);\n");
|
||||
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
||||
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
||||
WRITE(p, "float2 u_fbotexSize : register(c%i);\n", CONST_PS_FBOTEXSIZE);
|
||||
WRITE(p, "sampler fbotex : register(s1);\n");
|
||||
if (lang == HLSL_DX9) {
|
||||
if (doTexture)
|
||||
WRITE(p, "sampler tex : register(s0);\n");
|
||||
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
||||
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
||||
WRITE(p, "float2 u_fbotexSize : register(c%i);\n", CONST_PS_FBOTEXSIZE);
|
||||
WRITE(p, "sampler fbotex : register(s1);\n");
|
||||
}
|
||||
if (replaceBlendFuncA >= GE_SRCBLEND_FIXA) {
|
||||
WRITE(p, "float3 u_blendFixA : register(c%i);\n", CONST_PS_BLENDFIXA);
|
||||
}
|
||||
if (replaceBlendFuncB >= GE_DSTBLEND_FIXB) {
|
||||
WRITE(p, "float3 u_blendFixB : register(c%i);\n", CONST_PS_BLENDFIXB);
|
||||
}
|
||||
}
|
||||
if (replaceBlendFuncA >= GE_SRCBLEND_FIXA) {
|
||||
WRITE(p, "float3 u_blendFixA : register(c%i);\n", CONST_PS_BLENDFIXA);
|
||||
if (gstate_c.needShaderTexClamp && doTexture) {
|
||||
WRITE(p, "float4 u_texclamp : register(c%i);\n", CONST_PS_TEXCLAMP);
|
||||
if (textureAtOffset) {
|
||||
WRITE(p, "float2 u_texclampoff : register(c%i);\n", CONST_PS_TEXCLAMPOFF);
|
||||
}
|
||||
}
|
||||
if (replaceBlendFuncB >= GE_DSTBLEND_FIXB) {
|
||||
WRITE(p, "float3 u_blendFixB : register(c%i);\n", CONST_PS_BLENDFIXB);
|
||||
}
|
||||
}
|
||||
if (gstate_c.needShaderTexClamp && doTexture) {
|
||||
WRITE(p, "float4 u_texclamp : register(c%i);\n", CONST_PS_TEXCLAMP);
|
||||
if (textureAtOffset) {
|
||||
WRITE(p, "float2 u_texclampoff : register(c%i);\n", CONST_PS_TEXCLAMPOFF);
|
||||
}
|
||||
}
|
||||
|
||||
if (enableAlphaTest || enableColorTest) {
|
||||
WRITE(p, "float4 u_alphacolorref : register(c%i);\n", CONST_PS_ALPHACOLORREF);
|
||||
WRITE(p, "float4 u_alphacolormask : register(c%i);\n", CONST_PS_ALPHACOLORMASK);
|
||||
}
|
||||
if (stencilToAlpha && replaceAlphaWithStencilType == STENCIL_VALUE_UNIFORM) {
|
||||
WRITE(p, "float u_stencilReplaceValue : register(c%i);\n", CONST_PS_STENCILREPLACE);
|
||||
}
|
||||
if (doTexture && texFunc == GE_TEXFUNC_BLEND) {
|
||||
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
|
||||
}
|
||||
if (enableFog) {
|
||||
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
|
||||
if (enableAlphaTest || enableColorTest) {
|
||||
WRITE(p, "float4 u_alphacolorref : register(c%i);\n", CONST_PS_ALPHACOLORREF);
|
||||
WRITE(p, "float4 u_alphacolormask : register(c%i);\n", CONST_PS_ALPHACOLORMASK);
|
||||
}
|
||||
if (stencilToAlpha && replaceAlphaWithStencilType == STENCIL_VALUE_UNIFORM) {
|
||||
WRITE(p, "float u_stencilReplaceValue : register(c%i);\n", CONST_PS_STENCILREPLACE);
|
||||
}
|
||||
if (doTexture && texFunc == GE_TEXFUNC_BLEND) {
|
||||
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
|
||||
}
|
||||
if (enableFog) {
|
||||
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
|
||||
}
|
||||
} else {
|
||||
WRITE(p, "cbuffer base : register(b0) %s;\n", cb_baseStr);
|
||||
}
|
||||
|
||||
if (enableAlphaTest) {
|
||||
@ -122,7 +127,12 @@ bool GenerateFragmentShaderDX9(const ShaderID &id, char *buffer) {
|
||||
WRITE(p, " float2 v_fogdepth: TEXCOORD1;\n");
|
||||
}
|
||||
WRITE(p, "};\n");
|
||||
WRITE(p, "float4 main( PS_IN In ) : COLOR\n");
|
||||
|
||||
if (lang == HLSL_DX9) {
|
||||
WRITE(p, "float4 main( PS_IN In ) : COLOR\n");
|
||||
} else {
|
||||
WRITE(p, "float4 main( PS_IN In ) : SV_Target\n");
|
||||
}
|
||||
WRITE(p, "{\n");
|
||||
|
||||
if (isModeClear) {
|
||||
|
@ -18,10 +18,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "GPU/Common/ShaderId.h"
|
||||
#include "GPU/Common/ShaderCommon.h"
|
||||
|
||||
namespace DX9 {
|
||||
|
||||
bool GenerateFragmentShaderDX9(const ShaderID &id, char *buffer);
|
||||
bool GenerateFragmentShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage lang = HLSL_DX9);
|
||||
|
||||
#define CONST_PS_TEXENV 0
|
||||
#define CONST_PS_ALPHACOLORREF 1
|
||||
|
@ -576,7 +576,7 @@ VSShader *ShaderManagerDX9::ApplyShader(int prim, u32 vertType) {
|
||||
VSShader *vs;
|
||||
if (vsIter == vsCache_.end()) {
|
||||
// Vertex shader not in cache. Let's compile it.
|
||||
GenerateVertexShaderDX9(VSID, codeBuffer_);
|
||||
GenerateVertexShaderHLSL(VSID, codeBuffer_);
|
||||
vs = new VSShader(device_, VSID, codeBuffer_, useHWTransform);
|
||||
|
||||
if (vs->Failed()) {
|
||||
@ -592,7 +592,7 @@ VSShader *ShaderManagerDX9::ApplyShader(int prim, u32 vertType) {
|
||||
// next time and we'll do this over and over...
|
||||
|
||||
// Can still work with software transform.
|
||||
GenerateVertexShaderDX9(VSID, codeBuffer_);
|
||||
GenerateVertexShaderHLSL(VSID, codeBuffer_);
|
||||
vs = new VSShader(device_, VSID, codeBuffer_, false);
|
||||
}
|
||||
|
||||
@ -606,7 +606,7 @@ VSShader *ShaderManagerDX9::ApplyShader(int prim, u32 vertType) {
|
||||
PSShader *fs;
|
||||
if (fsIter == fsCache_.end()) {
|
||||
// Fragment shader not in cache. Let's compile it.
|
||||
GenerateFragmentShaderDX9(FSID, codeBuffer_);
|
||||
GenerateFragmentShaderHLSL(FSID, codeBuffer_);
|
||||
fs = new PSShader(device_, FSID, codeBuffer_);
|
||||
fsCache_[FSID] = fs;
|
||||
} else {
|
||||
|
@ -86,8 +86,8 @@ public:
|
||||
void DirtyShader();
|
||||
void DirtyLastShader();
|
||||
|
||||
int NumVertexShaders() const { return (int)vsCache_.size(); }
|
||||
int NumFragmentShaders() const { return (int)fsCache_.size(); }
|
||||
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
|
||||
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
|
||||
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
||||
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
|
||||
|
@ -1027,8 +1027,6 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry, bool replaceImage
|
||||
if (replaced.Valid()) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::Status(replaced.AlphaStatus()));
|
||||
}
|
||||
|
||||
UpdateSamplingParams(*entry, true);
|
||||
}
|
||||
|
||||
D3DFORMAT TextureCacheDX9::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
#include "../Globals.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "GPU/Directx9/VertexShaderGeneratorDX9.h"
|
||||
#include "GPU/Common/VertexDecoderCommon.h"
|
||||
#include "GPU/Common/ShaderUniforms.h"
|
||||
|
||||
#undef WRITE
|
||||
|
||||
@ -54,7 +55,7 @@ enum DoLightComputation {
|
||||
LIGHT_FULL,
|
||||
};
|
||||
|
||||
void GenerateVertexShaderDX9(const ShaderID &id, char *buffer) {
|
||||
void GenerateVertexShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage lang) {
|
||||
char *p = buffer;
|
||||
const u32 vertType = gstate.vertType;
|
||||
|
||||
@ -105,74 +106,80 @@ void GenerateVertexShaderDX9(const ShaderID &id, char *buffer) {
|
||||
|
||||
WRITE(p, "#pragma warning( disable : 3571 )\n");
|
||||
|
||||
if (isModeThrough) {
|
||||
WRITE(p, "float4x4 u_proj_through : register(c%i);\n", CONST_VS_PROJ_THROUGH);
|
||||
} else {
|
||||
WRITE(p, "float4x4 u_proj : register(c%i);\n", CONST_VS_PROJ);
|
||||
// Add all the uniforms we'll need to transform properly.
|
||||
}
|
||||
if (lang == HLSL_DX9) {
|
||||
if (isModeThrough) {
|
||||
WRITE(p, "float4x4 u_proj_through : register(c%i);\n", CONST_VS_PROJ_THROUGH);
|
||||
} else {
|
||||
WRITE(p, "float4x4 u_proj : register(c%i);\n", CONST_VS_PROJ);
|
||||
// Add all the uniforms we'll need to transform properly.
|
||||
}
|
||||
|
||||
if (enableFog) {
|
||||
WRITE(p, "float2 u_fogcoef : register(c%i);\n", CONST_VS_FOGCOEF);
|
||||
}
|
||||
if (useHWTransform || !hasColor)
|
||||
WRITE(p, "float4 u_matambientalpha : register(c%i);\n", CONST_VS_MATAMBIENTALPHA); // matambient + matalpha
|
||||
if (enableFog) {
|
||||
WRITE(p, "float2 u_fogcoef : register(c%i);\n", CONST_VS_FOGCOEF);
|
||||
}
|
||||
if (useHWTransform || !hasColor)
|
||||
WRITE(p, "float4 u_matambientalpha : register(c%i);\n", CONST_VS_MATAMBIENTALPHA); // matambient + matalpha
|
||||
|
||||
if (useHWTransform) {
|
||||
// When transforming by hardware, we need a great deal more uniforms...
|
||||
WRITE(p, "float4x3 u_world : register(c%i);\n", CONST_VS_WORLD);
|
||||
WRITE(p, "float4x3 u_view : register(c%i);\n", CONST_VS_VIEW);
|
||||
if (doTextureTransform)
|
||||
WRITE(p, "float4x3 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX);
|
||||
if (enableBones) {
|
||||
if (useHWTransform) {
|
||||
// When transforming by hardware, we need a great deal more uniforms...
|
||||
WRITE(p, "float4x3 u_world : register(c%i);\n", CONST_VS_WORLD);
|
||||
WRITE(p, "float4x3 u_view : register(c%i);\n", CONST_VS_VIEW);
|
||||
if (doTextureTransform)
|
||||
WRITE(p, "float4x3 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX);
|
||||
if (enableBones) {
|
||||
#ifdef USE_BONE_ARRAY
|
||||
WRITE(p, "float4x3 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0);
|
||||
WRITE(p, "float4x3 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0);
|
||||
#else
|
||||
for (int i = 0; i < numBoneWeights; i++) {
|
||||
WRITE(p, "float4x3 u_bone%i : register(c%i);\n", i, CONST_VS_BONE0 + i * 3);
|
||||
}
|
||||
for (int i = 0; i < numBoneWeights; i++) {
|
||||
WRITE(p, "float4x3 u_bone%i : register(c%i);\n", i, CONST_VS_BONE0 + i * 3);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (doTexture) {
|
||||
WRITE(p, "float4 u_uvscaleoffset : register(c%i);\n", CONST_VS_UVSCALEOFFSET);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (doLight[i] != LIGHT_OFF) {
|
||||
// This is needed for shade mapping
|
||||
WRITE(p, "float3 u_lightpos%i : register(c%i);\n", i, CONST_VS_LIGHTPOS + i);
|
||||
}
|
||||
if (doLight[i] == LIGHT_FULL) {
|
||||
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
||||
GELightComputation comp = static_cast<GELightComputation>(id.Bits(VS_BIT_LIGHT0_COMP + 4 * i, 2));
|
||||
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
WRITE(p, "float3 u_lightatt%i : register(c%i);\n", i, CONST_VS_LIGHTATT + i);
|
||||
|
||||
if (type == GE_LIGHTTYPE_SPOT || type == GE_LIGHTTYPE_UNKNOWN) {
|
||||
WRITE(p, "float3 u_lightdir%i : register(c%i);\n", i, CONST_VS_LIGHTDIR + i);
|
||||
WRITE(p, "float u_lightangle%i : register(c%i);\n", i, CONST_VS_LIGHTANGLE + i);
|
||||
WRITE(p, "float u_lightspotCoef%i : register(c%i);\n", i, CONST_VS_LIGHTSPOTCOEF + i);
|
||||
if (doTexture) {
|
||||
WRITE(p, "float4 u_uvscaleoffset : register(c%i);\n", CONST_VS_UVSCALEOFFSET);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (doLight[i] != LIGHT_OFF) {
|
||||
// This is needed for shade mapping
|
||||
WRITE(p, "float3 u_lightpos%i : register(c%i);\n", i, CONST_VS_LIGHTPOS + i);
|
||||
}
|
||||
WRITE(p, "float3 u_lightambient%i : register(c%i);\n", i, CONST_VS_LIGHTAMBIENT + i);
|
||||
WRITE(p, "float3 u_lightdiffuse%i : register(c%i);\n", i, CONST_VS_LIGHTDIFFUSE + i);
|
||||
if (doLight[i] == LIGHT_FULL) {
|
||||
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
||||
GELightComputation comp = static_cast<GELightComputation>(id.Bits(VS_BIT_LIGHT0_COMP + 4 * i, 2));
|
||||
|
||||
if (comp != GE_LIGHTCOMP_ONLYDIFFUSE) {
|
||||
WRITE(p, "float3 u_lightspecular%i : register(c%i);\n", i, CONST_VS_LIGHTSPECULAR + i);
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
WRITE(p, "float3 u_lightatt%i : register(c%i);\n", i, CONST_VS_LIGHTATT + i);
|
||||
|
||||
if (type == GE_LIGHTTYPE_SPOT || type == GE_LIGHTTYPE_UNKNOWN) {
|
||||
WRITE(p, "float3 u_lightdir%i : register(c%i);\n", i, CONST_VS_LIGHTDIR + i);
|
||||
WRITE(p, "float u_lightangle%i : register(c%i);\n", i, CONST_VS_LIGHTANGLE + i);
|
||||
WRITE(p, "float u_lightspotCoef%i : register(c%i);\n", i, CONST_VS_LIGHTSPOTCOEF + i);
|
||||
}
|
||||
WRITE(p, "float3 u_lightambient%i : register(c%i);\n", i, CONST_VS_LIGHTAMBIENT + i);
|
||||
WRITE(p, "float3 u_lightdiffuse%i : register(c%i);\n", i, CONST_VS_LIGHTDIFFUSE + i);
|
||||
|
||||
if (comp != GE_LIGHTCOMP_ONLYDIFFUSE) {
|
||||
WRITE(p, "float3 u_lightspecular%i : register(c%i);\n", i, CONST_VS_LIGHTSPECULAR + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (enableLighting) {
|
||||
WRITE(p, "float4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT);
|
||||
if ((gstate.materialupdate & 2) == 0 || !hasColor)
|
||||
WRITE(p, "float3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE);
|
||||
// if ((gstate.materialupdate & 4) == 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (enableLighting) {
|
||||
WRITE(p, "float4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT);
|
||||
if ((gstate.materialupdate & 2) == 0 || !hasColor)
|
||||
WRITE(p, "float3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE);
|
||||
// if ((gstate.materialupdate & 4) == 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||
WRITE(p, "float4 u_depthRange : register(c%i);\n", CONST_VS_DEPTHRANGE);
|
||||
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||
WRITE(p, "float4 u_depthRange : register(c%i);\n", CONST_VS_DEPTHRANGE);
|
||||
}
|
||||
} else {
|
||||
WRITE(p, "cbuffer base : register(b0) %s;\n", cb_baseStr);
|
||||
WRITE(p, "cbuffer lights: register(b1) %s;\n", cb_vs_lightsStr);
|
||||
WRITE(p, "cbuffer bones : register(b2) %s;\n", cb_vs_bonesStr);
|
||||
}
|
||||
|
||||
// And the "varyings".
|
||||
@ -216,7 +223,11 @@ void GenerateVertexShaderDX9(const ShaderID &id, char *buffer) {
|
||||
}
|
||||
|
||||
WRITE(p, "struct VS_OUT {\n");
|
||||
WRITE(p, " float4 gl_Position : POSITION;\n");
|
||||
if (lang == HLSL_DX9) {
|
||||
WRITE(p, " float4 gl_Position : POSITION;\n");
|
||||
} else {
|
||||
WRITE(p, " float4 gl_Position : SV_Position;\n");
|
||||
}
|
||||
if (doTexture) {
|
||||
WRITE(p, " float3 v_texcoord : TEXCOORD0;\n");
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace DX9 {
|
||||
|
||||
// #define USE_BONE_ARRAY
|
||||
|
||||
void GenerateVertexShaderDX9(const ShaderID &id, char *buffer);
|
||||
void GenerateVertexShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage lang = HLSL_DX9);
|
||||
|
||||
#define CONST_VS_PROJ 0
|
||||
#define CONST_VS_PROJ_THROUGH 4
|
||||
|
@ -1188,9 +1188,9 @@ void GPU_GLES::GetStats(char *buffer, size_t bufsize) {
|
||||
(int)textureCacheGL_->NumLoadedTextures(),
|
||||
gpuStats.numTexturesDecoded,
|
||||
gpuStats.numTextureInvalidations,
|
||||
shaderManagerGL_->NumVertexShaders(),
|
||||
shaderManagerGL_->NumFragmentShaders(),
|
||||
shaderManagerGL_->NumPrograms());
|
||||
shaderManagerGL_->GetNumVertexShaders(),
|
||||
shaderManagerGL_->GetNumFragmentShaders(),
|
||||
shaderManagerGL_->GetNumPrograms());
|
||||
}
|
||||
|
||||
void GPU_GLES::ClearCacheNextFrame() {
|
||||
|
@ -1084,9 +1084,9 @@ void ShaderManagerGLES::Save(const std::string &filename) {
|
||||
header.version = CACHE_VERSION;
|
||||
header.reserved = 0;
|
||||
header.featureFlags = gstate_c.featureFlags;
|
||||
header.numVertexShaders = NumVertexShaders();
|
||||
header.numFragmentShaders = NumFragmentShaders();
|
||||
header.numLinkedPrograms = NumPrograms();
|
||||
header.numVertexShaders = GetNumVertexShaders();
|
||||
header.numFragmentShaders = GetNumFragmentShaders();
|
||||
header.numLinkedPrograms = GetNumPrograms();
|
||||
fwrite(&header, 1, sizeof(header), f);
|
||||
for (auto iter : vsCache_) {
|
||||
ShaderID id = iter.first;
|
||||
|
@ -155,9 +155,9 @@ public:
|
||||
void DirtyShader();
|
||||
void DirtyLastShader(); // disables vertex arrays
|
||||
|
||||
int NumVertexShaders() const { return (int)vsCache_.size(); }
|
||||
int NumFragmentShaders() const { return (int)fsCache_.size(); }
|
||||
int NumPrograms() const { return (int)linkedShaderCache_.size(); }
|
||||
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
|
||||
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
|
||||
int GetNumPrograms() const { return (int)linkedShaderCache_.size(); }
|
||||
|
||||
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
||||
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
|
||||
|
@ -66,9 +66,8 @@ bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
|
||||
#endif
|
||||
case GPUCORE_DIRECTX11:
|
||||
#if defined(_WIN32)
|
||||
// SetGPU(new D3D11_GPU(ctx, draw));
|
||||
// break;
|
||||
return false;
|
||||
SetGPU(new GPU_D3D11(ctx, draw));
|
||||
break;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -203,6 +203,7 @@
|
||||
<ClInclude Include="Common\TextureScalerCommon.h" />
|
||||
<ClInclude Include="Common\TransformCommon.h" />
|
||||
<ClInclude Include="Common\VertexDecoderCommon.h" />
|
||||
<ClInclude Include="D3D11\D3D11Util.h" />
|
||||
<ClInclude Include="D3D11\DepalettizeShaderD3D11.h" />
|
||||
<ClInclude Include="D3D11\DrawEngineD3D11.h" />
|
||||
<ClInclude Include="D3D11\FragmentShaderGeneratorD3D11.h" />
|
||||
@ -210,6 +211,7 @@
|
||||
<ClInclude Include="D3D11\GPU_D3D11.h" />
|
||||
<ClInclude Include="D3D11\ShaderManagerD3D11.h" />
|
||||
<ClInclude Include="D3D11\TextureCacheD3D11.h" />
|
||||
<ClInclude Include="D3D11\TextureScalerD3D11.h" />
|
||||
<ClInclude Include="D3D11\VertexShaderGeneratorD3D11.h" />
|
||||
<ClInclude Include="Debugger\Breakpoints.h" />
|
||||
<ClInclude Include="Debugger\Stepping.h" />
|
||||
@ -296,6 +298,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="Common\VertexDecoderCommon.cpp" />
|
||||
<ClCompile Include="Common\VertexDecoderX86.cpp" />
|
||||
<ClCompile Include="D3D11\D3D11Util.cpp" />
|
||||
<ClCompile Include="D3D11\DepalettizeShaderD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\DrawEngineD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\FragmentShaderGeneratorD3D11.cpp" />
|
||||
@ -303,7 +306,9 @@
|
||||
<ClCompile Include="D3D11\GPU_D3D11.cpp" />
|
||||
<ClCompile Include="D3D11\ShaderManagerD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\StateMappingD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\StencilBufferD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\TextureCacheD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\TextureScalerD3D11.cpp" />
|
||||
<ClCompile Include="D3D11\VertexShaderGeneratorD3D11.cpp" />
|
||||
<ClCompile Include="Debugger\Breakpoints.cpp" />
|
||||
<ClCompile Include="Debugger\Stepping.cpp" />
|
||||
|
@ -249,6 +249,12 @@
|
||||
<ClInclude Include="D3D11\DepalettizeShaderD3D11.h">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="D3D11\TextureScalerD3D11.h">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="D3D11\D3D11Util.h">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Math3D.cpp">
|
||||
@ -485,5 +491,14 @@
|
||||
<ClCompile Include="D3D11\DepalettizeShaderD3D11.cpp">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="D3D11\TextureScalerD3D11.cpp">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="D3D11\D3D11Util.cpp">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="D3D11\StencilBufferD3D11.cpp">
|
||||
<Filter>D3D11</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -78,16 +78,17 @@ static const VkComponentMapping VULKAN_1555_SWIZZLE = { VK_COMPONENT_SWIZZLE_B,
|
||||
static const VkComponentMapping VULKAN_565_SWIZZLE = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
|
||||
static const VkComponentMapping VULKAN_8888_SWIZZLE = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
|
||||
|
||||
|
||||
CachedTextureVulkan::~CachedTextureVulkan() {
|
||||
delete texture_;
|
||||
}
|
||||
|
||||
SamplerCache::~SamplerCache() {
|
||||
for (auto iter : cache_) {
|
||||
vulkan_->Delete().QueueDeleteSampler(iter.second);
|
||||
}
|
||||
}
|
||||
|
||||
CachedTextureVulkan::~CachedTextureVulkan() {
|
||||
delete texture_;
|
||||
}
|
||||
|
||||
VkSampler SamplerCache::GetOrCreateSampler(const SamplerCacheKey &key) {
|
||||
auto iter = cache_.find(key);
|
||||
if (iter != cache_.end()) {
|
||||
|
@ -37,28 +37,6 @@ class VulkanTexture;
|
||||
class VulkanPushBuffer;
|
||||
class VulkanDeviceAllocator;
|
||||
|
||||
struct SamplerCacheKey {
|
||||
SamplerCacheKey() : fullKey(0) {}
|
||||
|
||||
union {
|
||||
u32 fullKey;
|
||||
struct {
|
||||
bool mipEnable : 1;
|
||||
bool minFilt : 1;
|
||||
bool mipFilt : 1;
|
||||
bool magFilt : 1;
|
||||
bool sClamp : 1;
|
||||
bool tClamp : 1;
|
||||
int lodBias : 4;
|
||||
int maxLevel : 4;
|
||||
};
|
||||
};
|
||||
|
||||
bool operator < (const SamplerCacheKey &other) const {
|
||||
return fullKey < other.fullKey;
|
||||
}
|
||||
};
|
||||
|
||||
class CachedTextureVulkan {
|
||||
public:
|
||||
CachedTextureVulkan() : texture_(nullptr) {
|
||||
|
2
dx9sdk
2
dx9sdk
@ -1 +1 @@
|
||||
Subproject commit a2e5de9de341a8659aa1199e03636f5a4cea1318
|
||||
Subproject commit 7324553f8f4952a576c7f2d42df0accb0335d23c
|
@ -316,6 +316,8 @@ enum class NativeObject {
|
||||
CONTEXT,
|
||||
DEVICE,
|
||||
DEVICE_EX,
|
||||
BACKBUFFER_COLOR_VIEW,
|
||||
BACKBUFFER_DEPTH_VIEW,
|
||||
};
|
||||
|
||||
enum FBColorDepth {
|
||||
@ -610,6 +612,7 @@ public:
|
||||
BindTextures(stage, 1, &texture);
|
||||
} // from sampler 0 and upwards
|
||||
|
||||
// Call this with 0 to signal that you have been drawing on your own, and need the state reset on the next pipeline bind.
|
||||
virtual void BindPipeline(Pipeline *pipeline) = 0;
|
||||
|
||||
// TODO: Add more sophisticated draws with buffer offsets, and multidraws.
|
||||
|
@ -100,6 +100,10 @@ public:
|
||||
return (uintptr_t)device_;
|
||||
case NativeObject::CONTEXT:
|
||||
return (uintptr_t)context_;
|
||||
case NativeObject::BACKBUFFER_COLOR_VIEW:
|
||||
return (uintptr_t)bbRenderTargetView_;
|
||||
case NativeObject::BACKBUFFER_DEPTH_VIEW:
|
||||
return (uintptr_t)bbDepthStencilView_;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -792,6 +796,18 @@ void D3D11DrawContext::UpdateDynamicUniformBuffer(const void *ub, size_t size) {
|
||||
}
|
||||
|
||||
void D3D11DrawContext::BindPipeline(Pipeline *pipeline) {
|
||||
if (pipeline == nullptr) {
|
||||
// This is a signal to forget all our caching.
|
||||
curBlend_ = nullptr;
|
||||
curDepth_ = nullptr;
|
||||
curRaster_ = nullptr;
|
||||
curPS_ = nullptr;
|
||||
curVS_ = nullptr;
|
||||
curGS_ = nullptr;
|
||||
curInputLayout_ = nullptr;
|
||||
curTopology_ = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||
}
|
||||
|
||||
D3D11Pipeline *dPipeline = (D3D11Pipeline *)pipeline;
|
||||
if (curPipeline_ == dPipeline)
|
||||
return;
|
||||
@ -840,7 +856,6 @@ void D3D11DrawContext::ApplyCurrentState() {
|
||||
if (nextIndexBuffer_) {
|
||||
context_->IASetIndexBuffer(nextIndexBuffer_, DXGI_FORMAT_R32_UINT, nextIndexBufferOffset_);
|
||||
}
|
||||
|
||||
if (curPipeline_->dynamicUniforms) {
|
||||
context_->VSSetConstantBuffers(0, 1, &curPipeline_->dynamicUniforms);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user