Skip to content

Commit

Permalink
Unify stencil buffer upload using Draw. Only OpenGL tested yet (shade…
Browse files Browse the repository at this point in the history
…rs need adaptation).
  • Loading branch information
hrydgard committed Aug 3, 2022
1 parent d4d92e3 commit 9bead44
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 792 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,6 @@ set(GPU_GLES
GPU/GLES/ShaderManagerGLES.h
GPU/GLES/StateMappingGLES.cpp
GPU/GLES/StateMappingGLES.h
GPU/GLES/StencilBufferGLES.cpp
GPU/GLES/TextureCacheGLES.cpp
GPU/GLES/TextureCacheGLES.h
GPU/GLES/DrawEngineGLES.cpp
Expand All @@ -1479,7 +1478,6 @@ set(GPU_VULKAN
GPU/Vulkan/ShaderManagerVulkan.h
GPU/Vulkan/StateMappingVulkan.cpp
GPU/Vulkan/StateMappingVulkan.h
GPU/Vulkan/StencilBufferVulkan.cpp
GPU/Vulkan/TextureCacheVulkan.cpp
GPU/Vulkan/TextureCacheVulkan.h
GPU/Vulkan/VulkanUtil.cpp
Expand All @@ -1499,7 +1497,6 @@ set(GPU_D3D9
GPU/Directx9/ShaderManagerDX9.h
GPU/Directx9/StateMappingDX9.cpp
GPU/Directx9/StateMappingDX9.h
GPU/Directx9/StencilBufferDX9.cpp
GPU/Directx9/TextureCacheDX9.cpp
GPU/Directx9/TextureCacheDX9.h
)
Expand All @@ -1519,7 +1516,6 @@ set(GPU_D3D11
GPU/D3D11/ShaderManagerD3D11.h
GPU/D3D11/StateMappingD3D11.cpp
GPU/D3D11/StateMappingD3D11.h
GPU/D3D11/StencilBufferD3D11.cpp
GPU/D3D11/TextureCacheD3D11.cpp
GPU/D3D11/TextureCacheD3D11.h
)
Expand Down
1 change: 1 addition & 0 deletions Common/GPU/D3D11/thin3d_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class D3D11DrawContext : public DrawContext {
uint8_t stencilRef_ = 0;
uint8_t stencilWriteMask_ = 0xFF;
uint8_t stencilCompareMask_ = 0xFF;

bool stencilDirty_ = true;

// Temporaries
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/OpenGL/thin3d_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ void OpenGLContext::ApplySamplers() {
const OpenGLSamplerState *samp = boundSamplers_[i];
const GLRTexture *tex = boundTextures_[i];
if (tex) {
_assert_(samp);
_assert_msg_(samp, "Sampler missing");
} else {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions Common/GPU/thin3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Draw {
// Useful in UBOs
typedef int bool32;

enum class Comparison : int {
enum class Comparison : uint8_t {
NEVER,
LESS,
EQUAL,
Expand All @@ -37,7 +37,7 @@ enum class Comparison : int {
};

// Had to prefix with LOGIC, too many clashes
enum class LogicOp : int {
enum class LogicOp : uint8_t {
LOGIC_CLEAR,
LOGIC_SET,
LOGIC_COPY,
Expand All @@ -56,7 +56,7 @@ enum class LogicOp : int {
LOGIC_OR_INVERTED,
};

enum class BlendOp : int {
enum class BlendOp : uint8_t {
ADD,
SUBTRACT,
REV_SUBTRACT,
Expand Down Expand Up @@ -96,7 +96,7 @@ enum class StencilOp {
DECREMENT_AND_WRAP = 7,
};

enum class TextureFilter : int {
enum class TextureFilter : uint8_t {
NEAREST = 0,
LINEAR = 1,
};
Expand Down
4 changes: 4 additions & 0 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,10 @@ void FramebufferManagerCommon::DeviceLost() {
DoRelease(reinterpretVBuf_);
DoRelease(reinterpretSampler_);
DoRelease(reinterpretVS_);
DoRelease(stencilUploadFs_);
DoRelease(stencilUploadVs_);
DoRelease(stencilUploadSampler_);
DoRelease(stencilUploadPipeline_);
presentation_->DeviceLost();
draw_ = nullptr;
}
Expand Down
9 changes: 8 additions & 1 deletion GPU/Common/FramebufferManagerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class FramebufferManagerCommon {
void NotifyVideoUpload(u32 addr, int size, int width, GEBufferFormat fmt);
void UpdateFromMemory(u32 addr, int size, bool safe);
void ApplyClearToMemory(int x1, int y1, int x2, int y2, u32 clearColor);
virtual bool NotifyStencilUpload(u32 addr, int size, StencilUpload flags = StencilUpload::NEEDS_CLEAR) = 0;
bool NotifyStencilUpload(u32 addr, int size, StencilUpload flags = StencilUpload::NEEDS_CLEAR);
// Returns true if it's sure this is a direct FBO->FBO transfer and it has already handle it.
// In that case we hardly need to actually copy the bytes in VRAM, they will be wrong anyway (unless
// read framebuffers is on, in which case this should always return false).
Expand Down Expand Up @@ -467,4 +467,11 @@ class FramebufferManagerCommon {
Draw::ShaderModule *reinterpretVS_ = nullptr;
Draw::SamplerState *reinterpretSampler_ = nullptr;
Draw::Buffer *reinterpretVBuf_ = nullptr;

// Common implementation of stencil buffer upload. Also not 100% optimal, but not perforamnce
// critical either.
Draw::Pipeline *stencilUploadPipeline_ = nullptr;
Draw::ShaderModule *stencilUploadVs_ = nullptr;
Draw::ShaderModule *stencilUploadFs_ = nullptr;
Draw::SamplerState *stencilUploadSampler_ = nullptr;
};
Loading

0 comments on commit 9bead44

Please sign in to comment.