9#include <Common/EnumTraits.hpp>
10#include <Common/Graphics/Formats.hpp>
11#include <Common/Graphics/Image.hpp>
13#include "RenderGraphResourceRef.hpp"
15namespace Grindstone::Renderer {
19 enum class ImageSizeInfo : uint32_t {
24 ViewportRelative = 1u << 30u,
27 SwapchainRelative = 1u << 31u,
29 MetaBits = Multiply | ViewportRelative | SwapchainRelative,
30 SizeBits = ~static_cast<uint32_t>(MetaBits)
33 bool operator==(
const MetaSize& other)
const {
34 return value == other.value;
37 explicit operator uint32_t()
const {
41 static const MetaSize Pixels(uint32_t x) {
return { .value = x }; };
42 static const MetaSize Viewport() {
return {
static_cast<uint32_t
>(ImageSizeInfo::ViewportRelative) }; };
43 static const MetaSize Swapchain() {
return {
static_cast<uint32_t
>(ImageSizeInfo::SwapchainRelative) }; };
44 static MetaSize MultiplyViewport(uint32_t x) {
return {
static_cast<uint32_t
>(ImageSizeInfo::ViewportRelative) |
static_cast<uint32_t
>(ImageSizeInfo::Multiply) | x }; }
45 static MetaSize MultiplySwapchain(uint32_t x) {
return {
static_cast<uint32_t
>(ImageSizeInfo::SwapchainRelative) |
static_cast<uint32_t
>(ImageSizeInfo::Multiply) | x }; }
47 static MetaSize DivideViewport(uint32_t x) {
return {
static_cast<uint32_t
>(ImageSizeInfo::ViewportRelative) | x }; }
48 static MetaSize DivideSwapchain(uint32_t x) {
return {
static_cast<uint32_t
>(ImageSizeInfo::SwapchainRelative) | x }; }
50 inline bool IsSwapchainRelative()
const {
51 return value &
static_cast<uint32_t
>(ImageSizeInfo::SwapchainRelative);
54 inline bool IsViewportRelative()
const {
55 return value &
static_cast<uint32_t
>(ImageSizeInfo::ViewportRelative);
58 inline bool IsMultiply()
const {
59 return value &
static_cast<uint32_t
>(ImageSizeInfo::Multiply);
62 inline bool IsDivide()
const {
63 return (value &
static_cast<uint32_t
>(ImageSizeInfo::Multiply)) == 0;
66 uint32_t Resolve(uint32_t viewportResolution, uint32_t swapchainResolution)
const {
67 uint32_t size = value &
static_cast<uint32_t
>(ImageSizeInfo::SizeBits);
68 bool isAbsoluteSize = (size == 0);
70 if (IsViewportRelative()) {
74 : viewportResolution * size;
79 : viewportResolution / size;
82 else if (IsSwapchainRelative()) {
86 : swapchainResolution * size;
91 : swapchainResolution / size;
104 static const MetaSize2D Zero() {
return { 0, 0 }; };
106 static const MetaSize2D Pixels(uint32_t x, uint32_t y) {
return { MetaSize::Pixels(x), MetaSize::Pixels(y) }; };
107 static const MetaSize2D Viewport() {
return { MetaSize::Viewport(), MetaSize::Viewport() }; };
108 static const MetaSize2D Swapchain() {
return { MetaSize::Swapchain(), MetaSize::Swapchain() }; };
110 static MetaSize2D MultiplyViewport(uint32_t x) {
return { MetaSize::MultiplyViewport(x), MetaSize::MultiplyViewport(x) }; }
111 static MetaSize2D MultiplySwapchain(uint32_t x) {
return { MetaSize::MultiplySwapchain(x), MetaSize::MultiplySwapchain(x) }; }
113 static MetaSize2D DivideViewport(uint32_t x) {
return { MetaSize::DivideViewport(x), MetaSize::DivideViewport(x) }; }
114 static MetaSize2D DivideSwapchain(uint32_t x) {
return { MetaSize::DivideSwapchain(x), MetaSize::DivideSwapchain(x) }; }
116 bool operator==(
const MetaSize2D& other)
const {
117 return x == other.x && y == other.y;
120 Grindstone::Math::Uint2 Resolve(Grindstone::Math::Uint2 viewportResolution, Grindstone::Math::Uint2 swapchainResolution)
const {
121 return { x.Resolve(viewportResolution.x, swapchainResolution.x), y.Resolve(viewportResolution.y, swapchainResolution.y) };
124 Grindstone::Math::Uint2 Resolve(Grindstone::Math::Uint2 swapchainResolution)
const {
125 GS_ASSERT(!x.IsViewportRelative());
126 GS_ASSERT(!y.IsViewportRelative());
127 return { x.Resolve(0, swapchainResolution.x), y.Resolve(0, swapchainResolution.y) };
135 static const MetaRect Pixels(uint32_t width, uint32_t height) {
136 return { MetaSize2D::Zero(), MetaSize2D::Pixels(width, height) };
138 static const MetaRect Pixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
139 return { MetaSize2D::Pixels(x, y), MetaSize2D::Pixels(width, height) };
141 static const MetaRect Viewport() {
return { MetaSize2D::Zero(), MetaSize2D::Viewport() }; }
142 static const MetaRect Swapchain() {
return { MetaSize2D::Zero(), MetaSize2D::Swapchain() }; }
144 bool operator==(
const MetaRect& other)
const {
145 return offset == other.offset && extent == other.extent;
148 Grindstone::Math::IntRect2D Resolve(Grindstone::Math::Uint2 viewportResolution, Grindstone::Math::Uint2 swapchainResolution)
const {
149 return { offset.Resolve(viewportResolution, swapchainResolution), extent.Resolve(viewportResolution, swapchainResolution) };
153 return { offset.Resolve(swapchainResolution), extent.Resolve(swapchainResolution) };
157 enum class RenderGraphImageUsage : uint16_t {
163 ColorAttachment = 1 << 4,
164 DepthAttachment = 1 << 5,
165 StencilAttachment = 1 << 6,
166 SubpassInputAttachment = 1 << 7,
169 SampledRead =
static_cast<uint16_t
>(RenderGraphImageUsage::Sampled) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
170 StorageRead =
static_cast<uint16_t
>(RenderGraphImageUsage::Storage) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
171 StorageWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::Storage) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
172 StorageReadWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::StorageRead) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
173 ColorAttachmentRead =
static_cast<uint16_t
>(RenderGraphImageUsage::ColorAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
174 ColorAttachmentWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::ColorAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
175 ColorAttachmentReadWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::ColorAttachmentRead) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
176 DepthAttachmentRead =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
177 DepthAttachmentWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
178 DepthAttachmentReadWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachmentRead) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
179 StencilAttachmentRead =
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
180 StencilAttachmentWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
181 StencilAttachmentReadWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachmentRead) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write),
182 DepthStencilAttachmentRead =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachmentRead) |
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachment),
183 DepthStencilAttachmentWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachmentWrite) |
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachment),
184 DepthStencilAttachmentReadWrite =
static_cast<uint16_t
>(RenderGraphImageUsage::DepthAttachmentReadWrite) |
static_cast<uint16_t
>(RenderGraphImageUsage::StencilAttachment),
185 SubpassInputAttachmentRead =
static_cast<uint16_t
>(RenderGraphImageUsage::SubpassInputAttachment) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
186 TransferSrc =
static_cast<uint16_t
>(RenderGraphImageUsage::Transfer) |
static_cast<uint16_t
>(RenderGraphImageUsage::Read),
187 TransferDst =
static_cast<uint16_t
>(RenderGraphImageUsage::Transfer) |
static_cast<uint16_t
>(RenderGraphImageUsage::Write)
191GS_ENUM_FLAGS_FUNCS(Grindstone::Renderer::RenderGraphImageUsage)
193namespace Grindstone::Renderer {
196 RenderGraphImageUsage usage;
199 Grindstone::GraphicsAPI::LoadOp loadOp;
205 bool IsRead()
const {
206 return Any(usage & RenderGraphImageUsage::Read);
209 bool IsWrite()
const {
210 return Any(usage & RenderGraphImageUsage::Write);
213 bool IsTransfer()
const {
214 return Any(usage & RenderGraphImageUsage::Transfer);
217 bool IsShaderInput()
const {
218 return Any(usage & (RenderGraphImageUsage::Sampled | RenderGraphImageUsage::Storage));
221 bool IsAttachment()
const {
222 return Any(usage & (RenderGraphImageUsage::ColorAttachment | RenderGraphImageUsage::DepthAttachment | RenderGraphImageUsage::StencilAttachment));
227 Grindstone::String name;
229 uint32_t samples = 1;
230 uint32_t mipLevels = 1;
232 uint32_t arrayLayers = 1;
233 Grindstone::GraphicsAPI::Format format;
235 GraphicsAPI::ImageDimension imageDimensions = GraphicsAPI::ImageDimension::Dimension2D;
236 GraphicsAPI::MemoryUsage memoryUsage = GraphicsAPI::MemoryUsage::GPUOnly;
239 Grindstone::GraphicsAPI::ImageLayout externalInitialLayout;
240 Grindstone::GraphicsAPI::AccessFlags externalInitialAccessFlags;
241 Grindstone::GraphicsAPI::PipelineStageBit externalInitialPipelineStage;
242 Grindstone::GraphicsAPI::ImageLayout externalFinalLayout;
243 Grindstone::GraphicsAPI::AccessFlags externalFinalAccessFlags;
244 Grindstone::GraphicsAPI::PipelineStageBit externalFinalPipelineStage;
249 size == other.size &&
250 samples == other.samples &&
251 mipLevels == other.mipLevels &&
252 arrayLayers == other.arrayLayers &&
253 depth == other.depth &&
254 format == other.format;
260 Grindstone::GraphicsAPI::LoadOp loadOp;
267 struct hash<Grindstone::Renderer::MetaSize> {
269 size_t result = std::hash<size_t>{}(
270 static_cast<size_t>(desc.value)
276 struct hash<Grindstone::Renderer::MetaSize2D> {
278 size_t result = std::hash<size_t>{}(
279 static_cast<size_t>(
static_cast<uint32_t
>(desc.x)) |
280 static_cast<size_t>(
static_cast<uint32_t
>(desc.y)) << 32
286 struct hash<Grindstone::Renderer::MetaRect> {
289 std::hash<Grindstone::Renderer::MetaSize2D>{}(desc.offset) ^
290 std::hash<Grindstone::Renderer::MetaSize2D>{}(desc.extent);
295 struct hash<Grindstone::Renderer::ImageDescription> {
297 size_t result = std::hash<Grindstone::Renderer::MetaSize2D>{}(desc.size);
299 result ^= std::hash<size_t>{}(
300 static_cast<size_t>(desc.samples) |
301 static_cast<size_t>(desc.mipLevels) << 32
304 result ^= std::hash<size_t>{}(
305 static_cast<size_t>(desc.depth) |
306 static_cast<size_t>(desc.arrayLayers) << 32
309 result ^= std::hash<size_t>{}(
310 static_cast<size_t>(desc.format) |
311 static_cast<size_t>(desc.imageDimensions) << 32
314 result ^= std::hash<size_t>{}(
315 static_cast<size_t>(desc.memoryUsage) |
316 static_cast<size_t>(desc.imageUsage.GetValueUnderlying()) << 32
Definition Bitset.hpp:331
Definition AttachmentInfo.hpp:258
Definition AttachmentInfo.hpp:226
Definition AttachmentInfo.hpp:194
Definition RenderGraphResourceRef.hpp:51
Definition Formats.hpp:48