DiligentGraphics / DiligentCore

A modern cross-platform low-level graphics API
http://diligentgraphics.com/diligent-engine/
Apache License 2.0
631 stars 136 forks source link

shouldn't clear the m_AttachmentClearValues inDeviceContextGLImpl::NextSubpass #497

Open widefire opened 4 months ago

widefire commented 4 months ago

https://github.com/DiligentGraphics/DiligentCore/blob/8be34c5ac4021eec223cc4609e79fa71421063f8/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp#L658 call m_AttachmentClearValues.clear() in DeviceContextGLImpl::NextSubpass(),if there more than two subpass,the clear value not exists after first call for NextSubpass. delete this line work well.

TheMostDiligent commented 4 months ago

Can you provide a render pass description that reproduces this issue?

widefire commented 4 months ago

Yes,It's a thee subpass render pass.

  1. the first subpass render primitives and generate gbuffers like 'COLOR_BUFFER,ENTITY_BUFFER,VELOCITY_BUFFER(MOTION)...'
  2. the second subpass is anti-aliasing pass
  3. the last pass for final image process and display.

draw code like this : `context->BeginRenderPass(attr); { DrawScenePass(); }

{ // call NextSubpass() will clear m_AttachmentClearValues in GL-Backend.https://github.com/DiligentGraphics/DiligentCore/blob/8be34c5ac4021eec223cc4609e79fa71421063f8/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp#L658 context->NextSubpass(); AAPass(); }

{ // in the last pass ,need clear the final render-target, // but m_AttachmentClearValues was cleared,so the program will crush at https://github.com/DiligentGraphics/DiligentCore/blob/8be34c5ac4021eec223cc4609e79fa71421063f8/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp#L502 context->NextSubpass(); FinalScreenPass(); }

context->EndRenderPass();`

DirectX and Vulkan backend no this issue ..

the attachments like this `{ attachments[COLOR_BUFFER].Format = rtv_fmts[COLOR_BUFFER]; attachments[COLOR_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_RENDER_TARGET; attachments[COLOR_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[COLOR_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_CLEAR; attachments[COLOR_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_DISCARD; }

{ /*

{ attachments[VELOCITY_BUFFER].Format = rtv_fmts[VELOCITY_BUFFER]; attachments[VELOCITY_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_RENDER_TARGET; attachments[VELOCITY_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[VELOCITY_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_CLEAR; attachments[VELOCITY_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }

{ attachments[DEPTH_STENCIL_BUFFER].Format = dsv_fmt; attachments[DEPTH_STENCIL_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_DEPTH_WRITE; attachments[DEPTH_STENCIL_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[DEPTH_STENCIL_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_CLEAR; attachments[DEPTH_STENCIL_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }

{ attachments[PREV_COLOR_BUFFER].Format = rtv_fmts[COLOR_BUFFER]; attachments[PREV_COLOR_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[PREV_COLOR_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[PREV_COLOR_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_LOAD; attachments[PREV_COLOR_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }

{ attachments[PREV_DEPTH_STENCIL_BUFFER].Format = dsv_fmt; attachments[PREV_DEPTH_STENCIL_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_DEPTH_WRITE; attachments[PREV_DEPTH_STENCIL_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[PREV_DEPTH_STENCIL_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_LOAD; attachments[PREV_DEPTH_STENCIL_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }

{ attachments[AA_COLOR_BUFFER].Format = rtv_fmts[COLOR_BUFFER]; attachments[AA_COLOR_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_RENDER_TARGET; attachments[AA_COLOR_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_INPUT_ATTACHMENT; attachments[AA_COLOR_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_CLEAR; attachments[AA_COLOR_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }

{ attachments[FINAL_COLOR_BUFFER].Format = _graphic_device->GetSwapChain()->GetDesc().ColorBufferFormat; attachments[FINAL_COLOR_BUFFER].InitialState = RESOURCE_STATE::RESOURCE_STATE_RENDER_TARGET; attachments[FINAL_COLOR_BUFFER].FinalState = RESOURCE_STATE::RESOURCE_STATE_SHADER_RESOURCE; attachments[FINAL_COLOR_BUFFER].LoadOp = ATTACHMENT_LOAD_OP::ATTACHMENT_LOAD_OP_CLEAR; attachments[FINAL_COLOR_BUFFER].StoreOp = ATTACHMENT_STORE_OP::ATTACHMENT_STORE_OP_STORE; }`