From d5cee65dceda87bca1850918ff320bb72c959825 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Wed, 6 Mar 2019 22:45:46 +0000 Subject: [PATCH] general refactor; script updates; new sample script added; --- Documentation/ScriptingAPI-Documentation.md | 13 + Editor/EmitterWindow.cpp | 21 +- Editor/EmitterWindow.h | 1 + WickedEngine/CommonInclude.h | 7 - WickedEngine/RenderPath3D_Deferred.cpp | 2 + WickedEngine/RenderPath3D_TiledDeferred.cpp | 2 + WickedEngine/wiEmittedParticle.cpp | 11 +- WickedEngine/wiEmittedParticle.h | 3 +- WickedEngine/wiFFTGenerator.cpp | 115 +- WickedEngine/wiFFTGenerator.h | 19 +- WickedEngine/wiFont.cpp | 14 +- WickedEngine/wiGPUBVH.cpp | 170 ++- WickedEngine/wiGPUBVH.h | 22 +- WickedEngine/wiGPUSortLib.cpp | 46 +- WickedEngine/wiGPUSortLib.h | 10 +- WickedEngine/wiGraphicsDevice_DX11.cpp | 22 + WickedEngine/wiGraphicsDevice_DX12.cpp | 25 +- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 25 +- WickedEngine/wiGraphicsResource.h | 21 +- WickedEngine/wiLensFlare.cpp | 9 +- WickedEngine/wiOcean.cpp | 17 +- WickedEngine/wiOcean.h | 1 - WickedEngine/wiRenderer.cpp | 1046 +++++++++---------- WickedEngine/wiSceneSystem_BindLua.cpp | 216 ++++ WickedEngine/wiSceneSystem_BindLua.h | 28 + WickedEngine/wiSceneSystem_Decl.h | 3 + WickedEngine/wiVersion.cpp | 2 +- WickedEngine/wiWidget.cpp | 7 +- models/emitter_smoke.wiscene | Bin 555 -> 756 bytes scripts/debug_draw.lua | 1 + scripts/emitter_burst.lua | 23 + scripts/move_object.lua | 1 + scripts/pick.lua | 3 +- scripts/rotate_model.lua | 1 + scripts/set_material_color.lua | 1 + scripts/set_material_emissive.lua | 1 + 36 files changed, 1064 insertions(+), 845 deletions(-) create mode 100644 scripts/emitter_burst.lua diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index f31f91daa..c4b74bfcf 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -346,6 +346,19 @@ Describes an orientation in 3D space. - SetBaseColor() - SetEmissiveColor() +#### EmitterComponent +- Burst(int value) -- spawns a specific amount of particles immediately +- SetEmitCount(float value) -- set the emitted particle count per second +- SetSize(float value) -- set particle starting size +- SetLife(float value) -- set particle lifetime +- SetNormalFactor(float value) -- set normal factor that modulates emit velocities +- SetRandomness(float value) -- set general randomness factor +- SetLifeRandomness(float value) -- set lifetime randomness factor +- SetScaleX(float value) -- set scaling along lifetime in X axis +- SetScaleY(float value) -- set scaling along lifetime in Y axis +- SetRotation(float value) -- set rotation speed +- SetMotionBlurAmount(float value) -- set the motion elongation factor + ## High Level Interface ### MainComponent This is the main entry point and manages the lifetime of the application. Even though it is called a component, it is not part of the entity-component system diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index a992a7736..7ab0e3788 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -25,6 +25,18 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) float step = 35; + emitterNameField = new wiTextInputField("EmitterName"); + emitterNameField->SetPos(XMFLOAT2(x, y += step)); + emitterNameField->SetSize(XMFLOAT2(300, 20)); + emitterNameField->OnInputAccepted([&](wiEventArgs args) { + NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + if (name != nullptr) + { + *name = args.sValue; + } + }); + emitterWindow->AddWidget(emitterNameField); + addButton = new wiButton("Add Emitter"); addButton->SetPos(XMFLOAT2(x, y += step)); addButton->SetSize(XMFLOAT2(150, 30)); @@ -160,14 +172,14 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) infoLabel = new wiLabel("EmitterInfo"); - infoLabel->SetSize(XMFLOAT2(380, 140)); + infoLabel->SetSize(XMFLOAT2(380, 120)); infoLabel->SetPos(XMFLOAT2(x, y += step)); emitterWindow->AddWidget(infoLabel); maxParticlesSlider = new wiSlider(100.0f, 1000000.0f, 10000, 100000, "Max particle count: "); maxParticlesSlider->SetSize(XMFLOAT2(360, 30)); - maxParticlesSlider->SetPos(XMFLOAT2(x, y += step + 140)); + maxParticlesSlider->SetPos(XMFLOAT2(x, y += step + 120)); maxParticlesSlider->OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) @@ -515,7 +527,6 @@ void EmitterWindow::UpdateData() stringstream ss(""); ss.precision(2); - ss << "Emitter name: " << name->name << " (" << entity << ")" << endl; ss << "Emitter Mesh: " << (meshName != nullptr ? meshName->name : "NO EMITTER MESH") << " (" << emitter->meshID << ")" << endl; ss << "Memort Budget: " << emitter->GetMemorySizeInBytes() / 1024.0f / 1024.0f << " MB" << endl; ss << endl; @@ -534,4 +545,8 @@ void EmitterWindow::UpdateData() } infoLabel->SetText(ss.str()); + + ss.str(""); + ss << name->name << " (" << entity << ")"; + emitterNameField->SetText(ss.str()); } diff --git a/Editor/EmitterWindow.h b/Editor/EmitterWindow.h index fcef2d70b..5429ddcf1 100644 --- a/Editor/EmitterWindow.h +++ b/Editor/EmitterWindow.h @@ -28,6 +28,7 @@ public: wiWindow* emitterWindow; + wiTextInputField* emitterNameField; wiButton* addButton; wiButton* restartButton; wiComboBox* meshComboBox; diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index 99d68303e..70b0e9e9d 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -41,13 +41,6 @@ inline void SwapPtr(T*& a, T*& b) b = swap; } -template -inline void RECREATE(T*& myObject) -{ - SAFE_DELETE(myObject); - myObject = new T; -} - static const XMFLOAT4X4 IDENTITYMATRIX = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp index f95f0668f..5e94312df 100644 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ b/WickedEngine/RenderPath3D_Deferred.cpp @@ -124,6 +124,8 @@ void RenderPath3D_Deferred::RenderScene(GRAPHICSTHREAD threadID) lightbuffer_specular.get(), }; device->BindRenderTargets(ARRAYSIZE(rts), rts, rtGBuffer.depth->GetTexture(), threadID); + float clear[] = { 0,0,0,0 }; + device->ClearRenderTarget(rtGBuffer.GetTexture(1), clear, threadID); device->ClearDepthStencil(rtGBuffer.depth->GetTexture(), CLEAR_DEPTH | CLEAR_STENCIL, 0, 0, threadID); ViewPort vp; vp.Width = (float)rts[0]->GetDesc().Width; diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp index 70bdcdfd6..12e0c09fb 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred.cpp @@ -45,6 +45,8 @@ void RenderPath3D_TiledDeferred::RenderScene(GRAPHICSTHREAD threadID) lightbuffer_specular.get(), }; device->BindRenderTargets(ARRAYSIZE(rts), rts, rtGBuffer.depth->GetTexture(), threadID); + float clear[] = { 0,0,0,0 }; + device->ClearRenderTarget(rtGBuffer.GetTexture(1), clear, threadID); device->ClearDepthStencil(rtGBuffer.depth->GetTexture(), CLEAR_DEPTH | CLEAR_STENCIL, 0, 0, threadID); ViewPort vp; vp.Width = (float)rts[0]->GetDesc().Width; diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 608c73cbf..e8b0d42ec 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -238,6 +238,9 @@ void wiEmittedParticle::UpdateCPU(const TransformComponent& transform, float dt) emit += (float)count*dt; + emit += burst; + burst = 0; + // Swap CURRENT alivelist with NEW alivelist aliveList[0].swap(aliveList[1]); @@ -247,12 +250,12 @@ void wiEmittedParticle::UpdateCPU(const TransformComponent& transform, float dt) wiRenderer::GetDevice()->DownloadResource(counterBuffer.get(), debugDataReadbackBuffer.get(), &debugData, GRAPHICSTHREAD_IMMEDIATE); } } -void wiEmittedParticle::Burst(float num) +void wiEmittedParticle::Burst(int num) { if (IsPaused()) return; - emit += num; + burst += num; } void wiEmittedParticle::Restart() { @@ -376,7 +379,7 @@ void wiEmittedParticle::UpdateGPU(const TransformComponent& transform, const Mat device->EventEnd(threadID); // 2.) Sort particle index list based on partition grid cell index: - wiGPUSortLib::Sort(MAX_PARTICLES, sphPartitionCellIndices.get(), counterBuffer.get(), PARTICLECOUNTER_OFFSET_ALIVECOUNT, aliveList[0].get(), threadID); + wiGPUSortLib::Sort(MAX_PARTICLES, *sphPartitionCellIndices.get(), *counterBuffer.get(), PARTICLECOUNTER_OFFSET_ALIVECOUNT, *aliveList[0].get(), threadID); // 3.) Reset grid cell offset buffer with invalid offsets (max uint): device->EventBegin("PartitionOffsetsReset", threadID); @@ -503,7 +506,7 @@ void wiEmittedParticle::UpdateGPU(const TransformComponent& transform, const Mat #endif // DEBUG_SORTING - wiGPUSortLib::Sort(MAX_PARTICLES, distanceBuffer.get(), counterBuffer.get(), PARTICLECOUNTER_OFFSET_ALIVECOUNT_AFTERSIMULATION, aliveList[1].get(), threadID); + wiGPUSortLib::Sort(MAX_PARTICLES, *distanceBuffer.get(), *counterBuffer.get(), PARTICLECOUNTER_OFFSET_ALIVECOUNT_AFTERSIMULATION, *aliveList[1].get(), threadID); #ifdef DEBUG_SORTING diff --git a/WickedEngine/wiEmittedParticle.h b/WickedEngine/wiEmittedParticle.h index f4859cec0..fa7fac104 100644 --- a/WickedEngine/wiEmittedParticle.h +++ b/WickedEngine/wiEmittedParticle.h @@ -43,13 +43,14 @@ private: void CreateSelfBuffers(); float emit = 0.0f; + int burst = 0; bool buffersUpToDate = false; uint32_t MAX_PARTICLES = 1000; public: void UpdateCPU(const TransformComponent& transform, float dt); - void Burst(float num); + void Burst(int num); void Restart(); // Must have a transform and material component, but mesh is optional diff --git a/WickedEngine/wiFFTGenerator.cpp b/WickedEngine/wiFFTGenerator.cpp index af149e43a..42d9590fa 100644 --- a/WickedEngine/wiFFTGenerator.cpp +++ b/WickedEngine/wiFFTGenerator.cpp @@ -14,9 +14,10 @@ static const ComputeShader* pRadix008A_CS2 = nullptr; static ComputePSO PSO1; static ComputePSO PSO2; -void radix008A(CSFFT512x512_Plan* fft_plan, - GPUResource* pUAV_Dst, - GPUResource* pSRV_Src, +void radix008A( + const CSFFT512x512_Plan& fft_plan, + const GPUResource& pUAV_Dst, + const GPUResource& pSRV_Src, UINT thread_count, UINT istride, GRAPHICSTHREAD threadID) @@ -27,10 +28,10 @@ void radix008A(CSFFT512x512_Plan* fft_plan, GraphicsDevice* device = wiRenderer::GetDevice(); // Buffers - GPUResource* cs_srvs[1] = { pSRV_Src }; + const GPUResource* cs_srvs[1] = { &pSRV_Src }; device->BindResources(CS, cs_srvs, TEXSLOT_ONDEMAND0, 1, threadID); - GPUResource* cs_uavs[1] = { pUAV_Dst }; + const GPUResource* cs_uavs[1] = { &pUAV_Dst }; device->BindUAVs(CS, cs_uavs, 0, ARRAYSIZE(cs_uavs), threadID); // Shader @@ -53,50 +54,49 @@ void radix008A(CSFFT512x512_Plan* fft_plan, device->UnbindUAVs(0, 1, threadID); } -void fft_512x512_c2c(CSFFT512x512_Plan* fft_plan, - GPUResource* pUAV_Dst, - GPUResource* pSRV_Dst, - GPUResource* pSRV_Src, +void fft_512x512_c2c( + const CSFFT512x512_Plan& fft_plan, + const GPUResource& pUAV_Dst, + const GPUResource& pSRV_Dst, + const GPUResource& pSRV_Src, GRAPHICSTHREAD threadID) { - const UINT thread_count = fft_plan->slices * (512 * 512) / 8; - GPUResource* pUAV_Tmp = fft_plan->pUAV_Tmp; - GPUResource* pSRV_Tmp = fft_plan->pSRV_Tmp; + const UINT thread_count = fft_plan.slices * (512 * 512) / 8; GraphicsDevice* device = wiRenderer::GetDevice(); - GPUBuffer* cs_cbs; + const GPUBuffer* cs_cbs; UINT istride = 512 * 512 / 8; - cs_cbs = fft_plan->pRadix008A_CB[0]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Tmp, pSRV_Src, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[0]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, fft_plan.pBuffer_Tmp, pSRV_Src, thread_count, istride, threadID); istride /= 8; - cs_cbs = fft_plan->pRadix008A_CB[1]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Dst, pSRV_Tmp, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[1]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, pUAV_Dst, fft_plan.pBuffer_Tmp, thread_count, istride, threadID); istride /= 8; - cs_cbs = fft_plan->pRadix008A_CB[2]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Tmp, pSRV_Dst, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[2]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, fft_plan.pBuffer_Tmp, pSRV_Dst, thread_count, istride, threadID); istride /= 8; - cs_cbs = fft_plan->pRadix008A_CB[3]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Dst, pSRV_Tmp, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[3]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, pUAV_Dst, fft_plan.pBuffer_Tmp, thread_count, istride, threadID); istride /= 8; - cs_cbs = fft_plan->pRadix008A_CB[4]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Tmp, pSRV_Dst, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[4]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, fft_plan.pBuffer_Tmp, pSRV_Dst, thread_count, istride, threadID); istride /= 8; - cs_cbs = fft_plan->pRadix008A_CB[5]; - device->BindConstantBuffer(CS, &cs_cbs[0], CB_GETBINDSLOT(FFTGeneratorCB), threadID); - radix008A(fft_plan, pUAV_Dst, pSRV_Tmp, thread_count, istride, threadID); + cs_cbs = &fft_plan.pRadix008A_CB[5]; + device->BindConstantBuffer(CS, cs_cbs, CB_GETBINDSLOT(FFTGeneratorCB), threadID); + radix008A(fft_plan, pUAV_Dst, fft_plan.pBuffer_Tmp, thread_count, istride, threadID); } -void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UINT slices) +void create_cbuffers_512x512(CSFFT512x512_Plan& plan, GraphicsDevice* device, UINT slices) { // Create 6 cbuffers for 512x512 transform. @@ -112,20 +112,6 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI cb_data.SysMemPitch = 0; cb_data.SysMemSlicePitch = 0; - //struct CB_Structure - //{ - // UINT thread_count; - // UINT ostride; - // UINT istride; - // UINT pstride; - // float phase_base; - //}; - - for (int i = 0; i < ARRAYSIZE(plan->pRadix008A_CB); ++i) - { - plan->pRadix008A_CB[i] = new GPUBuffer; - } - // Buffer 0 const UINT thread_count = slices * (512 * 512) / 8; UINT ostride = 512 * 512 / 8; @@ -135,8 +121,7 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf0 = { thread_count, ostride, istride, 512, (float)phase_base }; cb_data.pSysMem = &cb_data_buf0; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[0]); - assert(plan->pRadix008A_CB[0]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[0]); // Buffer 1 istride /= 8; @@ -145,8 +130,7 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf1 = { thread_count, ostride, istride, 512, (float)phase_base }; cb_data.pSysMem = &cb_data_buf1; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[1]); - assert(plan->pRadix008A_CB[1]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[1]); // Buffer 2 istride /= 8; @@ -155,8 +139,7 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf2 = { thread_count, ostride, istride, 512, (float)phase_base }; cb_data.pSysMem = &cb_data_buf2; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[2]); - assert(plan->pRadix008A_CB[2]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[2]); // Buffer 3 istride /= 8; @@ -166,8 +149,7 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf3 = { thread_count, ostride, istride, 1, (float)phase_base }; cb_data.pSysMem = &cb_data_buf3; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[3]); - assert(plan->pRadix008A_CB[3]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[3]); // Buffer 4 istride /= 8; @@ -176,8 +158,7 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf4 = { thread_count, ostride, istride, 1, (float)phase_base }; cb_data.pSysMem = &cb_data_buf4; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[4]); - assert(plan->pRadix008A_CB[4]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[4]); // Buffer 5 istride /= 8; @@ -186,16 +167,14 @@ void create_cbuffers_512x512(CSFFT512x512_Plan* plan, GraphicsDevice* device, UI FFTGeneratorCB cb_data_buf5 = { thread_count, ostride, istride, 1, (float)phase_base }; cb_data.pSysMem = &cb_data_buf5; - device->CreateBuffer(&cb_desc, &cb_data, plan->pRadix008A_CB[5]); - assert(plan->pRadix008A_CB[5]); + device->CreateBuffer(&cb_desc, &cb_data, &plan.pRadix008A_CB[5]); } -void fft512x512_create_plan(CSFFT512x512_Plan* plan, UINT slices) +void fft512x512_create_plan(CSFFT512x512_Plan& plan, UINT slices) { GraphicsDevice* device = wiRenderer::GetDevice(); - plan->slices = slices; - + plan.slices = slices; // Constants // Create 6 cbuffers for 512x512 transform @@ -210,19 +189,7 @@ void fft512x512_create_plan(CSFFT512x512_Plan* plan, UINT slices) buf_desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; buf_desc.StructureByteStride = sizeof(float) * 2; - plan->pBuffer_Tmp = new GPUBuffer; - device->CreateBuffer(&buf_desc, nullptr, plan->pBuffer_Tmp); - - plan->pSRV_Tmp = (GPUResource*)plan->pBuffer_Tmp; - plan->pUAV_Tmp = (GPUResource*)plan->pBuffer_Tmp; -} - -void fft512x512_destroy_plan(CSFFT512x512_Plan* plan) -{ - SAFE_DELETE(plan->pBuffer_Tmp); - - for (int i = 0; i < 6; i++) - SAFE_DELETE(plan->pRadix008A_CB[i]); + device->CreateBuffer(&buf_desc, nullptr, &plan.pBuffer_Tmp); } diff --git a/WickedEngine/wiFFTGenerator.h b/WickedEngine/wiFFTGenerator.h index 4e2091cb4..c375879d5 100644 --- a/WickedEngine/wiFFTGenerator.h +++ b/WickedEngine/wiFFTGenerator.h @@ -19,12 +19,9 @@ typedef struct CSFFT_512x512_Data_t UINT slices; // For 512x512 config, we need 6 constant buffers - wiGraphicsTypes::GPUBuffer* pRadix008A_CB[6]; + wiGraphicsTypes::GPUBuffer pRadix008A_CB[6]; - // Temporary buffers - wiGraphicsTypes::GPUBuffer* pBuffer_Tmp; - wiGraphicsTypes::GPUResource* pUAV_Tmp; - wiGraphicsTypes::GPUResource* pSRV_Tmp; + wiGraphicsTypes::GPUBuffer pBuffer_Tmp; static void LoadShaders(); } CSFFT512x512_Plan; @@ -41,13 +38,13 @@ typedef struct CSFFT_512x512_Data_t #define FFT_INVERSE 1 -void fft512x512_create_plan(CSFFT512x512_Plan* plan, UINT slices); -void fft512x512_destroy_plan(CSFFT512x512_Plan* plan); +void fft512x512_create_plan(CSFFT512x512_Plan& plan, UINT slices); -void fft_512x512_c2c(CSFFT512x512_Plan* fft_plan, - wiGraphicsTypes::GPUResource* pUAV_Dst, - wiGraphicsTypes::GPUResource* pSRV_Dst, - wiGraphicsTypes::GPUResource* pSRV_Src, +void fft_512x512_c2c( + const CSFFT512x512_Plan& fft_plan, + const wiGraphicsTypes::GPUResource& pUAV_Dst, + const wiGraphicsTypes::GPUResource& pSRV_Dst, + const wiGraphicsTypes::GPUResource& pSRV_Src, GRAPHICSTHREAD threadID); diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index d923f7ce0..7cd50f4b9 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -37,10 +37,10 @@ namespace wiFont_Internal DepthStencilState depthStencilState; Sampler sampler; - std::unique_ptr vertexLayout; + VertexLayout vertexLayout; const VertexShader *vertexShader = nullptr; const PixelShader *pixelShader = nullptr; - GraphicsPSO *PSO = nullptr; + GraphicsPSO PSO; atomic_bool initialized = false; @@ -306,8 +306,7 @@ void wiFont::LoadShaders() }; vertexShader = static_cast(wiResourceManager::GetShaderManager().add(path + "fontVS.cso", wiResourceManager::VERTEXSHADER)); - vertexLayout.reset(new VertexLayout); - wiRenderer::GetDevice()->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShader->code, vertexLayout.get()); + wiRenderer::GetDevice()->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShader->code, &vertexLayout); pixelShader = static_cast(wiResourceManager::GetShaderManager().add(path + "fontPS.cso", wiResourceManager::PIXELSHADER)); @@ -316,14 +315,13 @@ void wiFont::LoadShaders() GraphicsPSODesc desc; desc.vs = vertexShader; desc.ps = pixelShader; - desc.il = vertexLayout.get(); + desc.il = &vertexLayout; desc.bs = &blendState; desc.rs = &rasterizerState; desc.dss = &depthStencilState; desc.numRTs = 1; desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat(); - RECREATE(PSO); - wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO); + wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, &PSO); } void wiFont::BindPersistentState(GRAPHICSTHREAD threadID) @@ -502,7 +500,7 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) device->EventBegin("Font", threadID); - device->BindGraphicsPSO(PSO, threadID); + device->BindGraphicsPSO(&PSO, threadID); device->BindSampler(PS, &sampler, SSLOT_ONDEMAND1, threadID); GPUBuffer* vbs[] = { diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index 0b1f924ae..7eb0a5723 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -26,9 +26,9 @@ enum CSTYPES_BVH CSTYPE_BVH_COUNT }; static const ComputeShader* computeShaders[CSTYPE_BVH_COUNT] = {}; -static ComputePSO* CPSO[CSTYPE_BVH_COUNT] = {}; +static ComputePSO CPSO[CSTYPE_BVH_COUNT]; -static GPUBuffer* constantBuffer = nullptr; +static GPUBuffer constantBuffer; wiGPUBVH::wiGPUBVH() { @@ -43,7 +43,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) { GraphicsDevice* device = wiRenderer::GetDevice(); - if (constantBuffer == nullptr) + if (!constantBuffer.IsValid()) { GPUBufferDesc bd; bd.Usage = USAGE_DYNAMIC; @@ -51,9 +51,8 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) bd.BindFlags = BIND_CONSTANT_BUFFER; bd.ByteWidth = sizeof(BVHCB); - constantBuffer = new GPUBuffer; - device->CreateBuffer(&bd, nullptr, constantBuffer); - device->SetName(constantBuffer, "BVHGeneratorCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffer); + device->SetName(&constantBuffer, "BVHGeneratorCB"); } // Pre-gather scene properties: @@ -78,18 +77,6 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) GPUBufferDesc desc; HRESULT hr; - bvhNodeBuffer.reset(new GPUBuffer); - bvhAABBBuffer.reset(new GPUBuffer); - bvhFlagBuffer.reset(new GPUBuffer); - triangleBuffer.reset(new GPUBuffer); - clusterCounterBuffer.reset(new GPUBuffer); - clusterIndexBuffer.reset(new GPUBuffer); - clusterMortonBuffer.reset(new GPUBuffer); - clusterSortedMortonBuffer.reset(new GPUBuffer); - clusterOffsetBuffer.reset(new GPUBuffer); - clusterAABBBuffer.reset(new GPUBuffer); - clusterConeBuffer.reset(new GPUBuffer); - desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(BVHNode); desc.ByteWidth = desc.StructureByteStride * maxClusterCount * 2; @@ -97,9 +84,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, bvhNodeBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &bvhNodeBuffer); assert(SUCCEEDED(hr)); - device->SetName(bvhNodeBuffer.get(), "BVHNodeBuffer"); + device->SetName(&bvhNodeBuffer, "BVHNodeBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(BVHAABB); @@ -108,9 +95,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, bvhAABBBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &bvhAABBBuffer); assert(SUCCEEDED(hr)); - device->SetName(bvhAABBBuffer.get(), "BVHAABBBuffer"); + device->SetName(&bvhAABBBuffer, "BVHAABBBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(uint); @@ -119,9 +106,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, bvhFlagBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &bvhFlagBuffer); assert(SUCCEEDED(hr)); - device->SetName(bvhFlagBuffer.get(), "BVHFlagBuffer"); + device->SetName(&bvhFlagBuffer, "BVHFlagBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(BVHMeshTriangle); @@ -130,9 +117,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, triangleBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &triangleBuffer); assert(SUCCEEDED(hr)); - device->SetName(triangleBuffer.get(), "BVHTriangleBuffer"); + device->SetName(&triangleBuffer, "BVHTriangleBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(uint); @@ -141,9 +128,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterCounterBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterCounterBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterCounterBuffer.get(), "BVHClusterCounterBuffer"); + device->SetName(&clusterCounterBuffer, "BVHClusterCounterBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(uint); @@ -152,9 +139,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterIndexBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterIndexBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterIndexBuffer.get(), "BVHClusterIndexBuffer"); + device->SetName(&clusterIndexBuffer, "BVHClusterIndexBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(uint); @@ -163,11 +150,11 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterMortonBuffer.get()); - hr = device->CreateBuffer(&desc, nullptr, clusterSortedMortonBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterMortonBuffer); + hr = device->CreateBuffer(&desc, nullptr, &clusterSortedMortonBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterMortonBuffer.get(), "BVHClusterMortonBuffer"); - device->SetName(clusterSortedMortonBuffer.get(), "BVHSortedClusterMortonBuffer"); + device->SetName(&clusterMortonBuffer, "BVHClusterMortonBuffer"); + device->SetName(&clusterSortedMortonBuffer, "BVHSortedClusterMortonBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(uint2); @@ -176,9 +163,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterOffsetBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterOffsetBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterOffsetBuffer.get(), "BVHClusterOffsetBuffer"); + device->SetName(&clusterOffsetBuffer, "BVHClusterOffsetBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(BVHAABB); @@ -187,9 +174,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterAABBBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterAABBBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterAABBBuffer.get(), "BVHClusterAABBBuffer"); + device->SetName(&clusterAABBBuffer, "BVHClusterAABBBuffer"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.StructureByteStride = sizeof(ClusterCone); @@ -198,9 +185,9 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) desc.Format = FORMAT_UNKNOWN; desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - hr = device->CreateBuffer(&desc, nullptr, clusterConeBuffer.get()); + hr = device->CreateBuffer(&desc, nullptr, &clusterConeBuffer); assert(SUCCEEDED(hr)); - device->SetName(clusterConeBuffer.get(), "BVHClusterConeBuffer"); + device->SetName(&clusterConeBuffer, "BVHClusterConeBuffer"); } static GPUBuffer* indirectBuffer = nullptr; // GPU job kicks @@ -228,12 +215,12 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Reset", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_RESET], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_RESET], threadID); GPUResource* uavs[] = { - clusterCounterBuffer.get(), - bvhNodeBuffer.get(), - bvhAABBBuffer.get(), + &clusterCounterBuffer, + &bvhNodeBuffer, + &bvhAABBBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); @@ -247,14 +234,14 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Classification", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_CLASSIFICATION], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_CLASSIFICATION], threadID); GPUResource* uavs[] = { - triangleBuffer.get(), - clusterCounterBuffer.get(), - clusterIndexBuffer.get(), - clusterMortonBuffer.get(), - clusterOffsetBuffer.get(), - clusterAABBBuffer.get(), + &triangleBuffer, + &clusterCounterBuffer, + &clusterIndexBuffer, + &clusterMortonBuffer, + &clusterOffsetBuffer, + &clusterAABBBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); @@ -273,11 +260,11 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) cb.xTraceBVHMeshTriangleCount = (uint)mesh.indices.size() / 3; cb.xTraceBVHMeshVertexPOSStride = sizeof(MeshComponent::Vertex_POS); - device->UpdateBuffer(constantBuffer, &cb, threadID); + device->UpdateBuffer(&constantBuffer, &cb, threadID); triangleCount += cb.xTraceBVHMeshTriangleCount; - device->BindConstantBuffer(CS, constantBuffer, CB_GETBINDSLOT(BVHCB), threadID); + device->BindConstantBuffer(CS, &constantBuffer, CB_GETBINDSLOT(BVHCB), threadID); GPUResource* res[] = { mesh.indexBuffer.get(), @@ -302,19 +289,19 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Sort Cluster Mortons", threadID); - wiGPUSortLib::Sort(maxClusterCount, clusterMortonBuffer.get(), clusterCounterBuffer.get(), 0, clusterIndexBuffer.get(), threadID); + wiGPUSortLib::Sort(maxClusterCount, clusterMortonBuffer, clusterCounterBuffer, 0, clusterIndexBuffer, threadID); device->EventEnd(threadID); device->EventBegin("BVH - Kick Jobs", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_KICKJOBS], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_KICKJOBS], threadID); GPUResource* uavs[] = { indirectBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); GPUResource* res[] = { - clusterCounterBuffer.get(), + &clusterCounterBuffer, }; device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); @@ -327,20 +314,20 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Cluster Processor", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_CLUSTERPROCESSOR], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_CLUSTERPROCESSOR], threadID); GPUResource* uavs[] = { - clusterSortedMortonBuffer.get(), - clusterConeBuffer.get(), + &clusterSortedMortonBuffer, + &clusterConeBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); GPUResource* res[] = { - clusterCounterBuffer.get(), - clusterIndexBuffer.get(), - clusterMortonBuffer.get(), - clusterOffsetBuffer.get(), - clusterAABBBuffer.get(), - triangleBuffer.get(), + &clusterCounterBuffer, + &clusterIndexBuffer, + &clusterMortonBuffer, + &clusterOffsetBuffer, + &clusterAABBBuffer, + &triangleBuffer, }; device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); @@ -354,16 +341,16 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Build Hierarchy", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_HIERARCHY], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_HIERARCHY], threadID); GPUResource* uavs[] = { - bvhNodeBuffer.get(), - bvhFlagBuffer.get(), + &bvhNodeBuffer, + &bvhFlagBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); GPUResource* res[] = { - clusterCounterBuffer.get(), - clusterSortedMortonBuffer.get(), + &clusterCounterBuffer, + &clusterSortedMortonBuffer, }; device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); @@ -377,18 +364,18 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) device->EventBegin("BVH - Propagate AABB", threadID); { - device->BindComputePSO(CPSO[CSTYPE_BVH_PROPAGATEAABB], threadID); + device->BindComputePSO(&CPSO[CSTYPE_BVH_PROPAGATEAABB], threadID); GPUResource* uavs[] = { - bvhAABBBuffer.get(), - bvhFlagBuffer.get(), + &bvhAABBBuffer, + &bvhFlagBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); GPUResource* res[] = { - clusterCounterBuffer.get(), - clusterIndexBuffer.get(), - clusterAABBBuffer.get(), - bvhNodeBuffer.get(), + &clusterCounterBuffer, + &clusterIndexBuffer, + &clusterAABBBuffer, + &bvhNodeBuffer, }; device->BindResources(CS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); @@ -406,7 +393,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) bool download_success; // Download cluster count: - readback_desc = clusterCounterBuffer->GetDesc(); + readback_desc = clusterCounterBuffer.GetDesc(); readback_desc.Usage = USAGE_STAGING; readback_desc.CPUAccessFlags = CPU_ACCESS_READ; readback_desc.BindFlags = 0; @@ -414,7 +401,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) GPUBuffer readback_clusterCounterBuffer; device->CreateBuffer(&readback_desc, nullptr, &readback_clusterCounterBuffer); uint clusterCount; - download_success = device->DownloadResource(clusterCounterBuffer.get(), &readback_clusterCounterBuffer, &clusterCount, threadID); + download_success = device->DownloadResource(&clusterCounterBuffer, &readback_clusterCounterBuffer, &clusterCount, threadID); assert(download_success); if (clusterCount > 0) @@ -422,7 +409,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) const uint leafNodeOffset = clusterCount - 1; // Validate node buffer: - readback_desc = bvhNodeBuffer->GetDesc(); + readback_desc = bvhNodeBuffer.GetDesc(); readback_desc.Usage = USAGE_STAGING; readback_desc.CPUAccessFlags = CPU_ACCESS_READ; readback_desc.BindFlags = 0; @@ -430,7 +417,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) GPUBuffer readback_nodeBuffer; device->CreateBuffer(&readback_desc, nullptr, &readback_nodeBuffer); vector nodes(readback_desc.ByteWidth / sizeof(BVHNode)); - download_success = device->DownloadResource(bvhNodeBuffer.get(), &readback_nodeBuffer, nodes.data(), threadID); + download_success = device->DownloadResource(&bvhNodeBuffer, &readback_nodeBuffer, nodes.data(), threadID); assert(download_success); set visitedLeafs; vector stack; @@ -463,7 +450,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) } // Validate flag buffer: - readback_desc = bvhFlagBuffer->GetDesc(); + readback_desc = bvhFlagBuffer.GetDesc(); readback_desc.Usage = USAGE_STAGING; readback_desc.CPUAccessFlags = CPU_ACCESS_READ; readback_desc.BindFlags = 0; @@ -471,7 +458,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) GPUBuffer readback_flagBuffer; device->CreateBuffer(&readback_desc, nullptr, &readback_flagBuffer); vector flags(readback_desc.ByteWidth / sizeof(uint)); - download_success = device->DownloadResource(bvhFlagBuffer.get(), &readback_flagBuffer, flags.data(), threadID); + download_success = device->DownloadResource(&bvhFlagBuffer, &readback_flagBuffer, flags.data(), threadID); assert(download_success); for (auto& x : flags) { @@ -493,13 +480,13 @@ void wiGPUBVH::Bind(SHADERSTAGE stage, GRAPHICSTHREAD threadID) GraphicsDevice* device = wiRenderer::GetDevice(); GPUResource* res[] = { - triangleBuffer.get(), - clusterCounterBuffer.get(), - clusterIndexBuffer.get(), - clusterOffsetBuffer.get(), - clusterConeBuffer.get(), - bvhNodeBuffer.get(), - bvhAABBBuffer.get(), + &triangleBuffer, + &clusterCounterBuffer, + &clusterIndexBuffer, + &clusterOffsetBuffer, + &clusterConeBuffer, + &bvhNodeBuffer, + &bvhAABBBuffer, }; device->BindResources(stage, res, TEXSLOT_ONDEMAND1, ARRAYSIZE(res), threadID); } @@ -522,7 +509,6 @@ void wiGPUBVH::LoadShaders() { ComputePSODesc desc; desc.cs = computeShaders[i]; - RECREATE(CPSO[i]); - device->CreateComputePSO(&desc, CPSO[i]); + device->CreateComputePSO(&desc, &CPSO[i]); } } diff --git a/WickedEngine/wiGPUBVH.h b/WickedEngine/wiGPUBVH.h index d66937251..bc79bdac4 100644 --- a/WickedEngine/wiGPUBVH.h +++ b/WickedEngine/wiGPUBVH.h @@ -10,17 +10,17 @@ class wiGPUBVH { private: - std::unique_ptr bvhNodeBuffer; - std::unique_ptr bvhAABBBuffer; - std::unique_ptr bvhFlagBuffer; - std::unique_ptr triangleBuffer; - std::unique_ptr clusterCounterBuffer; - std::unique_ptr clusterIndexBuffer; - std::unique_ptr clusterMortonBuffer; - std::unique_ptr clusterSortedMortonBuffer; - std::unique_ptr clusterOffsetBuffer; - std::unique_ptr clusterAABBBuffer; - std::unique_ptr clusterConeBuffer; + wiGraphicsTypes::GPUBuffer bvhNodeBuffer; + wiGraphicsTypes::GPUBuffer bvhAABBBuffer; + wiGraphicsTypes::GPUBuffer bvhFlagBuffer; + wiGraphicsTypes::GPUBuffer triangleBuffer; + wiGraphicsTypes::GPUBuffer clusterCounterBuffer; + wiGraphicsTypes::GPUBuffer clusterIndexBuffer; + wiGraphicsTypes::GPUBuffer clusterMortonBuffer; + wiGraphicsTypes::GPUBuffer clusterSortedMortonBuffer; + wiGraphicsTypes::GPUBuffer clusterOffsetBuffer; + wiGraphicsTypes::GPUBuffer clusterAABBBuffer; + wiGraphicsTypes::GPUBuffer clusterConeBuffer; uint32_t maxTriangleCount = 0; uint32_t maxClusterCount = 0; diff --git a/WickedEngine/wiGPUSortLib.cpp b/WickedEngine/wiGPUSortLib.cpp index adbbea499..11a948910 100644 --- a/WickedEngine/wiGPUSortLib.cpp +++ b/WickedEngine/wiGPUSortLib.cpp @@ -7,8 +7,8 @@ using namespace wiGraphicsTypes; namespace wiGPUSortLib { - static std::unique_ptr indirectBuffer; - static std::unique_ptr sortCB; + static GPUBuffer indirectBuffer; + static GPUBuffer sortCB; static const ComputeShader* kickoffSortCS = nullptr; static const ComputeShader* sortCS = nullptr; static const ComputeShader* sortInnerCS = nullptr; @@ -27,8 +27,7 @@ namespace wiGPUSortLib bd.BindFlags = BIND_CONSTANT_BUFFER; bd.MiscFlags = 0; bd.ByteWidth = sizeof(SortConstants); - sortCB.reset(new GPUBuffer); - wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, sortCB.get()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &sortCB); bd.Usage = USAGE_DEFAULT; @@ -36,8 +35,7 @@ namespace wiGPUSortLib bd.BindFlags = BIND_UNORDERED_ACCESS; bd.MiscFlags = RESOURCE_MISC_DRAWINDIRECT_ARGS | RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; bd.ByteWidth = sizeof(IndirectDispatchArgs); - indirectBuffer.reset(new GPUBuffer); - wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, indirectBuffer.get()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &indirectBuffer); } @@ -73,7 +71,13 @@ namespace wiGPUSortLib } - void Sort(UINT maxCount, GPUBuffer* comparisonBuffer_read, GPUBuffer* counterBuffer_read, UINT counterReadOffset, GPUBuffer* indexBuffer_write, GRAPHICSTHREAD threadID) + void Sort( + UINT maxCount, + const GPUBuffer& comparisonBuffer_read, + const GPUBuffer& counterBuffer_read, + UINT counterReadOffset, + const GPUBuffer& indexBuffer_write, + GRAPHICSTHREAD threadID) { static bool init = false; if (!init) @@ -90,8 +94,8 @@ namespace wiGPUSortLib SortConstants sc; sc.counterReadOffset = counterReadOffset; - device->UpdateBuffer(sortCB.get(), &sc, threadID); - device->BindConstantBuffer(CS, sortCB.get(), CB_GETBINDSLOT(SortConstants), threadID); + device->UpdateBuffer(&sortCB, &sc, threadID); + device->BindConstantBuffer(CS, &sortCB, CB_GETBINDSLOT(SortConstants), threadID); device->UnbindUAVs(0, 8, threadID); @@ -99,13 +103,13 @@ namespace wiGPUSortLib { device->BindComputePSO(&CPSO_kickoffSort, threadID); - GPUResource* res[] = { - counterBuffer_read, + const GPUResource* res[] = { + &counterBuffer_read, }; device->BindResources(CS, res, 0, ARRAYSIZE(res), threadID); - GPUResource* uavs[] = { - indirectBuffer.get(), + const GPUResource* uavs[] = { + &indirectBuffer, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); @@ -116,14 +120,14 @@ namespace wiGPUSortLib } - GPUResource* uavs[] = { - indexBuffer_write, + const GPUResource* uavs[] = { + &indexBuffer_write, }; device->BindUAVs(CS, uavs, 0, ARRAYSIZE(uavs), threadID); - GPUResource* resources[] = { - counterBuffer_read, - comparisonBuffer_read, + const GPUResource* resources[] = { + &counterBuffer_read, + &comparisonBuffer_read, }; device->BindResources(CS, resources, 0, ARRAYSIZE(resources), threadID); @@ -146,7 +150,7 @@ namespace wiGPUSortLib // sort all buffers of size 512 (and presort bigger ones) device->BindComputePSO(&CPSO_sort, threadID); - device->DispatchIndirect(indirectBuffer.get(), 0, threadID); + device->DispatchIndirect(&indirectBuffer, 0, threadID); device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); } @@ -189,8 +193,8 @@ namespace wiGPUSortLib } sc.counterReadOffset = counterReadOffset; - device->UpdateBuffer(sortCB.get(), &sc, threadID); - device->BindConstantBuffer(CS, sortCB.get(), CB_GETBINDSLOT(SortConstants), threadID); + device->UpdateBuffer(&sortCB, &sc, threadID); + device->BindConstantBuffer(CS, &sortCB, CB_GETBINDSLOT(SortConstants), threadID); device->Dispatch(numThreadGroups, 1, 1, threadID); device->UAVBarrier(uavs, ARRAYSIZE(uavs), threadID); diff --git a/WickedEngine/wiGPUSortLib.h b/WickedEngine/wiGPUSortLib.h index a861251d1..004f8bc34 100644 --- a/WickedEngine/wiGPUSortLib.h +++ b/WickedEngine/wiGPUSortLib.h @@ -12,11 +12,17 @@ namespace wiGPUSortLib // counterBuffer_read - Buffer containing count of values to sort (Read Only) // counterReadOffset - Byte offset into the counter buffer to read the count value (Read Only) // indexBuffer_write - The index list which to sort. Contains index values which can index the sortBase_read buffer. This will be modified (Read + Write) - void Sort(UINT maxCount, wiGraphicsTypes::GPUBuffer* comparisonBuffer_read, wiGraphicsTypes::GPUBuffer* counterBuffer_read, UINT counterReadOffset, wiGraphicsTypes::GPUBuffer* indexBuffer_write, GRAPHICSTHREAD threadID); + void Sort( + UINT maxCount, + const wiGraphicsTypes::GPUBuffer& comparisonBuffer_read, + const wiGraphicsTypes::GPUBuffer& counterBuffer_read, + UINT counterReadOffset, + const wiGraphicsTypes::GPUBuffer& indexBuffer_write, + GRAPHICSTHREAD threadID + ); void Initialize(); void LoadShaders(); - void CleanUp(); }; #endif // _WI_GPU_SORTLIB_H_ diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index 21e1a92d8..3c09731d3 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1591,6 +1591,8 @@ Texture2D GraphicsDevice_DX11::GetBackBuffer() HRESULT GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) { + DestroyBuffer(pBuffer); + DestroyResource(pBuffer); pBuffer->type = GPUResource::BUFFER; pBuffer->Register(this); @@ -1699,6 +1701,8 @@ HRESULT GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subr } HRESULT GraphicsDevice_DX11::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) { + DestroyTexture1D(pTexture1D); + DestroyResource(pTexture1D); pTexture1D->type = GPUResource::TEXTURE_1D; pTexture1D->Register(this); @@ -1749,6 +1753,8 @@ HRESULT GraphicsDevice_DX11::CreateTexture1D(const TextureDesc* pDesc, const Sub } HRESULT GraphicsDevice_DX11::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) { + DestroyTexture2D(pTexture2D); + DestroyResource(pTexture2D); pTexture2D->type = GPUResource::TEXTURE_2D; pTexture2D->Register(this); @@ -1863,6 +1869,8 @@ HRESULT GraphicsDevice_DX11::CreateTexture2D(const TextureDesc* pDesc, const Sub } HRESULT GraphicsDevice_DX11::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) { + DestroyTexture3D(pTexture3D); + DestroyResource(pTexture3D); pTexture3D->type = GPUResource::TEXTURE_3D; pTexture3D->Register(this); @@ -2545,6 +2553,7 @@ HRESULT GraphicsDevice_DX11::CreateDepthStencilView(Texture2D* pTexture) } HRESULT GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { + DestroyInputLayout(pInputLayout); pInputLayout->Register(this); pInputLayout->desc.reserve((size_t)NumElements); @@ -2573,6 +2582,7 @@ HRESULT GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputEle } HRESULT GraphicsDevice_DX11::CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) { + DestroyVertexShader(pVertexShader); pVertexShader->Register(this); pVertexShader->code.data = new BYTE[BytecodeLength]; @@ -2582,6 +2592,7 @@ HRESULT GraphicsDevice_DX11::CreateVertexShader(const void *pShaderBytecode, SIZ } HRESULT GraphicsDevice_DX11::CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) { + DestroyPixelShader(pPixelShader); pPixelShader->Register(this); pPixelShader->code.data = new BYTE[BytecodeLength]; @@ -2591,6 +2602,7 @@ HRESULT GraphicsDevice_DX11::CreatePixelShader(const void *pShaderBytecode, SIZE } HRESULT GraphicsDevice_DX11::CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, GeometryShader *pGeometryShader) { + DestroyGeometryShader(pGeometryShader); pGeometryShader->Register(this); pGeometryShader->code.data = new BYTE[BytecodeLength]; @@ -2600,6 +2612,7 @@ HRESULT GraphicsDevice_DX11::CreateGeometryShader(const void *pShaderBytecode, S } HRESULT GraphicsDevice_DX11::CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, HullShader *pHullShader) { + DestroyHullShader(pHullShader); pHullShader->Register(this); pHullShader->code.data = new BYTE[BytecodeLength]; @@ -2609,6 +2622,7 @@ HRESULT GraphicsDevice_DX11::CreateHullShader(const void *pShaderBytecode, SIZE_ } HRESULT GraphicsDevice_DX11::CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, DomainShader *pDomainShader) { + DestroyDomainShader(pDomainShader); pDomainShader->Register(this); pDomainShader->code.data = new BYTE[BytecodeLength]; @@ -2618,6 +2632,7 @@ HRESULT GraphicsDevice_DX11::CreateDomainShader(const void *pShaderBytecode, SIZ } HRESULT GraphicsDevice_DX11::CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ComputeShader *pComputeShader) { + DestroyComputeShader(pComputeShader); pComputeShader->Register(this); pComputeShader->code.data = new BYTE[BytecodeLength]; @@ -2627,6 +2642,7 @@ HRESULT GraphicsDevice_DX11::CreateComputeShader(const void *pShaderBytecode, SI } HRESULT GraphicsDevice_DX11::CreateBlendState(const BlendStateDesc *pBlendStateDesc, BlendState *pBlendState) { + DestroyBlendState(pBlendState); pBlendState->Register(this); D3D11_BLEND_DESC desc; @@ -2649,6 +2665,7 @@ HRESULT GraphicsDevice_DX11::CreateBlendState(const BlendStateDesc *pBlendStateD } HRESULT GraphicsDevice_DX11::CreateDepthStencilState(const DepthStencilStateDesc *pDepthStencilStateDesc, DepthStencilState *pDepthStencilState) { + DestroyDepthStencilState(pDepthStencilState); pDepthStencilState->Register(this); D3D11_DEPTH_STENCIL_DESC desc; @@ -2672,6 +2689,7 @@ HRESULT GraphicsDevice_DX11::CreateDepthStencilState(const DepthStencilStateDesc } HRESULT GraphicsDevice_DX11::CreateRasterizerState(const RasterizerStateDesc *pRasterizerStateDesc, RasterizerState *pRasterizerState) { + DestroyRasterizerState(pRasterizerState); pRasterizerState->Register(this); pRasterizerState->desc = *pRasterizerStateDesc; @@ -2749,6 +2767,7 @@ HRESULT GraphicsDevice_DX11::CreateRasterizerState(const RasterizerStateDesc *pR } HRESULT GraphicsDevice_DX11::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) { + DestroySamplerState(pSamplerState); pSamplerState->Register(this); D3D11_SAMPLER_DESC desc; @@ -2771,6 +2790,7 @@ HRESULT GraphicsDevice_DX11::CreateSamplerState(const SamplerDesc *pSamplerDesc, } HRESULT GraphicsDevice_DX11::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuery) { + DestroyQuery(pQuery); pQuery->Register(this); HRESULT hr = E_FAIL; @@ -2808,6 +2828,7 @@ HRESULT GraphicsDevice_DX11::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQ } HRESULT GraphicsDevice_DX11::CreateGraphicsPSO(const GraphicsPSODesc* pDesc, GraphicsPSO* pso) { + DestroyGraphicsPSO(pso); pso->Register(this); pso->desc = *pDesc; @@ -2816,6 +2837,7 @@ HRESULT GraphicsDevice_DX11::CreateGraphicsPSO(const GraphicsPSODesc* pDesc, Gra } HRESULT GraphicsDevice_DX11::CreateComputePSO(const ComputePSODesc* pDesc, ComputePSO* pso) { + DestroyComputePSO(pso); pso->Register(this); pso->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 77f404026..f282f9c59 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -2068,6 +2068,8 @@ namespace wiGraphicsTypes HRESULT GraphicsDevice_DX12::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) { + DestroyBuffer(pBuffer); + DestroyResource(pBuffer); pBuffer->type = GPUResource::BUFFER; pBuffer->Register(this); @@ -2225,6 +2227,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) { + DestroyTexture1D(pTexture1D); + DestroyResource(pTexture1D); pTexture1D->type = GPUResource::TEXTURE_1D; pTexture1D->Register(this); @@ -2237,6 +2241,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) { + DestroyTexture2D(pTexture2D); + DestroyResource(pTexture2D); pTexture2D->type = GPUResource::TEXTURE_2D; pTexture2D->Register(this); @@ -2865,6 +2871,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) { + DestroyTexture3D(pTexture3D); + DestroyResource(pTexture3D); pTexture3D->type = GPUResource::TEXTURE_3D; pTexture3D->Register(this); @@ -2877,6 +2885,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { + DestroyInputLayout(pInputLayout); pInputLayout->Register(this); pInputLayout->desc.reserve((size_t)NumElements); @@ -2889,6 +2898,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) { + DestroyVertexShader(pVertexShader); pVertexShader->Register(this); pVertexShader->code.data = new BYTE[BytecodeLength]; @@ -2899,6 +2909,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) { + DestroyPixelShader(pPixelShader); pPixelShader->Register(this); pPixelShader->code.data = new BYTE[BytecodeLength]; @@ -2909,6 +2920,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, GeometryShader *pGeometryShader) { + DestroyGeometryShader(pGeometryShader); pGeometryShader->Register(this); pGeometryShader->code.data = new BYTE[BytecodeLength]; @@ -2919,6 +2931,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, HullShader *pHullShader) { + DestroyHullShader(pHullShader); pHullShader->Register(this); pHullShader->code.data = new BYTE[BytecodeLength]; @@ -2929,6 +2942,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, DomainShader *pDomainShader) { + DestroyDomainShader(pDomainShader); pDomainShader->Register(this); pDomainShader->code.data = new BYTE[BytecodeLength]; @@ -2939,6 +2953,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ComputeShader *pComputeShader) { + DestroyComputeShader(pComputeShader); pComputeShader->Register(this); pComputeShader->code.data = new BYTE[BytecodeLength]; @@ -2949,6 +2964,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateBlendState(const BlendStateDesc *pBlendStateDesc, BlendState *pBlendState) { + DestroyBlendState(pBlendState); pBlendState->Register(this); pBlendState->desc = *pBlendStateDesc; @@ -2956,6 +2972,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateDepthStencilState(const DepthStencilStateDesc *pDepthStencilStateDesc, DepthStencilState *pDepthStencilState) { + DestroyDepthStencilState(pDepthStencilState); pDepthStencilState->Register(this); pDepthStencilState->desc = *pDepthStencilStateDesc; @@ -2963,6 +2980,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateRasterizerState(const RasterizerStateDesc *pRasterizerStateDesc, RasterizerState *pRasterizerState) { + DestroyRasterizerState(pRasterizerState); pRasterizerState->Register(this); pRasterizerState->desc = *pRasterizerStateDesc; @@ -2970,6 +2988,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) { + DestroySamplerState(pSamplerState); pSamplerState->Register(this); D3D12_SAMPLER_DESC desc; @@ -2996,7 +3015,9 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuery) { - pQuery->Register(this); + // TODO! + //DestroyQuery(pQuery); + //pQuery->Register(this); HRESULT hr = E_FAIL; @@ -3006,6 +3027,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateGraphicsPSO(const GraphicsPSODesc* pDesc, GraphicsPSO* pso) { + DestroyGraphicsPSO(pso); pso->Register(this); pso->desc = *pDesc; @@ -3148,6 +3170,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_DX12::CreateComputePSO(const ComputePSODesc* pDesc, ComputePSO* pso) { + DestroyComputePSO(pso); pso->Register(this); pso->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 796a2ab25..83e94f282 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -2445,6 +2445,8 @@ namespace wiGraphicsTypes HRESULT GraphicsDevice_Vulkan::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) { + DestroyBuffer(pBuffer); + DestroyResource(pBuffer); pBuffer->type = GPUResource::BUFFER; pBuffer->Register(this); @@ -2640,6 +2642,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) { + DestroyTexture1D(pTexture1D); + DestroyResource(pTexture1D); pTexture1D->type = GPUResource::TEXTURE_1D; pTexture1D->Register(this); @@ -2649,6 +2653,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) { + DestroyTexture2D(pTexture2D); + DestroyResource(pTexture2D); pTexture2D->type = GPUResource::TEXTURE_2D; pTexture2D->Register(this); @@ -3175,6 +3181,8 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) { + DestroyTexture3D(pTexture3D); + DestroyResource(pTexture3D); pTexture3D->type = GPUResource::TEXTURE_3D; pTexture3D->Register(this); @@ -3184,6 +3192,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { + DestroyInputLayout(pInputLayout); pInputLayout->Register(this); pInputLayout->desc.reserve((size_t)NumElements); @@ -3196,6 +3205,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) { + DestroyVertexShader(pVertexShader); pVertexShader->Register(this); pVertexShader->code.data = new BYTE[BytecodeLength]; @@ -3206,6 +3216,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) { + DestroyPixelShader(pPixelShader); pPixelShader->Register(this); pPixelShader->code.data = new BYTE[BytecodeLength]; @@ -3216,6 +3227,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, GeometryShader *pGeometryShader) { + DestroyGeometryShader(pGeometryShader); pGeometryShader->Register(this); pGeometryShader->code.data = new BYTE[BytecodeLength]; @@ -3226,6 +3238,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, HullShader *pHullShader) { + DestroyHullShader(pHullShader); pHullShader->Register(this); pHullShader->code.data = new BYTE[BytecodeLength]; @@ -3236,6 +3249,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, DomainShader *pDomainShader) { + DestroyDomainShader(pDomainShader); pDomainShader->Register(this); pDomainShader->code.data = new BYTE[BytecodeLength]; @@ -3246,6 +3260,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ComputeShader *pComputeShader) { + DestroyComputeShader(pComputeShader); pComputeShader->Register(this); pComputeShader->code.data = new BYTE[BytecodeLength]; @@ -3256,6 +3271,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateBlendState(const BlendStateDesc *pBlendStateDesc, BlendState *pBlendState) { + DestroyBlendState(pBlendState); pBlendState->Register(this); pBlendState->desc = *pBlendStateDesc; @@ -3263,6 +3279,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateDepthStencilState(const DepthStencilStateDesc *pDepthStencilStateDesc, DepthStencilState *pDepthStencilState) { + DestroyDepthStencilState(pDepthStencilState); pDepthStencilState->Register(this); pDepthStencilState->desc = *pDepthStencilStateDesc; @@ -3270,6 +3287,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateRasterizerState(const RasterizerStateDesc *pRasterizerStateDesc, RasterizerState *pRasterizerState) { + DestroyRasterizerState(pRasterizerState); pRasterizerState->Register(this); pRasterizerState->desc = *pRasterizerStateDesc; @@ -3277,6 +3295,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) { + DestroySamplerState(pSamplerState); pSamplerState->Register(this); pSamplerState->desc = *pSamplerDesc; @@ -3461,12 +3480,15 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateQuery(const GPUQueryDesc *pDesc, GPUQuery *pQuery) { - pQuery->Register(this); + // TODO! + //DestroyQuery(pQuery); + //pQuery->Register(this); return E_FAIL; } HRESULT GraphicsDevice_Vulkan::CreateGraphicsPSO(const GraphicsPSODesc* pDesc, GraphicsPSO* pso) { + DestroyGraphicsPSO(pso); pso->Register(this); pso->desc = *pDesc; @@ -3949,6 +3971,7 @@ namespace wiGraphicsTypes } HRESULT GraphicsDevice_Vulkan::CreateComputePSO(const ComputePSODesc* pDesc, ComputePSO* pso) { + DestroyComputePSO(pso); pso->Register(this); pso->desc = *pDesc; diff --git a/WickedEngine/wiGraphicsResource.h b/WickedEngine/wiGraphicsResource.h index 205c9aede..5c35b975a 100644 --- a/WickedEngine/wiGraphicsResource.h +++ b/WickedEngine/wiGraphicsResource.h @@ -16,14 +16,14 @@ namespace wiGraphicsTypes struct GraphicsDeviceChild { GraphicsDevice* device = nullptr; - void Register(GraphicsDevice* dev) { device = dev; } + inline void Register(GraphicsDevice* dev) { device = dev; } + inline bool IsValid() const { return device != nullptr; } }; struct ShaderByteCode { - BYTE* data; - size_t size; - ShaderByteCode() :data(nullptr), size(0) {} + BYTE* data = nullptr; + size_t size = 0; ~ShaderByteCode() { SAFE_DELETE_ARRAY(data); } }; @@ -89,7 +89,6 @@ namespace wiGraphicsTypes Sampler(); ~Sampler(); - bool IsValid() { return resource != WI_NULL_HANDLE; } const SamplerDesc& GetDesc() const { return desc; } }; @@ -112,8 +111,8 @@ namespace wiGraphicsTypes wiCPUHandle UAV = WI_NULL_HANDLE; // main resource UAV std::vector additionalUAVs; // can be used for sub-resources if requested - wiCPUHandle resource; - wiCPUHandle resourceMemory; + wiCPUHandle resource = WI_NULL_HANDLE; + wiCPUHandle resourceMemory = WI_NULL_HANDLE; GPUResource(); virtual ~GPUResource(); @@ -127,7 +126,6 @@ namespace wiGraphicsTypes GPUBuffer(); virtual ~GPUBuffer(); - bool IsValid() { return resource != WI_NULL_HANDLE; } const GPUBufferDesc& GetDesc() const { return desc; } }; @@ -228,20 +226,19 @@ namespace wiGraphicsTypes struct GPUQuery : public GraphicsDeviceChild { - wiCPUHandle resource; + wiCPUHandle resource = WI_NULL_HANDLE; GPUQueryDesc desc; GPUQuery(); virtual ~GPUQuery(); - bool IsValid() { return resource != WI_NULL_HANDLE; } const GPUQueryDesc& GetDesc() const { return desc; } }; struct GraphicsPSO : public GraphicsDeviceChild { - wiCPUHandle pipeline; + wiCPUHandle pipeline = WI_NULL_HANDLE; GraphicsPSODesc desc; const GraphicsPSODesc& GetDesc() const { return desc; } @@ -251,7 +248,7 @@ namespace wiGraphicsTypes }; struct ComputePSO : public GraphicsDeviceChild { - wiCPUHandle pipeline; + wiCPUHandle pipeline = WI_NULL_HANDLE; ComputePSODesc desc; const ComputePSODesc& GetDesc() const { return desc; } diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index bdbc12be0..f3a9007cc 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -9,7 +9,7 @@ using namespace wiGraphicsTypes; namespace wiLensFlare { - static std::unique_ptr constantBuffer; + static GPUBuffer constantBuffer; static const PixelShader *pixelShader = nullptr; static const GeometryShader *geometryShader = nullptr; static const VertexShader *vertexShader = nullptr; @@ -32,8 +32,8 @@ namespace wiLensFlare XMStoreFloat4(&cb.xSunPos, lightPos / XMVectorSet((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 1, 1)); cb.xScreen = XMFLOAT4((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0, 0); - device->UpdateBuffer(constantBuffer.get(), &cb, threadID); - device->BindConstantBuffer(GS, constantBuffer.get(), CB_GETBINDSLOT(LensFlareCB), threadID); + device->UpdateBuffer(&constantBuffer, &cb, threadID); + device->BindConstantBuffer(GS, &constantBuffer, CB_GETBINDSLOT(LensFlareCB), threadID); int i = 0; @@ -90,8 +90,7 @@ namespace wiLensFlare bd.ByteWidth = sizeof(LensFlareCB); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - constantBuffer.reset(new GPUBuffer); - wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, constantBuffer.get()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &constantBuffer); RasterizerStateDesc rs; diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index e7421ddd7..746dcf7df 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -280,7 +280,7 @@ void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, float time, // ------------------------------------ Perform FFT ------------------------------------------- - fft_512x512_c2c(&m_fft_plan, &m_pBuffer_Float_Dxyz, &m_pBuffer_Float_Dxyz, &m_pBuffer_Float2_Ht, threadID); + fft_512x512_c2c(m_fft_plan, m_pBuffer_Float_Dxyz, m_pBuffer_Float_Dxyz, m_pBuffer_Float2_Ht, threadID); @@ -464,24 +464,11 @@ void wiOcean::Initialize() LoadShaders(); CSFFT_512x512_Data_t::LoadShaders(); - fft512x512_create_plan(&m_fft_plan, 3); + fft512x512_create_plan(m_fft_plan, 3); wiBackLog::post("wiOcean Initialized"); } -void wiOcean::CleanUp() -{ - fft512x512_destroy_plan(&m_fft_plan); - - SAFE_DELETE(m_pUpdateSpectrumCS); - SAFE_DELETE(m_pUpdateDisplacementMapCS); - SAFE_DELETE(m_pUpdateGradientFoldingCS); - - SAFE_DELETE(g_pOceanSurfVS); - SAFE_DELETE(g_pOceanSurfPS); - SAFE_DELETE(g_pWireframePS); -} - Texture2D* wiOcean::getDisplacementMap() { return &m_pDisplacementMap; diff --git a/WickedEngine/wiOcean.h b/WickedEngine/wiOcean.h index 81b968061..8857e05b8 100644 --- a/WickedEngine/wiOcean.h +++ b/WickedEngine/wiOcean.h @@ -21,7 +21,6 @@ public: wiGraphicsTypes::Texture2D* getGradientMap(); static void Initialize(); - static void CleanUp(); static void LoadShaders(); protected: diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 0eb7fe3f8..8a940cb90 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -49,21 +49,22 @@ namespace wiRenderer GraphicsDevice* graphicsDevice = nullptr; -Sampler *samplers[SSLOT_COUNT] = {}; -const VertexShader *vertexShaders[VSTYPE_LAST] = {}; -const PixelShader *pixelShaders[PSTYPE_LAST] = {}; -const GeometryShader *geometryShaders[GSTYPE_LAST] = {}; -const HullShader *hullShaders[HSTYPE_LAST] = {}; -const DomainShader *domainShaders[DSTYPE_LAST] = {}; -const ComputeShader *computeShaders[CSTYPE_LAST] = {}; -VertexLayout *vertexLayouts[VLTYPE_LAST] = {}; -RasterizerState *rasterizers[RSTYPE_LAST] = {}; -DepthStencilState *depthStencils[DSSTYPE_LAST] = {}; -BlendState *blendStates[BSTYPE_LAST] = {}; -GPUBuffer *constantBuffers[CBTYPE_LAST] = {}; -GPUBuffer *resourceBuffers[RBTYPE_LAST] = {}; -Texture *textures[TEXTYPE_LAST] = {}; -Sampler *customsamplers[SSTYPE_LAST] = {}; +const VertexShader* vertexShaders[VSTYPE_LAST] = {}; +const PixelShader* pixelShaders[PSTYPE_LAST] = {}; +const GeometryShader* geometryShaders[GSTYPE_LAST] = {}; +const HullShader* hullShaders[HSTYPE_LAST] = {}; +const DomainShader* domainShaders[DSTYPE_LAST] = {}; +const ComputeShader* computeShaders[CSTYPE_LAST] = {}; +Texture* textures[TEXTYPE_LAST] = {}; + +VertexLayout vertexLayouts[VLTYPE_LAST]; +RasterizerState rasterizers[RSTYPE_LAST]; +DepthStencilState depthStencils[DSSTYPE_LAST]; +BlendState blendStates[BSTYPE_LAST]; +GPUBuffer constantBuffers[CBTYPE_LAST]; +GPUBuffer resourceBuffers[RBTYPE_LAST]; +Sampler samplers[SSLOT_COUNT]; +Sampler customsamplers[SSTYPE_LAST]; string SHADERPATH = "shaders/"; @@ -368,7 +369,7 @@ GFX_STRUCT InstanceAtlas const Sampler* GetSampler(int slot) { - return samplers[slot]; + return &samplers[slot]; } const VertexShader* GetVertexShader(VSTYPES id) { @@ -396,23 +397,23 @@ const ComputeShader* GetComputeShader(VSTYPES id) } const VertexLayout* GetVertexLayout(VLTYPES id) { - return vertexLayouts[id]; + return &vertexLayouts[id]; } const RasterizerState* GetRasterizerState(RSTYPES id) { - return rasterizers[id]; + return &rasterizers[id]; } const DepthStencilState* GetDepthStencilState(DSSTYPES id) { - return depthStencils[id]; + return &depthStencils[id]; } const BlendState* GetBlendState(BSTYPES id) { - return blendStates[id]; + return &blendStates[id]; } const GPUBuffer* GetConstantBuffer(CBTYPES id) { - return constantBuffers[id]; + return &constantBuffers[id]; } const Texture* GetTexture(TEXTYPES id) { @@ -421,9 +422,7 @@ const Texture* GetTexture(TEXTYPES id) void ModifySampler(const SamplerDesc& desc, int slot) { - SAFE_DELETE(samplers[slot]); - samplers[slot] = new wiGraphicsTypes::Sampler; - GetDevice()->CreateSamplerState(&desc, samplers[slot]); + GetDevice()->CreateSamplerState(&desc, &samplers[slot]); } std::string& GetShaderPath() @@ -502,42 +501,10 @@ void CleanUp() wiEmittedParticle::CleanUp(); wiCube::CleanUp(); - for (int i = 0; i < VLTYPE_LAST; ++i) - { - SAFE_DELETE(vertexLayouts[i]); - } - for (int i = 0; i < RSTYPE_LAST; ++i) - { - SAFE_DELETE(rasterizers[i]); - } - for (int i = 0; i < DSSTYPE_LAST; ++i) - { - SAFE_DELETE(depthStencils[i]); - } - for (int i = 0; i < BSTYPE_LAST; ++i) - { - SAFE_DELETE(blendStates[i]); - } - for (int i = 0; i < CBTYPE_LAST; ++i) - { - SAFE_DELETE(constantBuffers[i]); - } - for (int i = 0; i < RBTYPE_LAST; ++i) - { - SAFE_DELETE(resourceBuffers[i]); - } for (int i = 0; i < TEXTYPE_LAST; ++i) { SAFE_DELETE(textures[i]); } - for (int i = 0; i < SSLOT_COUNT_PERSISTENT; ++i) - { - SAFE_DELETE(samplers[i]); - } - for (int i = 0; i < SSTYPE_LAST; ++i) - { - SAFE_DELETE(customsamplers[i]); - } SAFE_DELETE(graphicsDevice); } @@ -610,10 +577,10 @@ enum OBJECTRENDERING_POM OBJECTRENDERING_POM_ENABLED, OBJECTRENDERING_POM_COUNT }; -GraphicsPSO* PSO_object[RENDERPASS_COUNT][BLENDMODE_COUNT][OBJECTRENDERING_DOUBLESIDED_COUNT][OBJECTRENDERING_TESSELLATION_COUNT][OBJECTRENDERING_ALPHATEST_COUNT][OBJECTRENDERING_TRANSPARENCY_COUNT][OBJECTRENDERING_NORMALMAP_COUNT][OBJECTRENDERING_PLANARREFLECTION_COUNT][OBJECTRENDERING_POM_COUNT] = {}; -GraphicsPSO* PSO_object_water[RENDERPASS_COUNT] = {}; -GraphicsPSO* PSO_object_wire = nullptr; -GraphicsPSO* GetObjectPSO(RENDERPASS renderPass, bool doublesided, bool tessellation, const MaterialComponent& material, bool forceAlphaTestForDithering) +GraphicsPSO PSO_object[RENDERPASS_COUNT][BLENDMODE_COUNT][OBJECTRENDERING_DOUBLESIDED_COUNT][OBJECTRENDERING_TESSELLATION_COUNT][OBJECTRENDERING_ALPHATEST_COUNT][OBJECTRENDERING_TRANSPARENCY_COUNT][OBJECTRENDERING_NORMALMAP_COUNT][OBJECTRENDERING_PLANARREFLECTION_COUNT][OBJECTRENDERING_POM_COUNT]; +GraphicsPSO PSO_object_water[RENDERPASS_COUNT]; +GraphicsPSO PSO_object_wire; +inline const GraphicsPSO* GetObjectPSO(RENDERPASS renderPass, bool doublesided, bool tessellation, const MaterialComponent& material, bool forceAlphaTestForDithering) { if (IsWireRender()) { @@ -623,14 +590,14 @@ GraphicsPSO* GetObjectPSO(RENDERPASS renderPass, bool doublesided, bool tessella case RENDERPASS_DEFERRED: case RENDERPASS_FORWARD: case RENDERPASS_TILEDFORWARD: - return PSO_object_wire; + return &PSO_object_wire; } return nullptr; } if (material.IsWater()) { - return PSO_object_water[renderPass]; + return &PSO_object_water[renderPass]; } const bool alphatest = material.IsAlphaTestEnabled() || forceAlphaTestForDithering; @@ -640,10 +607,12 @@ GraphicsPSO* GetObjectPSO(RENDERPASS renderPass, bool doublesided, bool tessella const bool pom = material.parallaxOcclusionMapping > 0; const BLENDMODE blendMode = material.blendMode; - return PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][transparent][normalmap][planarreflection][pom]; + const GraphicsPSO& pso = PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][transparent][normalmap][planarreflection][pom]; + assert(pso.IsValid()); + return &pso; } -GraphicsPSO* PSO_object_hologram = nullptr; +GraphicsPSO PSO_object_hologram; std::vector customShaders; int RegisterCustomShader(const CustomShader& customShader) { @@ -655,7 +624,7 @@ const std::vector& GetCustomShaders() { return customShaders; } -GraphicsPSO* GetCustomShaderPSO(RENDERPASS renderPass, uint32_t renderTypeFlags, int customShaderID) +inline const GraphicsPSO* GetCustomShaderPSO(RENDERPASS renderPass, uint32_t renderTypeFlags, int customShaderID) { if (customShaderID >= 0 && customShaderID < customShaders.size()) { @@ -1102,14 +1071,14 @@ PSTYPES GetPSTYPE(RENDERPASS renderPass, bool alphatest, bool transparent, bool return realPS; } -GraphicsPSO* PSO_decal = nullptr; -GraphicsPSO* PSO_occlusionquery = nullptr; -GraphicsPSO* PSO_impostor[RENDERPASS_COUNT] = {}; -GraphicsPSO* PSO_impostor_wire = nullptr; -GraphicsPSO* PSO_captureimpostor_albedo = nullptr; -GraphicsPSO* PSO_captureimpostor_normal = nullptr; -GraphicsPSO* PSO_captureimpostor_surface = nullptr; -GraphicsPSO* GetImpostorPSO(RENDERPASS renderPass) +GraphicsPSO PSO_decal; +GraphicsPSO PSO_occlusionquery; +GraphicsPSO PSO_impostor[RENDERPASS_COUNT]; +GraphicsPSO PSO_impostor_wire; +GraphicsPSO PSO_captureimpostor_albedo; +GraphicsPSO PSO_captureimpostor_normal; +GraphicsPSO PSO_captureimpostor_surface; +inline const GraphicsPSO* GetImpostorPSO(RENDERPASS renderPass) { if (IsWireRender()) { @@ -1119,21 +1088,21 @@ GraphicsPSO* GetImpostorPSO(RENDERPASS renderPass) case RENDERPASS_DEFERRED: case RENDERPASS_FORWARD: case RENDERPASS_TILEDFORWARD: - return PSO_impostor_wire; + return &PSO_impostor_wire; } return nullptr; } - return PSO_impostor[renderPass]; + return &PSO_impostor[renderPass]; } -GraphicsPSO* PSO_deferredlight[LightComponent::LIGHTTYPE_COUNT] = {}; -GraphicsPSO* PSO_lightvisualizer[LightComponent::LIGHTTYPE_COUNT] = {}; -GraphicsPSO* PSO_volumetriclight[LightComponent::LIGHTTYPE_COUNT] = {}; -GraphicsPSO* PSO_enviromentallight = nullptr; +GraphicsPSO PSO_deferredlight[LightComponent::LIGHTTYPE_COUNT]; +GraphicsPSO PSO_lightvisualizer[LightComponent::LIGHTTYPE_COUNT]; +GraphicsPSO PSO_volumetriclight[LightComponent::LIGHTTYPE_COUNT]; +GraphicsPSO PSO_enviromentallight; -GraphicsPSO* PSO_renderlightmap_indirect = nullptr; -GraphicsPSO* PSO_renderlightmap_direct = nullptr; +GraphicsPSO PSO_renderlightmap_indirect; +GraphicsPSO PSO_renderlightmap_direct; enum SKYRENDERING { @@ -1144,7 +1113,7 @@ enum SKYRENDERING SKYRENDERING_ENVMAPCAPTURE_DYNAMIC, SKYRENDERING_COUNT }; -GraphicsPSO* PSO_sky[SKYRENDERING_COUNT] = {}; +GraphicsPSO PSO_sky[SKYRENDERING_COUNT]; enum DEBUGRENDERING { @@ -1159,7 +1128,7 @@ enum DEBUGRENDERING DEBUGRENDERING_RAYTRACE_BVH, DEBUGRENDERING_COUNT }; -GraphicsPSO* PSO_debug[DEBUGRENDERING_COUNT] = {}; +GraphicsPSO PSO_debug[DEBUGRENDERING_COUNT]; enum TILEDLIGHTING_TYPE { @@ -1179,8 +1148,8 @@ enum TILEDLIGHTING_DEBUG TILEDLIGHTING_DEBUG_ENABLED, TILEDLIGHTING_DEBUG_COUNT }; -ComputePSO* CPSO_tiledlighting[TILEDLIGHTING_TYPE_COUNT][TILEDLIGHTING_CULLING_COUNT][TILEDLIGHTING_DEBUG_COUNT] = {}; -ComputePSO* CPSO[CSTYPE_LAST] = {}; +ComputePSO CPSO_tiledlighting[TILEDLIGHTING_TYPE_COUNT][TILEDLIGHTING_CULLING_COUNT][TILEDLIGHTING_DEBUG_COUNT]; +ComputePSO CPSO[CSTYPE_LAST]; @@ -1541,8 +1510,8 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re { TessellationCB tessCB; tessCB.g_f4TessFactors = XMFLOAT4(tessF, tessF, tessF, tessF); - device->UpdateBuffer(constantBuffers[CBTYPE_TESSELLATION], &tessCB, threadID); - device->BindConstantBuffer(HS, constantBuffers[CBTYPE_TESSELLATION], CBSLOT_RENDERER_TESSELLATION, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_TESSELLATION], &tessCB, threadID); + device->BindConstantBuffer(HS, &constantBuffers[CBTYPE_TESSELLATION], CBSLOT_RENDERER_TESSELLATION, threadID); } if (forwardLightmaskRequest) @@ -1550,8 +1519,8 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re const CameraComponent* camera = renderQueue.camera == nullptr ? &GetCamera() : renderQueue.camera; const FrameCulling& culling = frameCullings.at(camera); ForwardEntityMaskCB cb = ForwardEntityCullingCPU(culling, instancedBatch.aabb, renderPass); - device->UpdateBuffer(constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); } device->BindIndexBuffer(mesh.indexBuffer.get(), mesh.GetIndexFormat(), 0, threadID); @@ -1573,7 +1542,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re } const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); - GraphicsPSO* pso = nullptr; + const GraphicsPSO* pso = nullptr; if (material.IsCustomShader()) { pso = GetCustomShaderPSO(renderPass, renderTypeFlags, material.GetCustomShaderID()); @@ -1760,7 +1729,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re void RenderImpostors(const CameraComponent& camera, RENDERPASS renderPass, GRAPHICSTHREAD threadID) { const Scene& scene = GetScene(); - GraphicsPSO* impostorRequest = GetImpostorPSO(renderPass); + const GraphicsPSO* impostorRequest = GetImpostorPSO(renderPass); if (scene.impostors.GetCount() > 0 && impostorRequest != nullptr) { @@ -1821,7 +1790,7 @@ void RenderImpostors(const CameraComponent& camera, RENDERPASS renderPass, GRAPH MiscCB cb; cb.g_xColor.x = (float)instances.offset; - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &cb, threadID); device->BindResource(VS, instances.buffer, TEXSLOT_ONDEMAND0, threadID); device->BindResource(PS, textures[TEXTYPE_2D_IMPOSTORARRAY], TEXSLOT_ONDEMAND0, threadID); @@ -1837,18 +1806,13 @@ void LoadShaders() { GraphicsDevice* device = GetDevice(); - for (int i = 0; i < VLTYPE_LAST; ++i) - { - vertexLayouts[i] = new VertexLayout; - } - { VertexLayoutDesc layout[] = { { "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; vertexShaders[VSTYPE_OBJECT_DEBUG] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_debug.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_DEBUG]->code, vertexLayouts[VLTYPE_OBJECT_DEBUG]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_DEBUG]->code, &vertexLayouts[VLTYPE_OBJECT_DEBUG]); } { VertexLayoutDesc layout[] = @@ -1868,7 +1832,7 @@ void LoadShaders() { "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, 4, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_OBJECT_COMMON] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_COMMON]->code, vertexLayouts[VLTYPE_OBJECT_ALL]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_COMMON]->code, &vertexLayouts[VLTYPE_OBJECT_ALL]); } { @@ -1882,7 +1846,7 @@ void LoadShaders() { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_positionstream.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM]->code, vertexLayouts[VLTYPE_OBJECT_POS]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM]->code, &vertexLayouts[VLTYPE_OBJECT_POS]); } { @@ -1897,7 +1861,7 @@ void LoadShaders() { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_OBJECT_SIMPLE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_simple.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_SIMPLE]->code, vertexLayouts[VLTYPE_OBJECT_POS_TEX]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_SIMPLE]->code, &vertexLayouts[VLTYPE_OBJECT_POS_TEX]); } { @@ -1911,7 +1875,7 @@ void LoadShaders() { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_SHADOW] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW]->code, vertexLayouts[VLTYPE_SHADOW_POS]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW]->code, &vertexLayouts[VLTYPE_SHADOW_POS]); } { @@ -1926,7 +1890,7 @@ void LoadShaders() { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW_ALPHATEST]->code, vertexLayouts[VLTYPE_SHADOW_POS_TEX]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW_ALPHATEST]->code, &vertexLayouts[VLTYPE_SHADOW_POS_TEX]); vertexShaders[VSTYPE_SHADOW_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS_transparent.cso", wiResourceManager::VERTEXSHADER)); @@ -1940,7 +1904,7 @@ void LoadShaders() { "TEXCOORD", 0, FORMAT_R32G32B32A32_FLOAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; vertexShaders[VSTYPE_LINE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "linesVS.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_LINE]->code, vertexLayouts[VLTYPE_LINE]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_LINE]->code, &vertexLayouts[VLTYPE_LINE]); } @@ -1952,7 +1916,7 @@ void LoadShaders() { "TEXCOORD", 1, FORMAT_R32G32B32A32_FLOAT, 0, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; vertexShaders[VSTYPE_TRAIL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "trailVS.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_TRAIL]->code, vertexLayouts[VLTYPE_TRAIL]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_TRAIL]->code, &vertexLayouts[VLTYPE_TRAIL]); } @@ -1967,7 +1931,7 @@ void LoadShaders() { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 2, VertexLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; vertexShaders[VSTYPE_RENDERLIGHTMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "renderlightmapVS.cso", wiResourceManager::VERTEXSHADER)); - device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_RENDERLIGHTMAP]->code, vertexLayouts[VLTYPE_RENDERLIGHTMAP]); + device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_RENDERLIGHTMAP]->code, &vertexLayouts[VLTYPE_RENDERLIGHTMAP]); } @@ -2169,7 +2133,7 @@ void LoadShaders() GraphicsPSODesc desc; desc.vs = vertexShaders[realVS]; - desc.il = vertexLayouts[realVL]; + desc.il = &vertexLayouts[realVL]; desc.hs = hullShaders[realHS]; desc.ds = domainShaders[realDS]; desc.gs = geometryShaders[realGS]; @@ -2178,16 +2142,16 @@ void LoadShaders() switch (blendMode) { case BLENDMODE_OPAQUE: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; break; case BLENDMODE_ALPHA: - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; break; case BLENDMODE_ADDITIVE: - desc.bs = blendStates[BSTYPE_ADDITIVE]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; break; case BLENDMODE_PREMULTIPLIED: - desc.bs = blendStates[BSTYPE_PREMULTIPLIED]; + desc.bs = &blendStates[BSTYPE_PREMULTIPLIED]; break; default: assert(0); @@ -2199,7 +2163,7 @@ void LoadShaders() case RENDERPASS_DEPTHONLY: case RENDERPASS_SHADOW: case RENDERPASS_SHADOWCUBE: - desc.bs = blendStates[transparency ? BSTYPE_TRANSPARENTSHADOWMAP : BSTYPE_COLORWRITEDISABLE]; + desc.bs = &blendStates[transparency ? BSTYPE_TRANSPARENTSHADOWMAP : BSTYPE_COLORWRITEDISABLE]; break; default: break; @@ -2209,19 +2173,19 @@ void LoadShaders() { case RENDERPASS_SHADOW: case RENDERPASS_SHADOWCUBE: - desc.dss = depthStencils[transparency ? DSSTYPE_DEPTHREAD : DSSTYPE_SHADOW]; + desc.dss = &depthStencils[transparency ? DSSTYPE_DEPTHREAD : DSSTYPE_SHADOW]; break; case RENDERPASS_TILEDFORWARD: - desc.dss = depthStencils[transparency ? DSSTYPE_DEFAULT : DSSTYPE_DEPTHREADEQUAL]; + desc.dss = &depthStencils[transparency ? DSSTYPE_DEFAULT : DSSTYPE_DEPTHREADEQUAL]; break; case RENDERPASS_ENVMAPCAPTURE: - desc.dss = depthStencils[DSSTYPE_ENVMAP]; + desc.dss = &depthStencils[DSSTYPE_ENVMAP]; break; case RENDERPASS_VOXELIZE: - desc.dss = depthStencils[DSSTYPE_XRAY]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; break; default: - desc.dss = depthStencils[DSSTYPE_DEFAULT]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; break; } @@ -2229,13 +2193,13 @@ void LoadShaders() { case RENDERPASS_SHADOW: case RENDERPASS_SHADOWCUBE: - desc.rs = rasterizers[doublesided ? RSTYPE_SHADOW_DOUBLESIDED : RSTYPE_SHADOW]; + desc.rs = &rasterizers[doublesided ? RSTYPE_SHADOW_DOUBLESIDED : RSTYPE_SHADOW]; break; case RENDERPASS_VOXELIZE: - desc.rs = rasterizers[RSTYPE_VOXELIZE]; + desc.rs = &rasterizers[RSTYPE_VOXELIZE]; break; default: - desc.rs = rasterizers[doublesided ? RSTYPE_DOUBLESIDED : RSTYPE_FRONT]; + desc.rs = &rasterizers[doublesided ? RSTYPE_DOUBLESIDED : RSTYPE_FRONT]; break; } @@ -2320,8 +2284,7 @@ void LoadShaders() desc.pt = TRIANGLELIST; } - RECREATE(PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][transparency][normalmap][planarreflection][pom]); - device->CreateGraphicsPSO(&desc, PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][transparency][normalmap][planarreflection][pom]); + device->CreateGraphicsPSO(&desc, &PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][transparency][normalmap][planarreflection][pom]); } } } @@ -2342,25 +2305,24 @@ void LoadShaders() GraphicsPSODesc desc; desc.vs = vertexShaders[realVS]; - desc.il = vertexLayouts[realVL]; + desc.il = &vertexLayouts[realVL]; desc.ps = pixelShaders[PSTYPE_OBJECT_HOLOGRAM]; - desc.bs = blendStates[BSTYPE_ADDITIVE]; - desc.rs = rasterizers[DSSTYPE_DEFAULT]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; + desc.rs = &rasterizers[DSSTYPE_DEFAULT]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; desc.pt = TRIANGLELIST; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = DSFormat_full; - RECREATE(PSO_object_hologram); - device->CreateGraphicsPSO(&desc, PSO_object_hologram); + device->CreateGraphicsPSO(&desc, &PSO_object_hologram); CustomShader customShader; customShader.name = "Hologram"; - customShader.passes[RENDERPASS_FORWARD].pso = PSO_object_hologram; - customShader.passes[RENDERPASS_TILEDFORWARD].pso = PSO_object_hologram; + customShader.passes[RENDERPASS_FORWARD].pso = &PSO_object_hologram; + customShader.passes[RENDERPASS_TILEDFORWARD].pso = &PSO_object_hologram; RegisterCustomShader(customShader); } @@ -2368,75 +2330,70 @@ void LoadShaders() { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_WATER]; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; - desc.dss = depthStencils[DSSTYPE_DEFAULT]; - desc.il = vertexLayouts[VLTYPE_OBJECT_POS_TEX]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; + desc.il = &vertexLayouts[VLTYPE_OBJECT_POS_TEX]; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = DSFormat_full; desc.ps = pixelShaders[PSTYPE_OBJECT_FORWARD_WATER]; - RECREATE(PSO_object_water[RENDERPASS_FORWARD]); - device->CreateGraphicsPSO(&desc, PSO_object_water[RENDERPASS_FORWARD]); + device->CreateGraphicsPSO(&desc, &PSO_object_water[RENDERPASS_FORWARD]); desc.ps = pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_WATER]; - RECREATE(PSO_object_water[RENDERPASS_TILEDFORWARD]); - device->CreateGraphicsPSO(&desc, PSO_object_water[RENDERPASS_TILEDFORWARD]); + device->CreateGraphicsPSO(&desc, &PSO_object_water[RENDERPASS_TILEDFORWARD]); - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; - desc.rs = rasterizers[RSTYPE_SHADOW]; - desc.bs = blendStates[BSTYPE_TRANSPARENTSHADOWMAP]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_SHADOW]; + desc.bs = &blendStates[BSTYPE_TRANSPARENTSHADOWMAP]; desc.vs = vertexShaders[VSTYPE_SHADOW_TRANSPARENT]; desc.ps = pixelShaders[PSTYPE_SHADOW_WATER]; - RECREATE(PSO_object_water[RENDERPASS_SHADOW]); - device->CreateGraphicsPSO(&desc, PSO_object_water[RENDERPASS_SHADOW]); + + device->CreateGraphicsPSO(&desc, &PSO_object_water[RENDERPASS_SHADOW]); } { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_OBJECT_SIMPLE]; desc.ps = pixelShaders[PSTYPE_OBJECT_SIMPLEST]; - desc.rs = rasterizers[RSTYPE_WIRE]; - desc.bs = blendStates[BSTYPE_OPAQUE]; - desc.dss = depthStencils[DSSTYPE_DEFAULT]; - desc.il = vertexLayouts[VLTYPE_OBJECT_POS_TEX]; + desc.rs = &rasterizers[RSTYPE_WIRE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; + desc.il = &vertexLayouts[VLTYPE_OBJECT_POS_TEX]; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = DSFormat_full; - RECREATE(PSO_object_wire); - device->CreateGraphicsPSO(&desc, PSO_object_wire); + device->CreateGraphicsPSO(&desc, &PSO_object_wire); } { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_DECAL]; desc.ps = pixelShaders[PSTYPE_DECAL]; - desc.rs = rasterizers[RSTYPE_FRONT]; - desc.bs = blendStates[BSTYPE_DECAL]; - desc.dss = depthStencils[DSSTYPE_DECAL]; + desc.rs = &rasterizers[RSTYPE_FRONT]; + desc.bs = &blendStates[BSTYPE_DECAL]; + desc.dss = &depthStencils[DSSTYPE_DECAL]; desc.pt = TRIANGLESTRIP; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_gbuffer_0; //desc.RTFormats[1] = RTFormat_gbuffer_1; - RECREATE(PSO_decal); - device->CreateGraphicsPSO(&desc, PSO_decal); + device->CreateGraphicsPSO(&desc, &PSO_decal); } { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_CUBE]; - desc.rs = rasterizers[RSTYPE_OCCLUDEE]; - desc.bs = blendStates[BSTYPE_COLORWRITEDISABLE]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_OCCLUDEE]; + desc.bs = &blendStates[BSTYPE_COLORWRITEDISABLE]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; desc.pt = TRIANGLESTRIP; desc.DSFormat = DSFormat_small; - RECREATE(PSO_occlusionquery); - device->CreateGraphicsPSO(&desc, PSO_occlusionquery); + device->CreateGraphicsPSO(&desc, &PSO_occlusionquery); } for (int renderPass = 0; renderPass < RENDERPASS_COUNT; ++renderPass) { @@ -2451,9 +2408,9 @@ void LoadShaders() } GraphicsPSODesc desc; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; // well, we don't need double sided impostors, but might be helpful if something breaks - desc.bs = blendStates[BSTYPE_OPAQUE]; - desc.dss = depthStencils[renderPass == RENDERPASS_TILEDFORWARD ? DSSTYPE_DEPTHREADEQUAL : DSSTYPE_DEFAULT]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; // well, we don't need double sided impostors, but might be helpful if something breaks + desc.bs = &blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[renderPass == RENDERPASS_TILEDFORWARD ? DSSTYPE_DEPTHREADEQUAL : DSSTYPE_DEFAULT]; desc.il = nullptr; switch (renderPass) @@ -2493,48 +2450,43 @@ void LoadShaders() } desc.DSFormat = DSFormat_full; - RECREATE(PSO_impostor[renderPass]); - device->CreateGraphicsPSO(&desc, PSO_impostor[renderPass]); + device->CreateGraphicsPSO(&desc, &PSO_impostor[renderPass]); } { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_IMPOSTOR]; desc.ps = pixelShaders[PSTYPE_IMPOSTOR_WIRE]; - desc.rs = rasterizers[RSTYPE_WIRE]; - desc.bs = blendStates[BSTYPE_OPAQUE]; - desc.dss = depthStencils[DSSTYPE_DEFAULT]; + desc.rs = &rasterizers[RSTYPE_WIRE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; desc.il = nullptr; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = DSFormat_full; - RECREATE(PSO_impostor_wire); - device->CreateGraphicsPSO(&desc, PSO_impostor_wire); + device->CreateGraphicsPSO(&desc, &PSO_impostor_wire); } { GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_OBJECT_COMMON]; - desc.rs = rasterizers[RSTYPE_FRONT]; - desc.bs = blendStates[BSTYPE_OPAQUE]; - desc.dss = depthStencils[DSSTYPE_CAPTUREIMPOSTOR]; - desc.il = vertexLayouts[VLTYPE_OBJECT_ALL]; + desc.rs = &rasterizers[RSTYPE_FRONT]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_CAPTUREIMPOSTOR]; + desc.il = &vertexLayouts[VLTYPE_OBJECT_ALL]; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_impostor; desc.DSFormat = DSFormat_small; desc.ps = pixelShaders[PSTYPE_CAPTUREIMPOSTOR_ALBEDO]; - RECREATE(PSO_captureimpostor_albedo); - device->CreateGraphicsPSO(&desc, PSO_captureimpostor_albedo); + device->CreateGraphicsPSO(&desc, &PSO_captureimpostor_albedo); desc.ps = pixelShaders[PSTYPE_CAPTUREIMPOSTOR_NORMAL]; - RECREATE(PSO_captureimpostor_normal); - device->CreateGraphicsPSO(&desc, PSO_captureimpostor_normal); + device->CreateGraphicsPSO(&desc, &PSO_captureimpostor_normal); desc.ps = pixelShaders[PSTYPE_CAPTUREIMPOSTOR_SURFACE]; - RECREATE(PSO_captureimpostor_surface); - device->CreateGraphicsPSO(&desc, PSO_captureimpostor_surface); + device->CreateGraphicsPSO(&desc, &PSO_captureimpostor_surface); } for (int type = 0; type < LightComponent::LIGHTTYPE_COUNT; ++type) @@ -2544,45 +2496,45 @@ void LoadShaders() // deferred lights: desc.pt = TRIANGLELIST; - desc.rs = rasterizers[RSTYPE_BACK]; - desc.bs = blendStates[BSTYPE_DEFERREDLIGHT]; + desc.rs = &rasterizers[RSTYPE_BACK]; + desc.bs = &blendStates[BSTYPE_DEFERREDLIGHT]; switch (type) { case LightComponent::DIRECTIONAL: desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_DIRLIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; break; case LightComponent::POINT: desc.vs = vertexShaders[VSTYPE_POINTLIGHT]; desc.ps = pixelShaders[PSTYPE_POINTLIGHT]; - desc.dss = depthStencils[DSSTYPE_LIGHT]; + desc.dss = &depthStencils[DSSTYPE_LIGHT]; break; case LightComponent::SPOT: desc.vs = vertexShaders[VSTYPE_SPOTLIGHT]; desc.ps = pixelShaders[PSTYPE_SPOTLIGHT]; - desc.dss = depthStencils[DSSTYPE_LIGHT]; + desc.dss = &depthStencils[DSSTYPE_LIGHT]; break; case LightComponent::SPHERE: desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_SPHERELIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; break; case LightComponent::DISC: desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_DISCLIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; break; case LightComponent::RECTANGLE: desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_RECTANGLELIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; break; case LightComponent::TUBE: desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_TUBELIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; break; } @@ -2591,8 +2543,7 @@ void LoadShaders() desc.RTFormats[1] = RTFormat_deferred_lightbuffer; desc.DSFormat = DSFormat_full; - RECREATE(PSO_deferredlight[type]); - device->CreateGraphicsPSO(&desc, PSO_deferredlight[type]); + device->CreateGraphicsPSO(&desc, &PSO_deferredlight[type]); @@ -2600,40 +2551,40 @@ void LoadShaders() if (type != LightComponent::DIRECTIONAL) { - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; desc.ps = pixelShaders[PSTYPE_LIGHTVISUALIZER]; switch (type) { case LightComponent::POINT: - desc.bs = blendStates[BSTYPE_ADDITIVE]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_POINTLIGHT]; - desc.rs = rasterizers[RSTYPE_FRONT]; + desc.rs = &rasterizers[RSTYPE_FRONT]; break; case LightComponent::SPOT: - desc.bs = blendStates[BSTYPE_ADDITIVE]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT]; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; break; case LightComponent::SPHERE: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT]; - desc.rs = rasterizers[RSTYPE_FRONT]; + desc.rs = &rasterizers[RSTYPE_FRONT]; break; case LightComponent::DISC: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT]; - desc.rs = rasterizers[RSTYPE_FRONT]; + desc.rs = &rasterizers[RSTYPE_FRONT]; break; case LightComponent::RECTANGLE: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT]; - desc.rs = rasterizers[RSTYPE_BACK]; + desc.rs = &rasterizers[RSTYPE_BACK]; break; case LightComponent::TUBE: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT]; - desc.rs = rasterizers[RSTYPE_FRONT]; + desc.rs = &rasterizers[RSTYPE_FRONT]; break; } @@ -2641,17 +2592,16 @@ void LoadShaders() desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = DSFormat_full; - RECREATE(PSO_lightvisualizer[type]); - device->CreateGraphicsPSO(&desc, PSO_lightvisualizer[type]); + device->CreateGraphicsPSO(&desc, &PSO_lightvisualizer[type]); } // volumetric lights: if (type <= LightComponent::SPOT) { - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.bs = blendStates[BSTYPE_ADDITIVE]; - desc.rs = rasterizers[RSTYPE_BACK]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; + desc.rs = &rasterizers[RSTYPE_BACK]; switch (type) { @@ -2673,8 +2623,7 @@ void LoadShaders() desc.RTFormats[0] = RTFormat_hdr; desc.DSFormat = FORMAT_UNKNOWN; - RECREATE(PSO_volumetriclight[type]); - device->CreateGraphicsPSO(&desc, PSO_volumetriclight[type]); + device->CreateGraphicsPSO(&desc, &PSO_volumetriclight[type]); } @@ -2683,60 +2632,57 @@ void LoadShaders() GraphicsPSODesc desc; desc.vs = vertexShaders[VSTYPE_DIRLIGHT]; desc.ps = pixelShaders[PSTYPE_ENVIRONMENTALLIGHT]; - desc.rs = rasterizers[RSTYPE_BACK]; - desc.bs = blendStates[BSTYPE_ENVIRONMENTALLIGHT]; - desc.dss = depthStencils[DSSTYPE_DIRLIGHT]; + desc.rs = &rasterizers[RSTYPE_BACK]; + desc.bs = &blendStates[BSTYPE_ENVIRONMENTALLIGHT]; + desc.dss = &depthStencils[DSSTYPE_DIRLIGHT]; desc.numRTs = 2; desc.RTFormats[0] = RTFormat_deferred_lightbuffer; desc.RTFormats[1] = RTFormat_deferred_lightbuffer; desc.DSFormat = DSFormat_full; - RECREATE(PSO_enviromentallight); - device->CreateGraphicsPSO(&desc, PSO_enviromentallight); + device->CreateGraphicsPSO(&desc, &PSO_enviromentallight); } { GraphicsPSODesc desc; - desc.il = vertexLayouts[VLTYPE_RENDERLIGHTMAP]; + desc.il = &vertexLayouts[VLTYPE_RENDERLIGHTMAP]; desc.vs = vertexShaders[VSTYPE_RENDERLIGHTMAP]; desc.ps = pixelShaders[PSTYPE_RENDERLIGHTMAP_INDIRECT]; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; - desc.dss = depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_lightmap_object; desc.DSFormat = FORMAT_UNKNOWN; - RECREATE(PSO_renderlightmap_indirect); - device->CreateGraphicsPSO(&desc, PSO_renderlightmap_indirect); + device->CreateGraphicsPSO(&desc, &PSO_renderlightmap_indirect); } { GraphicsPSODesc desc; - desc.il = vertexLayouts[VLTYPE_RENDERLIGHTMAP]; + desc.il = &vertexLayouts[VLTYPE_RENDERLIGHTMAP]; desc.vs = vertexShaders[VSTYPE_RENDERLIGHTMAP]; desc.ps = pixelShaders[PSTYPE_RENDERLIGHTMAP_DIRECT]; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; - desc.dss = depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; desc.numRTs = 1; desc.RTFormats[0] = RTFormat_lightmap_object; desc.DSFormat = FORMAT_UNKNOWN; - RECREATE(PSO_renderlightmap_direct); - device->CreateGraphicsPSO(&desc, PSO_renderlightmap_direct); + device->CreateGraphicsPSO(&desc, &PSO_renderlightmap_direct); } for (int type = 0; type < SKYRENDERING_COUNT; ++type) { GraphicsPSODesc desc; - desc.rs = rasterizers[RSTYPE_SKY]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_SKY]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; switch (type) { case SKYRENDERING_STATIC: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_SKY]; desc.ps = pixelShaders[PSTYPE_SKY_STATIC]; desc.numRTs = 2; @@ -2745,7 +2691,7 @@ void LoadShaders() desc.DSFormat = DSFormat_full; break; case SKYRENDERING_DYNAMIC: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_SKY]; desc.ps = pixelShaders[PSTYPE_SKY_DYNAMIC]; desc.numRTs = 2; @@ -2754,7 +2700,7 @@ void LoadShaders() desc.DSFormat = DSFormat_full; break; case SKYRENDERING_SUN: - desc.bs = blendStates[BSTYPE_ADDITIVE]; + desc.bs = &blendStates[BSTYPE_ADDITIVE]; desc.vs = vertexShaders[VSTYPE_SKY]; desc.ps = pixelShaders[PSTYPE_SUN]; desc.numRTs = 1; @@ -2762,7 +2708,7 @@ void LoadShaders() desc.DSFormat = DSFormat_full; break; case SKYRENDERING_ENVMAPCAPTURE_STATIC: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_ENVMAP_SKY]; desc.ps = pixelShaders[PSTYPE_ENVMAP_SKY_STATIC]; desc.gs = geometryShaders[GSTYPE_ENVMAP_SKY]; @@ -2771,7 +2717,7 @@ void LoadShaders() desc.DSFormat = DSFormat_small; break; case SKYRENDERING_ENVMAPCAPTURE_DYNAMIC: - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.vs = vertexShaders[VSTYPE_ENVMAP_SKY]; desc.ps = pixelShaders[PSTYPE_ENVMAP_SKY_DYNAMIC]; desc.gs = geometryShaders[GSTYPE_ENVMAP_SKY]; @@ -2781,8 +2727,7 @@ void LoadShaders() break; } - RECREATE(PSO_sky[type]); - device->CreateGraphicsPSO(&desc, PSO_sky[type]); + device->CreateGraphicsPSO(&desc, &PSO_sky[type]); } for (int debug = 0; debug < DEBUGRENDERING_COUNT; ++debug) { @@ -2797,85 +2742,84 @@ void LoadShaders() case DEBUGRENDERING_ENVPROBE: desc.vs = vertexShaders[VSTYPE_SPHERE]; desc.ps = pixelShaders[PSTYPE_CUBEMAP]; - desc.dss = depthStencils[DSSTYPE_DEFAULT]; - desc.rs = rasterizers[RSTYPE_FRONT]; - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; + desc.rs = &rasterizers[RSTYPE_FRONT]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.pt = TRIANGLELIST; break; case DEBUGRENDERING_GRID: desc.vs = vertexShaders[VSTYPE_LINE]; desc.ps = pixelShaders[PSTYPE_LINE]; - desc.il = vertexLayouts[VLTYPE_LINE]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; - desc.rs = rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.il = &vertexLayouts[VLTYPE_LINE]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = LINELIST; break; case DEBUGRENDERING_CUBE: desc.vs = vertexShaders[VSTYPE_LINE]; desc.ps = pixelShaders[PSTYPE_LINE]; - desc.il = vertexLayouts[VLTYPE_LINE]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; - desc.rs = rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.il = &vertexLayouts[VLTYPE_LINE]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = LINELIST; break; case DEBUGRENDERING_LINES: desc.vs = vertexShaders[VSTYPE_LINE]; desc.ps = pixelShaders[PSTYPE_LINE]; - desc.il = vertexLayouts[VLTYPE_LINE]; - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.rs = rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.il = &vertexLayouts[VLTYPE_LINE]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = LINELIST; break; case DEBUGRENDERING_EMITTER: desc.vs = vertexShaders[VSTYPE_OBJECT_DEBUG]; desc.ps = pixelShaders[PSTYPE_OBJECT_DEBUG]; - desc.il = vertexLayouts[VLTYPE_OBJECT_DEBUG]; - desc.dss = depthStencils[DSSTYPE_DEPTHREAD]; - desc.rs = rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.il = &vertexLayouts[VLTYPE_OBJECT_DEBUG]; + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.pt = TRIANGLELIST; break; case DEBUGRENDERING_VOXEL: desc.vs = vertexShaders[VSTYPE_VOXEL]; desc.ps = pixelShaders[PSTYPE_VOXEL]; desc.gs = geometryShaders[GSTYPE_VOXEL]; - desc.dss = depthStencils[DSSTYPE_DEFAULT]; - desc.rs = rasterizers[RSTYPE_BACK]; - desc.bs = blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; + desc.rs = &rasterizers[RSTYPE_BACK]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.pt = POINTLIST; break; case DEBUGRENDERING_FORCEFIELD_POINT: desc.vs = vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_POINT]; desc.ps = pixelShaders[PSTYPE_FORCEFIELDVISUALIZER]; - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.rs = rasterizers[RSTYPE_BACK]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_BACK]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = TRIANGLELIST; break; case DEBUGRENDERING_FORCEFIELD_PLANE: desc.vs = vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_PLANE]; desc.ps = pixelShaders[PSTYPE_FORCEFIELDVISUALIZER]; - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.rs = rasterizers[RSTYPE_FRONT]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_FRONT]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = TRIANGLESTRIP; break; case DEBUGRENDERING_RAYTRACE_BVH: desc.vs = vertexShaders[VSTYPE_RAYTRACE_SCREEN]; desc.ps = pixelShaders[PSTYPE_RAYTRACE_DEBUGBVH]; - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.rs = rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; + desc.dss = &depthStencils[DSSTYPE_XRAY]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; desc.pt = TRIANGLELIST; desc.DSFormat = FORMAT_UNKNOWN; break; } - RECREATE(PSO_debug[debug]); - HRESULT hr = device->CreateGraphicsPSO(&desc, PSO_debug[debug]); + HRESULT hr = device->CreateGraphicsPSO(&desc, &PSO_debug[debug]); assert(SUCCEEDED(hr)); } @@ -2903,8 +2847,8 @@ void LoadShaders() ComputePSODesc desc; desc.cs = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + name, wiResourceManager::COMPUTESHADER)); - RECREATE(CPSO_tiledlighting[i][j][k]); - device->CreateComputePSO(&desc, CPSO_tiledlighting[i][j][k]); + + device->CreateComputePSO(&desc, &CPSO_tiledlighting[i][j][k]); } } } @@ -2913,8 +2857,7 @@ void LoadShaders() { ComputePSODesc desc; desc.cs = computeShaders[i]; - RECREATE(CPSO[i]); - device->CreateComputePSO(&desc, CPSO[i]); + device->CreateComputePSO(&desc, &CPSO[i]); } @@ -2923,11 +2866,6 @@ void LoadBuffers() { GraphicsDevice* device = GetDevice(); - for (int i = 0; i < CBTYPE_LAST; ++i) - { - constantBuffers[i] = new GPUBuffer; - } - GPUBufferDesc bd; bd.BindFlags = BIND_CONSTANT_BUFFER; @@ -2937,71 +2875,71 @@ void LoadBuffers() bd.CPUAccessFlags = 0; bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof(FrameCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FRAME]); - device->SetName(constantBuffers[CBTYPE_FRAME], "FrameCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_FRAME]); + device->SetName(&constantBuffers[CBTYPE_FRAME], "FrameCB"); // The other constant buffers will be updated frequently (more than once per frame) so they should reside in DYNAMIC GPU memory! bd.Usage = USAGE_DYNAMIC; bd.CPUAccessFlags = CPU_ACCESS_WRITE; bd.ByteWidth = sizeof(CameraCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CAMERA]); - device->SetName(constantBuffers[CBTYPE_CAMERA], "CameraCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_CAMERA]); + device->SetName(&constantBuffers[CBTYPE_CAMERA], "CameraCB"); bd.ByteWidth = sizeof(MiscCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MISC]); - device->SetName(constantBuffers[CBTYPE_MISC], "MiscCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_MISC]); + device->SetName(&constantBuffers[CBTYPE_MISC], "MiscCB"); bd.ByteWidth = sizeof(APICB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_API]); - device->SetName(constantBuffers[CBTYPE_API], "APICB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_API]); + device->SetName(&constantBuffers[CBTYPE_API], "APICB"); // On demand buffers... bd.ByteWidth = sizeof(VolumeLightCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_VOLUMELIGHT]); - device->SetName(constantBuffers[CBTYPE_VOLUMELIGHT], "VolumelightCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_VOLUMELIGHT]); + device->SetName(&constantBuffers[CBTYPE_VOLUMELIGHT], "VolumelightCB"); bd.ByteWidth = sizeof(DecalCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DECAL]); - device->SetName(constantBuffers[CBTYPE_DECAL], "DecalCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_DECAL]); + device->SetName(&constantBuffers[CBTYPE_DECAL], "DecalCB"); bd.ByteWidth = sizeof(CubemapRenderCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CUBEMAPRENDER]); - device->SetName(constantBuffers[CBTYPE_CUBEMAPRENDER], "CubemapRenderCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_CUBEMAPRENDER]); + device->SetName(&constantBuffers[CBTYPE_CUBEMAPRENDER], "CubemapRenderCB"); bd.ByteWidth = sizeof(TessellationCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_TESSELLATION]); - device->SetName(constantBuffers[CBTYPE_TESSELLATION], "TessellationCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_TESSELLATION]); + device->SetName(&constantBuffers[CBTYPE_TESSELLATION], "TessellationCB"); bd.ByteWidth = sizeof(DispatchParamsCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DISPATCHPARAMS]); - device->SetName(constantBuffers[CBTYPE_DISPATCHPARAMS], "DispatchParamsCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_DISPATCHPARAMS]); + device->SetName(&constantBuffers[CBTYPE_DISPATCHPARAMS], "DispatchParamsCB"); bd.ByteWidth = sizeof(CloudGeneratorCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_CLOUDGENERATOR]); - device->SetName(constantBuffers[CBTYPE_CLOUDGENERATOR], "CloudGeneratorCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_CLOUDGENERATOR]); + device->SetName(&constantBuffers[CBTYPE_CLOUDGENERATOR], "CloudGeneratorCB"); bd.ByteWidth = sizeof(TracedRenderingCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_RAYTRACE]); - device->SetName(constantBuffers[CBTYPE_RAYTRACE], "RayTraceCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_RAYTRACE]); + device->SetName(&constantBuffers[CBTYPE_RAYTRACE], "RayTraceCB"); bd.ByteWidth = sizeof(GenerateMIPChainCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MIPGEN]); - device->SetName(constantBuffers[CBTYPE_MIPGEN], "MipGeneratorCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_MIPGEN]); + device->SetName(&constantBuffers[CBTYPE_MIPGEN], "MipGeneratorCB"); bd.ByteWidth = sizeof(FilterEnvmapCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FILTERENVMAP]); - device->SetName(constantBuffers[CBTYPE_FILTERENVMAP], "FilterEnvmapCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_FILTERENVMAP]); + device->SetName(&constantBuffers[CBTYPE_FILTERENVMAP], "FilterEnvmapCB"); bd.ByteWidth = sizeof(CopyTextureCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_COPYTEXTURE]); - device->SetName(constantBuffers[CBTYPE_COPYTEXTURE], "CopyTextureCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_COPYTEXTURE]); + device->SetName(&constantBuffers[CBTYPE_COPYTEXTURE], "CopyTextureCB"); bd.ByteWidth = sizeof(ForwardEntityMaskCB); - device->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_FORWARDENTITYMASK]); - device->SetName(constantBuffers[CBTYPE_FORWARDENTITYMASK], "ForwardEntityMaskCB"); + device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_FORWARDENTITYMASK]); + device->SetName(&constantBuffers[CBTYPE_FORWARDENTITYMASK], "ForwardEntityMaskCB"); @@ -3009,11 +2947,6 @@ void LoadBuffers() // Resource Buffers: - for (int i = 0; i < RBTYPE_LAST; ++i) - { - resourceBuffers[i] = new GPUBuffer; - } - // These will be used intensively by multiple shaders, so better to place them in GPU-only (USAGE_DEFAULT) memory: bd.Usage = USAGE_DEFAULT; bd.CPUAccessFlags = 0; @@ -3023,27 +2956,20 @@ void LoadBuffers() bd.BindFlags = BIND_SHADER_RESOURCE; bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; bd.StructureByteStride = sizeof(ShaderEntityType); - device->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_ENTITYARRAY]); - device->SetName(resourceBuffers[RBTYPE_ENTITYARRAY], "EntityArray"); + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_ENTITYARRAY]); + device->SetName(&resourceBuffers[RBTYPE_ENTITYARRAY], "EntityArray"); bd.ByteWidth = sizeof(XMMATRIX) * MATRIXARRAY_COUNT; bd.BindFlags = BIND_SHADER_RESOURCE; bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; bd.StructureByteStride = sizeof(XMMATRIX); - device->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_MATRIXARRAY]); - device->SetName(resourceBuffers[RBTYPE_MATRIXARRAY], "MatrixArray"); - - SAFE_DELETE(resourceBuffers[RBTYPE_VOXELSCENE]); // lazy init on request + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_MATRIXARRAY]); + device->SetName(&resourceBuffers[RBTYPE_MATRIXARRAY], "MatrixArray"); } void SetUpStates() { GraphicsDevice* device = GetDevice(); - for (int i = 0; i < SSLOT_COUNT; ++i) - { - samplers[i] = new Sampler; - } - SamplerDesc samplerDesc; samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; @@ -3058,68 +2984,67 @@ void SetUpStates() samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = FLT_MAX; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_LINEAR_MIRROR]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_LINEAR_CLAMP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_CLAMP]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_LINEAR_WRAP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_WRAP]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_POINT_MIRROR]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_MIRROR]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_POINT_WRAP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_WRAP]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_POINT_CLAMP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_CLAMP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; samplerDesc.MaxAnisotropy = 16; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_ANISO_CLAMP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_CLAMP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; samplerDesc.MaxAnisotropy = 16; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_ANISO_WRAP]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_WRAP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR; samplerDesc.MaxAnisotropy = 16; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_ANISO_MIRROR]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_MIRROR]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; samplerDesc.MaxAnisotropy = 16; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_OBJECTSHADER]); + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_OBJECTSHADER]); - ZeroMemory(&samplerDesc, sizeof(SamplerDesc)); samplerDesc.Filter = FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; @@ -3127,12 +3052,7 @@ void SetUpStates() samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 0; samplerDesc.ComparisonFunc = COMPARISON_GREATER_EQUAL; - device->CreateSamplerState(&samplerDesc, samplers[SSLOT_CMP_DEPTH]); - - for (int i = 0; i < SSTYPE_LAST; ++i) - { - customsamplers[i] = new Sampler; - } + device->CreateSamplerState(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]); samplerDesc.Filter = FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; @@ -3147,13 +3067,9 @@ void SetUpStates() samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = FLT_MAX; - device->CreateSamplerState(&samplerDesc, customsamplers[SSTYPE_MAXIMUM_CLAMP]); + device->CreateSamplerState(&samplerDesc, &customsamplers[SSTYPE_MAXIMUM_CLAMP]); - for (int i = 0; i < RSTYPE_LAST; ++i) - { - rasterizers[i] = new RasterizerState; - } RasterizerStateDesc rs; rs.FillMode = FILL_SOLID; @@ -3166,7 +3082,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_FRONT]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_FRONT]); rs.FillMode = FILL_SOLID; @@ -3179,7 +3095,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_SHADOW]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_SHADOW]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_NONE; @@ -3191,7 +3107,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_SHADOW_DOUBLESIDED]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_SHADOW_DOUBLESIDED]); rs.FillMode = FILL_WIREFRAME; rs.CullMode = CULL_BACK; @@ -3203,9 +3119,9 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_WIRE]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_WIRE]); rs.AntialiasedLineEnable = true; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_WIRE_SMOOTH]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_WIRE_SMOOTH]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_NONE; @@ -3217,7 +3133,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_DOUBLESIDED]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_DOUBLESIDED]); rs.FillMode = FILL_WIREFRAME; rs.CullMode = CULL_NONE; @@ -3229,9 +3145,9 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_WIRE_DOUBLESIDED]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_WIRE_DOUBLESIDED]); rs.AntialiasedLineEnable = true; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_FRONT; @@ -3243,7 +3159,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_BACK]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_BACK]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_FRONT; @@ -3255,7 +3171,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_OCCLUDEE]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_OCCLUDEE]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_FRONT; @@ -3267,7 +3183,7 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_SKY]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_SKY]); rs.FillMode = FILL_SOLID; rs.CullMode = CULL_NONE; @@ -3279,12 +3195,10 @@ void SetUpStates() rs.MultisampleEnable = false; rs.AntialiasedLineEnable = false; rs.ConservativeRasterizationEnable = false; // do it in the shader for now... - device->CreateRasterizerState(&rs, rasterizers[RSTYPE_VOXELIZE]); + device->CreateRasterizerState(&rs, &rasterizers[RSTYPE_VOXELIZE]); + + - for (int i = 0; i < DSSTYPE_LAST; ++i) - { - depthStencils[i] = new DepthStencilState; - } DepthStencilStateDesc dsd; dsd.DepthEnable = true; @@ -3302,19 +3216,19 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_REPLACE; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DEFAULT]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFAULT]); dsd.DepthEnable = true; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; dsd.DepthFunc = COMPARISON_GREATER; dsd.StencilEnable = false; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_SHADOW]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_SHADOW]); dsd.DepthEnable = true; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; dsd.DepthFunc = COMPARISON_GREATER; dsd.StencilEnable = false; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_CAPTUREIMPOSTOR]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_CAPTUREIMPOSTOR]); dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; @@ -3331,7 +3245,7 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DIRLIGHT]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DIRLIGHT]); dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; @@ -3348,7 +3262,7 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_LIGHT]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_LIGHT]); dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; @@ -3365,7 +3279,7 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DECAL]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DECAL]); dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; @@ -3382,36 +3296,34 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_STENCILREAD_MATCH]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD_MATCH]); dsd.DepthEnable = true; dsd.StencilEnable = false; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = COMPARISON_GREATER_EQUAL; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DEPTHREAD]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEPTHREAD]); dsd.DepthEnable = false; dsd.StencilEnable = false; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_XRAY]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_XRAY]); dsd.DepthEnable = true; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = COMPARISON_EQUAL; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_DEPTHREADEQUAL]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEPTHREADEQUAL]); dsd.DepthEnable = true; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; dsd.DepthFunc = COMPARISON_GREATER; - device->CreateDepthStencilState(&dsd, depthStencils[DSSTYPE_ENVMAP]); + device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_ENVMAP]); + + - for (int i = 0; i < BSTYPE_LAST; ++i) - { - blendStates[i] = new BlendState; - } BlendStateDesc bd; bd.RenderTarget[0].BlendEnable = false; @@ -3424,7 +3336,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_OPAQUE]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_OPAQUE]); bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; @@ -3436,7 +3348,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_TRANSPARENT]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_TRANSPARENT]); bd.RenderTarget[0].BlendEnable = true; bd.RenderTarget[0].SrcBlend = BLEND_ONE; @@ -3448,7 +3360,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.IndependentBlendEnable = false; bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_PREMULTIPLIED]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_PREMULTIPLIED]); bd.RenderTarget[0].BlendEnable = true; @@ -3461,14 +3373,14 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_ADDITIVE]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_ADDITIVE]); bd.RenderTarget[0].BlendEnable = false; bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_DISABLE; bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_COLORWRITEDISABLE]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_COLORWRITEDISABLE]); bd.RenderTarget[0].BlendEnable = true; @@ -3481,7 +3393,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_RED | COLOR_WRITE_ENABLE_GREEN | COLOR_WRITE_ENABLE_BLUE; // alpha is not written by deferred lights! bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_DEFERREDLIGHT]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_DEFERREDLIGHT]); bd.RenderTarget[0].BlendEnable = true; bd.RenderTarget[0].SrcBlend = BLEND_ONE; @@ -3493,7 +3405,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_ENVIRONMENTALLIGHT]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_ENVIRONMENTALLIGHT]); bd.RenderTarget[0].SrcBlend = BLEND_INV_SRC_COLOR; bd.RenderTarget[0].DestBlend = BLEND_INV_DEST_COLOR; @@ -3505,7 +3417,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_INVERSE]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_INVERSE]); bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; @@ -3520,7 +3432,7 @@ void SetUpStates() bd.RenderTarget[1].RenderTargetWriteMask = COLOR_WRITE_ENABLE_RED | COLOR_WRITE_ENABLE_GREEN; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = true; - device->CreateBlendState(&bd, blendStates[BSTYPE_DECAL]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_DECAL]); bd.RenderTarget[0].SrcBlend = BLEND_DEST_COLOR; @@ -3533,7 +3445,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_MULTIPLY]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_MULTIPLY]); bd.RenderTarget[0].SrcBlend = BLEND_DEST_COLOR; @@ -3546,7 +3458,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; bd.AlphaToCoverageEnable = false; bd.IndependentBlendEnable = false; - device->CreateBlendState(&bd, blendStates[BSTYPE_TRANSPARENTSHADOWMAP]); + device->CreateBlendState(&bd, &blendStates[BSTYPE_TRANSPARENTSHADOWMAP]); } @@ -4077,8 +3989,8 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) entityArrayCount_ForceFields = entityCounter - entityArrayOffset_ForceFields; // Issue GPU entity array update: - device->UpdateBuffer(resourceBuffers[RBTYPE_ENTITYARRAY], entityArray, threadID, sizeof(ShaderEntityType)*entityCounter); - device->UpdateBuffer(resourceBuffers[RBTYPE_MATRIXARRAY], matrixArray, threadID, sizeof(XMMATRIX)*matrixCounter); + device->UpdateBuffer(&resourceBuffers[RBTYPE_ENTITYARRAY], entityArray, threadID, sizeof(ShaderEntityType)*entityCounter); + device->UpdateBuffer(&resourceBuffers[RBTYPE_MATRIXARRAY], matrixArray, threadID, sizeof(XMMATRIX)*matrixCounter); // Temporary array for GPU entities can be freed now: frameAllocators[threadID].free(sizeof(ShaderEntityType)*SHADER_ENTITY_COUNT); @@ -4086,8 +3998,8 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) // Bind the GPU entity array for all shaders that need it here: GPUResource* resources[] = { - resourceBuffers[RBTYPE_ENTITYARRAY], - resourceBuffers[RBTYPE_MATRIXARRAY], + &resourceBuffers[RBTYPE_ENTITYARRAY], + &resourceBuffers[RBTYPE_MATRIXARRAY], }; device->BindResources(VS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID); device->BindResources(PS, resources, SBSLOT_ENTITYARRAY, ARRAYSIZE(resources), threadID); @@ -4124,7 +4036,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) 0,0,0,0,0,0,0,0 }; device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - device->BindComputePSO(CPSO[CSTYPE_SKINNING_LDS], threadID); + device->BindComputePSO(&CPSO[CSTYPE_SKINNING_LDS], threadID); } CSTYPES targetCS = CSTYPE_SKINNING_LDS; @@ -4138,7 +4050,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) if (targetCS != lastCS) { lastCS = targetCS; - device->BindComputePSO(CPSO[targetCS], threadID); + device->BindComputePSO(&CPSO[targetCS], threadID); } // Upload bones for skinning to shader @@ -4293,7 +4205,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) { device->EventBegin("Occlusion Culling Render", threadID); - device->BindGraphicsPSO(PSO_occlusionquery, threadID); + device->BindGraphicsPSO(&PSO_occlusionquery, threadID); // TODO: This is not const, so not thread safe! Scene& scene = GetScene(); @@ -4338,7 +4250,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) // previous frame view*projection because these are drawn against the previous depth buffer: XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*GetPrevCamera().GetViewProjection())); // todo: obb - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &cb, threadID); // render bounding box to later read the occlusion status device->QueryBegin(query, threadID); @@ -4506,13 +4418,13 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) // Environmental light (envmap + voxelGI) is always drawn { - device->BindGraphicsPSO(PSO_enviromentallight, threadID); + device->BindGraphicsPSO(&PSO_enviromentallight, threadID); device->Draw(3, 0, threadID); // full screen triangle } for (int type = 0; type < LightComponent::LIGHTTYPE_COUNT; ++type) { - device->BindGraphicsPSO(PSO_deferredlight[type], threadID); + device->BindGraphicsPSO(&PSO_deferredlight[type], threadID); for (size_t i = 0; i < culling.culledLights.size(); ++i) { @@ -4531,7 +4443,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { MiscCB miscCb; miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(3, 0, threadID); // full screen triangle } @@ -4542,7 +4454,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); float sca = light.range + 1; XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(240, 0, threadID); // icosphere } @@ -4558,7 +4470,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(192, 0, threadID); // cone } @@ -4583,15 +4495,15 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID device->EventBegin("Light Visualizer Render", threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); XMMATRIX camrot = XMLoadFloat3x3(&camera.rotationMatrix); for (int type = LightComponent::POINT; type < LightComponent::LIGHTTYPE_COUNT; ++type) { - device->BindGraphicsPSO(PSO_lightvisualizer[type], threadID); + device->BindGraphicsPSO(&PSO_lightvisualizer[type], threadID); for (uint32_t lightIndex : culling.culledLights) { @@ -4613,7 +4525,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(108, 0, threadID); // circle } @@ -4627,7 +4539,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(192, 0, threadID); // cone } @@ -4640,7 +4552,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(2880, 0, threadID); // uv-sphere } @@ -4653,7 +4565,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(108, 0, threadID); // circle } @@ -4666,7 +4578,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(6, 0, threadID); // quad } @@ -4679,7 +4591,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_VOLUMELIGHT], &lcb, threadID); device->Draw(384, 0, threadID); // cylinder } @@ -4705,14 +4617,14 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) for (int type = 0; type < LightComponent::LIGHTTYPE_COUNT; ++type) { - GraphicsPSO* pso = PSO_volumetriclight[type]; + const GraphicsPSO& pso = PSO_volumetriclight[type]; - if (pso == nullptr) + if (!pso.IsValid()) { continue; } - device->BindGraphicsPSO(pso, threadID); + device->BindGraphicsPSO(&pso, threadID); for (size_t i = 0; i < culling.culledLights.size(); ++i) { @@ -4731,7 +4643,7 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { MiscCB miscCb; miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(3, 0, threadID); // full screen triangle } @@ -4742,7 +4654,7 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); float sca = light.range + 1; XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(240, 0, threadID); // icosphere } @@ -4758,7 +4670,7 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection() )); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); device->Draw(192, 0, threadID); // cone } @@ -4955,7 +4867,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui vp.MaxDepth = 1.0f; device->BindViewports(1, &vp, threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); + device->BindConstantBuffer(GS, &constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); break; } break; @@ -5025,7 +4937,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui { CameraCB cb; XMStoreFloat4x4(&cb.g_xCamera_VP, shcams[cascade].getVP()); - device->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CAMERA], &cb, threadID); device->ClearDepthStencil(shadowMapArray_2D.get(), CLEAR_DEPTH, 0.0f, 0, threadID, light.shadowMap_index + cascade); @@ -5099,7 +5011,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui { CameraCB cb; XMStoreFloat4x4(&cb.g_xCamera_VP, shcam.getVP()); - device->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CAMERA], &cb, threadID); device->ClearDepthStencil(shadowMapArray_2D.get(), CLEAR_DEPTH, 0.0f, 0, threadID, light.shadowMap_index); @@ -5167,7 +5079,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui MiscCB miscCb; miscCb.g_xColor = float4(light.position.x, light.position.y, light.position.z, 1.0f / light.GetRange()); // reciprocal range, to avoid division in shader - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); const float zNearP = 0.1f; const float zFarP = max(1.0f, light.range); @@ -5186,7 +5098,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui cameras[shcam].Update(XMLoadFloat3(&light.position)); XMStoreFloat4x4(&cb.xCubeShadowVP[shcam], cameras[shcam].getVP()); } - device->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); RenderMeshes(renderQueue, RENDERPASS_SHADOWCUBE, RENDERTYPE_OPAQUE, threadID); @@ -5231,7 +5143,7 @@ void DrawScene(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD if (renderPass == RENDERPASS_TILEDFORWARD) { - device->BindResource(PS, resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], SBSLOT_ENTITYTILES, threadID); + device->BindResource(PS, &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], SBSLOT_ENTITYTILES, threadID); } if (grass) @@ -5254,8 +5166,8 @@ void DrawScene(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD if (renderPass == RENDERPASS_FORWARD) { ForwardEntityMaskCB cb = ForwardEntityCullingCPU(culling, hair.aabb, renderPass); - device->UpdateBuffer(constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); } hair.Draw(camera, material, renderPass, false, threadID); @@ -5321,7 +5233,7 @@ void DrawScene_Transparent(const CameraComponent& camera, RENDERPASS renderPass, if (renderPass == RENDERPASS_TILEDFORWARD) { - device->BindResource(PS, resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], SBSLOT_ENTITYTILES, threadID); + device->BindResource(PS, &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], SBSLOT_ENTITYTILES, threadID); } if (ocean != nullptr) @@ -5345,8 +5257,8 @@ void DrawScene_Transparent(const CameraComponent& camera, RENDERPASS renderPass, if (renderPass == RENDERPASS_FORWARD) { ForwardEntityMaskCB cb = ForwardEntityCullingCPU(culling, hair.aabb, renderPass); - device->UpdateBuffer(constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), threadID); } hair.Draw(camera, material, renderPass, true, threadID); @@ -5403,12 +5315,12 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("DebugBoneLines", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); for (size_t i = 0; i < scene.armatures.GetCount(); ++i) { @@ -5468,12 +5380,12 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("DebugLines", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); struct LineSegment { @@ -5515,12 +5427,12 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("DebugPoints", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetProjection())); // only projection, we will expand in view space on CPU below to be camera facing! sb.g_xColor = XMFLOAT4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); // Will generate 2 line segments for each point forming a cross section: struct LineSegment @@ -5578,7 +5490,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("DebugBoxes", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { wiCube::GetVertexBuffer(), @@ -5596,7 +5508,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera.GetViewProjection())); sb.g_xColor = x.second; - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5611,7 +5523,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) device->EventBegin("Debug EnvProbes", threadID); // Envmap spheres: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); MiscCB sb; for (size_t i = 0; i < scene.probes.GetCount(); ++i) @@ -5619,7 +5531,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) const EnvironmentProbeComponent& probe = scene.probes[i]; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position)))); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); if (probe.textureIndex < 0) { @@ -5636,7 +5548,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) // Local proxy boxes: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { wiCube::GetVertexBuffer(), @@ -5662,7 +5574,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); sb.g_xColor = float4(0, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5675,7 +5587,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("GridHelper", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_GRID], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_GRID], threadID); static float col = 0.7f; static UINT gridVertexCount = 0; @@ -5723,7 +5635,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = float4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); GPUBuffer* vbs[] = { grid, @@ -5741,14 +5653,14 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("Debug Voxels", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_VOXEL], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_VOXEL], threadID); MiscCB sb; XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera.GetViewProjection())); sb.g_xColor = float4(1, 1, 1, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); device->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); @@ -5769,12 +5681,12 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); sb.g_xColor = float4(0, 1, 0, 1); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); if (mesh == nullptr) { // No mesh, just draw a box: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { wiCube::GetVertexBuffer(), }; @@ -5788,7 +5700,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) else { // Draw mesh wireframe: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_EMITTER], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_EMITTER], threadID); GPUBuffer* vbs[] = { mesh->streamoutBuffer_POS != nullptr ? mesh->streamoutBuffer_POS.get() : mesh->vertexBuffer_POS.get(), }; @@ -5817,16 +5729,16 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); switch (force.type) { case ENTITY_TYPE_FORCEFIELD_POINT: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); device->Draw(2880, 0, threadID); // uv-sphere break; case ENTITY_TYPE_FORCEFIELD_PLANE: - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); device->Draw(14, 0, threadID); // box break; } @@ -5842,7 +5754,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) { device->EventBegin("DebugCameras", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { wiCube::GetVertexBuffer(), @@ -5863,7 +5775,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection())); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5888,11 +5800,11 @@ void DrawSky(GRAPHICSTHREAD threadID) if (enviroMap != nullptr) { - device->BindGraphicsPSO(PSO_sky[SKYRENDERING_STATIC], threadID); + device->BindGraphicsPSO(&PSO_sky[SKYRENDERING_STATIC], threadID); } else { - device->BindGraphicsPSO(PSO_sky[SKYRENDERING_DYNAMIC], threadID); + device->BindGraphicsPSO(&PSO_sky[SKYRENDERING_DYNAMIC], threadID); if (scene.weather.cloudiness > 0) { device->BindResource(PS, textures[TEXTYPE_2D_CLOUDS], TEXSLOT_ONDEMAND0, threadID); @@ -5913,7 +5825,7 @@ void DrawSun(GRAPHICSTHREAD threadID) device->EventBegin("DrawSun", threadID); - device->BindGraphicsPSO(PSO_sky[SKYRENDERING_SUN], threadID); + device->BindGraphicsPSO(&PSO_sky[SKYRENDERING_SUN], threadID); if (enviroMap != nullptr) { @@ -5941,11 +5853,11 @@ void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) const Scene& scene = GetScene(); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),threadID); device->BindStencilRef(STENCILREF_DEFAULT, threadID); - device->BindGraphicsPSO(PSO_decal, threadID); + device->BindGraphicsPSO(&PSO_decal, threadID); for (size_t decalIndex : culling.culledDecals) { @@ -5962,7 +5874,7 @@ void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) MiscCB dcbvs; XMStoreFloat4x4(&dcbvs.g_xTransform, XMMatrixTranspose(decalWorld*camera.GetViewProjection())); - device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &dcbvs, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &dcbvs, threadID); DecalCB dcbps; XMStoreFloat4x4(&dcbps.xDecalVP, XMMatrixTranspose(XMMatrixInverse(nullptr, decalWorld))); // todo: cache the inverse! @@ -5974,7 +5886,7 @@ void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat3(&dcbps.eye, camera.GetEye()); dcbps.opacity = decal.GetOpacity(); dcbps.front = decal.front; - device->UpdateBuffer(constantBuffers[CBTYPE_DECAL], &dcbps, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_DECAL], &dcbps, threadID); device->Draw(14, 0, threadID); @@ -6136,13 +6048,13 @@ void RefreshEnvProbes(GRAPHICSTHREAD threadID) XMStoreFloat4x4(&cb.xCubeShadowVP[i], cameras[i].getVP()); } - device->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); - device->BindConstantBuffer(GS, constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CUBEMAPRENDER], &cb, threadID); + device->BindConstantBuffer(GS, &constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubemapRenderCB), threadID); CameraCB camcb; camcb.g_xCamera_CamPos = center; // only this will be used by envprobe rendering shaders the rest is read from cubemaprenderCB - device->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &camcb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CAMERA], &camcb, threadID); const LayerComponent& layer = *scene.layers.GetComponent(entity); const uint32_t layerMask = layer.GetLayerMask(); @@ -6184,12 +6096,12 @@ void RefreshEnvProbes(GRAPHICSTHREAD threadID) { if (enviroMap != nullptr) { - device->BindGraphicsPSO(PSO_sky[SKYRENDERING_ENVMAPCAPTURE_STATIC], threadID); + device->BindGraphicsPSO(&PSO_sky[SKYRENDERING_ENVMAPCAPTURE_STATIC], threadID); device->BindResource(PS, enviroMap, TEXSLOT_ONDEMAND0, threadID); } else { - device->BindGraphicsPSO(PSO_sky[SKYRENDERING_ENVMAPCAPTURE_DYNAMIC], threadID); + device->BindGraphicsPSO(&PSO_sky[SKYRENDERING_ENVMAPCAPTURE_DYNAMIC], threadID); device->BindResource(PS, textures[TEXTYPE_2D_CLOUDS], TEXSLOT_ONDEMAND0, threadID); } @@ -6208,7 +6120,7 @@ void RefreshEnvProbes(GRAPHICSTHREAD threadID) TextureDesc desc = texture->GetDesc(); int arrayIndex = probe.textureIndex; - device->BindComputePSO(CPSO[CSTYPE_FILTERENVMAP], threadID); + device->BindComputePSO(&CPSO[CSTYPE_FILTERENVMAP], threadID); desc.Width = 1; desc.Height = 1; @@ -6223,8 +6135,8 @@ void RefreshEnvProbes(GRAPHICSTHREAD threadID) cb.filterArrayIndex = arrayIndex; cb.filterRoughness = (float)i / (float)desc.MipLevels; cb.filterRayCount = 128; - device->UpdateBuffer(constantBuffers[CBTYPE_FILTERENVMAP], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_FILTERENVMAP], CB_GETBINDSLOT(FilterEnvmapCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_FILTERENVMAP], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_FILTERENVMAP], CB_GETBINDSLOT(FilterEnvmapCB), threadID); device->Dispatch( max(1, (UINT)ceilf((float)desc.Width / GENERATEMIPCHAIN_2D_BLOCK_SIZE)), @@ -6362,13 +6274,13 @@ void RefreshImpostors(GRAPHICSTHREAD threadID) switch (prop) { case 0: - device->BindGraphicsPSO(PSO_captureimpostor_albedo, threadID); + device->BindGraphicsPSO(&PSO_captureimpostor_albedo, threadID); break; case 1: - device->BindGraphicsPSO(PSO_captureimpostor_normal, threadID); + device->BindGraphicsPSO(&PSO_captureimpostor_normal, threadID); break; case 2: - device->BindGraphicsPSO(PSO_captureimpostor_surface, threadID); + device->BindGraphicsPSO(&PSO_captureimpostor_surface, threadID); break; } @@ -6479,7 +6391,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) HRESULT hr = device->CreateTexture3D(&desc, nullptr, (Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]); assert(SUCCEEDED(hr)); } - if (resourceBuffers[RBTYPE_VOXELSCENE] == nullptr) + if (!resourceBuffers[RBTYPE_VOXELSCENE].IsValid()) { GPUBufferDesc desc; desc.StructureByteStride = sizeof(UINT) * 2; @@ -6489,8 +6401,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) desc.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; desc.Usage = USAGE_DEFAULT; - resourceBuffers[RBTYPE_VOXELSCENE] = new GPUBuffer; - HRESULT hr = device->CreateBuffer(&desc, nullptr, resourceBuffers[RBTYPE_VOXELSCENE]); + HRESULT hr = device->CreateBuffer(&desc, nullptr, &resourceBuffers[RBTYPE_VOXELSCENE]); assert(SUCCEEDED(hr)); } @@ -6530,7 +6441,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) VP.MaxDepth = 1.0f; device->BindViewports(1, &VP, threadID); - GPUResource* UAVs[] = { resourceBuffers[RBTYPE_VOXELSCENE] }; + GPUResource* UAVs[] = { &resourceBuffers[RBTYPE_VOXELSCENE] }; device->BindUAVs(PS, UAVs, 0, 1, threadID); BindShadowmaps(PS, threadID); @@ -6541,16 +6452,16 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) // Copy the packed voxel scene data to a 3D texture, then delete the voxel scene emission data. The cone tracing will operate on the 3D texture device->EventBegin("Voxel Scene Copy - Clear", threadID); device->BindRenderTargets(0, nullptr, nullptr, threadID); - device->BindUAV(CS, resourceBuffers[RBTYPE_VOXELSCENE], 0, threadID); + device->BindUAV(CS, &resourceBuffers[RBTYPE_VOXELSCENE], 0, threadID); device->BindUAV(CS, textures[TEXTYPE_3D_VOXELRADIANCE], 1, threadID); if (device->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_UNORDEREDACCESSTEXTURE_LOAD_FORMAT_EXT)) { - device->BindComputePSO(CPSO[CSTYPE_VOXELSCENECOPYCLEAR_TEMPORALSMOOTHING], threadID); + device->BindComputePSO(&CPSO[CSTYPE_VOXELSCENECOPYCLEAR_TEMPORALSMOOTHING], threadID); } else { - device->BindComputePSO(CPSO[CSTYPE_VOXELSCENECOPYCLEAR], threadID); + device->BindComputePSO(&CPSO[CSTYPE_VOXELSCENECOPYCLEAR], threadID); } device->Dispatch((UINT)(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res / 256), 1, 1, threadID); device->EventEnd(threadID); @@ -6563,15 +6474,15 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) GenerateMipChain((Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE], MIPGENFILTER_LINEAR, threadID); device->BindUAV(CS, textures[TEXTYPE_3D_VOXELRADIANCE_HELPER], 0, threadID); device->BindResource(CS, textures[TEXTYPE_3D_VOXELRADIANCE], 0, threadID); - device->BindResource(CS, resourceBuffers[RBTYPE_VOXELSCENE], 1, threadID); - device->BindComputePSO(CPSO[CSTYPE_VOXELRADIANCESECONDARYBOUNCE], threadID); + device->BindResource(CS, &resourceBuffers[RBTYPE_VOXELSCENE], 1, threadID); + device->BindComputePSO(&CPSO[CSTYPE_VOXELRADIANCESECONDARYBOUNCE], threadID); device->Dispatch((UINT)(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res / 64), 1, 1, threadID); device->EventEnd(threadID); device->EventBegin("Voxel Scene Clear Normals", threadID); device->UnbindResources(1, 1, threadID); - device->BindUAV(CS, resourceBuffers[RBTYPE_VOXELSCENE], 0, threadID); - device->BindComputePSO(CPSO[CSTYPE_VOXELCLEARONLYNORMAL], threadID); + device->BindUAV(CS, &resourceBuffers[RBTYPE_VOXELSCENE], 0, threadID); + device->BindComputePSO(&CPSO[CSTYPE_VOXELCLEARONLYNORMAL], threadID); device->Dispatch((UINT)(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res / 256), 1, 1, threadID); device->EventEnd(threadID); @@ -6650,11 +6561,6 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf } if (_resolutionChanged) { - SAFE_DELETE(resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE]); - SAFE_DELETE(resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT]); - resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE] = new GPUBuffer; - resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT] = new GPUBuffer; - GPUBufferDesc bd; bd.StructureByteStride = sizeof(uint); bd.ByteWidth = tileCount.x * tileCount.y * bd.StructureByteStride * SHADER_ENTITY_TILE_BUCKET_COUNT; @@ -6662,11 +6568,11 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf bd.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE; bd.CPUAccessFlags = 0; bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; - device->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE]); - device->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT]); + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE]); + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT]); - device->SetName(resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], "EntityTiles_Opaque"); - device->SetName(resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], "EntityTiles_Transparent"); + device->SetName(&resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], "EntityTiles_Opaque"); + device->SetName(&resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], "EntityTiles_Transparent"); } // calculate the per-tile frustums once: @@ -6684,7 +6590,7 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf GPUResource* uavs[] = { frustumBuffer }; device->BindUAVs(CS, uavs, UAVSLOT_TILEFRUSTUMS, ARRAYSIZE(uavs), threadID); - device->BindComputePSO(CPSO[CSTYPE_TILEFRUSTUMS], threadID); + device->BindComputePSO(&CPSO[CSTYPE_TILEFRUSTUMS], threadID); DispatchParamsCB dispatchParams; dispatchParams.xDispatchParams_numThreads.x = tileCount.x; @@ -6693,8 +6599,8 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf dispatchParams.xDispatchParams_numThreadGroups.x = (UINT)ceilf(dispatchParams.xDispatchParams_numThreads.x / (float)TILED_CULLING_BLOCKSIZE); dispatchParams.xDispatchParams_numThreadGroups.y = (UINT)ceilf(dispatchParams.xDispatchParams_numThreads.y / (float)TILED_CULLING_BLOCKSIZE); dispatchParams.xDispatchParams_numThreadGroups.z = 1; - device->UpdateBuffer(constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, threadID); device->UnbindUAVs(UAVSLOT_TILEFRUSTUMS, 1, threadID); @@ -6730,7 +6636,7 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf device->BindResource(CS, frustumBuffer, SBSLOT_TILEFRUSTUMS, threadID); - device->BindComputePSO(CPSO_tiledlighting[deferred][GetAdvancedLightCulling()][GetDebugLightCulling()], threadID); + device->BindComputePSO(&CPSO_tiledlighting[deferred][GetAdvancedLightCulling()][GetDebugLightCulling()], threadID); if (GetDebugLightCulling()) { @@ -6749,14 +6655,14 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf dispatchParams.xDispatchParams_numThreads.y = dispatchParams.xDispatchParams_numThreadGroups.y * TILED_CULLING_BLOCKSIZE; dispatchParams.xDispatchParams_numThreads.z = 1; dispatchParams.xDispatchParams_value0 = (UINT)(frameCulling.culledLights.size() + frameCulling.culledEnvProbes.size() + frameCulling.culledDecals.size()); - device->UpdateBuffer(constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); if (deferred) { const GPUResource* uavs[] = { lightbuffer_diffuse, - resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], + &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], lightbuffer_specular, }; device->BindUAVs(CS, uavs, UAVSLOT_TILEDDEFERRED_DIFFUSE, ARRAYSIZE(uavs), threadID); @@ -6769,8 +6675,8 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf else { GPUResource* uavs[] = { - resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], - resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], + &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], + &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], }; device->BindUAVs(CS, uavs, UAVSLOT_ENTITYTILES_OPAQUE, ARRAYSIZE(uavs), threadID); @@ -6797,7 +6703,7 @@ void ResolveMSAADepthBuffer(const Texture2D* dst, const Texture2D* src, GRAPHICS TextureDesc desc = src->GetDesc(); - device->BindComputePSO(CPSO[CSTYPE_RESOLVEMSAADEPTHSTENCIL], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RESOLVEMSAADEPTHSTENCIL], threadID); device->Dispatch((UINT)ceilf(desc.Width / 16.f), (UINT)ceilf(desc.Height / 16.f), 1, threadID); @@ -6838,18 +6744,18 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR { case MIPGENFILTER_POINT: device->EventBegin("GenerateMipChain CubeArray - PointFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR: device->EventBegin("GenerateMipChain CubeArray - LinearFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR_MAXIMUM: device->EventBegin("GenerateMipChain CubeArray - LinearMaxFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; default: assert(0); @@ -6867,8 +6773,8 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR cb.outputResolution.x = desc.Width; cb.outputResolution.y = desc.Height; cb.arrayIndex = arrayIndex; - device->UpdateBuffer(constantBuffers[CBTYPE_MIPGEN], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); device->Dispatch( max(1, (UINT)ceilf((float)desc.Width / GENERATEMIPCHAIN_2D_BLOCK_SIZE)), @@ -6886,18 +6792,18 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR { case MIPGENFILTER_POINT: device->EventBegin("GenerateMipChain Cube - PointFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR: device->EventBegin("GenerateMipChain Cube - LinearFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR_MAXIMUM: device->EventBegin("GenerateMipChain Cube - LinearMaxFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; default: assert(0); // not implemented @@ -6915,8 +6821,8 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR cb.outputResolution.x = desc.Width; cb.outputResolution.y = desc.Height; cb.arrayIndex = 0; - device->UpdateBuffer(constantBuffers[CBTYPE_MIPGEN], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); device->Dispatch( max(1, (UINT)ceilf((float)desc.Width / GENERATEMIPCHAIN_2D_BLOCK_SIZE)), @@ -6936,26 +6842,26 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR { case MIPGENFILTER_POINT: device->EventBegin("GenerateMipChain 2D - PointFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR: device->EventBegin("GenerateMipChain 2D - LinearFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR_MAXIMUM: device->EventBegin("GenerateMipChain 2D - LinearMaxFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_GAUSSIAN: device->EventBegin("GenerateMipChain 2D - GaussianFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], threadID); break; case MIPGENFILTER_BICUBIC: device->EventBegin("GenerateMipChain 2D - BicubicFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC], threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC], threadID); break; default: assert(0); @@ -6973,8 +6879,8 @@ void GenerateMipChain(const Texture2D* texture, MIPGENFILTER filter, GRAPHICSTHR cb.outputResolution.x = desc.Width; cb.outputResolution.y = desc.Height; cb.arrayIndex = arrayIndex >= 0 ? (uint)arrayIndex : 0; - device->UpdateBuffer(constantBuffers[CBTYPE_MIPGEN], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); device->Dispatch( max(1, (UINT)ceilf((float)desc.Width / GENERATEMIPCHAIN_2D_BLOCK_SIZE)), @@ -7010,22 +6916,22 @@ void GenerateMipChain(const Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHR { case MIPGENFILTER_POINT: device->EventBegin("GenerateMipChain 3D - PointFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR: device->EventBegin("GenerateMipChain 3D - LinearFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_LINEAR_MAXIMUM: device->EventBegin("GenerateMipChain 3D - LinearMaxFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); - device->BindSampler(CS, customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], threadID); + device->BindSampler(CS, &customsamplers[SSTYPE_MAXIMUM_CLAMP], SSLOT_ONDEMAND0, threadID); break; case MIPGENFILTER_GAUSSIAN: device->EventBegin("GenerateMipChain 3D - GaussianFilter", threadID); - device->BindComputePSO(CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN], threadID); + device->BindComputePSO(&CPSO[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN], threadID); break; default: assert(0); // not implemented @@ -7045,8 +6951,8 @@ void GenerateMipChain(const Texture3D* texture, MIPGENFILTER filter, GRAPHICSTHR cb.outputResolution.y = desc.Height; cb.outputResolution.z = desc.Depth; cb.arrayIndex = arrayIndex >= 0 ? (uint)arrayIndex : 0; - device->UpdateBuffer(constantBuffers[CBTYPE_MIPGEN], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), threadID); device->Dispatch( max(1, (UINT)ceilf((float)desc.Width / GENERATEMIPCHAIN_3D_BLOCK_SIZE)), @@ -7078,12 +6984,12 @@ void CopyTexture2D(const Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, cons if (hdr) { device->EventBegin("CopyTexture2D_FLOAT4", threadID); - device->BindComputePSO(CPSO[CSTYPE_COPYTEXTURE2D_FLOAT4], threadID); + device->BindComputePSO(&CPSO[CSTYPE_COPYTEXTURE2D_FLOAT4], threadID); } else { device->EventBegin("CopyTexture2D_UNORM4", threadID); - device->BindComputePSO(CPSO[CSTYPE_COPYTEXTURE2D_UNORM4], threadID); + device->BindComputePSO(&CPSO[CSTYPE_COPYTEXTURE2D_UNORM4], threadID); } } else @@ -7091,12 +6997,12 @@ void CopyTexture2D(const Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, cons if (hdr) { device->EventBegin("CopyTexture2D_BORDEREXPAND_FLOAT4", threadID); - device->BindComputePSO(CPSO[CSTYPE_COPYTEXTURE2D_FLOAT4_BORDEREXPAND], threadID); + device->BindComputePSO(&CPSO[CSTYPE_COPYTEXTURE2D_FLOAT4_BORDEREXPAND], threadID); } else { device->EventBegin("CopyTexture2D_BORDEREXPAND_UNORM4", threadID); - device->BindComputePSO(CPSO[CSTYPE_COPYTEXTURE2D_UNORM4_BORDEREXPAND], threadID); + device->BindComputePSO(&CPSO[CSTYPE_COPYTEXTURE2D_UNORM4_BORDEREXPAND], threadID); } } @@ -7107,9 +7013,9 @@ void CopyTexture2D(const Texture2D* dst, UINT DstMIP, UINT DstX, UINT DstY, cons cb.xCopySrcSize.y = desc_src.Height >> SrcMIP; cb.xCopySrcMIP = SrcMIP; cb.xCopyBorderExpandStyle = (uint)borderExpand; - device->UpdateBuffer(constantBuffers[CBTYPE_COPYTEXTURE], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_COPYTEXTURE], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_COPYTEXTURE], CB_GETBINDSLOT(CopyTextureCB), threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_COPYTEXTURE], CB_GETBINDSLOT(CopyTextureCB), threadID); device->BindResource(CS, src, TEXSLOT_ONDEMAND0, threadID); @@ -7447,13 +7353,13 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA cb.xTracePixelOffset = XMFLOAT2(halton.x, halton.y); cb.xTraceRandomSeed = renderTime; - device->UpdateBuffer(constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); device->EventBegin("Clear", threadID); { - device->BindComputePSO(CPSO[CSTYPE_RAYTRACE_CLEAR], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_CLEAR], threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); const GPUResource* uavs[] = { result, @@ -7469,9 +7375,9 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA device->EventBegin("Launch Rays", threadID); { - device->BindComputePSO(CPSO[CSTYPE_RAYTRACE_LAUNCH], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_LAUNCH], threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); GPUResource* uavs[] = { rayBuffer[0], @@ -7513,15 +7419,15 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA const int __writeBufferID = (bounce + 1) % 2; cb.xTraceRandomSeed = renderTime + (float)bounce; - device->UpdateBuffer(constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); // 1.) Kick off raytracing jobs for this bounce device->EventBegin("Kick Raytrace Jobs", threadID); { // Prepare indirect dispatch based on counter buffer value: - device->BindComputePSO(CPSO[CSTYPE_RAYTRACE_KICKJOBS], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_KICKJOBS], threadID); GPUResource* res[] = { counterBuffer[__readBufferID], @@ -7551,7 +7457,7 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA device->EventBegin("Light Sampling Rays", threadID); { // Indirect dispatch on active rays: - device->BindComputePSO(CPSO[CSTYPE_RAYTRACE_LIGHTSAMPLING], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_LIGHTSAMPLING], threadID); const GPUResource* res[] = { counterBuffer[__readBufferID], @@ -7585,7 +7491,7 @@ void DrawTracedScene(const CameraComponent& camera, const Texture2D* result, GRA device->EventBegin("Primary Rays Bounce", threadID); { // Indirect dispatch on active rays: - device->BindComputePSO(CPSO[CSTYPE_RAYTRACE_PRIMARY], threadID); + device->BindComputePSO(&CPSO[CSTYPE_RAYTRACE_PRIMARY], threadID); const GPUResource* res[] = { counterBuffer[__readBufferID], @@ -7625,7 +7531,7 @@ void DrawTracedSceneBVH(GRAPHICSTHREAD threadID) GraphicsDevice* device = GetDevice(); device->EventBegin("DebugRaytraceBVH", threadID); - device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_RAYTRACE_BVH], threadID); + device->BindGraphicsPSO(&PSO_debug[DEBUGRENDERING_RAYTRACE_BVH], threadID); sceneBVH.Bind(PS, threadID); device->Draw(3, 0, threadID); device->EventEnd(threadID); @@ -7655,10 +7561,10 @@ void GenerateClouds(const Texture2D* dst, UINT refinementCount, float randomness { cb.xRefinementCount = refinementCount; } - device->UpdateBuffer(constantBuffers[CBTYPE_CLOUDGENERATOR], &cb, threadID); - device->BindConstantBuffer(CS, constantBuffers[CBTYPE_CLOUDGENERATOR], CB_GETBINDSLOT(CloudGeneratorCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_CLOUDGENERATOR], &cb, threadID); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_CLOUDGENERATOR], CB_GETBINDSLOT(CloudGeneratorCB), threadID); - device->BindComputePSO(CPSO[CSTYPE_CLOUDGENERATOR], threadID); + device->BindComputePSO(&CPSO[CSTYPE_CLOUDGENERATOR], threadID); device->Dispatch((UINT)ceilf(dst_desc.Width / (float)CLOUDGENERATOR_BLOCKSIZE), (UINT)ceilf(dst_desc.Height / (float)CLOUDGENERATOR_BLOCKSIZE), 1, threadID); device->UnbindResources(TEXSLOT_ONDEMAND0, 1, threadID); @@ -8014,18 +7920,18 @@ void RenderObjectLightMap(const ObjectComponent& object, GRAPHICSTHREAD threadID cb.xTraceRandomSeed = renderTime; // random seed cb.xTraceUserData = 1.0f / (lightmapIterationCount + 1.0f); // accumulation factor (alpha) cb.xTraceUserData2.x = lightmapBakeBounceCount; - device->UpdateBuffer(constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); - device->BindConstantBuffer(VS, constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); - device->BindConstantBuffer(PS, constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); + device->UpdateBuffer(&constantBuffers[CBTYPE_RAYTRACE], &cb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_RAYTRACE], CB_GETBINDSLOT(TracedRenderingCB), threadID); // Render direct lighting part: - device->BindGraphicsPSO(PSO_renderlightmap_direct, threadID); + device->BindGraphicsPSO(&PSO_renderlightmap_direct, threadID); device->DrawIndexedInstanced((UINT)mesh.indices.size(), 1, 0, 0, 0, threadID); if (lightmapBakeBounceCount > 0) { // Render indirect lighting part: - device->BindGraphicsPSO(PSO_renderlightmap_indirect, threadID); + device->BindGraphicsPSO(&PSO_renderlightmap_indirect, threadID); device->DrawIndexedInstanced((UINT)mesh.indices.size(), 1, 0, 0, 0, threadID); } @@ -8133,13 +8039,13 @@ void BindPersistentState(GRAPHICSTHREAD threadID) for (int i = 0; i < SSLOT_COUNT; ++i) { - device->BindSampler(stage, samplers[i], i, threadID); + device->BindSampler(stage, &samplers[i], i, threadID); } - device->BindConstantBuffer(stage, constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(stage, constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(stage, constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - device->BindConstantBuffer(stage, constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); } } @@ -8279,7 +8185,7 @@ void UpdateFrameCB(GRAPHICSTHREAD threadID) cb.g_xFrame_WorldBoundsExtents_Inverse.y = 1.0f / cb.g_xFrame_WorldBoundsExtents.y; cb.g_xFrame_WorldBoundsExtents_Inverse.z = 1.0f / cb.g_xFrame_WorldBoundsExtents.z; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_FRAME], &cb, threadID); + GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_FRAME], &cb, threadID); } void UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD threadID) { @@ -8290,21 +8196,21 @@ void UpdateCameraCB(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&cb.g_xCamera_Proj, XMMatrixTranspose(camera.GetProjection())); cb.g_xCamera_CamPos = camera.Eye; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], &cb, threadID); + GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_CAMERA], &cb, threadID); } APICB apiCB[GRAPHICSTHREAD_COUNT]; void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID) { apiCB[threadID].g_xClipPlane = clipPlane; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); + GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) { if (alphaRef != apiCB[threadID].g_xAlphaRef) { apiCB[threadID].g_xAlphaRef = alphaRef; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); + GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } } void BindGBufferTextures(const Texture2D* slot0, const Texture2D* slot1, const Texture2D* slot2, GRAPHICSTHREAD threadID) @@ -8380,7 +8286,7 @@ const Texture2D* GetLuminance(const Texture2D* sourceImage, GRAPHICSTHREAD threa { // Pass 1 : Create luminance map from scene tex TextureDesc luminance_map_desc = luminance_map->GetDesc(); - device->BindComputePSO(CPSO[CSTYPE_LUMINANCE_PASS1], threadID); + device->BindComputePSO(&CPSO[CSTYPE_LUMINANCE_PASS1], threadID); device->BindResource(CS, sourceImage, TEXSLOT_ONDEMAND0, threadID); device->BindUAV(CS, luminance_map.get(), 0, threadID); device->Dispatch(luminance_map_desc.Width/16, luminance_map_desc.Height/16, 1, threadID); @@ -8390,7 +8296,7 @@ const Texture2D* GetLuminance(const Texture2D* sourceImage, GRAPHICSTHREAD threa for (size_t i = 0; i < luminance_avg.size(); ++i) { luminance_avg_desc = luminance_avg[i]->GetDesc(); - device->BindComputePSO(CPSO[CSTYPE_LUMINANCE_PASS2], threadID); + device->BindComputePSO(&CPSO[CSTYPE_LUMINANCE_PASS2], threadID); device->BindUAV(CS, luminance_avg[i], 0, threadID); if (i > 0) { diff --git a/WickedEngine/wiSceneSystem_BindLua.cpp b/WickedEngine/wiSceneSystem_BindLua.cpp index ad118cc71..0039c3e45 100644 --- a/WickedEngine/wiSceneSystem_BindLua.cpp +++ b/WickedEngine/wiSceneSystem_BindLua.cpp @@ -38,6 +38,7 @@ void Bind() Luna::Register(L); Luna::Register(L); Luna::Register(L); + Luna::Register(L); } } @@ -59,6 +60,7 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Component_GetCamera), lunamethod(Scene_BindLua, Component_GetAnimation), lunamethod(Scene_BindLua, Component_GetMaterial), + lunamethod(Scene_BindLua, Component_GetEmitter), lunamethod(Scene_BindLua, Component_Attach), lunamethod(Scene_BindLua, Component_Detach), lunamethod(Scene_BindLua, Component_DetachChildren), @@ -284,6 +286,23 @@ int Scene_BindLua::Component_GetMaterial(lua_State* L) } return 0; } +int Scene_BindLua::Component_GetEmitter(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wiLua::SGetInt(L, 1); + + wiEmittedParticle* component = scene->emitters.GetComponent(entity); + Luna::push(L, new EmitterComponent_BindLua(component)); + return 1; + } + else + { + wiLua::SError(L, "Scene::Component_GetAnimation(Entity entity) not enough arguments!"); + } + return 0; +} int Scene_BindLua::Component_Attach(lua_State* L) { @@ -872,4 +891,201 @@ int MaterialComponent_BindLua::SetEmissiveColor(lua_State* L) } + + + + + + + + +const char EmitterComponent_BindLua::className[] = "EmitterComponent"; + +Luna::FunctionType EmitterComponent_BindLua::methods[] = { + lunamethod(EmitterComponent_BindLua, Burst), + lunamethod(EmitterComponent_BindLua, SetEmitCount), + lunamethod(EmitterComponent_BindLua, SetSize), + lunamethod(EmitterComponent_BindLua, SetLife), + lunamethod(EmitterComponent_BindLua, SetNormalFactor), + lunamethod(EmitterComponent_BindLua, SetRandomness), + lunamethod(EmitterComponent_BindLua, SetLifeRandomness), + lunamethod(EmitterComponent_BindLua, SetScaleX), + lunamethod(EmitterComponent_BindLua, SetScaleY), + lunamethod(EmitterComponent_BindLua, SetRotation), + lunamethod(EmitterComponent_BindLua, SetmotionBlurAmount), + { NULL, NULL } +}; +Luna::PropertyType EmitterComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +EmitterComponent_BindLua::EmitterComponent_BindLua(lua_State *L) +{ + owning = true; + component = new wiEmittedParticle; +} +EmitterComponent_BindLua::~EmitterComponent_BindLua() +{ + if (owning) + { + delete component; + } +} + +int EmitterComponent_BindLua::Burst(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->Burst(wiLua::SGetInt(L, 1)); + } + else + { + wiLua::SError(L, "Burst(int value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetEmitCount(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->count = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetEmitCount(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetSize(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->size = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetSize(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetLife(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->life = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetLife(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetNormalFactor(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->normal_factor = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetNormalFactor(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetRandomness(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->random_factor = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetRandomness(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetLifeRandomness(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->random_life = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetLifeRandomness(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetScaleX(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->scaleX = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetScaleX(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetScaleY(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->scaleY = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetScaleY(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetRotation(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->rotation = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetRotation(float value) not enough arguments!"); + } + + return 0; +} +int EmitterComponent_BindLua::SetmotionBlurAmount(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->motionBlurAmount = wiLua::SGetFloat(L, 1); + } + else + { + wiLua::SError(L, "SetmotionBlurAmount(float value) not enough arguments!"); + } + + return 0; +} + + } diff --git a/WickedEngine/wiSceneSystem_BindLua.h b/WickedEngine/wiSceneSystem_BindLua.h index 59f8c90d6..363e4e431 100644 --- a/WickedEngine/wiSceneSystem_BindLua.h +++ b/WickedEngine/wiSceneSystem_BindLua.h @@ -36,6 +36,7 @@ namespace wiSceneSystem_BindLua int Component_GetCamera(lua_State* L); int Component_GetAnimation(lua_State* L); int Component_GetMaterial(lua_State* L); + int Component_GetEmitter(lua_State* L); int Component_Attach(lua_State* L); int Component_Detach(lua_State* L); @@ -161,5 +162,32 @@ namespace wiSceneSystem_BindLua int SetEmissiveColor(lua_State* L); }; + class EmitterComponent_BindLua + { + public: + bool owning = false; + wiSceneSystem::wiEmittedParticle* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + EmitterComponent_BindLua(wiSceneSystem::wiEmittedParticle* component) :component(component) {} + EmitterComponent_BindLua(lua_State *L); + ~EmitterComponent_BindLua(); + + int Burst(lua_State* L); + int SetEmitCount(lua_State* L); + int SetSize(lua_State* L); + int SetLife(lua_State* L); + int SetNormalFactor(lua_State* L); + int SetRandomness(lua_State* L); + int SetLifeRandomness(lua_State* L); + int SetScaleX(lua_State* L); + int SetScaleY(lua_State* L); + int SetRotation(lua_State* L); + int SetmotionBlurAmount(lua_State* L); + }; + } diff --git a/WickedEngine/wiSceneSystem_Decl.h b/WickedEngine/wiSceneSystem_Decl.h index 05066697c..d56fb7075 100644 --- a/WickedEngine/wiSceneSystem_Decl.h +++ b/WickedEngine/wiSceneSystem_Decl.h @@ -23,4 +23,7 @@ namespace wiSceneSystem struct AnimationComponent; struct WeatherComponent; struct Scene; + + class wiEmittedParticle; // todo: rename + class wiHairParticle; // todo: rename } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index c77ae81ac..a639eb51d 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 24; // minor bug fixes, alterations, refactors, updates - const int revision = 48; + const int revision = 49; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index d1cfd49c7..712536a91 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -18,7 +18,7 @@ using namespace wiGraphicsTypes; using namespace wiSceneSystem; -static wiGraphicsTypes::GraphicsPSO* PSO_colorpicker = nullptr; +static wiGraphicsTypes::GraphicsPSO PSO_colorpicker; wiWidget::wiWidget() : TransformComponent() @@ -260,8 +260,7 @@ void wiWidget::LoadShaders() desc.numRTs = 1; desc.RTFormats[0] = wiRenderer::GetDevice()->GetBackBufferFormat(); desc.pt = TRIANGLESTRIP; - RECREATE(PSO_colorpicker); - HRESULT hr = wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, PSO_colorpicker); + HRESULT hr = wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, &PSO_colorpicker); assert(SUCCEEDED(hr)); } @@ -1792,7 +1791,7 @@ void wiColorPicker::Render(wiGUI* gui) XMMATRIX __cam = wiRenderer::GetDevice()->GetScreenProjection(); wiRenderer::GetDevice()->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CBSLOT_RENDERER_MISC, threadID); - wiRenderer::GetDevice()->BindGraphicsPSO(PSO_colorpicker, threadID); + wiRenderer::GetDevice()->BindGraphicsPSO(&PSO_colorpicker, threadID); MiscCB cb; diff --git a/models/emitter_smoke.wiscene b/models/emitter_smoke.wiscene index dc473a395d48496f7c630e6bab23ec73cbe47a70..c3542929e7441d1428f6536629b4a3cf65ef2f64 100644 GIT binary patch delta 249 zcmZ3@@`aUAaw4O+5E}yo6zAq=r!p`^HG5B<&nP!BK#c{=He?i;*r&_ZU=LC?aiiMA z+Y(Gb##cRFMyN)J9z({e$qtNM6Z<$OTQEvYKF#O>(LbM2iK)SUvLT~J{n;}#Wjw9` delta 97 zcmeyux|)SiY$Bt$JRbuDq^4w+m4(_jJdCp$8VOl;Gg fcvxoQZ5gHp`-wmGVB+PI0~mQH?_kV;35Wmy^V%E} diff --git a/scripts/debug_draw.lua b/scripts/debug_draw.lua index 28db2a4f1..d26ac6015 100644 --- a/scripts/debug_draw.lua +++ b/scripts/debug_draw.lua @@ -1,4 +1,5 @@ -- This script will draw some debug primitives in the world such as line, point, box +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: debug_draw.lua") diff --git a/scripts/emitter_burst.lua b/scripts/emitter_burst.lua new file mode 100644 index 000000000..87e0e2cb4 --- /dev/null +++ b/scripts/emitter_burst.lua @@ -0,0 +1,23 @@ +-- This script will load a particle emitter model and burst-spawn particles from it periodically +killProcesses() -- stops all running lua coroutine processes + +backlog_post("---> START SCRIPT: emitter_burst.lua") + +scene = GetScene() +scene.Clear() +LoadModel("../models/emitter_smoke.wiscene") +emitter_entity = scene.Entity_FindByName("smoke") -- query the emitter entity by name +emitter_component = scene.Component_GetEmitter(emitter_entity) +emitter_component.SetEmitCount(0) -- don't emit continuously +emitter_component.SetNormalFactor(20) -- set starting speed to particles +emitter_component.SetLife(0.3) -- particles will be short lived (around 0.3 sec if we don't account for life randomness) +emitter_component.SetSize(0.1) -- adjust starting particle size + +runProcess(function() + while true do + emitter_component.Burst(50) -- Burst 50 particles at once + waitSeconds(2) -- then wait for 2 seconds before bursting again + end +end) + +backlog_post("---> END SCRIPT: emitter_burst.lua") diff --git a/scripts/move_object.lua b/scripts/move_object.lua index fe7b1bc45..d350b28e5 100644 --- a/scripts/move_object.lua +++ b/scripts/move_object.lua @@ -1,4 +1,5 @@ -- This script will load a teapot model with lights, and move the teapot's lid up and down +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: move_object.lua") diff --git a/scripts/pick.lua b/scripts/pick.lua index 5c97723c4..edda30cce 100644 --- a/scripts/pick.lua +++ b/scripts/pick.lua @@ -1,4 +1,5 @@ -- This script will load a teapot model and demonstrate picking it with a ray +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: pick.lua") @@ -9,7 +10,7 @@ model_entity = LoadModel("../models/teapot.wiscene") runProcess(function() local t = 0 while true do - t = t + 0.05 + t = t + 0.02 -- Create a Ray by specifying origin and direction (and also animate the ray origin along sine wave): local ray = Ray(Vector(math.sin(t) * 4,1,-10), Vector(0,0,1)) diff --git a/scripts/rotate_model.lua b/scripts/rotate_model.lua index 2f428c091..cefe33749 100644 --- a/scripts/rotate_model.lua +++ b/scripts/rotate_model.lua @@ -1,4 +1,5 @@ -- This script will load a teapot model with lights and rotate the whole model +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: rotate_model.lua") diff --git a/scripts/set_material_color.lua b/scripts/set_material_color.lua index 70ea4091b..b7afffed4 100644 --- a/scripts/set_material_color.lua +++ b/scripts/set_material_color.lua @@ -1,4 +1,5 @@ -- This script will load a teapot model and animate its base color between red and green +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: set_material_color.lua") diff --git a/scripts/set_material_emissive.lua b/scripts/set_material_emissive.lua index a7d67ee47..0ae70201b 100644 --- a/scripts/set_material_emissive.lua +++ b/scripts/set_material_emissive.lua @@ -1,4 +1,5 @@ -- This script will load a teapot model and animate its emissive color and intensity +killProcesses() -- stops all running lua coroutine processes backlog_post("---> START SCRIPT: set_material_color.lua")