mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
D3D11: Implement depth texturing. Fixes, for D3D11, #6411.
This commit is contained in:
parent
d3339d93b0
commit
e80a526015
@ -38,6 +38,12 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang
|
||||
WRITE(p, "SamplerState texSamp : register(s0);\n");
|
||||
WRITE(p, "Texture2D<float4> tex : register(t0);\n");
|
||||
WRITE(p, "Texture2D<float4> pal : register(t3);\n");
|
||||
// Support for depth.
|
||||
if (pixelFormat == GE_FORMAT_DEPTH16) {
|
||||
WRITE(p, "cbuffer params : register(b0) {\n");
|
||||
WRITE(p, " float z_scale; float z_offset;\n");
|
||||
WRITE(p, "};\n");
|
||||
}
|
||||
} else if (language == GLSL_VULKAN) {
|
||||
WRITE(p, "#version 450\n");
|
||||
WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
|
||||
@ -53,7 +59,6 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang
|
||||
WRITE(p, " float z_scale; float z_offset;\n");
|
||||
WRITE(p, "};\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
if (gl_extensions.IsGLES) {
|
||||
WRITE(p, "#version 300 es\n");
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "Core/Reporting.h"
|
||||
#include "GPU/ge_constants.h"
|
||||
#include "GPU/GPUState.h"
|
||||
#include "GPU/Common/GPUStateUtils.h"
|
||||
#include "GPU/D3D11/FragmentShaderGeneratorD3D11.h"
|
||||
#include "GPU/D3D11/TextureCacheD3D11.h"
|
||||
#include "GPU/D3D11/FramebufferManagerD3D11.h"
|
||||
@ -39,6 +40,12 @@
|
||||
#include "ext/xxhash.h"
|
||||
#include "Common/Math/math_util.h"
|
||||
|
||||
// For depth depal
|
||||
struct DepthPushConstants {
|
||||
float z_scale;
|
||||
float z_offset;
|
||||
float pad[2];
|
||||
};
|
||||
|
||||
#define INVALID_TEX (ID3D11ShaderResourceView *)(-1LL)
|
||||
|
||||
@ -113,6 +120,9 @@ TextureCacheD3D11::TextureCacheD3D11(Draw::DrawContext *draw)
|
||||
isBgraBackend_ = true;
|
||||
lastBoundTexture = INVALID_TEX;
|
||||
|
||||
D3D11_BUFFER_DESC desc{ sizeof(DepthPushConstants), D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, D3D11_CPU_ACCESS_WRITE };
|
||||
_dbg_assert_(SUCCEEDED(device_->CreateBuffer(&desc, nullptr, &depalConstants_)));
|
||||
|
||||
HRESULT result = 0;
|
||||
|
||||
SetupTextureDecoder();
|
||||
@ -121,6 +131,8 @@ TextureCacheD3D11::TextureCacheD3D11(Draw::DrawContext *draw)
|
||||
}
|
||||
|
||||
TextureCacheD3D11::~TextureCacheD3D11() {
|
||||
depalConstants_->Release();
|
||||
|
||||
// pFramebufferVertexDecl->Release();
|
||||
Clear(true);
|
||||
}
|
||||
@ -355,8 +367,9 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
|
||||
ID3D11PixelShader *pshader = nullptr;
|
||||
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;
|
||||
bool need_depalettize = IsClutFormat(texFormat);
|
||||
bool depth = channel == NOTIFY_FB_DEPTH;
|
||||
if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) {
|
||||
pshader = depalShaderCache_->GetDepalettizePixelShader(clutMode, framebuffer->drawnFormat);
|
||||
pshader = depalShaderCache_->GetDepalettizePixelShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat);
|
||||
}
|
||||
|
||||
if (pshader) {
|
||||
@ -382,8 +395,20 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
|
||||
draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "ApplyTextureFramebuffer_DepalShader");
|
||||
context_->PSSetShaderResources(3, 1, &clutTexture);
|
||||
context_->PSSetSamplers(3, 1, &stockD3D11.samplerPoint2DWrap);
|
||||
framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY | BINDFBCOLOR_FORCE_SELF);
|
||||
draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0);
|
||||
context_->PSSetSamplers(0, 1, &stockD3D11.samplerPoint2DWrap);
|
||||
|
||||
if (depth) {
|
||||
DepthScaleFactors scaleFactors = GetDepthScaleFactors();
|
||||
DepthPushConstants push;
|
||||
push.z_scale = scaleFactors.scale;
|
||||
push.z_offset = scaleFactors.offset;
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
context_->Map(depalConstants_, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &push, sizeof(push));
|
||||
context_->Unmap(depalConstants_, 0);
|
||||
context_->PSSetConstantBuffers(0, 1, &depalConstants_);
|
||||
}
|
||||
shaderApply.Shade();
|
||||
|
||||
context_->PSSetShaderResources(0, 1, &nullTexture); // Make D3D11 validation happy. Really of no consequence since we rebind anyway.
|
||||
|
@ -91,6 +91,7 @@ private:
|
||||
SamplerCacheD3D11 samplerCache_;
|
||||
|
||||
ID3D11ShaderResourceView *lastBoundTexture;
|
||||
ID3D11Buffer *depalConstants_;
|
||||
|
||||
int decimationCounter_;
|
||||
int texelsScaledThisFrame_;
|
||||
@ -99,6 +100,7 @@ private:
|
||||
FramebufferManagerD3D11 *framebufferManagerD3D11_;
|
||||
DepalShaderCacheD3D11 *depalShaderCache_;
|
||||
ShaderManagerD3D11 *shaderManager_;
|
||||
|
||||
};
|
||||
|
||||
DXGI_FORMAT GetClutDestFormatD3D11(GEPaletteFormat format);
|
||||
|
Loading…
Reference in New Issue
Block a user