Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to use ResolveSubresource in MSAA RTs for postprocessing effects?

Started by isu diss Oct 24, 2020 at 4:19 AM 3 replies 5.7k views
Original Post
isu diss
isu diss

I have enabled MSAA. It works fine without post-processing effects such as lens flare.

without msaa
with msaa 4x

the problem comes when i enable the postprocessing effects lens flare. I lose all the antialiasing and some artifacts in the image. Debugging also shows this

with msaa 4x and pp fx lens flare

I create render to textures with msaa enabled. I will create classes for render to texture mechanism in the future. this is just for testing.

		// DOWNSAMPLE SCENE TEXTURE
RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &DSRTV, RE_D3D11_DepthStencilView);
RE_D3D11_ImmediateContext->ClearRenderTargetView(DSRTV, Colors::Black);
RE_D3D11_ImmediateContext->ClearDepthStencilView(RE_D3D11_DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
		RE_D3D11_ImmediateContext->OMSetDepthStencilState(RE_D3D11_DepthState_DD, 1);

mysky->Render(RE_D3D11_ImmediateContext, RE_D3D11_SamplerState_Main, mycam, RE_LightDirection);
		RE_D3D11_ImmediateContext->OMSetDepthStencilState(RE_D3D11_DepthState_DE, 1);
		
for (auto G3DQ_Iter = RE_3D_Graphics_Queue.begin(); G3DQ_Iter != RE_3D_Graphics_Queue.end(); G3DQ_Iter++)
		{
(*G3DQ_Iter)->Execute_Render_Commands_For_Scene(RE_D3D11_ImmediateContext, RE_D3D11_SamplerState_Main, RE_D3D11_CSM_SRV, mycam, RE_LightDirection, mLightViewProjection, XMMatrixIdentity());
		}

RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &NULLRTV, NULLDSV);




		//SOURCE GENERATION
RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &LFGRTV, RE_D3D11_DepthStencilView);
RE_D3D11_ImmediateContext->ClearRenderTargetView(LFGRTV, Colors::Black);
RE_D3D11_ImmediateContext->ClearDepthStencilView(RE_D3D11_DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

mylf->SourceGenDraw(RE_D3D11_ImmediateContext, RE_D3D11_SamplerState_Main, DSSRV);

RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &NULLRTV, NULLDSV);



RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &RE_D3D11_RenderTargetView_Main, RE_D3D11_DepthStencilView);
RE_D3D11_ImmediateContext->ClearRenderTargetView(RE_D3D11_RenderTargetView_Main, Colors::Black);
RE_D3D11_ImmediateContext->ClearDepthStencilView(RE_D3D11_DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

mylf->FinalDraw(RE_D3D11_ImmediateContext, RE_D3D11_SamplerState_Main, DSSRV, LFGSRV);

RE_D3D11_ImmediateContext->OMSetRenderTargets(1, &NULLRTV, NULLDSV);

Debug:

D3D11 ERROR: ID3D11DeviceContext::Draw: The Shader Resource View dimension declared in the shader code (TEXTURE2D) does not match the view type bound to slot 0 of the Pixel Shader unit (TEXTURE2DMS). This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]

D3D11 ERROR: ID3D11DeviceContext::Draw: The Shader Resource View dimension declared in the shader code (TEXTURE2D) does not match the view type bound to slot 1 of the Pixel Shader unit (TEXTURE2DMS). This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]

D3D11 ERROR: ID3D11DeviceContext::Draw: The Shader Resource View dimension declared in the shader code (TEXTURE2D) does not match the view type bound to slot 2 of the Pixel Shader unit (TEXTURE2DMS). This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]

I know why that happens. cos i dont use Texture2DMS in shader. I just want to know how to use ResolveSubresource in this scenario? Any thoughts?

isu diss
isu diss

I fixed the problem by resolving MSAA Texture into non-MSAA Texture using ResolveSubresource and used in the lensflare shader.

ddlox
ddlox

ok good, now is the future, so “I will create classes for render to texture mechanism in the future.” ?

have fun ?

isu diss
isu diss

This is how I did it.

1st Step - Render the scene to a MSAA Texture(DST2D)

2nd Step - Resolve above MSAA Texture into Non-MSAA Texture

RE_D3D11_ImmediateContext->ResolveSubresource(LFUST2D(non msaa), 0, DST2D(msaa), 0, DXGI_FORMAT_R32G32B32A32_FLOAT);

3rd step - Postprocessing on a Non-MSAA RTV (passing LFUSSRV )

4th Step - Final Draw on a MSAA Texture(RE_D3D11_RenderTargetView_Main) passing SRVs for processing LFUSSRV, LFGSRV

That's it. ?

with msaa 4x and lens flare

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.