From d7eab778fb2d0ab7102e986d0faaf4da0cbb12db Mon Sep 17 00:00:00 2001 From: SirLynix Date: Tue, 22 Nov 2022 18:16:06 +0100 Subject: [PATCH] Graphics/FrameGraph: Add FramePassAttachmentSize enum instead of boolean --- examples/DeferredShading/main.cpp | 5 +++ include/Nazara/Graphics/BakedFrameGraph.hpp | 2 +- include/Nazara/Graphics/FrameGraph.hpp | 2 +- .../Nazara/Graphics/FramePassAttachment.hpp | 8 +++- src/Nazara/Graphics/BakedFrameGraph.cpp | 43 +++++++++++-------- src/Nazara/Graphics/ForwardFramePipeline.cpp | 2 +- src/Nazara/Graphics/FrameGraph.cpp | 10 ++--- src/Nazara/Graphics/TextSprite.cpp | 6 +-- 8 files changed, 48 insertions(+), 30 deletions(-) diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index f92bab1c3..b3e96bcb5 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -719,6 +719,7 @@ int main() godRaysTexture = graph.AddAttachment({ "God rays texture", Nz::PixelFormat::RGBA16F, + Nz::FramePassAttachmentSize::SwapchainFactor, 50'000, 50'000 }); @@ -729,6 +730,7 @@ int main() bloomBrightOutput = graph.AddAttachment({ "Bloom bright output", Nz::PixelFormat::RGBA16F, + Nz::FramePassAttachmentSize::SwapchainFactor, bloomSize, bloomSize }); @@ -738,6 +740,7 @@ int main() bloomTextures[i * 2 + 0] = graph.AddAttachment({ "Bloom texture #" + std::to_string(i), Nz::PixelFormat::RGBA16F, + Nz::FramePassAttachmentSize::SwapchainFactor, bloomSize, bloomSize }); @@ -746,6 +749,7 @@ int main() bloomTextures[i * 2 + 1] = graph.AddAttachment({ "Bloom texture #" + std::to_string(i), Nz::PixelFormat::RGBA16F, + Nz::FramePassAttachmentSize::SwapchainFactor, bloomSize, bloomSize }); @@ -756,6 +760,7 @@ int main() toneMappingOutput = graph.AddAttachment({ "Tone mapping", Nz::PixelFormat::RGBA8, + Nz::FramePassAttachmentSize::SwapchainFactor, 100'000, 100'000 }); diff --git a/include/Nazara/Graphics/BakedFrameGraph.hpp b/include/Nazara/Graphics/BakedFrameGraph.hpp index 6ddc482ef..2fd9a7059 100644 --- a/include/Nazara/Graphics/BakedFrameGraph.hpp +++ b/include/Nazara/Graphics/BakedFrameGraph.hpp @@ -85,11 +85,11 @@ namespace Nz { std::string name; std::shared_ptr texture; + FramePassAttachmentSize size; PixelFormat format; TextureUsageFlags usage; unsigned int width; unsigned int height; - bool hasFixedSize; }; std::shared_ptr m_commandPool; diff --git a/include/Nazara/Graphics/FrameGraph.hpp b/include/Nazara/Graphics/FrameGraph.hpp index b0201bfde..b65efac0c 100644 --- a/include/Nazara/Graphics/FrameGraph.hpp +++ b/include/Nazara/Graphics/FrameGraph.hpp @@ -88,10 +88,10 @@ namespace Nz { std::string name; PixelFormat format; + FramePassAttachmentSize size; TextureUsageFlags usage; unsigned int width; unsigned int height; - bool hasFixedSize; }; struct WorkData diff --git a/include/Nazara/Graphics/FramePassAttachment.hpp b/include/Nazara/Graphics/FramePassAttachment.hpp index 26b04ef63..0723cab99 100644 --- a/include/Nazara/Graphics/FramePassAttachment.hpp +++ b/include/Nazara/Graphics/FramePassAttachment.hpp @@ -14,13 +14,19 @@ namespace Nz { + enum class FramePassAttachmentSize + { + Fixed, + SwapchainFactor + }; + struct FramePassAttachment { std::string name; PixelFormat format; + FramePassAttachmentSize size = FramePassAttachmentSize::SwapchainFactor; unsigned int width = 100'000; unsigned int height = 100'000; - bool hasFixedSize = false; }; } diff --git a/src/Nazara/Graphics/BakedFrameGraph.cpp b/src/Nazara/Graphics/BakedFrameGraph.cpp index 9152ebf4e..32a238e37 100644 --- a/src/Nazara/Graphics/BakedFrameGraph.cpp +++ b/src/Nazara/Graphics/BakedFrameGraph.cpp @@ -153,15 +153,20 @@ namespace Nz textureCreationParams.type = ImageType::E2D; textureCreationParams.usageFlags = textureData.usage; textureCreationParams.pixelFormat = textureData.format; - if (textureData.hasFixedSize) + + textureCreationParams.width = 1; + textureCreationParams.height = 1; + switch (textureData.size) { - textureCreationParams.width = textureData.width; - textureCreationParams.height = textureData.height; - } - else - { - textureCreationParams.width = textureData.width * frameWidth / 100'000; - textureCreationParams.height = textureData.height * frameHeight / 100'000; + case FramePassAttachmentSize::Fixed: + textureCreationParams.width = textureData.width; + textureCreationParams.height = textureData.height; + break; + + case FramePassAttachmentSize::SwapchainFactor: + textureCreationParams.width = frameWidth * textureData.width / 100'000; + textureCreationParams.height = frameHeight * textureData.height / 100'000; + break; } textureData.texture = renderDevice->InstantiateTexture(textureCreationParams); @@ -181,17 +186,19 @@ namespace Nz auto& textureData = m_textures[textureId]; textures.push_back(textureData.texture); - unsigned int width; - unsigned int height; - if (textureData.hasFixedSize) + unsigned int width = 1; + unsigned int height = 1; + switch (textureData.size) { - width = textureData.width; - height = textureData.height; - } - else - { - width = frameWidth * textureData.width / 100'000; - height = frameHeight * textureData.height / 100'000; + case FramePassAttachmentSize::Fixed: + width = textureData.width; + height = textureData.height; + break; + + case FramePassAttachmentSize::SwapchainFactor: + width = frameWidth * textureData.width / 100'000; + height = frameHeight * textureData.height / 100'000; + break; } framebufferWidth = std::min(framebufferWidth, width); diff --git a/src/Nazara/Graphics/ForwardFramePipeline.cpp b/src/Nazara/Graphics/ForwardFramePipeline.cpp index b49a7b7fe..3bb51a8b7 100644 --- a/src/Nazara/Graphics/ForwardFramePipeline.cpp +++ b/src/Nazara/Graphics/ForwardFramePipeline.cpp @@ -581,8 +581,8 @@ namespace Nz lightData->shadowMapAttachmentIndex = frameGraph.AddAttachment({ "Shadowmap", shadowMapFormat, + FramePassAttachmentSize::Fixed, shadowMapSize, shadowMapSize, - true // fixed size }); if (!lightData->camera) diff --git a/src/Nazara/Graphics/FrameGraph.cpp b/src/Nazara/Graphics/FrameGraph.cpp index 7b5a15516..da0f3c5c5 100644 --- a/src/Nazara/Graphics/FrameGraph.cpp +++ b/src/Nazara/Graphics/FrameGraph.cpp @@ -115,10 +115,10 @@ namespace Nz auto& bakedTexture = bakedTextures.emplace_back(); bakedTexture.name = std::move(texture.name); bakedTexture.format = texture.format; - bakedTexture.hasFixedSize = texture.hasFixedSize; bakedTexture.height = texture.height; - bakedTexture.usage = texture.usage; - bakedTexture.width = texture.width; + bakedTexture.size = texture.size; + bakedTexture.usage = texture.usage; + bakedTexture.width = texture.width; } return BakedFrameGraph(std::move(bakedPasses), std::move(bakedTextures), std::move(m_pending.attachmentToTextures), std::move(m_pending.passIdToPhysicalPassIndex)); @@ -954,7 +954,7 @@ namespace Nz if (data.format != attachmentData.format || data.width != attachmentData.width || data.height != attachmentData.height || - data.hasFixedSize != attachmentData.hasFixedSize) + data.size != attachmentData.size) continue; m_pending.texturePool.erase(it); @@ -974,7 +974,7 @@ namespace Nz data.format = attachmentData.format; data.width = attachmentData.width; data.height = attachmentData.height; - data.hasFixedSize = attachmentData.hasFixedSize; + data.size = attachmentData.size; return textureId; } diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 06dd4a500..64e70c403 100644 --- a/src/Nazara/Graphics/TextSprite.cpp +++ b/src/Nazara/Graphics/TextSprite.cpp @@ -198,15 +198,15 @@ namespace Nz std::size_t offset = indices->first + indices->count; offset *= 4; - for (std::size_t index : { 0, 2, 1, 3 }) + for (std::size_t cornerIndex : { 0, 2, 1, 3 }) { // Set the position, color and UV of our vertices // Remember that indices->count is a counter here, not a count value m_vertices[offset].color = glyph.color; - m_vertices[offset].position = glyph.corners[index]; + m_vertices[offset].position = glyph.corners[cornerIndex]; m_vertices[offset].position.y = bounds.height - m_vertices[offset].position.y; m_vertices[offset].position *= scale; - m_vertices[offset].uv.Set(uvRect.GetCorner((glyph.flipped) ? flippedCorners[index] : normalCorners[index])); + m_vertices[offset].uv.Set(uvRect.GetCorner((glyph.flipped) ? flippedCorners[cornerIndex] : normalCorners[cornerIndex])); offset++; }