Skip to content

Commit

Permalink
Replaced most pipeline states with new render pipeline layout, remove…
Browse files Browse the repository at this point in the history
…d pipeline builder, significant progress towards #31
  • Loading branch information
adepke committed Apr 7, 2022
1 parent 9123c8c commit d1f2495
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 444 deletions.
61 changes: 31 additions & 30 deletions VanguardEngine/Source/Rendering/Atmosphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Rendering/RenderGraph.h>
#include <Rendering/RenderPass.h>
#include <Rendering/ResourceManager.h>
#include <Rendering/PipelineBuilder.h>
#include <Rendering/ShaderStructs.h>
#include <Core/CoreComponents.h>
#include <Rendering/RenderComponents.h>
Expand Down Expand Up @@ -112,7 +111,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(transmittanceHandle, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
list.FlushBarriers();

list.BindPipelineState(transmissionPrecompute);
list.BindPipeline(transmissionPrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand All @@ -137,7 +136,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(deltaIrradianceTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
list.FlushBarriers();

list.BindPipelineState(directIrradiancePrecompute);
list.BindPipeline(directIrradiancePrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand All @@ -164,7 +163,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(deltaMieTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
list.FlushBarriers();

list.BindPipelineState(singleScatteringPrecompute);
list.BindPipeline(singleScatteringPrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand Down Expand Up @@ -199,7 +198,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(deltaIrradianceTexture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
list.FlushBarriers();

list.BindPipelineState(scatteringDensityPrecompute);
list.BindPipeline(scatteringDensityPrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand All @@ -226,7 +225,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(deltaIrradianceTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
list.FlushBarriers();

list.BindPipelineState(indirectIrradiancePrecompute);
list.BindPipeline(indirectIrradiancePrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand All @@ -253,7 +252,7 @@ void Atmosphere::Precompute(CommandList& list, TextureHandle transmittanceHandle
list.TransitionBarrier(deltaScatteringDensityTexture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
list.FlushBarriers();

list.BindPipelineState(multipleScatteringPrecompute);
list.BindPipeline(multipleScatteringPrecomputeLayout);
list.BindDescriptorAllocator(device->GetDescriptorAllocator());
list.BindConstants("bindData", bindData);
list.Dispatch((uint32_t)dispatchX, (uint32_t)dispatchY, (uint32_t)dispatchZ);
Expand Down Expand Up @@ -288,32 +287,34 @@ void Atmosphere::Initialize(RenderDevice* inDevice, entt::registry& registry)
{
device = inDevice;

ComputePipelineStateDescription precomputeState;
precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "TransmittanceLutMain" };
transmissionPrecompute.Build(*device, precomputeState);
transmissionPrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "TransmittanceLutMain" });

precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "DirectIrradianceLutMain" };
directIrradiancePrecompute.Build(*device, precomputeState);
directIrradiancePrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "DirectIrradianceLutMain" });

precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "SingleScatteringLutMain" };
singleScatteringPrecompute.Build(*device, precomputeState);
singleScatteringPrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "SingleScatteringLutMain" });

precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "ScatteringDensityLutMain" };
scatteringDensityPrecompute.Build(*device, precomputeState);
scatteringDensityPrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "ScatteringDensityLutMain" });

precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "IndirectIrradianceLutMain" };
indirectIrradiancePrecompute.Build(*device, precomputeState);
indirectIrradiancePrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "IndirectIrradianceLutMain" });

precomputeState.shader = { "Atmosphere/AtmospherePrecompute", "MultipleScatteringLutMain" };
multipleScatteringPrecompute.Build(*device, precomputeState);
multipleScatteringPrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/AtmospherePrecompute", "MultipleScatteringLutMain" });

ComputePipelineStateDescription sunTransmittanceStateDesc;
sunTransmittanceStateDesc.shader = { "Atmosphere/SunTransmittance", "Main" };
sunTransmittanceState.Build(*device, sunTransmittanceStateDesc);
renderLayout = RenderPipelineLayout{}
.VertexShader({ "Atmosphere/AtmosphereRender", "VSMain" })
.PixelShader({ "Atmosphere/AtmosphereRender", "PSMain" })
.DepthEnabled(true, false, DepthTestFunction::GreaterEqual); // Draw where the depth buffer is at the clear value.

