Skip to content

Commit 1fb9cfd

Browse files
committed
create helper function for rasterization kill
1 parent 05518c0 commit 1fb9cfd

File tree

5 files changed

+37
-65
lines changed

5 files changed

+37
-65
lines changed

src/Cafe/HW/Latte/Core/LatteShader.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h"
1010
#include "Cafe/OS/libs/gx2/GX2.h" // todo - remove dependency
1111
#include "Cafe/GraphicPack/GraphicPack2.h"
12+
#include "HW/Latte/Core/Latte.h"
1213
#include "HW/Latte/Renderer/Renderer.h"
1314
#include "util/helpers/StringParser.h"
1415
#include "config/ActiveSettings.h"
@@ -543,20 +544,7 @@ void LatteSHRC_UpdateVSBaseHash(uint8* vertexShaderPtr, uint32 vertexShaderSize,
543544

544545
if (!usesGeometryShader)
545546
{
546-
// Rasterization
547-
bool rasterizationEnabled = !LatteGPUState.contextNew.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
548-
549-
// HACK
550-
if (!LatteGPUState.contextNew.PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
551-
rasterizationEnabled = true;
552-
553-
const auto& polygonControlReg = LatteGPUState.contextNew.PA_SU_SC_MODE_CNTL;
554-
uint32 cullFront = polygonControlReg.get_CULL_FRONT();
555-
uint32 cullBack = polygonControlReg.get_CULL_BACK();
556-
if (cullFront && cullBack)
557-
rasterizationEnabled = false;
558-
559-
if (rasterizationEnabled)
547+
if (LatteGPUState.contextNew.IsRasterizationEnabled())
560548
vsHash += 51ULL;
561549

562550
// Vertex fetch

src/Cafe/HW/Latte/ISA/LatteReg.h

+32-14
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ namespace Latte
5252
{
5353
// same as E_TILEMODE but contains additional options with special meaning
5454
TM_LINEAR_GENERAL = 0,
55-
TM_LINEAR_ALIGNED = 1,
55+
TM_LINEAR_ALIGNED = 1,
5656

5757
// micro-tiled
58-
TM_1D_TILED_THIN1 = 2,
59-
TM_1D_TILED_THICK = 3,
58+
TM_1D_TILED_THIN1 = 2,
59+
TM_1D_TILED_THICK = 3,
6060

6161
// macro-tiled
62-
TM_2D_TILED_THIN1 = 4,
63-
TM_2D_TILED_THIN2 = 5,
64-
TM_2D_TILED_THIN4 = 6,
65-
TM_2D_TILED_THICK = 7,
62+
TM_2D_TILED_THIN1 = 4,
63+
TM_2D_TILED_THIN2 = 5,
64+
TM_2D_TILED_THIN4 = 6,
65+
TM_2D_TILED_THICK = 7,
6666

67-
TM_2B_TILED_THIN1 = 8,
68-
TM_2B_TILED_THIN2 = 9,
67+
TM_2B_TILED_THIN1 = 8,
68+
TM_2B_TILED_THIN2 = 9,
6969
TM_2B_TILED_THIN4 = 10,
7070
TM_2B_TILED_THICK = 11,
7171

@@ -179,7 +179,7 @@ namespace Latte
179179
HWFMT_4_4_4_4 = 0xB,
180180
HWFMT_5_5_5_1 = 0xC,
181181
HWFMT_32 = 0xD,
182-
HWFMT_32_FLOAT = 0xE,
182+
HWFMT_32_FLOAT = 0xE,
183183
HWFMT_16_16 = 0xF,
184184
HWFMT_16_16_FLOAT = 0x10,
185185
HWFMT_8_24 = 0x11,
@@ -284,7 +284,7 @@ namespace Latte
284284
R32_G32_B32_A32_UINT = (HWFMT_32_32_32_32 | FMT_BIT_INT),
285285
R32_G32_B32_A32_SINT = (HWFMT_32_32_32_32 | FMT_BIT_INT | FMT_BIT_SIGNED),
286286
R32_G32_B32_A32_FLOAT = (HWFMT_32_32_32_32_FLOAT | FMT_BIT_FLOAT),
287-
287+
288288
// depth
289289
D24_S8_UNORM = (HWFMT_8_24),
290290
D24_S8_FLOAT = (HWFMT_8_24 | FMT_BIT_FLOAT),
@@ -353,7 +353,7 @@ namespace Latte
353353
enum GPU_LIMITS
354354
{
355355
NUM_VERTEX_BUFFERS = 16,
356-
NUM_TEXTURES_PER_STAGE = 18,
356+
NUM_TEXTURES_PER_STAGE = 18,
357357
NUM_SAMPLERS_PER_STAGE = 18, // is this 16 or 18?
358358
NUM_COLOR_ATTACHMENTS = 8,
359359
};
@@ -1579,7 +1579,7 @@ struct LatteContextRegister
15791579
/* +0x3A4C0 */ _LatteRegisterSetTextureUnit SQ_TEX_START_GS[Latte::GPU_LIMITS::NUM_TEXTURES_PER_STAGE];
15801580

15811581
uint8 padding_3A6B8[0x3C000 - 0x3A6B8];
1582-
1582+
15831583
/* +0x3C000 */ _LatteRegisterSetSampler SQ_TEX_SAMPLER[18 * 3];
15841584

15851585
/* +0x3C288 */
@@ -1598,6 +1598,24 @@ struct LatteContextRegister
15981598
{
15991599
return (uint32*)hleSpecialState;
16001600
}
1601+
1602+
bool IsRasterizationEnabled() const
1603+
{
1604+
bool rasterizationEnabled = !PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
1605+
1606+
// GX2SetSpecialState(0, true) enables DX_RASTERIZATION_KILL, but still expects depth writes to happen? -> Research which stages are disabled by DX_RASTERIZATION_KILL exactly
1607+
// for now we use a workaround:
1608+
if (!PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
1609+
rasterizationEnabled = true;
1610+
1611+
// Culling both front and back faces effectively disables rasterization
1612+
uint32 cullFront = PA_SU_SC_MODE_CNTL.get_CULL_FRONT();
1613+
uint32 cullBack = PA_SU_SC_MODE_CNTL.get_CULL_BACK();
1614+
if (cullFront && cullBack)
1615+
rasterizationEnabled = false;
1616+
1617+
return rasterizationEnabled;
1618+
}
16011619
};
16021620

16031621
static_assert(sizeof(LatteContextRegister) == 0x10000 * 4 + 9 * 4);
@@ -1664,4 +1682,4 @@ static_assert(offsetof(LatteContextRegister, SQ_PGM_RESOURCES_ES) == Latte::REGA
16641682
static_assert(offsetof(LatteContextRegister, SQ_PGM_START_GS) == Latte::REGADDR::SQ_PGM_START_GS * 4);
16651683
static_assert(offsetof(LatteContextRegister, SQ_PGM_RESOURCES_GS) == Latte::REGADDR::SQ_PGM_RESOURCES_GS * 4);
16661684
static_assert(offsetof(LatteContextRegister, SPI_VS_OUT_CONFIG) == Latte::REGADDR::SPI_VS_OUT_CONFIG * 4);
1667-
static_assert(offsetof(LatteContextRegister, LATTE_SPI_VS_OUT_ID_N) == Latte::REGADDR::SPI_VS_OUT_ID_0 * 4);
1685+
static_assert(offsetof(LatteContextRegister, LATTE_SPI_VS_OUT_ID_N) == Latte::REGADDR::SPI_VS_OUT_ID_0 * 4);

src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -3938,21 +3938,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
39383938
bool fetchVertexManually = (usesGeometryShader || (shaderContext->fetchShader && shaderContext->fetchShader->mtlFetchVertexManually));
39393939

39403940
// Rasterization
3941-
rasterizationEnabled = true;
3942-
if (shader->shaderType == LatteConst::ShaderType::Vertex && !usesGeometryShader)
3943-
{
3944-
rasterizationEnabled = !shaderContext->contextRegistersNew->PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
3945-
3946-
// HACK
3947-
if (!shaderContext->contextRegistersNew->PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
3948-
rasterizationEnabled = true;
3949-
3950-
const auto& polygonControlReg = shaderContext->contextRegistersNew->PA_SU_SC_MODE_CNTL;
3951-
uint32 cullFront = polygonControlReg.get_CULL_FRONT();
3952-
uint32 cullBack = polygonControlReg.get_CULL_BACK();
3953-
if (cullFront && cullBack)
3954-
rasterizationEnabled = false;
3955-
}
3941+
rasterizationEnabled = shaderContext->contextRegistersNew->IsRasterizationEnabled();
39563942

39573943
StringBuf* src = new StringBuf(1024*1024*12); // reserve 12MB for generated source (we resize-to-fit at the end)
39583944
shaderContext->shaderSource = src;

src/Cafe/HW/Latte/Renderer/Metal/MetalPipelineCompiler.cpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,7 @@ void MetalPipelineCompiler::InitFromState(const LatteFetchShader* fetchShader, c
295295
m_usesGeometryShader = (geometryShader != nullptr || isPrimitiveRect);
296296

297297
// Rasterization
298-
m_rasterizationEnabled = !lcr.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
299-
300-
// HACK
301-
// TODO: include this in the hash?
302-
if (!lcr.PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
303-
m_rasterizationEnabled = true;
304-
305-
// Culling both front and back faces effectively disables rasterization
306-
const auto& polygonControlReg = lcr.PA_SU_SC_MODE_CNTL;
307-
uint32 cullFront = polygonControlReg.get_CULL_FRONT();
308-
uint32 cullBack = polygonControlReg.get_CULL_BACK();
309-
if (cullFront && cullBack)
310-
m_rasterizationEnabled = false;
298+
m_rasterizationEnabled = lcr.IsRasterizationEnabled();
311299

312300
// Shaders
313301
m_vertexShaderMtl = static_cast<RendererShaderMtl*>(vertexShader->shader);

src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -1065,15 +1065,7 @@ void MetalRenderer::draw_beginSequence()
10651065
LatteRenderTarget_updateViewport();
10661066
LatteRenderTarget_updateScissorBox();
10671067

1068-
// check for conditions which would turn the drawcalls into no-ops
1069-
bool rasterizerEnable = !LatteGPUState.contextNew.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
1070-
1071-
// GX2SetSpecialState(0, true) enables DX_RASTERIZATION_KILL, but still expects depth writes to happen? -> Research which stages are disabled by DX_RASTERIZATION_KILL exactly
1072-
// for now we use a workaround:
1073-
if (!LatteGPUState.contextNew.PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
1074-
rasterizerEnable = true;
1075-
1076-
if (!rasterizerEnable && !streamoutEnable)
1068+
if (!LatteGPUState.contextNew.IsRasterizationEnabled() && !streamoutEnable)
10771069
m_state.m_skipDrawSequence = true;
10781070
}
10791071

0 commit comments

Comments
 (0)