Rise
The Vieneo Province
Loading...
Searching...
No Matches
CloudPass11.h
Go to the documentation of this file.
1#pragma once
2#include "Device11.h"
3#include "Program11.h"
4#include "CloudTemporal11.h"
5#include <d3d11_1.h>
6#include <DirectXMath.h>
7#include <array>
8#include <filesystem>
9#include <memory>
10
11namespace Rendering
12{
13 // GPU portion of the cloud renderer. Weather/lightning scheduling and
14 // camera data enter through the same named parameters as the SM3 baseline.
15 // All draw work is native D3D11; the scene's original depth samples remain
16 // shader-readable throughout the composite, without copies/vendor paths.
18 {
19 public:
21 HRESULT Initialize(ID3D11Device* device, const std::filesystem::path& shaderDirectory={});
22 // Background creation and private-device first-use preparation. Polls
23 // without waiting; S_FALSE means work/presentation remains.
24 // Prepares the selected MSAA count without changing the live cloud path.
25 HRESULT PrepareLoadingStep(ID3D11DeviceContext* context,UINT samples,bool organic);
27 {
28 std::string shader;
29 unsigned current=0,total=0;
30 bool complete=false;
31 };
35 HRESULT Render(ID3D11DeviceContext* context, Parameters11& parameters,
36 ID3D11RenderTargetView* scene, const SceneDepth11& depth,
37 const D3D11_VIEWPORT& viewport, unsigned activeHeadlights = 0, bool atmosphericFog = false, bool spatialRain = false, bool belowNominalCloudBase = false);
38 HRESULT RenderSkyRing(ID3D11DeviceContext* context, Parameters11& parameters,
39 ID3D11RenderTargetView* scene, const SceneDepth11& depth, const D3D11_VIEWPORT& viewport,
40 ID3D11ShaderResourceView* atmosphere, ID3D11Buffer* vertices,
41 const DirectX::XMFLOAT4X4& world, UINT segments, float physicalScale);
42 HRESULT RenderRainLines(ID3D11DeviceContext* context, Parameters11& parameters,
43 ID3D11RenderTargetView* scene, const SceneDepth11& depth, const D3D11_VIEWPORT& viewport,
44 ID3D11Buffer* vertices, const DirectX::XMFLOAT4X4& world, UINT drops);
45 HRESULT RenderRainParticles(ID3D11DeviceContext* context, Parameters11& parameters,
46 ID3D11RenderTargetView* scene, const SceneDepth11& depth, const D3D11_VIEWPORT& viewport,
47 ID3D11Buffer* vertices, ID3D11Buffer* indices, UINT drops, bool cloudAttenuation = true);
48 // Opt-in diagnostic output; preparation failure leaves normal clouds usable.
49 void SetAdOpacityTarget(ID3D11RenderTargetView* target) { adOpacityTarget=target;adOpacityWritten=false; }
50 bool AdOpacityWritten() const { return adOpacityWritten; }
51 void Reset();
53 {
56 for(auto& direct:topDirect)direct.ReleaseTargets();
58 }
59 bool OrganicOrbitAvailable() const {return orbitalReady;}
60 bool OrganicFlightAvailable() const {return organicReady;}
61 HRESULT ConfigureOrganic(bool enabled,bool aboveDeck);
62 enum class OrganicPath { Legacy,Flight,Top };
65 void ConfigureTemporal(const CloudTemporal11::Frame& frame,bool enabled)
66 {
69 }
71 // Offscreen before/after comparisons retain the original renderer in this build.
74#ifdef RISE_CLOUD_TEST_TEMPORAL_DIAGNOSTICS
75 unsigned TestTopLoadingFallbacks() const {return testTopLoadingFallbacks;}
76 static unsigned TestLoadingActiveWorkers();
77#endif
80 // Offscreen quality/performance comparisons; does not change scene MSAA.
81 void SetResolutionScale(float value) { resolutionScale=value>=.125f && value<=.5f ? value : .5f; }
82 float ResolutionScale() const { return resolutionScale; }
83 ID3D11ShaderResourceView* Image() const { return temporalEnabled && temporal.Image() ? temporal.Image() : image.srv.Get(); }
84 ID3D11ShaderResourceView* Distance() const { return temporalEnabled && temporal.Distance() ? temporal.Distance() : distance.srv.Get(); }
85 ID3D11ShaderResourceView* HeadlightDepth() const { return headlight.srv.Get(); }
86 const std::string& Status() const { return status; }
87 private:
88 struct Target
89 {
90 Microsoft::WRL::ComPtr<ID3D11Texture2D> texture;
91 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv;
92 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv;
93 };
94 HRESULT TargetCreate(Target& target, UINT w, UINT h, DXGI_FORMAT format);
95 HRESULT Draw(ID3D11DeviceContext* context, Program11& program, Parameters11& parameters);
96 HRESULT ValidateScene(ID3D11DeviceContext* context, ID3D11RenderTargetView* scene,
97 const SceneDepth11& depth, const D3D11_VIEWPORT& viewport);
98 HRESULT Geometry(ID3D11DeviceContext* context, Program11& program, Parameters11& parameters,
99 ID3D11RenderTargetView* scene, const SceneDepth11& depth, const D3D11_VIEWPORT& viewport,
100 ID3D11Buffer* vertices, UINT stride, UINT count, D3D11_PRIMITIVE_TOPOLOGY topology,
101 ID3D11Buffer* indices = nullptr, UINT indexCount = 0, bool premultiplied = false);
102 HRESULT Fail(const char* stage, HRESULT hr);
103 Microsoft::WRL::ComPtr<ID3D11Device> device;
104 Microsoft::WRL::ComPtr<ID3DDeviceContextState> passState;
105 Microsoft::WRL::ComPtr<ID3D11RasterizerState> raster;
106 Microsoft::WRL::ComPtr<ID3D11DepthStencilState> compositeDepth, disabledDepth;
107 Microsoft::WRL::ComPtr<ID3D11BlendState> blend, straightBlend;
108 std::vector<Microsoft::WRL::ComPtr<ID3D11SamplerState>> samplers;
111 std::array<Program11,4> cachedComposite,visibleComposite;
112 std::array<bool,4> cachedCompositeAvailable{};
116 std::array<Program11,4> compositePixel, compositeEdge;
119 {
121 std::array<Program11,4> pixel,edge,fogPixel,fogEdge;
122 std::array<Program11,4> adPixel,adEdge,adFogPixel,adFogEdge;
123 bool adReady=false;
124 void Reset()
125 {
126 march.Reset();adReady=false;
127 for(auto* list:{&pixel,&edge,&fogPixel,&fogEdge,&adPixel,&adEdge,&adFogPixel,&adFogEdge})
128 for(auto& program:*list)program.Reset();
129 }
130 };
132 HRESULT PreparePrograms(unsigned variant,bool fog,bool headlights,bool spatialRain,bool rainMaskEnabled,bool cached,bool sharedSearch,bool directComposite);
133 HRESULT PrepareTopDirectPrograms(unsigned variant);
134 HRESULT PrepareTopDirectWork(unsigned variant);
135 HRESULT PrepareTopDirectTargets(unsigned variant,const D3D11_TEXTURE2D_DESC& scene);
136 HRESULT PrepareCompositeWork(unsigned variant);
137 HRESULT LoadFullscreenProgram(Program11& program,const std::string& name);
139 {
141 std::string name;
143 DXGI_FORMAT format;
145 };
146 struct LoadingWorker;
147 std::shared_ptr<LoadingWorker> loadingWorker;
148 uint64_t loadingSequence=0;
149 bool loadingAdopted=false;
150 void CancelLoading();
151 std::vector<LoadingJob> LoadingJobs(UINT samples,bool organic,size_t& topBegin);
152 HRESULT PrepareLoadingObjects(const LoadingJob& job,unsigned variant);
153 HRESULT PrepareLoadingStepNow(ID3D11DeviceContext* context,UINT samples,bool organic);
154 void AdoptLoadingPrograms(CloudPass11& prepared);
155 void StartLoadingWorker(UINT samples,bool organic);
159 {
162 Microsoft::WRL::ComPtr<ID3D11ComputeShader> scan;
163 Microsoft::WRL::ComPtr<ID3D11Buffer> arguments;
164 Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> argumentView;
165 bool available=false,failed=false;
167 void Reset()
168 {
170 scan.Reset();argumentView.Reset();arguments.Reset();available=failed=false;
171 }
172 };
173 std::array<TopDirectState,4> topDirect;
174#ifdef RISE_CLOUD_TEST_TEMPORAL_DIAGNOSTICS
175 unsigned testTopLoadingFallbacks=0;
176#endif
179 bool organicReady=false;
180 std::array<unsigned,8> loadingStep{};
183 unsigned loadingVariant=~0u;
186 std::array<Program11,4> adPixel, adEdge, adFogPixel, adFogEdge;
187 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> adOpacityTarget;
188 Microsoft::WRL::ComPtr<ID3D11BlendState> adBlend;
189 std::filesystem::path shaderDirectory;
193 std::array<bool,4> sharedSearchAvailable{};
194 std::array<Program11,4> completeComposite;
195 std::array<bool,4> compositeWorkAvailable{};
196 std::array<Microsoft::WRL::ComPtr<ID3D11ComputeShader>,4> compositeWorkScan;
197 Microsoft::WRL::ComPtr<ID3D11Buffer> compositeArguments;
198 Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> compositeArgumentsView;
199 std::array<Program11,4> classifyHidden;
201 std::array<bool,4> hiddenAvailable{};
203 Microsoft::WRL::ComPtr<ID3D11Texture2D> hiddenDepthTexture;
204 Microsoft::WRL::ComPtr<ID3D11DepthStencilView> hiddenDepth;
205 Microsoft::WRL::ComPtr<ID3D11DepthStencilState> hiddenWrite,hiddenRead;
209 std::string status="native cloud pass not initialized";
210 };
211}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
std::array< Program11, 4 > seededEdge
HRESULT LoadFullscreenProgram(Program11 &program, const std::string &name)
HRESULT RenderRainParticles(ID3D11DeviceContext *context, Parameters11 &parameters, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, ID3D11Buffer *vertices, ID3D11Buffer *indices, UINT drops, bool cloudAttenuation=true)
void SetRainMsaaSharingEnabled(bool enabled)
Definition CloudPass11.h:78
std::array< bool, 4 > hiddenAvailable
const LoadingProgress & LoadingStatus() const
Definition CloudPass11.h:32
std::filesystem::path shaderDirectory
LoadingProgress loadingDisplayProgress
void SetAdOpacityTarget(ID3D11RenderTargetView *target)
Definition CloudPass11.h:49
std::array< bool, 4 > cachedCompositeAvailable
std::array< Program11, 4 > adPixel
Microsoft::WRL::ComPtr< ID3D11UnorderedAccessView > compositeArgumentsView
std::array< Program11, 4 > visibleComposite
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
ID3D11ShaderResourceView * Image() const
Definition CloudPass11.h:83
HRESULT PrepareLoadingStepNow(ID3D11DeviceContext *context, UINT samples, bool organic)
std::array< Program11, 4 > compositeFogPixel
std::array< bool, 4 > sharedSearchAvailable
std::array< bool, 4 > compositeWorkAvailable
std::array< Program11, 4 > adFogPixel
std::array< Microsoft::WRL::ComPtr< ID3D11ComputeShader >, 4 > compositeWorkScan
OrganicPrograms organicTop
Microsoft::WRL::ComPtr< ID3D11BlendState > adBlend
Microsoft::WRL::ComPtr< ID3D11Buffer > compositeArguments
HRESULT PrepareLoadingObjects(const LoadingJob &job, unsigned variant)
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > adOpacityTarget
CloudTemporal11::Frame temporalFrame
ID3D11ShaderResourceView * Distance() const
Definition CloudPass11.h:84
std::array< Program11, 4 > adFogEdge
std::array< Program11, 4 > completeComposite
void ConfigureTemporal(const CloudTemporal11::Frame &frame, bool enabled)
Definition CloudPass11.h:65
void SetHiddenRayOptimizationEnabled(bool enabled)
Definition CloudPass11.h:73
const std::string & Status() const
Definition CloudPass11.h:86
std::shared_ptr< LoadingWorker > loadingWorker
bool OrganicOrbitAvailable() const
Definition CloudPass11.h:59
HRESULT RenderRainLines(ID3D11DeviceContext *context, Parameters11 &parameters, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, ID3D11Buffer *vertices, const DirectX::XMFLOAT4X4 &world, UINT drops)
OrganicPrograms * activeOrganic
std::array< Program11, 4 > classifyHidden
bool AdOpacityWritten() const
Definition CloudPass11.h:50
LoadingProgress loadingProgress
HRESULT ConfigureOrganic(bool enabled, bool aboveDeck)
void SetRainCloudOcclusionEnabled(bool enabled)
Definition CloudPass11.h:79
HRESULT PrepareCompositeWork(unsigned variant)
CloudTemporal11 temporal
std::array< Program11, 4 > firstHitClassify
std::array< Program11, 4 > cachedComposite
bool OrganicFlightAvailable() const
Definition CloudPass11.h:60
Microsoft::WRL::ComPtr< ID3D11BlendState > straightBlend
std::array< Program11, 4 > compositeEdge
std::vector< Microsoft::WRL::ComPtr< ID3D11SamplerState > > samplers
std::array< TopDirectState, 4 > topDirect
HRESULT ValidateScene(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport)
HRESULT RenderSkyRing(ID3D11DeviceContext *context, Parameters11 &parameters, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, ID3D11ShaderResourceView *atmosphere, ID3D11Buffer *vertices, const DirectX::XMFLOAT4X4 &world, UINT segments, float physicalScale)
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > disabledDepth
HRESULT PreparePrograms(unsigned variant, bool fog, bool headlights, bool spatialRain, bool rainMaskEnabled, bool cached, bool sharedSearch, bool directComposite)
Program11 organicRainParticles
OrganicPath SelectedOrganicPath() const
Definition CloudPass11.h:63
HRESULT PrepareTopDirectTargets(unsigned variant, const D3D11_TEXTURE2D_DESC &scene)
void SetResolutionScale(float value)
Definition CloudPass11.h:81
void StartLoadingWorker(UINT samples, bool organic)
std::array< Program11, 4 > compositePixel
std::array< Program11, 4 > rainEdge
ID3D11ShaderResourceView * HeadlightDepth() const
Definition CloudPass11.h:85
Microsoft::WRL::ComPtr< ID3D11RasterizerState > raster
HRESULT Render(ID3D11DeviceContext *context, Parameters11 &parameters, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, unsigned activeHeadlights=0, bool atmosphericFog=false, bool spatialRain=false, bool belowNominalCloudBase=false)
void SetVisibilityOptimizationEnabled(bool enabled)
Definition CloudPass11.h:72
OrganicPrograms organicFlight
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > compositeDepth
Microsoft::WRL::ComPtr< ID3D11BlendState > blend
std::array< unsigned, 8 > loadingStep
void AdoptLoadingPrograms(CloudPass11 &prepared)
Microsoft::WRL::ComPtr< ID3D11Device > device
HRESULT TargetCreate(Target &target, UINT w, UINT h, DXGI_FORMAT format)
std::array< Program11, 4 > rainPixel
HRESULT PrepareLoadingStep(ID3D11DeviceContext *context, UINT samples, bool organic)
std::array< Program11, 4 > compositeFogEdge
HRESULT Draw(ID3D11DeviceContext *context, Program11 &program, Parameters11 &parameters)
Microsoft::WRL::ComPtr< ID3D11Texture2D > hiddenDepthTexture
HRESULT Geometry(ID3D11DeviceContext *context, Program11 &program, Parameters11 &parameters, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, ID3D11Buffer *vertices, UINT stride, UINT count, D3D11_PRIMITIVE_TOPOLOGY topology, ID3D11Buffer *indices=nullptr, UINT indexCount=0, bool premultiplied=false)
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > hiddenRead
std::array< Program11, 4 > adEdge
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > hiddenWrite
Microsoft::WRL::ComPtr< ID3DDeviceContextState > passState
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > hiddenDepth
HRESULT Fail(const char *stage, HRESULT hr)
HRESULT PrepareTopDirectPrograms(unsigned variant)
HRESULT PrepareTopDirectWork(unsigned variant)
std::array< Program11, 4 > rainClassify
std::vector< LoadingJob > LoadingJobs(UINT samples, bool organic, size_t &topBegin)
std::array< Program11, 4 > seededFogEdge
float ResolutionScale() const
Definition CloudPass11.h:82
ID3D11ShaderResourceView * Image() const
ID3D11ShaderResourceView * Distance() const
std::array< Program11, 4 > edge
std::array< Program11, 4 > adPixel
std::array< Program11, 4 > adFogEdge
std::array< Program11, 4 > pixel
std::array< Program11, 4 > adFogPixel
std::array< Program11, 4 > fogEdge
std::array< Program11, 4 > fogPixel
std::array< Program11, 4 > adEdge
Microsoft::WRL::ComPtr< ID3D11Texture2D > texture
Definition CloudPass11.h:90
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > srv
Definition CloudPass11.h:92
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > rtv
Definition CloudPass11.h:91
Microsoft::WRL::ComPtr< ID3D11ComputeShader > scan
Microsoft::WRL::ComPtr< ID3D11Buffer > arguments
Microsoft::WRL::ComPtr< ID3D11UnorderedAccessView > argumentView