Foundation
Loading...
Searching...
No Matches
RenderResource.hpp
Go to the documentation of this file.
1#pragma once
2#include <Core/Variant.hpp>
4#include "RenderPass.hpp"
6{
7 using namespace RHI;
8 using namespace Core;
10 RHIBufferDesc, RHITextureDesc, /* RHIAccelerationStructureDesc - not yet. Do we want to do this in RG at all? */
12 >;
13 const size_t kTextureAspectCount = 3; // Color, depth, stencil @ref RHITextureAspectFlag
18 {
19 ResourceHandle handle; // Index to tracked resources
22 bool hasComputeUsage{false}; // Used in a compute pass?
23 bool hasGraphicsUsage{false}; // Used in a graphics pass?
24 /* --- states --- */
25 // (Buffer) Last known state
26 // Transitions here are always global since granularity would be too fine. And seems
27 // like drivers don't really care?
28 // See Also: https://www.reddit.com/r/vulkan/comments/v2mswb/global_memory_barriers_vs_bufferimage_memory/
29 // TODO: Investigate
31 {
32 // Last pass to write at Setup time
34 // Last pass to transition at Execute time
36 // Last frame the transition was executed
38 // Last queue this resource is owned by
39 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
40 // [Only used by @ref ExecuteReleaseQueueResources]
44 void reset()
45 {
47 access = {};
48 stage = {};
49 }
51
52 // (Texture) Per-subresource states
55 {
56 size_t layer{0}, mip{0};
58 /* -- states -- */
59 // Last pass to write at Setup time
61 // Last pass to transition at Execute time
63 // Last frame the transition was executed
65 // Last queue this resource is owned by
66 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
67 // [Only used by @ref ExecuteReleaseQueueResources]
72 void reset()
73 {
75 access = {};
76 stage = {};
77 layout = {};
78 }
80 };
81 // [mip...,
82 // layer...,
83 // aspect...]
86 {
87 auto [mip_begin, mip_end] = range.GetMipLevelRange();
92 return Views::all(Span{
95 }) |
96 Views::filter(
97 [=](const SubresourceState& state)
98 {
99 return (RHITextureAspectFlag(state.aspect) & range.layer.aspect) && state.mip >= mip_begin &&
100 state.mip <= mip_end && state.layer >= layer_begin && state.layer <= layer_end;
101 });
102 }
103
105 // (Acceleration Structure) Last known state
108 {
109 lastBufferState = {};
110 lastASState = {};
111 for (auto& sta : lastSubresourceStates)
112 sta.reset();
113 }
116 };
136}
#define CHECK(expr)
Definition Logging.hpp:41
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Definition Resource.hpp:57
Handle type for RHI Objects.
Definition Details.hpp:42
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:86
Definition Resource.hpp:190
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:130
std::basic_string< char > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:112
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:55
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149
std::span< T > Span
Alias for std::span
Definition Container.hpp:60
RHITextureLayout
Definition Common.hpp:148
RHIDeviceQueueType
Definition Common.hpp:109
static constexpr Handle kInvalidHandle
Definition Details.hpp:9
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
Handle ResourceHandle
Definition RenderPass.hpp:11
const size_t kTextureAspectCount
Definition RenderResource.hpp:13
Handle PassHandle
Definition RenderPass.hpp:10
Definition Resource.hpp:28
Definition Resource.hpp:116
RHITextureAspectFlag aspect
Definition Resource.hpp:135
RHITextureSubresourceLayer layer
Definition Resource.hpp:143
Pair< uint32_t, uint32_t > GetMipLevelRange() const
Definition Resource.hpp:147
Pair< uint32_t, uint32_t > GetArrayLayerRange() const
Definition Resource.hpp:152
Helper class containing runtime resources either imported, or created by the Renderer.
Definition RenderResource.hpp:121
Vector< Variant< RHIBuffer *, RHIDeviceScopedHandle< RHIBuffer >, RHITexture *, RHIDeviceScopedHandle< RHITexture >, RHIAccelerationStructure * > > resources
Definition RenderResource.hpp:125
Vector< RHIDeviceScopedHandle< RHIDeviceSampler > > samplers
Definition RenderResource.hpp:127
Vector< Variant< RHITextureScopedHandle< RHITextureView >, RHITextureHandle< RHITextureView > > > views
Definition RenderResource.hpp:126
ExecuteResources(Allocator *allocator)
Definition RenderResource.hpp:128
void fit(ResourceHandle handle)
Definition RenderResource.hpp:129
RHIPipelineStage stage
Definition RenderResource.hpp:43
size_t lastProducedFrame
Definition RenderResource.hpp:37
PassHandle lastProducer
Definition RenderResource.hpp:35
RHIResourceAccess access
Definition RenderResource.hpp:42
bool executeTempTransitionFlag
Definition RenderResource.hpp:41
RHIDeviceQueueType lastOwnerQueue
Definition RenderResource.hpp:39
PassHandle producer
Definition RenderResource.hpp:33
void reset()
Definition RenderResource.hpp:44
RHIResourceAccess access
Definition RenderResource.hpp:69
RHIDeviceQueueType lastOwnerQueue
Definition RenderResource.hpp:66
void reset()
Definition RenderResource.hpp:72
bool executeTempTransitionFlag
Definition RenderResource.hpp:68
RHIPipelineStage stage
Definition RenderResource.hpp:70
RHITextureAspectFlagBits aspect
Definition RenderResource.hpp:57
RHITextureLayout layout
Definition RenderResource.hpp:71
PassHandle producer
Definition RenderResource.hpp:60
size_t lastProducedFrame
Definition RenderResource.hpp:64
PassHandle lastProducer
Definition RenderResource.hpp:62
RHITextureSubresourceRange ToRange() const
Definition RenderResource.cpp:3
size_t mip
Definition RenderResource.hpp:56
size_t layer
Definition RenderResource.hpp:56
Internal tracking information for a resource in the frame graph.
Definition RenderResource.hpp:18
Vector< SubresourceState > lastSubresourceStates
Definition RenderResource.hpp:84
auto GetLastSubresourceStateOf(RHITextureSubresourceRange const &range)
Definition RenderResource.hpp:85
bool hasGraphicsUsage
Definition RenderResource.hpp:23
String name
Definition RenderResource.hpp:20
void ResetStates()
Definition RenderResource.hpp:107
ResourceDefinition desc
Definition RenderResource.hpp:21
AccelerationStructureState lastASState
Definition RenderResource.hpp:106
uint32_t textureMips
Definition RenderResource.hpp:53
uint32_t textureLayers
Definition RenderResource.hpp:53
bool hasComputeUsage
Definition RenderResource.hpp:22
struct Foundation::RenderCore::TrackedResource::BufferState lastBufferState
ResourceHandle handle
Definition RenderResource.hpp:19