renderpassify stage 2

This commit is contained in:
turanszkij
2019-10-28 18:47:08 +01:00
parent 9a9758d559
commit 003c092f0d
6 changed files with 161 additions and 101 deletions
+5 -14
View File
@@ -88,8 +88,8 @@ void RenderPath3D::ResizeBuffers()
TextureDesc desc;
desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE;
desc.Format = wiRenderer::RTFormat_hdr;
desc.Width = wiRenderer::GetInternalResolution().x / 2;
desc.Height = wiRenderer::GetInternalResolution().y / 2;
desc.Width = wiRenderer::GetInternalResolution().x;
desc.Height = wiRenderer::GetInternalResolution().y;
device->CreateTexture2D(&desc, nullptr, &rtReflection);
device->SetName(&rtReflection, "rtReflection");
}
@@ -235,15 +235,6 @@ void RenderPath3D::ResizeBuffers()
device->CreateTexture2D(&desc, nullptr, &smallDepth);
device->SetName(&smallDepth, "smallDepth");
}
{
TextureDesc desc;
desc.BindFlags = BIND_DEPTH_STENCIL;
desc.Format = wiRenderer::DSFormat_small;
desc.Width = wiRenderer::GetInternalResolution().x / 2;
desc.Height = wiRenderer::GetInternalResolution().y / 2;
device->CreateTexture2D(&desc, nullptr, &depthBuffer_reflection);
device->SetName(&depthBuffer_reflection, "depthBuffer_reflection");
}
// Render passes:
{
@@ -257,7 +248,7 @@ void RenderPath3D::ResizeBuffers()
RenderPassDesc desc;
desc.numAttachments = 2;
desc.attachments[0] = { RenderPassAttachment::RENDERTARGET,RenderPassAttachment::OP_DONTCARE,&rtReflection,-1 };
desc.attachments[1] = { RenderPassAttachment::DEPTH_STENCIL,RenderPassAttachment::OP_CLEAR,&depthBuffer_reflection,-1 };
desc.attachments[1] = { RenderPassAttachment::DEPTH_STENCIL,RenderPassAttachment::OP_CLEAR,&depthBuffer,-1 };
device->CreateRenderPass(&desc, &renderpass_reflection);
}
@@ -362,8 +353,8 @@ void RenderPath3D::RenderReflections(CommandList cmd) const
device->BeginRenderPass(&renderpass_reflection, cmd);
ViewPort vp;
vp.Width = (float)depthBuffer_reflection.GetDesc().Width;
vp.Height = (float)depthBuffer_reflection.GetDesc().Height;
vp.Width = (float)depthBuffer.GetDesc().Width;
vp.Height = (float)depthBuffer.GetDesc().Height;
device->BindViewports(1, &vp, cmd);
// reverse clipping if underwater
+69 -70
View File
@@ -67,7 +67,6 @@ protected:
wiGraphics::Texture2D depthBuffer_Copy; // used for shader resource, single sample
wiGraphics::Texture2D rtLinearDepth; // linear depth result
wiGraphics::Texture2D smallDepth; // downsampled depth buffer
wiGraphics::Texture2D depthBuffer_reflection; // depth-test for reflection rendering
wiGraphics::RenderPass renderpass_occlusionculling;
wiGraphics::RenderPass renderpass_reflection;
@@ -112,81 +111,81 @@ protected:
public:
const wiGraphics::Texture2D* GetDepthStencil() const override { return &depthBuffer; }
inline float getExposure() const { return exposure; }
inline float getBloomThreshold() const { return bloomThreshold; }
inline float getSSAOBlur() const { return ssaoBlur; }
inline float getDepthOfFieldFocus() const { return dofFocus; }
inline float getDepthOfFieldStrength() const { return dofStrength; }
inline float getSharpenFilterAmount() const { return sharpenFilterAmount; }
inline float getOutlineThreshold() const { return outlineThreshold; }
inline float getOutlineThickness() const { return outlineThickness; }
inline XMFLOAT4 getOutlineColor() const { return outlineColor; }
inline float getSSAORange() const { return ssaoRange; }
inline UINT getSSAOSampleCount() const { return ssaoSampleCount; }
inline float getChromaticAberrationAmount() const { return chromaticAberrationAmount; }
constexpr float getExposure() const { return exposure; }
constexpr float getBloomThreshold() const { return bloomThreshold; }
constexpr float getSSAOBlur() const { return ssaoBlur; }
constexpr float getDepthOfFieldFocus() const { return dofFocus; }
constexpr float getDepthOfFieldStrength() const { return dofStrength; }
constexpr float getSharpenFilterAmount() const { return sharpenFilterAmount; }
constexpr float getOutlineThreshold() const { return outlineThreshold; }
constexpr float getOutlineThickness() const { return outlineThickness; }
constexpr XMFLOAT4 getOutlineColor() const { return outlineColor; }
constexpr float getSSAORange() const { return ssaoRange; }
constexpr UINT getSSAOSampleCount() const { return ssaoSampleCount; }
constexpr float getChromaticAberrationAmount() const { return chromaticAberrationAmount; }
inline bool getSSAOEnabled() const { return ssaoEnabled; }
inline bool getSSREnabled() const { return ssrEnabled; }
inline bool getShadowsEnabled() const { return shadowsEnabled; }
inline bool getReflectionsEnabled() const { return reflectionsEnabled; }
inline bool getFXAAEnabled() const { return fxaaEnabled; }
inline bool getBloomEnabled() const { return bloomEnabled; }
inline bool getColorGradingEnabled() const { return colorGradingEnabled; }
inline bool getEmittedParticlesEnabled() const { return emittedParticlesEnabled; }
inline bool getHairParticlesEnabled() const { return hairParticlesEnabled; }
inline bool getHairParticlesReflectionEnabled() const { return hairParticlesReflectionEnabled; }
inline bool getVolumeLightsEnabled() const { return volumeLightsEnabled; }
inline bool getLightShaftsEnabled() const { return lightShaftsEnabled; }
inline bool getLensFlareEnabled() const { return lensFlareEnabled; }
inline bool getMotionBlurEnabled() const { return motionBlurEnabled; }
inline bool getSSSEnabled() const { return sssEnabled; }
inline bool getDepthOfFieldEnabled() const { return depthOfFieldEnabled; }
inline bool getEyeAdaptionEnabled() const { return eyeAdaptionEnabled; }
inline bool getTessellationEnabled() const { return tessellationEnabled && wiRenderer::GetDevice()->CheckCapability(wiGraphics::GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION); }
inline bool getSharpenFilterEnabled() const { return sharpenFilterEnabled && getSharpenFilterAmount() > 0; }
inline bool getOutlineEnabled() const { return outlineEnabled; }
inline bool getChromaticAberrationEnabled() const { return chromaticAberrationEnabled; }
constexpr bool getSSAOEnabled() const { return ssaoEnabled; }
constexpr bool getSSREnabled() const { return ssrEnabled; }
constexpr bool getShadowsEnabled() const { return shadowsEnabled; }
constexpr bool getReflectionsEnabled() const { return reflectionsEnabled; }
constexpr bool getFXAAEnabled() const { return fxaaEnabled; }
constexpr bool getBloomEnabled() const { return bloomEnabled; }
constexpr bool getColorGradingEnabled() const { return colorGradingEnabled; }
constexpr bool getEmittedParticlesEnabled() const { return emittedParticlesEnabled; }
constexpr bool getHairParticlesEnabled() const { return hairParticlesEnabled; }
constexpr bool getHairParticlesReflectionEnabled() const { return hairParticlesReflectionEnabled; }
constexpr bool getVolumeLightsEnabled() const { return volumeLightsEnabled; }
constexpr bool getLightShaftsEnabled() const { return lightShaftsEnabled; }
constexpr bool getLensFlareEnabled() const { return lensFlareEnabled; }
constexpr bool getMotionBlurEnabled() const { return motionBlurEnabled; }
constexpr bool getSSSEnabled() const { return sssEnabled; }
constexpr bool getDepthOfFieldEnabled() const { return depthOfFieldEnabled; }
constexpr bool getEyeAdaptionEnabled() const { return eyeAdaptionEnabled; }
constexpr bool getTessellationEnabled() const { return tessellationEnabled && wiRenderer::GetDevice()->CheckCapability(wiGraphics::GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION); }
constexpr bool getSharpenFilterEnabled() const { return sharpenFilterEnabled && getSharpenFilterAmount() > 0; }
constexpr bool getOutlineEnabled() const { return outlineEnabled; }
constexpr bool getChromaticAberrationEnabled() const { return chromaticAberrationEnabled; }
inline const wiGraphics::Texture2D* getColorGradingTexture() const { return colorGradingTex; }
constexpr const wiGraphics::Texture2D* getColorGradingTexture() const { return colorGradingTex; }
inline constexpr UINT getMSAASampleCount() const { return msaaSampleCount; }
constexpr UINT getMSAASampleCount() const { return msaaSampleCount; }
inline void setExposure(float value) { exposure = value; }
inline void setBloomThreshold(float value){ bloomThreshold = value; }
inline void setSSAOBlur(float value){ ssaoBlur = value; }
inline void setDepthOfFieldFocus(float value){ dofFocus = value; }
inline void setDepthOfFieldStrength(float value){ dofStrength = value; }
inline void setSharpenFilterAmount(float value) { sharpenFilterAmount = value; }
inline void setOutlineThreshold(float value) { outlineThreshold = value; }
inline void setOutlineThickness(float value) { outlineThickness = value; }
inline void setOutlineColor(const XMFLOAT4& value) { outlineColor = value; }
inline void setSSAORange(float value) { ssaoRange = value; }
inline void setSSAOSampleCount(UINT value) { ssaoSampleCount = value; }
inline void setChromaticAberrationAmount(float value) { chromaticAberrationAmount = value; }
constexpr void setExposure(float value) { exposure = value; }
constexpr void setBloomThreshold(float value){ bloomThreshold = value; }
constexpr void setSSAOBlur(float value){ ssaoBlur = value; }
constexpr void setDepthOfFieldFocus(float value){ dofFocus = value; }
constexpr void setDepthOfFieldStrength(float value){ dofStrength = value; }
constexpr void setSharpenFilterAmount(float value) { sharpenFilterAmount = value; }
constexpr void setOutlineThreshold(float value) { outlineThreshold = value; }
constexpr void setOutlineThickness(float value) { outlineThickness = value; }
constexpr void setOutlineColor(const XMFLOAT4& value) { outlineColor = value; }
constexpr void setSSAORange(float value) { ssaoRange = value; }
constexpr void setSSAOSampleCount(UINT value) { ssaoSampleCount = value; }
constexpr void setChromaticAberrationAmount(float value) { chromaticAberrationAmount = value; }
inline void setSSAOEnabled(bool value){ ssaoEnabled = value; }
inline void setSSREnabled(bool value){ ssrEnabled = value; }
inline void setShadowsEnabled(bool value){ shadowsEnabled = value; }
inline void setReflectionsEnabled(bool value){ reflectionsEnabled = value; }
inline void setFXAAEnabled(bool value){ fxaaEnabled = value; }
inline void setBloomEnabled(bool value){ bloomEnabled = value; }
inline void setColorGradingEnabled(bool value){ colorGradingEnabled = value; }
inline void setEmitterParticlesEnabled(bool value){ emittedParticlesEnabled = value; }
inline void setHairParticlesEnabled(bool value) { hairParticlesEnabled = value; }
inline void setHairParticlesReflectionEnabled(bool value) { hairParticlesReflectionEnabled = value; }
inline void setVolumeLightsEnabled(bool value){ volumeLightsEnabled = value; }
inline void setLightShaftsEnabled(bool value){ lightShaftsEnabled = value; }
inline void setLensFlareEnabled(bool value){ lensFlareEnabled = value; }
inline void setMotionBlurEnabled(bool value){ motionBlurEnabled = value; }
inline void setSSSEnabled(bool value){ sssEnabled = value; }
inline void setDepthOfFieldEnabled(bool value){ depthOfFieldEnabled = value; }
inline void setEyeAdaptionEnabled(bool value) { eyeAdaptionEnabled = value; }
inline void setTessellationEnabled(bool value) { tessellationEnabled = value; }
inline void setSharpenFilterEnabled(bool value) { sharpenFilterEnabled = value; }
inline void setOutlineEnabled(bool value) { outlineEnabled = value; }
inline void setChromaticAberrationEnabled(bool value) { chromaticAberrationEnabled = value; }
constexpr void setSSAOEnabled(bool value){ ssaoEnabled = value; }
constexpr void setSSREnabled(bool value){ ssrEnabled = value; }
constexpr void setShadowsEnabled(bool value){ shadowsEnabled = value; }
constexpr void setReflectionsEnabled(bool value){ reflectionsEnabled = value; }
constexpr void setFXAAEnabled(bool value){ fxaaEnabled = value; }
constexpr void setBloomEnabled(bool value){ bloomEnabled = value; }
constexpr void setColorGradingEnabled(bool value){ colorGradingEnabled = value; }
constexpr void setEmitterParticlesEnabled(bool value){ emittedParticlesEnabled = value; }
constexpr void setHairParticlesEnabled(bool value) { hairParticlesEnabled = value; }
constexpr void setHairParticlesReflectionEnabled(bool value) { hairParticlesReflectionEnabled = value; }
constexpr void setVolumeLightsEnabled(bool value){ volumeLightsEnabled = value; }
constexpr void setLightShaftsEnabled(bool value){ lightShaftsEnabled = value; }
constexpr void setLensFlareEnabled(bool value){ lensFlareEnabled = value; }
constexpr void setMotionBlurEnabled(bool value){ motionBlurEnabled = value; }
constexpr void setSSSEnabled(bool value){ sssEnabled = value; }
constexpr void setDepthOfFieldEnabled(bool value){ depthOfFieldEnabled = value; }
constexpr void setEyeAdaptionEnabled(bool value) { eyeAdaptionEnabled = value; }
constexpr void setTessellationEnabled(bool value) { tessellationEnabled = value; }
constexpr void setSharpenFilterEnabled(bool value) { sharpenFilterEnabled = value; }
constexpr void setOutlineEnabled(bool value) { outlineEnabled = value; }
constexpr void setChromaticAberrationEnabled(bool value) { chromaticAberrationEnabled = value; }
inline void setColorGradingTexture(const wiGraphics::Texture2D* tex) { colorGradingTex = tex; }
constexpr void setColorGradingTexture(const wiGraphics::Texture2D* tex) { colorGradingTex = tex; }
virtual void setMSAASampleCount(UINT value) { if (msaaSampleCount != value) { msaaSampleCount = value; ResizeBuffers(); } }
+14
View File
@@ -149,3 +149,17 @@ bool GraphicsDevice::IsFormatBlockCompressed(FORMAT value) const
return false;
}
bool GraphicsDevice::IsFormatStencilSupport(FORMAT value) const
{
switch (value)
{
case FORMAT_R32G8X24_TYPELESS:
case FORMAT_D32_FLOAT_S8X24_UINT:
case FORMAT_R24G8_TYPELESS:
case FORMAT_D24_UNORM_S8_UINT:
return true;
}
return false;
}
+1
View File
@@ -107,6 +107,7 @@ namespace wiGraphics
uint32_t GetFormatStride(FORMAT value) const;
bool IsFormatUnorm(FORMAT value) const;
bool IsFormatBlockCompressed(FORMAT value) const;
bool IsFormatStencilSupport(FORMAT value) const;
inline XMMATRIX GetScreenProjection() const
{
+13 -10
View File
@@ -2645,8 +2645,8 @@ void GraphicsDevice_DX11::BeginRenderPass(const RenderPass* renderpass, CommandL
const RenderPassDesc& desc = renderpass->GetDesc();
UINT rt_count = 0;
ID3D11RenderTargetView* renderTargetViews[8] = {};
ID3D11DepthStencilView* depthStencilView = nullptr;
ID3D11RenderTargetView* RTVs[8] = {};
ID3D11DepthStencilView* DSV = nullptr;
for (UINT i = 0; i < desc.numAttachments; ++i)
{
const RenderPassAttachment& attachment = desc.attachments[i];
@@ -2657,17 +2657,17 @@ void GraphicsDevice_DX11::BeginRenderPass(const RenderPass* renderpass, CommandL
{
if (subresource < 0 || texture->subresourceRTVs.empty())
{
renderTargetViews[rt_count] = (ID3D11RenderTargetView*)texture->RTV;
RTVs[rt_count] = (ID3D11RenderTargetView*)texture->RTV;
}
else
{
assert(texture->subresourceRTVs.size() > size_t(subresource) && "Invalid RTV subresource!");
renderTargetViews[rt_count] = (ID3D11RenderTargetView*)texture->subresourceRTVs[subresource];
RTVs[rt_count] = (ID3D11RenderTargetView*)texture->subresourceRTVs[subresource];
}
if (attachment.op == RenderPassAttachment::OP_CLEAR)
{
deviceContexts[cmd]->ClearRenderTargetView(renderTargetViews[rt_count], texture->desc.clear.color);
deviceContexts[cmd]->ClearRenderTargetView(RTVs[rt_count], texture->desc.clear.color);
}
rt_count++;
@@ -2676,17 +2676,20 @@ void GraphicsDevice_DX11::BeginRenderPass(const RenderPass* renderpass, CommandL
{
if (subresource < 0 || texture->subresourceDSVs.empty())
{
depthStencilView = (ID3D11DepthStencilView*)texture->DSV;
DSV = (ID3D11DepthStencilView*)texture->DSV;
}
else
{
assert(texture->subresourceDSVs.size() > size_t(subresource) && "Invalid DSV subresource!");
depthStencilView = (ID3D11DepthStencilView*)texture->subresourceDSVs[subresource];
DSV = (ID3D11DepthStencilView*)texture->subresourceDSVs[subresource];
}
if (attachment.op == RenderPassAttachment::OP_CLEAR)
{
deviceContexts[cmd]->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, texture->desc.clear.depthstencil.depth, texture->desc.clear.depthstencil.stencil);
UINT _flags = D3D11_CLEAR_DEPTH;
if (IsFormatStencilSupport(texture->desc.Format))
_flags |= D3D11_CLEAR_STENCIL;
deviceContexts[cmd]->ClearDepthStencilView(DSV, _flags, texture->desc.clear.depthstencil.depth, texture->desc.clear.depthstencil.stencil);
}
}
}
@@ -2697,14 +2700,14 @@ void GraphicsDevice_DX11::BeginRenderPass(const RenderPass* renderpass, CommandL
const UINT count = raster_uavs_count[cmd];
const UINT slot = raster_uavs_slot[cmd];
deviceContexts[cmd]->OMSetRenderTargetsAndUnorderedAccessViews(rt_count, renderTargetViews, depthStencilView, slot, count, &raster_uavs[cmd][slot], nullptr);
deviceContexts[cmd]->OMSetRenderTargetsAndUnorderedAccessViews(rt_count, RTVs, DSV, slot, count, &raster_uavs[cmd][slot], nullptr);
raster_uavs_count[cmd] = 0;
raster_uavs_slot[cmd] = 8;
}
else
{
deviceContexts[cmd]->OMSetRenderTargets(rt_count, renderTargetViews, depthStencilView);
deviceContexts[cmd]->OMSetRenderTargets(rt_count, RTVs, DSV);
}
}
void GraphicsDevice_DX11::EndRenderPass(CommandList cmd)
+59 -7
View File
@@ -2047,12 +2047,12 @@ namespace wiGraphics
D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON;
D3D12_CLEAR_VALUE optimizedClearValue = {};
optimizedClearValue.Color[0] = 0;
optimizedClearValue.Color[1] = 0;
optimizedClearValue.Color[2] = 0;
optimizedClearValue.Color[3] = 0;
optimizedClearValue.DepthStencil.Depth = 0.0f;
optimizedClearValue.DepthStencil.Stencil = 0;
optimizedClearValue.Color[0] = pTexture2D->desc.clear.color[0];
optimizedClearValue.Color[1] = pTexture2D->desc.clear.color[1];
optimizedClearValue.Color[2] = pTexture2D->desc.clear.color[2];
optimizedClearValue.Color[3] = pTexture2D->desc.clear.color[3];
optimizedClearValue.DepthStencil.Depth = pTexture2D->desc.clear.depthstencil.depth;
optimizedClearValue.DepthStencil.Stencil = pTexture2D->desc.clear.depthstencil.stencil;
optimizedClearValue.Format = desc.Format;
if (optimizedClearValue.Format == DXGI_FORMAT_R16_TYPELESS)
{
@@ -3189,11 +3189,63 @@ namespace wiGraphics
void GraphicsDevice_DX12::BeginRenderPass(const RenderPass* renderpass, CommandList cmd)
{
const RenderPassDesc& desc = renderpass->GetDesc();
UINT rt_count = 0;
D3D12_CPU_DESCRIPTOR_HANDLE RTVs[8] = {};
D3D12_CPU_DESCRIPTOR_HANDLE* DSV = nullptr;
for (UINT i = 0; i < desc.numAttachments; ++i)
{
const RenderPassAttachment& attachment = desc.attachments[i];
const Texture2D* texture = attachment.texture;
int subresource = attachment.subresource;
if (attachment.type == RenderPassAttachment::RENDERTARGET)
{
if (subresource < 0 || texture->subresourceRTVs.empty())
{
RTVs[rt_count] = ToNativeHandle(texture->RTV);
}
else
{
assert(texture->subresourceRTVs.size() > size_t(subresource) && "Invalid RTV subresource!");
RTVs[rt_count] = ToNativeHandle(texture->subresourceRTVs[subresource]);
}
if (attachment.op == RenderPassAttachment::OP_CLEAR)
{
GetDirectCommandList(cmd)->ClearRenderTargetView(RTVs[rt_count], texture->desc.clear.color, 0, nullptr);
}
rt_count++;
}
else
{
if (subresource < 0 || texture->subresourceDSVs.empty())
{
DSV = &ToNativeHandle(texture->DSV);
}
else
{
assert(texture->subresourceDSVs.size() > size_t(subresource) && "Invalid DSV subresource!");
DSV = &ToNativeHandle(texture->subresourceDSVs[subresource]);
}
if (attachment.op == RenderPassAttachment::OP_CLEAR)
{
UINT _flags = D3D12_CLEAR_FLAG_DEPTH;
if (IsFormatStencilSupport(texture->desc.Format))
_flags |= D3D12_CLEAR_FLAG_STENCIL;
GetDirectCommandList(cmd)->ClearDepthStencilView(*DSV, (D3D12_CLEAR_FLAGS)_flags, texture->desc.clear.depthstencil.depth, texture->desc.clear.depthstencil.stencil, 0, nullptr);
}
}
}
GetDirectCommandList(cmd)->OMSetRenderTargets(rt_count, RTVs, FALSE, DSV);
}
void GraphicsDevice_DX12::EndRenderPass(CommandList cmd)
{
GetDirectCommandList(cmd)->OMSetRenderTargets(0, nullptr, FALSE, nullptr);
}
void GraphicsDevice_DX12::BindScissorRects(UINT numRects, const Rect* rects, CommandList cmd) {
assert(rects != nullptr);