Skip to content

Commit 1be1571

Browse files
authored
Use special conditional survey shader instead of guest shader specialization (#234)
Fixes alpha test issues from the conditional survey logic needing early fragment test.
1 parent 1a32f18 commit 1be1571

6 files changed

Lines changed: 43 additions & 13 deletions

File tree

MarathonRecomp/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ set(MARATHON_RECOMP_UI_CXX_SOURCES
157157
"ui/achievement_menu.cpp"
158158
"ui/achievement_overlay.cpp"
159159
"ui/black_bar.cpp"
160-
"ui/button_window.cpp"
160+
"ui/button_window.cpp"
161161
"ui/common_menu.cpp"
162162
"ui/fader.cpp"
163163
"ui/game_window.cpp"
@@ -481,6 +481,7 @@ function(compile_pixel_shader FILE_PATH)
481481
endfunction()
482482

483483
compile_pixel_shader(blend_color_alpha_ps)
484+
compile_pixel_shader(conditional_survey_ps)
484485
compile_vertex_shader(copy_vs)
485486
compile_pixel_shader(copy_color_ps)
486487
compile_pixel_shader(copy_depth_ps)
@@ -549,7 +550,7 @@ BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/com
549550
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/main_menu9.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/main_menu9.dds" ARRAY_NAME "g_main_menu9" COMPRESSION_TYPE "zstd")
550551
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/arrow.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/arrow.dds" ARRAY_NAME "g_arrow" COMPRESSION_TYPE "zstd")
551552
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/window.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/window.dds" ARRAY_NAME "g_window" COMPRESSION_TYPE "zstd")
552-
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/select_arrow.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/select_arrow.dds" ARRAY_NAME "g_select_arrow" COMPRESSION_TYPE "zstd")
553+
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/common/select_arrow.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/common/select_arrow.dds" ARRAY_NAME "g_select_arrow" COMPRESSION_TYPE "zstd")
553554

554555
## Installer ##
555556
BIN2C(TARGET_OBJ MarathonRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/installer/install_001.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/installer/install_001.dds" ARRAY_NAME "g_install_001" COMPRESSION_TYPE "zstd")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
[earlydepthstencil]
4+
float4 shaderMain() : SV_Target
5+
{
6+
atomicFetchAddUint(g_ConditionalSurveyBuffer, g_conditionalSurveyIndex, 1);
7+
return float4(0.0, 0.0, 0.0, 0.0);
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
[[fragment]]
4+
[[early_fragment_tests]]
5+
float4 shaderMain(device AtomicUintBuffer* g_ConditionalSurveyBuffer [[buffer(4)]],
6+
constant PushConstants& g_PushConstants [[buffer(8)]])
7+
{
8+
atomicFetchAddUint(g_ConditionalSurveyBuffer, g_conditionalSurveyIndex, 1);
9+
return float4(0.0, 0.0, 0.0, 0.0);
10+
}

MarathonRecomp/gpu/video.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
#include <magic_enum/magic_enum.hpp>
4141
#endif
4242

43+
#define MARATHON_RECOMP
4344
#include "../../tools/XenosRecomp/XenosRecomp/shader_common.h"
4445

4546
#ifdef MARATHON_RECOMP_D3D12
4647
#include "shader/hlsl/blend_color_alpha_ps.hlsl.dxil.h"
48+
#include "shader/hlsl/conditional_survey_ps.hlsl.dxil.h"
4749
#include "shader/hlsl/copy_vs.hlsl.dxil.h"
4850
#include "shader/hlsl/copy_color_ps.hlsl.dxil.h"
4951
#include "shader/hlsl/copy_depth_ps.hlsl.dxil.h"
@@ -69,6 +71,7 @@
6971

7072
#ifdef MARATHON_RECOMP_METAL
7173
#include "shader/msl/blend_color_alpha_ps.metal.metallib.h"
74+
#include "shader/msl/conditional_survey_ps.metal.metallib.h"
7275
#include "shader/msl/copy_vs.metal.metallib.h"
7376
#include "shader/msl/copy_color_ps.metal.metallib.h"
7477
#include "shader/msl/copy_depth_ps.metal.metallib.h"
@@ -93,6 +96,7 @@
9396
#endif
9497

9598
#include "shader/hlsl/blend_color_alpha_ps.hlsl.spirv.h"
99+
#include "shader/hlsl/conditional_survey_ps.hlsl.spirv.h"
96100
#include "shader/hlsl/copy_vs.hlsl.spirv.h"
97101
#include "shader/hlsl/copy_color_ps.hlsl.spirv.h"
98102
#include "shader/hlsl/copy_depth_ps.hlsl.spirv.h"
@@ -188,6 +192,7 @@ struct PipelineState
188192
RenderFormat depthStencilFormat{};
189193
RenderSampleCounts sampleCount = RenderSampleCount::COUNT_1;
190194
bool enableAlphaToCoverage = false;
195+
bool enableConditionalSurvey = false;
191196
uint32_t specConstants = 0;
192197
};
193198
#pragma pack(pop)
@@ -1488,6 +1493,8 @@ static GuestShader* g_csdShader;
14881493
static std::unique_ptr<GuestShader> g_enhancedBurnoutBlurVSShader;
14891494
static std::unique_ptr<GuestShader> g_enhancedBurnoutBlurPSShader;
14901495

1496+
static std::unique_ptr<GuestShader> g_conditionalSurveyPSShader;
1497+
14911498
#if defined(MARATHON_RECOMP_D3D12)
14921499

14931500
#define CREATE_SHADER(NAME) \
@@ -2245,6 +2252,9 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
22452252
g_enhancedBurnoutBlurPSShader = std::make_unique<GuestShader>(ResourceType::PixelShader);
22462253
g_enhancedBurnoutBlurPSShader->shader = CREATE_SHADER(enhanced_burnout_blur_ps);
22472254

2255+
g_conditionalSurveyPSShader = std::make_unique<GuestShader>(ResourceType::PixelShader);
2256+
g_conditionalSurveyPSShader->shader = CREATE_SHADER(conditional_survey_ps);
2257+
22482258
CreateImGuiBackend();
22492259

22502260
auto gammaCorrectionShader = CREATE_SHADER(gamma_correction_ps);
@@ -4518,7 +4528,12 @@ static std::unique_ptr<RenderPipeline> CreateGraphicsPipeline(const PipelineStat
45184528
RenderGraphicsPipelineDesc desc;
45194529
desc.pipelineLayout = g_pipelineLayout.get();
45204530
desc.vertexShader = GetOrLinkShader(pipelineState.vertexShader, pipelineState.specConstants);
4521-
desc.pixelShader = pipelineState.pixelShader != nullptr ? GetOrLinkShader(pipelineState.pixelShader, pipelineState.specConstants) : nullptr;
4531+
if (pipelineState.enableConditionalSurvey)
4532+
desc.pixelShader = GetOrLinkShader(g_conditionalSurveyPSShader.get(), pipelineState.specConstants);
4533+
else if (pipelineState.pixelShader != nullptr)
4534+
desc.pixelShader = GetOrLinkShader(pipelineState.pixelShader, pipelineState.specConstants);
4535+
else
4536+
desc.pixelShader = nullptr;
45224537
desc.depthFunction = pipelineState.zFunc;
45234538
desc.depthEnabled = pipelineState.zEnable;
45244539
desc.depthWriteEnabled = pipelineState.zWriteEnable;
@@ -4666,6 +4681,7 @@ static RenderPipeline* CreateGraphicsPipelineInRenderThread(PipelineState pipeli
46664681
" depthStencilFormat: {}\n"
46674682
" sampleCount: {}\n"
46684683
" enableAlphaToCoverage: {}\n"
4684+
" enableConditionalSurvey: {}\n"
46694685
" specConstants: {:X}\n",
46704686
hash,
46714687
pipelineState.vertexShader->name,
@@ -4708,6 +4724,7 @@ static RenderPipeline* CreateGraphicsPipelineInRenderThread(PipelineState pipeli
47084724
magic_enum::enum_name(pipelineState.depthStencilFormat),
47094725
pipelineState.sampleCount,
47104726
pipelineState.enableAlphaToCoverage,
4727+
pipelineState.enableConditionalSurvey,
47114728
pipelineState.specConstants)
47124729
+ g_pipelineDebugText;
47134730
}
@@ -5720,7 +5737,6 @@ static void EndConditionalSurvey(GuestDevice* device)
57205737

57215738
static void ProcSetConditionalSurvey(const RenderCommand& cmd)
57225739
{
5723-
uint32_t specConstants = g_pipelineState.specConstants;
57245740
if (cmd.setConditionalSurvey.enabled)
57255741
{
57265742
// Clear previous survey result first.
@@ -5734,13 +5750,9 @@ static void ProcSetConditionalSurvey(const RenderCommand& cmd)
57345750
commandList->barriers(RenderBarrierStage::GRAPHICS, RenderBufferBarrier(g_conditionalSurveyBuffer.get(), RenderBufferAccess::READ | RenderBufferAccess::WRITE));
57355751

57365752
g_tempBuffers[g_frame].emplace_back(std::move(uploadBuffer));
5737-
5738-
specConstants |= SPEC_CONSTANT_CONDITIONAL_SURVEY;
57395753
}
5740-
else
5741-
specConstants &= ~SPEC_CONSTANT_CONDITIONAL_SURVEY;
57425754

5743-
SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.specConstants, specConstants);
5755+
SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.enableConditionalSurvey, cmd.setConditionalSurvey.enabled);
57445756
SetDirtyValue(g_dirtyStates.sharedConstants, g_sharedConstants.conditionalSurveyIndex, cmd.setConditionalSurvey.index);
57455757
}
57465758

@@ -7694,6 +7706,7 @@ class SDLEventListenerForPSOCaching : public SDLEventListener
76947706
"RenderFormat::{},"
76957707
"{},"
76967708
"{},"
7709+
"{},"
76977710
"0x{:X} }},",
76987711
pipelineState.vertexShader->shaderCacheEntry->hash,
76997712
pipelineState.pixelShader != nullptr ? pipelineState.pixelShader->shaderCacheEntry->hash : 0,
@@ -7747,6 +7760,7 @@ class SDLEventListenerForPSOCaching : public SDLEventListener
77477760
magic_enum::enum_name(pipelineState.depthStencilFormat),
77487761
pipelineState.sampleCount,
77497762
pipelineState.enableAlphaToCoverage,
7763+
pipelineState.enableConditionalSurvey,
77507764
pipelineState.specConstants);
77517765
}
77527766

MarathonRecomp/gpu/video.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#define SPEC_CONSTANT_ALPHA_TO_COVERAGE (1 << 3)
1717
#define SPEC_CONSTANT_REVERSE_Z (1 << 4)
1818

19-
#define SPEC_CONSTANT_CONDITIONAL_SURVEY (1 << 5)
20-
#define SPEC_CONSTANT_CONDITIONAL_RENDERING (1 << 6)
21-
2219
#define LOAD_ZSTD_TEXTURE(name) LoadTexture(decompressZstd(name, name##_uncompressed_size).get(), name##_uncompressed_size)
2320

2421
using namespace plume;

0 commit comments

Comments
 (0)