ComputePipelineStateDescription luminanceState;
luminanceState.shader = { "Atmosphere/Luminance", "Main" };
luminancePrecompute.Build(*device, luminanceState);
sunTransmittanceLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/SunTransmittance", "Main" });

luminancePrecomputeLayout = RenderPipelineLayout{}
.ComputeShader({ "Atmosphere/Luminance", "Main" });

TextureDescription transmittanceDesc{
.bindFlags = BindFlag::ShaderResource | BindFlag::UnorderedAccess,
Expand Down Expand Up @@ -414,7 +415,7 @@ AtmosphereResources Atmosphere::ImportResources(RenderGraph& graph)
return { transmittanceTag, scatteringTag, irradianceTag };
}

void Atmosphere::Render(RenderGraph& graph, AtmosphereResources resourceHandles, PipelineBuilder& pipelines, RenderResource cameraBuffer,
void Atmosphere::Render(RenderGraph& graph, AtmosphereResources resourceHandles, RenderResource cameraBuffer,
RenderResource depthStencil, RenderResource outputHDR, entt::registry& registry)
{
if (dirty)
Expand Down Expand Up @@ -459,7 +460,7 @@ void Atmosphere::Render(RenderGraph& graph, AtmosphereResources resourceHandles,
bindData.cameraBuffer = resources.Get(cameraBuffer);
bindData.cameraIndex = 0; // #TODO: Support multiple cameras.

list.BindPipelineState(pipelines["AtmosphereRender"]);
list.BindPipeline(renderLayout);
list.BindConstants("bindData", bindData);

list.DrawFullscreenQuad();
Expand Down Expand Up @@ -506,7 +507,7 @@ std::pair<RenderResource, RenderResource> Atmosphere::RenderEnvironmentMap(Rende
bindData.cameraBuffer = resources.Get(cameraBuffer);
bindData.cameraIndex = 0; // #TODO: Support multiple cameras.

list.BindPipelineState(luminancePrecompute);
list.BindPipeline(luminancePrecomputeLayout);
list.BindConstants("bindData", bindData);

list.Dispatch(luminanceTextureSize / 8, luminanceTextureSize / 8, 6);
Expand Down Expand Up @@ -545,7 +546,7 @@ std::pair<RenderResource, RenderResource> Atmosphere::RenderEnvironmentMap(Rende
bindData.cameraBuffer = resources.Get(cameraBuffer);
bindData.cameraIndex = 0; // #TODO: Support multiple cameras.

list.BindPipelineState(sunTransmittanceState);
list.BindPipeline(sunTransmittanceLayout);
list.BindConstants("bindData", bindData);

list.Dispatch(1, 1, 1);
Expand Down
21 changes: 11 additions & 10 deletions VanguardEngine/Source/Rendering/Atmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Rendering/Base.h>
#include <Rendering/ResourceHandle.h>
#include <Rendering/RenderGraphResource.h>
#include <Rendering/PipelineState.h>
#include <Rendering/RenderPipeline.h>

#include <entt/entt.hpp>

Expand Down Expand Up @@ -80,22 +80,23 @@ class Atmosphere
TextureHandle deltaScatteringDensityTexture;
TextureHandle deltaIrradianceTexture;

PipelineState transmissionPrecompute;
PipelineState directIrradiancePrecompute;
PipelineState singleScatteringPrecompute;
PipelineState scatteringDensityPrecompute;
PipelineState indirectIrradiancePrecompute;
PipelineState multipleScatteringPrecompute;
RenderPipelineLayout transmissionPrecomputeLayout;
RenderPipelineLayout directIrradiancePrecomputeLayout;
RenderPipelineLayout singleScatteringPrecomputeLayout;
RenderPipelineLayout scatteringDensityPrecomputeLayout;
RenderPipelineLayout indirectIrradiancePrecomputeLayout;
RenderPipelineLayout multipleScatteringPrecomputeLayout;

void Precompute(CommandList& list, TextureHandle transmittanceHandle, TextureHandle scatteringHandle, TextureHandle irradianceHandle);

PipelineState sunTransmittanceState;
RenderPipelineLayout renderLayout;
RenderPipelineLayout sunTransmittanceLayout;

static constexpr uint32_t luminanceTextureSize = 1024;
static_assert(luminanceTextureSize % 8 == 0, "luminanceTextureSize must be evenly divisible by 8.");

TextureHandle luminanceTexture;
PipelineState luminancePrecompute;
RenderPipelineLayout luminancePrecomputeLayout;

entt::entity sunLight; // Directional light entity for direct solar illumination.

Expand All @@ -104,7 +105,7 @@ class Atmosphere
void Initialize(RenderDevice* inDevice, entt::registry& registry);

AtmosphereResources ImportResources(RenderGraph& graph);
void Render(RenderGraph& graph, AtmosphereResources resourceHandles, PipelineBuilder& pipeline, RenderResource cameraBuffer,
void Render(RenderGraph& graph, AtmosphereResources resourceHandles, RenderResource cameraBuffer,
RenderResource depthStencil, RenderResource outputHDRs, entt::registry& registry);
std::pair<RenderResource, RenderResource> RenderEnvironmentMap(RenderGraph& graph, AtmosphereResources resourceHandles, RenderResource cameraBuffer);
void MarkModelDirty() { dirty = true; }
Expand Down
21 changes: 9 additions & 12 deletions VanguardEngine/Source/Rendering/Bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ void Bloom::Initialize(RenderDevice* inDevice)
{
device = inDevice;

ComputePipelineStateDescription extractStateDesc;
extractStateDesc.shader = { "Bloom/Extract.hlsl", "Main" };
extractState.Build(*device, extractStateDesc);
extractLayout = RenderPipelineLayout{}
.ComputeShader({ "Bloom/Extract.hlsl", "Main" });

ComputePipelineStateDescription downsampleStateDesc;
downsampleStateDesc.shader = { "Bloom/Downsample.hlsl", "Main" };
downsampleState.Build(*device, downsampleStateDesc);
downsampleLayout = RenderPipelineLayout{}
.ComputeShader({ "Bloom/Downsample.hlsl", "Main" });

ComputePipelineStateDescription upsampleStateDesc;
upsampleStateDesc.shader = { "Bloom/Upsample.hlsl", "Main" };
upsampleState.Build(*device, upsampleStateDesc);
upsampleLayout = RenderPipelineLayout{}
.ComputeShader({ "Bloom/Upsample.hlsl", "Main" });
}

void Bloom::Render(RenderGraph& graph, const RenderResource hdrSource)
Expand All @@ -43,7 +40,7 @@ void Bloom::Render(RenderGraph& graph, const RenderResource hdrSource)
.UAV("", 0));
extractPass.Bind([&, hdrSource, extractTexture](CommandList& list, RenderPassResources& resources)
{
list.BindPipelineState(extractState);
list.BindPipeline(extractLayout);

struct BindData
{
Expand Down Expand Up @@ -81,7 +78,7 @@ void Bloom::Render(RenderGraph& graph, const RenderResource hdrSource)
downsamplePass.Write(extractTexture, downsampleExtractView);
downsamplePass.Bind([this, extractTexture, downsampleExtractViewNames](CommandList& list, RenderPassResources& resources)
{
list.BindPipelineState(downsampleState);
list.BindPipeline(downsampleLayout);

auto& extractTextureComponent = device->GetResourceManager().Get(resources.GetTexture(extractTexture));

Expand Down Expand Up @@ -127,7 +124,7 @@ void Bloom::Render(RenderGraph& graph, const RenderResource hdrSource)
.UAV("", 0));
compositionPass.Bind([this, extractTexture, hdrSource, upsampleExtractViewNames](CommandList& list, RenderPassResources& resources)
{
list.BindPipelineState(upsampleState);
list.BindPipeline(upsampleLayout);

auto& extractTextureComponent = device->GetResourceManager().Get(resources.GetTexture(extractTexture));
auto& hdrTextureComponent = device->GetResourceManager().Get(resources.GetTexture(hdrSource));
Expand Down
8 changes: 4 additions & 4 deletions VanguardEngine/Source/Rendering/Bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include <Rendering/PipelineState.h>
#include <Rendering/RenderPipeline.h>
#include <Rendering/RenderGraphResource.h>

class RenderDevice;
Expand All @@ -13,9 +13,9 @@ class Bloom
private:
RenderDevice* device;

PipelineState extractState;
PipelineState downsampleState;
PipelineState upsampleState;
RenderPipelineLayout extractLayout;
RenderPipelineLayout downsampleLayout;
RenderPipelineLayout upsampleLayout;

uint32_t bloomPasses = 0;

Expand Down
Loading

0 comments on commit d1f2495

Please sign in to comment.