fixed RT format mismatch with r_rtColorFormat > 0 and r_smaa > 0

only the inverse tone map needed multiple pipelines
This commit is contained in:
myT 2023-11-18 04:13:21 +01:00
parent 4795cf3666
commit 61fbcb5304
6 changed files with 27 additions and 16 deletions

View File

@ -581,9 +581,9 @@ struct CachedPSO
struct PostProcess
{
void Init();
void Draw();
void Draw(const char* renderPassName, HTexture renderTarget);
void ToneMap();
void InverseToneMap();
void InverseToneMap(int colorFormat);
void SetToneMapInput(HTexture toneMapInput);
void SetInverseToneMapInput(HTexture inverseToneMapInput);
@ -591,7 +591,7 @@ struct PostProcess
HRootSignature toneMapRootSignature;
HDescriptorTable toneMapDescriptorTable;
HPipeline inverseToneMapPipeline;
HPipeline inverseToneMapPipelines[RTCF_COUNT];
HRootSignature inverseToneMapRootSignature;
HDescriptorTable inverseToneMapDescriptorTable;
};

View File

@ -326,7 +326,7 @@ void GRP::EndFrame()
DrawGUI();
R_DrawGUI();
imgui.Draw();
post.Draw();
post.Draw("Post-process", GetSwapChainTexture());
world.EndFrame();
RHI::EndFrame();

View File

@ -65,6 +65,15 @@ void PostProcess::Init()
return;
}
TextureFormat::Id rtFormats[RTCF_COUNT] = {};
rtFormats[RTCF_R8G8B8A8] = TextureFormat::RGBA32_UNorm;
rtFormats[RTCF_R10G10B10A2] = TextureFormat::R10G10B10A2_UNorm;
rtFormats[RTCF_R16G16B16A16] = TextureFormat::RGBA64_UNorm;
for(int i = 0; i < RTCF_COUNT; ++i)
{
Q_assert((int)rtFormats[i] > 0 && (int)rtFormats[i] < TextureFormat::Count);
}
{
RootSignatureDesc desc("tone map");
desc.usingVertexBuffers = false;
@ -113,26 +122,26 @@ void PostProcess::Init()
update.SetSamplers(1, &grp.samplers[GetSamplerIndex(TW_CLAMP_TO_EDGE, TextureFilter::Linear)]);
UpdateDescriptorTable(inverseToneMapDescriptorTable, update);
}
for(int i = 0; i < RTCF_COUNT; ++i)
{
GraphicsPipelineDesc desc("inverse tone map", inverseToneMapRootSignature);
desc.vertexShader = ShaderByteCode(inverse_tone_map::g_vs);
desc.pixelShader = ShaderByteCode(inverse_tone_map::g_ps);
desc.depthStencil.DisableDepth();
desc.rasterizer.cullMode = CT_TWO_SIDED;
desc.AddRenderTarget(0, TextureFormat::RGBA32_UNorm);
inverseToneMapPipeline = CreateGraphicsPipeline(desc);
desc.AddRenderTarget(0, rtFormats[i]);
inverseToneMapPipelines[i] = CreateGraphicsPipeline(desc);
}
}
void PostProcess::Draw()
void PostProcess::Draw(const char* renderPassName, HTexture renderTarget)
{
SCOPED_RENDER_PASS("Post-process", 0.125f, 0.125f, 0.5f);
SCOPED_RENDER_PASS(renderPassName, 0.125f, 0.125f, 0.5f);
const HTexture swapChain = GetSwapChainTexture();
const TextureBarrier barriers[2] =
{
TextureBarrier(grp.renderTarget, ResourceStates::PixelShaderAccessBit),
TextureBarrier(swapChain, ResourceStates::RenderTargetBit)
TextureBarrier(renderTarget, ResourceStates::RenderTargetBit)
};
CmdBarrier(ARRAY_LEN(barriers), barriers);
@ -170,7 +179,7 @@ void PostProcess::Draw()
if(vsX != 1.0f || vsY != 1.0f)
{
CmdClearColorTarget(swapChain, colorBlack);
CmdClearColorTarget(renderTarget, colorBlack);
const int x = (glInfo.winWidth - glInfo.winWidth * vsX) / 2.0f;
const int y = (glInfo.winHeight - glInfo.winHeight * vsY) / 2.0f;
@ -191,7 +200,7 @@ void PostProcess::Draw()
pixelRC.brightness = r_brightness->value;
pixelRC.greyscale = r_greyscale->value;
CmdBindRenderTargets(1, &swapChain, NULL);
CmdBindRenderTargets(1, &renderTarget, NULL);
CmdBindPipeline(toneMapPipeline);
CmdBindRootSignature(toneMapRootSignature);
CmdBindDescriptorTable(toneMapRootSignature, toneMapDescriptorTable);
@ -219,13 +228,13 @@ void PostProcess::ToneMap()
CmdDraw(3, 0);
}
void PostProcess::InverseToneMap()
void PostProcess::InverseToneMap(int colorFormat)
{
InverseGammaPixelRC pixelRC = {};
pixelRC.gamma = r_gamma->value;
pixelRC.invBrightness = 1.0f / r_brightness->value;
CmdBindPipeline(inverseToneMapPipeline);
CmdBindPipeline(inverseToneMapPipelines[colorFormat]);
CmdBindRootSignature(inverseToneMapRootSignature);
CmdBindDescriptorTable(inverseToneMapRootSignature, inverseToneMapDescriptorTable);
CmdSetRootConstants(inverseToneMapRootSignature, ShaderStage::Pixel, &pixelRC);

View File

@ -357,7 +357,7 @@ void SMAA::Draw(const viewParms_t& parms)
CmdBarrier(ARRAY_LEN(barriers), barriers);
CmdBindRenderTargets(1, &inputTexture, NULL);
grp.post.ToneMap(); // writes to grp.renderTarget
grp.post.ToneMap(); // RTCF_R8G8B8A8 is assumed
}
CmdBindRootSignature(rootSignature);
@ -415,6 +415,6 @@ void SMAA::Draw(const viewParms_t& parms)
CmdBarrier(ARRAY_LEN(barriers), barriers);
CmdBindRenderTargets(1, &grp.renderTarget, NULL);
grp.post.InverseToneMap(); // writes to outputTexture
grp.post.InverseToneMap(r_rtColorFormat->integer);
}
}

View File

@ -160,6 +160,7 @@ namespace RHI
{
enum Id
{
Invalid,
RGBA32_UNorm,
RGBA64_UNorm,
RGBA64_Float,

View File

@ -997,6 +997,7 @@ extern trGlobals_t tr;
#define RTCF_R10G10B10A2 1
#define RTCF_R16G16B16A16 2
#define RTCF_MAX 2
#define RTCF_COUNT 3
// r_gpuPreference
#define GPUPREF_HIGHPERF 0