From 2869c570f1d0b67d2ee4304ea528bef3ef4b563e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Apr 2017 15:54:45 +1000 Subject: Renderer: Move depth state to VideoCommon and seperate from bpmem --- Source/Core/VideoCommon/RenderState.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Source/Core/VideoCommon/RenderState.cpp') diff --git a/Source/Core/VideoCommon/RenderState.cpp b/Source/Core/VideoCommon/RenderState.cpp index 7e6d845ccb..344ec5b32a 100644 --- a/Source/Core/VideoCommon/RenderState.cpp +++ b/Source/Core/VideoCommon/RenderState.cpp @@ -4,6 +4,13 @@ #include "VideoCommon/RenderState.h" +void DepthState::Generate(const BPMemory& bp) +{ + testenable = bp.zmode.testenable.Value(); + updateenable = bp.zmode.updateenable.Value(); + func = bp.zmode.func.Value(); +} + // If the framebuffer format has no alpha channel, it is assumed to // ONE on blending. As the backends may emulate this framebuffer // configuration with an alpha channel, we just drop all references -- cgit v1.2.3 From 836b9b9acbc2ff2d10d6f3c81e64b7b10b22f023 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Apr 2017 18:07:57 +1000 Subject: Renderer: Move cull mode to a rasterization state object Also moves logic for primitive handling to VideoCommon. --- Source/Core/VideoCommon/RenderState.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Source/Core/VideoCommon/RenderState.cpp') diff --git a/Source/Core/VideoCommon/RenderState.cpp b/Source/Core/VideoCommon/RenderState.cpp index 344ec5b32a..d019214206 100644 --- a/Source/Core/VideoCommon/RenderState.cpp +++ b/Source/Core/VideoCommon/RenderState.cpp @@ -4,6 +4,16 @@ #include "VideoCommon/RenderState.h" +void RasterizationState::Generate(const BPMemory& bp, PrimitiveType primitive_type) +{ + cullmode = bp.genMode.cullmode; + primitive = primitive_type; + + // Back-face culling should be disabled for points/lines. + if (primitive_type != PrimitiveType::Triangles && primitive_type != PrimitiveType::TriangleStrip) + cullmode = GenMode::CULL_NONE; +} + void DepthState::Generate(const BPMemory& bp) { testenable = bp.zmode.testenable.Value(); -- cgit v1.2.3 From 340aabbb06404481b8a496f506ebc9bae75fad6c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 9 Sep 2017 00:10:40 +1000 Subject: VideoCommon: Add helpers for generating common render states --- Source/Core/VideoCommon/RenderState.cpp | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'Source/Core/VideoCommon/RenderState.cpp') diff --git a/Source/Core/VideoCommon/RenderState.cpp b/Source/Core/VideoCommon/RenderState.cpp index d019214206..d8cd5e7f11 100644 --- a/Source/Core/VideoCommon/RenderState.cpp +++ b/Source/Core/VideoCommon/RenderState.cpp @@ -144,3 +144,37 @@ void BlendingState::Generate(const BPMemory& bp) } } } + +namespace RenderState +{ +RasterizationState GetNoCullRasterizationState() +{ + RasterizationState state = {}; + state.cullmode = GenMode::CULL_NONE; + return state; +} + +DepthState GetNoDepthTestingDepthStencilState() +{ + DepthState state = {}; + state.testenable = false; + state.updateenable = false; + state.func = ZMode::ALWAYS; + return state; +} + +BlendingState GetNoBlendingBlendState() +{ + BlendingState state = {}; + state.usedualsrc = false; + state.blendenable = false; + state.srcfactor = BlendMode::ONE; + state.srcfactoralpha = BlendMode::ONE; + state.dstfactor = BlendMode::ZERO; + state.dstfactoralpha = BlendMode::ZERO; + state.logicopenable = false; + state.colorupdate = true; + state.alphaupdate = true; + return state; +} +} -- cgit v1.2.3 From 24ddea04ce3c843dd1de3d34d775e9a49d195225 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 9 Sep 2017 18:30:15 +1000 Subject: VideoBackends: Move SamplerState to common --- Source/Core/VideoCommon/RenderState.cpp | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'Source/Core/VideoCommon/RenderState.cpp') diff --git a/Source/Core/VideoCommon/RenderState.cpp b/Source/Core/VideoCommon/RenderState.cpp index d8cd5e7f11..8f8d421730 100644 --- a/Source/Core/VideoCommon/RenderState.cpp +++ b/Source/Core/VideoCommon/RenderState.cpp @@ -3,6 +3,9 @@ // Refer to the license.txt file included. #include "VideoCommon/RenderState.h" +#include +#include +#include "VideoCommon/SamplerCommon.h" void RasterizationState::Generate(const BPMemory& bp, PrimitiveType primitive_type) { @@ -14,6 +17,12 @@ void RasterizationState::Generate(const BPMemory& bp, PrimitiveType primitive_ty cullmode = GenMode::CULL_NONE; } +RasterizationState& RasterizationState::operator=(const RasterizationState& rhs) +{ + hex = rhs.hex; + return *this; +} + void DepthState::Generate(const BPMemory& bp) { testenable = bp.zmode.testenable.Value(); @@ -21,6 +30,12 @@ void DepthState::Generate(const BPMemory& bp) func = bp.zmode.func.Value(); } +DepthState& DepthState::operator=(const DepthState& rhs) +{ + hex = rhs.hex; + return *this; +} + // If the framebuffer format has no alpha channel, it is assumed to // ONE on blending. As the backends may emulate this framebuffer // configuration with an alpha channel, we just drop all references @@ -145,6 +160,43 @@ void BlendingState::Generate(const BPMemory& bp) } } +BlendingState& BlendingState::operator=(const BlendingState& rhs) +{ + hex = rhs.hex; + return *this; +} + +void SamplerState::Generate(const BPMemory& bp, u32 index) +{ + const FourTexUnits& tex = bpmem.tex[index / 4]; + const TexMode0& tm0 = tex.texMode0[index % 4]; + const TexMode1& tm1 = tex.texMode1[index % 4]; + + // GX can configure the mip filter to none. However, D3D and Vulkan can't express this in their + // sampler states. Therefore, we set the min/max LOD to zero if this option is used. + min_filter = (tm0.min_filter & 4) != 0 ? Filter::Linear : Filter::Point; + mipmap_filter = (tm0.min_filter & 3) == TexMode0::TEXF_LINEAR ? Filter::Linear : Filter::Point; + mag_filter = tm0.mag_filter != 0 ? Filter::Linear : Filter::Point; + + // If mipmaps are disabled, clamp min/max lod + max_lod = SamplerCommon::AreBpTexMode0MipmapsEnabled(tm0) ? tm1.max_lod : 0; + min_lod = std::min(max_lod.Value(), tm1.min_lod); + lod_bias = SamplerCommon::AreBpTexMode0MipmapsEnabled(tm0) ? tm0.lod_bias : 0; + + // Address modes + static constexpr std::array address_modes = { + {AddressMode::Clamp, AddressMode::Repeat, AddressMode::MirroredRepeat, AddressMode::Repeat}}; + wrap_u = address_modes[tm0.wrap_s]; + wrap_v = address_modes[tm0.wrap_t]; + anisotropic_filtering = 0; +} + +SamplerState& SamplerState::operator=(const SamplerState& rhs) +{ + hex = rhs.hex; + return *this; +} + namespace RenderState { RasterizationState GetNoCullRasterizationState() @@ -177,4 +229,34 @@ BlendingState GetNoBlendingBlendState() state.alphaupdate = true; return state; } + +SamplerState GetPointSamplerState() +{ + SamplerState state = {}; + state.min_filter = SamplerState::Filter::Point; + state.mag_filter = SamplerState::Filter::Point; + state.mipmap_filter = SamplerState::Filter::Point; + state.wrap_u = SamplerState::AddressMode::Clamp; + state.wrap_v = SamplerState::AddressMode::Clamp; + state.min_lod = 0; + state.max_lod = 255; + state.lod_bias = 0; + state.anisotropic_filtering = false; + return state; +} + +SamplerState GetLinearSamplerState() +{ + SamplerState state = {}; + state.min_filter = SamplerState::Filter::Linear; + state.mag_filter = SamplerState::Filter::Linear; + state.mipmap_filter = SamplerState::Filter::Linear; + state.wrap_u = SamplerState::AddressMode::Clamp; + state.wrap_v = SamplerState::AddressMode::Clamp; + state.min_lod = 0; + state.max_lod = 255; + state.lod_bias = 0; + state.anisotropic_filtering = false; + return state; +} } -- cgit v1.2.3