diff --git a/bin/resources/bloom_bright.nzsl b/bin/resources/bloom_bright.nzsl index ad9c608c6..eeb831f55 100644 --- a/bin/resources/bloom_bright.nzsl +++ b/bin/resources/bloom_bright.nzsl @@ -15,7 +15,7 @@ struct ViewerData external { [set(0), binding(0)] viewerData: uniform, - [set(1), binding(0)] colorTexture: sampler2D, + [set(0), binding(1)] colorTexture: sampler2D, } struct FragIn diff --git a/bin/resources/bloom_final.nzsl b/bin/resources/bloom_final.nzsl index 1f218731c..b8a645713 100644 --- a/bin/resources/bloom_final.nzsl +++ b/bin/resources/bloom_final.nzsl @@ -15,8 +15,8 @@ struct ViewerData external { [set(0), binding(0)] viewerData: uniform, - [set(1), binding(0)] colorTexture: sampler2D, - [set(1), binding(1)] bloomTexture: sampler2D, + [set(0), binding(1)] colorTexture: sampler2D, + [set(0), binding(2)] bloomTexture: sampler2D, } struct FragIn diff --git a/bin/resources/deferred_frag.nzsl b/bin/resources/deferred_frag.nzsl index 0727b6e2a..ce83f2179 100644 --- a/bin/resources/deferred_frag.nzsl +++ b/bin/resources/deferred_frag.nzsl @@ -32,11 +32,12 @@ struct ViewerData external { - [set(0), binding(0)] viewerData: uniform, - [set(1), binding(0)] instanceData: uniform, - [set(2), binding(0)] settings: uniform, - [set(2), binding(2)] MaterialAlphaMap: sampler2D, - [set(2), binding(1)] MaterialDiffuseMap: sampler2D + [binding(0)] settings: uniform, + [binding(1)] MaterialDiffuseMap: sampler2D, + [binding(2)] MaterialAlphaMap: sampler2D, + [binding(3)] TextureOverlay: sampler2D, + [binding(4)] instanceData: uniform, + [binding(5)] viewerData: uniform, } struct InputData diff --git a/bin/resources/deferred_vert.nzsl b/bin/resources/deferred_vert.nzsl index 69d810dae..a5abeee63 100644 --- a/bin/resources/deferred_vert.nzsl +++ b/bin/resources/deferred_vert.nzsl @@ -28,9 +28,9 @@ struct ViewerData external { - [set(0), binding(0)] viewerData: uniform, - [set(1), binding(0)] instanceData: uniform, - [set(2), binding(0)] settings: uniform, + [binding(0)] settings: uniform, + [binding(4)] instanceData: uniform, + [binding(5)] viewerData: uniform, } struct InputData diff --git a/bin/resources/gaussian_blur.nzsl b/bin/resources/gaussian_blur.nzsl index 209308710..63c3e2c3d 100644 --- a/bin/resources/gaussian_blur.nzsl +++ b/bin/resources/gaussian_blur.nzsl @@ -15,7 +15,7 @@ struct ViewerData external { [set(0), binding(0)] viewerData: uniform, - [set(1), binding(0)] colorTexture: sampler2D, + [set(0), binding(1)] colorTexture: sampler2D, } struct FragIn diff --git a/bin/resources/lighting.nzsl b/bin/resources/lighting.nzsl index 176bd4f3e..74ee4da40 100644 --- a/bin/resources/lighting.nzsl +++ b/bin/resources/lighting.nzsl @@ -41,19 +41,14 @@ struct ViewerData [set(0)] external { - [binding(0)] viewerData: uniform + [binding(0)] viewerData: uniform, + [binding(1)] colorTexture: sampler2D, + [binding(2)] normalTexture: sampler2D, + [binding(3)] positionTexture: sampler2D, } [set(1)] external -{ - [binding(0)] colorTexture: sampler2D, - [binding(1)] normalTexture: sampler2D, - [binding(2)] positionTexture: sampler2D, -} - -[set(2)] -external { [binding(0)] lightParameters: uniform, } diff --git a/bin/resources/skybox.nzsl b/bin/resources/skybox.nzsl index e51b81d0f..a08f826b5 100644 --- a/bin/resources/skybox.nzsl +++ b/bin/resources/skybox.nzsl @@ -14,7 +14,8 @@ struct ViewerData external { - [set(1), binding(0)] skybox: samplerCube + [binding(0)] viewerData: uniform, + [binding(1)] skybox: samplerCube } struct VertOut @@ -40,11 +41,6 @@ fn main(input: VertOut) -> FragOut return output; } -external -{ - [set(0), binding(0)] viewerData: uniform -} - struct VertIn { [location(0)] position: vec3 diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index 1045f8df2..da74d1f93 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -129,11 +129,11 @@ int main() std::shared_ptr cubeMeshGfx = std::make_shared(*cubeMesh); Nz::RenderPipelineLayoutInfo skyboxPipelineLayoutInfo; - Nz::Graphics::FillViewerPipelineLayout(skyboxPipelineLayoutInfo); + Nz::Graphics::FillViewerPipelineLayout(skyboxPipelineLayoutInfo, 0); auto& textureBinding = skyboxPipelineLayoutInfo.bindings.emplace_back(); - textureBinding.setIndex = 1; - textureBinding.bindingIndex = 0; + textureBinding.setIndex = 0; + textureBinding.bindingIndex = 1; textureBinding.shaderStageFlags = Nz::ShaderStageType::Fragment; textureBinding.type = Nz::ShaderBindingType::Texture; @@ -238,20 +238,20 @@ int main() Nz::RenderPipelineLayoutInfo lightingPipelineLayoutInfo; - Nz::Graphics::FillViewerPipelineLayout(lightingPipelineLayoutInfo); + Nz::Graphics::FillViewerPipelineLayout(lightingPipelineLayoutInfo, 0); for (unsigned int i = 0; i < 3; ++i) { lightingPipelineLayoutInfo.bindings.push_back({ - 1, - i, + 0, + i + 1, Nz::ShaderBindingType::Texture, Nz::ShaderStageType::Fragment, }); } lightingPipelineLayoutInfo.bindings.push_back({ - 2, + 1, 0, Nz::ShaderBindingType::UniformBuffer, Nz::ShaderStageType::Fragment | Nz::ShaderStageType::Vertex, @@ -334,10 +334,10 @@ int main() // Bloom data Nz::RenderPipelineLayoutInfo bloomPipelineLayoutInfo; - Nz::Graphics::FillViewerPipelineLayout(bloomPipelineLayoutInfo); + Nz::Graphics::FillViewerPipelineLayout(bloomPipelineLayoutInfo, 0); bloomPipelineLayoutInfo.bindings.push_back({ - 1, 0, + 0, 1, Nz::ShaderBindingType::Texture, Nz::ShaderStageType::Fragment, }); @@ -362,16 +362,16 @@ int main() Nz::RenderPipelineLayoutInfo bloomBlendPipelineLayoutInfo; - Nz::Graphics::FillViewerPipelineLayout(bloomBlendPipelineLayoutInfo); + Nz::Graphics::FillViewerPipelineLayout(bloomBlendPipelineLayoutInfo, 0); bloomBlendPipelineLayoutInfo.bindings.push_back({ - 1, 0, + 0, 1, Nz::ShaderBindingType::Texture, Nz::ShaderStageType::Fragment, }); bloomBlendPipelineLayoutInfo.bindings.push_back({ - 1, 1, + 0, 2, Nz::ShaderBindingType::Texture, Nz::ShaderStageType::Fragment, }); @@ -519,10 +519,17 @@ int main() std::shared_ptr textureSampler = device->InstantiateTextureSampler({}); - std::shared_ptr skyboxShaderBinding = skyboxPipelineLayout->AllocateShaderBinding(1); + std::shared_ptr skyboxShaderBinding = skyboxPipelineLayout->AllocateShaderBinding(0); skyboxShaderBinding->Update({ { 0, + Nz::ShaderBinding::UniformBufferBinding { + viewerInstance.GetViewerBuffer().get(), + 0, viewerInstance.GetViewerBuffer()->GetSize() + } + }, + { + 1, Nz::ShaderBinding::TextureBinding { skyboxTexture.get(), textureSampler.get() @@ -645,8 +652,6 @@ int main() builder.SetScissor(renderArea); builder.SetViewport(renderArea); - builder.BindShaderBinding(Nz::Graphics::ViewerBindingSet, viewerInstance.GetShaderBinding()); - std::vector> elements; spaceshipModel.BuildElement(forwardPassIndex, modelInstance1, elements); spaceshipModel.BuildElement(forwardPassIndex, modelInstance2, elements); @@ -656,7 +661,10 @@ int main() for (const auto& element : elements) elementPointers.emplace_back(element.get()); - submeshRenderer.Render(*submeshRendererData, builder, elementPointers.data(), elementPointers.size()); + Nz::RenderFrame dummy; + + submeshRenderer.Prepare(viewerInstance, *submeshRendererData, dummy, elementPointers.data(), elementPointers.size()); + submeshRenderer.Render(viewerInstance, *submeshRendererData, builder, elementPointers.data(), elementPointers.size()); }); Nz::FramePass& lightingPass = graph.AddPass("Lighting pass"); @@ -674,12 +682,11 @@ int main() builder.BindIndexBuffer(*coneMeshGfx->GetIndexBuffer(0).get()); builder.BindVertexBuffer(0, *coneMeshGfx->GetVertexBuffer(0).get()); - builder.BindShaderBinding(0, viewerInstance.GetShaderBinding()); - builder.BindShaderBinding(1, *gbufferShaderBinding); + builder.BindShaderBinding(0, *gbufferShaderBinding); for (std::size_t i = 0; i < spotLights.size(); ++i) { - builder.BindShaderBinding(2, *lightingShaderBindings[i]); + builder.BindShaderBinding(1, *lightingShaderBindings[i]); builder.BindPipeline(*stencilPipeline); builder.DrawIndexed(coneMeshGfx->GetIndexCount(0)); @@ -702,14 +709,13 @@ int main() builder.SetScissor(renderArea); builder.SetViewport(renderArea); - builder.BindShaderBinding(0, viewerInstance.GetShaderBinding()); - builder.BindShaderBinding(1, *skyboxShaderBinding); + builder.BindShaderBinding(0, *skyboxShaderBinding); builder.BindIndexBuffer(*cubeMeshGfx->GetIndexBuffer(0)); builder.BindVertexBuffer(0, *cubeMeshGfx->GetVertexBuffer(0)); builder.BindPipeline(*skyboxPipeline); - builder.DrawIndexed(static_cast(cubeMeshGfx->GetIndexCount(0))); + builder.DrawIndexed(Nz::SafeCast(cubeMeshGfx->GetIndexCount(0))); }); forwardPass.SetExecutionCallback([&] { @@ -727,8 +733,7 @@ int main() builder.SetScissor(renderArea); builder.SetViewport(renderArea); - builder.BindShaderBinding(0, viewerInstance.GetShaderBinding()); - builder.BindShaderBinding(1, *bloomBrightShaderBinding); + builder.BindShaderBinding(0, *bloomBrightShaderBinding); builder.BindPipeline(*bloomBrightPipeline); builder.BindVertexBuffer(0, *fullscreenVertexBuffer); @@ -749,8 +754,7 @@ int main() builder.SetScissor(renderArea); builder.SetViewport(renderArea); - builder.BindShaderBinding(0, viewerInstance.GetShaderBinding()); - builder.BindShaderBinding(1, *gaussianBlurShaderBinding); + builder.BindShaderBinding(0, *gaussianBlurShaderBinding); builder.BindPipeline(*gaussianBlurPipeline); builder.BindVertexBuffer(0, *fullscreenVertexBuffer); @@ -770,8 +774,7 @@ int main() builder.SetScissor(renderArea); builder.SetViewport(renderArea); - builder.BindShaderBinding(0, viewerInstance.GetShaderBinding()); - builder.BindShaderBinding(1, *bloomBlendShaderBinding); + builder.BindShaderBinding(0, *bloomBlendShaderBinding); builder.BindPipeline(*bloomBlendPipeline); builder.BindVertexBuffer(0, *fullscreenVertexBuffer); @@ -936,24 +939,31 @@ int main() { frame.PushForRelease(std::move(gbufferShaderBinding)); - gbufferShaderBinding = lightingPipelineInfo.pipelineLayout->AllocateShaderBinding(1); + gbufferShaderBinding = lightingPipelineInfo.pipelineLayout->AllocateShaderBinding(0); gbufferShaderBinding->Update({ { 0, + Nz::ShaderBinding::UniformBufferBinding { + viewerInstance.GetViewerBuffer().get(), + 0, viewerInstance.GetViewerBuffer()->GetSize() + } + }, + { + 1, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(colorTexture).get(), textureSampler.get() } }, { - 1, + 2, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(normalTexture).get(), textureSampler.get() } }, { - 2, + 3, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(positionTexture).get(), textureSampler.get() @@ -966,7 +976,7 @@ int main() for (std::size_t i = 0; i < MaxPointLight; ++i) { - std::shared_ptr lightingShaderBinding = lightingPipelineInfo.pipelineLayout->AllocateShaderBinding(2); + std::shared_ptr lightingShaderBinding = lightingPipelineInfo.pipelineLayout->AllocateShaderBinding(1); lightingShaderBinding->Update({ { 0, @@ -982,10 +992,17 @@ int main() frame.PushForRelease(std::move(bloomBrightShaderBinding)); - bloomBrightShaderBinding = bloomPipelineInfo.pipelineLayout->AllocateShaderBinding(1); + bloomBrightShaderBinding = bloomPipelineInfo.pipelineLayout->AllocateShaderBinding(0); bloomBrightShaderBinding->Update({ { 0, + Nz::ShaderBinding::UniformBufferBinding { + viewerInstance.GetViewerBuffer().get(), + 0, viewerInstance.GetViewerBuffer()->GetSize() + } + }, + { + 1, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(lightOutput).get(), textureSampler.get() @@ -995,10 +1012,17 @@ int main() frame.PushForRelease(std::move(gaussianBlurShaderBinding)); - gaussianBlurShaderBinding = bloomPipelineInfo.pipelineLayout->AllocateShaderBinding(1); + gaussianBlurShaderBinding = bloomPipelineInfo.pipelineLayout->AllocateShaderBinding(0); gaussianBlurShaderBinding->Update({ { 0, + Nz::ShaderBinding::UniformBufferBinding { + viewerInstance.GetViewerBuffer().get(), + 0, viewerInstance.GetViewerBuffer()->GetSize() + } + }, + { + 1, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(bloomTextureA).get(), textureSampler.get() @@ -1008,17 +1032,24 @@ int main() frame.PushForRelease(std::move(bloomBlendShaderBinding)); - bloomBlendShaderBinding = bloomBlendPipelineInfo.pipelineLayout->AllocateShaderBinding(1); + bloomBlendShaderBinding = bloomBlendPipelineInfo.pipelineLayout->AllocateShaderBinding(0); bloomBlendShaderBinding->Update({ { 0, + Nz::ShaderBinding::UniformBufferBinding { + viewerInstance.GetViewerBuffer().get(), + 0, viewerInstance.GetViewerBuffer()->GetSize() + } + }, + { + 1, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(lightOutput).get(), textureSampler.get() } }, { - 1, + 2, Nz::ShaderBinding::TextureBinding { bakedGraph.GetAttachmentTexture(bloomTextureB).get(), textureSampler.get() diff --git a/examples/PhysicsDemo/main.cpp b/examples/PhysicsDemo/main.cpp index 0b402f7cd..fb22fe9d6 100644 --- a/examples/PhysicsDemo/main.cpp +++ b/examples/PhysicsDemo/main.cpp @@ -218,11 +218,11 @@ int main() registry.get(viewer).SetParent(registry, headingEntity); registry.get(viewer).SetPosition(Nz::Vector3f::Backward() * 2.5f + Nz::Vector3f::Up() * 1.f); - for (std::size_t x = 0; x < 1; ++x) + for (std::size_t x = 0; x < 2; ++x) { - for (std::size_t y = 0; y < 1; ++y) + for (std::size_t y = 0; y < 2; ++y) { - for (std::size_t z = 0; z < 1; ++z) + for (std::size_t z = 0; z < 2; ++z) { entt::entity entity = registry.create(); auto& entityGfx = registry.emplace(entity); diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index dcba6a776..260e3cda0 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -36,6 +36,16 @@ namespace Nz template void HashCombine(std::size_t& seed, const T& v); template bool IsPowerOfTwo(T value); template T ReverseBits(T integer); +#ifdef NAZARA_DEBUG + template && std::is_integral_v, int> = 0> To SafeCast(From value); + template && std::is_floating_point_v, int> = 0> To SafeCast(From value); + template && std::is_floating_point_v, int> = 0> To SafeCast(From value); + template && std::is_integral_v, int> = 0> To SafeCast(From value); + template&& std::is_integral_v, int> = 0> To SafeCast(From value); + template&& std::is_enum_v, int> = 0> To SafeCast(From value); +#else + template To SafeCast(From value); +#endif template constexpr auto UnderlyingCast(T value) -> std::underlying_type_t; template diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index b7125ef01..6bcb30e36 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -291,6 +292,75 @@ namespace Nz return reversed; } +#ifdef NAZARA_DEBUG + template && std::is_integral_v, int>> + To SafeCast(From value) + { + // Type capable of storing the biggest value between the two types + using MaxValueType = std::conditional_t<(sizeof(From) > sizeof(To) || (sizeof(From) == sizeof(To) && std::is_signed_v)), From, To>; + // Type capable of storing the smallest value between the two types + using MinValueType = std::conditional_t<(sizeof(From) > sizeof(To) || (sizeof(From) == sizeof(To) && std::is_signed_v)), From, To>; + + if constexpr (!std::is_signed_v) + assert(value >= 0); + + assert(static_cast(value) <= static_cast(std::numeric_limits::max())); + assert(static_cast(value) >= static_cast(std::numeric_limits::lowest())); + + return static_cast(value); + } + + template && std::is_floating_point_v, int>> + To SafeCast(From value) + { + // Type capable of storing the biggest value between the two types + using MaxValueType = std::conditional_t<(sizeof(From) > sizeof(To)), From, To>; + // Type capable of storing the smallest value between the two types + using MinValueType = std::conditional_t<(sizeof(From) > sizeof(To)), From, To>; + + assert(static_cast(value) <= static_cast(std::numeric_limits::max())); + assert(static_cast(value) >= static_cast(std::numeric_limits::lowest())); + + return static_cast(value); + } + + template && std::is_floating_point_v, int>> + To SafeCast(From value) + { + assert(floor(value) == value); + + assert(value <= static_cast(std::numeric_limits::max())); + assert(value >= static_cast(std::numeric_limits::lowest())); + + return static_cast(value); + } + + template && std::is_integral_v, int>> + To SafeCast(From value) + { + return static_cast(value); + } + + template && std::is_integral_v, int>> + To SafeCast(From value) + { + return static_cast(SafeCast>(value)); + } + + template && std::is_enum_v, int>> + To SafeCast(From value) + { + return SafeCast(static_cast>(value)); + } + +#else + template + To SafeCast(From value) + { + return static_cast(value); + } +#endif + template constexpr auto UnderlyingCast(T value) -> std::underlying_type_t { diff --git a/include/Nazara/Graphics/ElementRenderer.hpp b/include/Nazara/Graphics/ElementRenderer.hpp index ea6a4da96..31d998df2 100644 --- a/include/Nazara/Graphics/ElementRenderer.hpp +++ b/include/Nazara/Graphics/ElementRenderer.hpp @@ -19,6 +19,7 @@ namespace Nz class CommandBufferBuilder; class RenderElement; class RenderFrame; + class ViewerInstance; struct ElementRendererData; class NAZARA_GRAPHICS_API ElementRenderer @@ -28,8 +29,8 @@ namespace Nz virtual ~ElementRenderer(); virtual std::unique_ptr InstanciateData() = 0; - virtual void Prepare(ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer* elements, std::size_t elementCount); - virtual void Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* elements, std::size_t elementCount) = 0; + virtual void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer* elements, std::size_t elementCount); + virtual void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* elements, std::size_t elementCount) = 0; virtual void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame); }; diff --git a/include/Nazara/Graphics/Enums.hpp b/include/Nazara/Graphics/Enums.hpp index a1b985a98..20c811cb2 100644 --- a/include/Nazara/Graphics/Enums.hpp +++ b/include/Nazara/Graphics/Enums.hpp @@ -50,6 +50,17 @@ namespace Nz Orthographic, Perspective }; + + enum class PredefinedShaderBinding + { + InstanceDataUbo, + OverlayTexture, + ViewerDataUbo, + + Max = ViewerDataUbo + }; + + constexpr std::size_t PredefinedShaderBindingCount = static_cast(PredefinedShaderBinding::Max) + 1; } #endif // NAZARA_GRAPHICS_ENUMS_HPP diff --git a/include/Nazara/Graphics/ForwardFramePipeline.hpp b/include/Nazara/Graphics/ForwardFramePipeline.hpp index 135356944..f93233090 100644 --- a/include/Nazara/Graphics/ForwardFramePipeline.hpp +++ b/include/Nazara/Graphics/ForwardFramePipeline.hpp @@ -87,6 +87,7 @@ namespace Nz RenderQueue depthPrepassRenderQueue; RenderQueue forwardRenderQueue; ShaderBindingPtr blitShaderBinding; + bool prepare = true; bool rebuildDepthPrepass = true; bool rebuildForwardPass = true; }; diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index f08ece840..93a3f926d 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -42,7 +42,6 @@ namespace Nz inline MaterialPassRegistry& GetMaterialPassRegistry(); inline const MaterialPassRegistry& GetMaterialPassRegistry() const; inline PixelFormat GetPreferredDepthStencilFormat() const; - inline const std::shared_ptr& GetReferencePipelineLayout() const; inline const std::shared_ptr& GetRenderDevice() const; inline const RenderPassCache& GetRenderPassCache() const; inline TextureSamplerCache& GetSamplerCache(); @@ -55,17 +54,12 @@ namespace Nz struct DefaultTextures { - std::shared_ptr whiteTexture2d; + std::array, ImageTypeCount> whiteTextures; }; - static constexpr UInt32 DrawDataBindingSet = 2; - static constexpr UInt32 MaterialBindingSet = 3; - static constexpr UInt32 ViewerBindingSet = 0; - static constexpr UInt32 WorldBindingSet = 1; - - static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = DrawDataBindingSet); - static void FillViewerPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = ViewerBindingSet); - static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = WorldBindingSet); + static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set); + static void FillViewerPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set); + static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set); private: void BuildBlitPipeline(); @@ -80,7 +74,6 @@ namespace Nz std::shared_ptr m_renderDevice; std::shared_ptr m_blitPipeline; std::shared_ptr m_blitPipelineLayout; - std::shared_ptr m_referencePipelineLayout; std::shared_ptr m_fullscreenVertexDeclaration; DefaultTextures m_defaultTextures; MaterialPassRegistry m_materialPassRegistry; diff --git a/include/Nazara/Graphics/Graphics.inl b/include/Nazara/Graphics/Graphics.inl index b8d33f210..1f0fa8675 100644 --- a/include/Nazara/Graphics/Graphics.inl +++ b/include/Nazara/Graphics/Graphics.inl @@ -47,11 +47,6 @@ namespace Nz return m_preferredDepthStencilFormat; } - inline const std::shared_ptr& Graphics::GetReferencePipelineLayout() const - { - return m_referencePipelineLayout; - } - inline const std::shared_ptr& Graphics::GetRenderDevice() const { return m_renderDevice; diff --git a/include/Nazara/Graphics/Material.hpp b/include/Nazara/Graphics/Material.hpp index 042eb201e..27a1f7137 100644 --- a/include/Nazara/Graphics/Material.hpp +++ b/include/Nazara/Graphics/Material.hpp @@ -22,7 +22,7 @@ namespace Nz inline void AddPass(std::size_t passIndex, std::shared_ptr pass); inline void AddPass(std::string passName, std::shared_ptr pass); - inline MaterialPass* GetPass(std::size_t passIndex) const; + inline const std::shared_ptr& GetPass(std::size_t passIndex) const; inline bool HasPass(std::size_t passIndex) const; diff --git a/include/Nazara/Graphics/Material.inl b/include/Nazara/Graphics/Material.inl index e5055e34b..ebec3f1c9 100644 --- a/include/Nazara/Graphics/Material.inl +++ b/include/Nazara/Graphics/Material.inl @@ -21,17 +21,23 @@ namespace Nz return AddPass(registry.GetPassIndex(passName), std::move(pass)); } - inline MaterialPass* Material::GetPass(std::size_t passIndex) const + inline const std::shared_ptr& Material::GetPass(std::size_t passIndex) const { if (passIndex >= m_passes.size()) - return nullptr; + { + static std::shared_ptr dummy; + return dummy; + } - return m_passes[passIndex].get(); + return m_passes[passIndex]; } inline bool Material::HasPass(std::size_t passIndex) const { - return GetPass(passIndex) != nullptr; + if (passIndex >= m_passes.size()) + return false; + + return m_passes[passIndex] != nullptr; } inline void Material::RemovePass(std::size_t passIndex) diff --git a/include/Nazara/Graphics/MaterialPass.hpp b/include/Nazara/Graphics/MaterialPass.hpp index d863def35..fdb7bb124 100644 --- a/include/Nazara/Graphics/MaterialPass.hpp +++ b/include/Nazara/Graphics/MaterialPass.hpp @@ -52,6 +52,8 @@ namespace Nz inline void EnsurePipelineUpdate() const; + void FillShaderBinding(std::vector& bindings) const; + inline RendererComparison GetDepthCompareFunc() const; inline BlendEquation GetBlendAlphaModeEquation() const; inline BlendEquation GetBlendColorModeEquation() const; @@ -70,7 +72,6 @@ namespace Nz inline PrimitiveMode GetPrimitiveMode() const; inline const std::shared_ptr& GetSettings() const; inline const std::shared_ptr& GetShader(ShaderStageType shaderStage) const; - inline ShaderBinding& GetShaderBinding(); inline const std::shared_ptr& GetTexture(std::size_t textureIndex) const; inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const; inline const std::shared_ptr& GetUniformBuffer(std::size_t bufferIndex) const; @@ -109,12 +110,11 @@ namespace Nz NazaraSignal(OnMaterialRelease, const MaterialPass* /*material*/); private: + inline void InvalidateCommandBuffer(); inline void InvalidatePipeline(); - inline void InvalidateShaderBinding(); inline void InvalidateTextureSampler(std::size_t textureIndex); inline void InvalidateUniformData(std::size_t uniformBufferIndex); void UpdatePipeline() const; - void UpdateShaderBinding(); struct MaterialTexture { @@ -137,10 +137,8 @@ namespace Nz mutable std::shared_ptr m_pipeline; mutable MaterialPipelineInfo m_pipelineInfo; MaterialPassFlags m_flags; - ShaderBindingPtr m_shaderBinding; bool m_forceCommandBufferRegeneration; mutable bool m_pipelineUpdated; - bool m_shaderBindingUpdated; }; } diff --git a/include/Nazara/Graphics/MaterialPass.inl b/include/Nazara/Graphics/MaterialPass.inl index 011779eb2..a2c6a09c6 100644 --- a/include/Nazara/Graphics/MaterialPass.inl +++ b/include/Nazara/Graphics/MaterialPass.inl @@ -373,12 +373,6 @@ namespace Nz return m_pipelineInfo.shaders[UnderlyingCast(shaderStage)].uberShader; } - inline ShaderBinding& MaterialPass::GetShaderBinding() - { - assert(m_shaderBinding); - return *m_shaderBinding; - } - inline const std::shared_ptr& MaterialPass::GetTexture(std::size_t textureIndex) const { NazaraAssert(textureIndex < m_textures.size(), "Invalid texture index"); @@ -614,7 +608,8 @@ namespace Nz if (m_textures[textureIndex].texture != texture) { m_textures[textureIndex].texture = std::move(texture); - InvalidateShaderBinding(); + + InvalidateCommandBuffer(); } } @@ -624,6 +619,7 @@ namespace Nz if (m_textures[textureIndex].samplerInfo != samplerInfo) { m_textures[textureIndex].samplerInfo = std::move(samplerInfo); + InvalidateTextureSampler(textureIndex); } } @@ -635,10 +631,17 @@ namespace Nz { m_uniformBuffers[bufferIndex].buffer = std::move(uniformBuffer); m_uniformBuffers[bufferIndex].dataInvalidated = true; - InvalidateShaderBinding(); + + InvalidateCommandBuffer(); } } + inline void MaterialPass::InvalidateCommandBuffer() + { + m_forceCommandBufferRegeneration = true; + OnMaterialInvalidated(this); + } + inline void MaterialPass::InvalidatePipeline() { m_forceCommandBufferRegeneration = true; @@ -647,20 +650,12 @@ namespace Nz OnMaterialInvalidated(this); } - inline void MaterialPass::InvalidateShaderBinding() - { - m_forceCommandBufferRegeneration = true; - m_shaderBindingUpdated = false; - - OnMaterialInvalidated(this); - } - inline void MaterialPass::InvalidateTextureSampler(std::size_t textureIndex) { assert(textureIndex < m_textures.size()); m_textures[textureIndex].sampler.reset(); - InvalidateShaderBinding(); + InvalidateCommandBuffer(); } inline void MaterialPass::InvalidateUniformData(std::size_t uniformBufferIndex) @@ -674,4 +669,3 @@ namespace Nz } #include -#include "MaterialPass.hpp" diff --git a/include/Nazara/Graphics/MaterialSettings.hpp b/include/Nazara/Graphics/MaterialSettings.hpp index 6df859238..ce572a19e 100644 --- a/include/Nazara/Graphics/MaterialSettings.hpp +++ b/include/Nazara/Graphics/MaterialSettings.hpp @@ -28,6 +28,7 @@ namespace Nz struct SharedUniformBlock; struct Texture; struct UniformBlock; + using PredefinedBinding = std::array; inline MaterialSettings(); inline MaterialSettings(Builder builder); @@ -38,6 +39,7 @@ namespace Nz inline const Builder& GetBuilderData() const; inline const std::vector