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;
11 const size_t kTextureAspectCount = 3; // Color, depth, stencil @ref RHITextureAspectFlag
16 {
17 ResourceHandle handle; // Index to tracked resources
20 bool hasComputeUsage{false}; // Used in a compute pass?
21 bool hasGraphicsUsage{false}; // Used in a graphics pass?
22 /* --- states --- */
23 // (Buffer) Last known state
24 // Transitions here are always global since granularity would be too fine. And seems
25 // like drivers don't really care?
26 // See Also: https://www.reddit.com/r/vulkan/comments/v2mswb/global_memory_barriers_vs_bufferimage_memory/
27 // TODO: Investigate
29 {
30 // Last pass to write at Setup time
32 // Last pass to transition at Execute time
34 // Last frame the transition was executed
36 // Last queue this resource is owned by
37 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
38 // [Only used by @ref ExecuteReleaseQueueResources]
42 void reset()
43 {
45 access = {};
46 stage = {};
47 }
49
50 // (Texture) Per-subresource states
53 {
54 size_t layer{0}, mip{0};
56 /* -- states -- */
57 // Last pass to write at Setup time
59 // Last pass to transition at Execute time
61 // Last frame the transition was executed
63 // Last queue this resource is owned by
64 RHIDeviceQueueType lastOwnerQueue{RHIDeviceQueueType::Undefined};
65 // [Only used by @ref ExecuteReleaseQueueResources]
70 void reset()
71 {
73 access = {};
74 stage = {};
75 layout = {};
76 }
78 };
79 // [mip...,
80 // layer...,
81 // aspect...]
84 {
85 auto [mip_begin, mip_end] = range.GetMipLevelRange();
88 return Views::all(Span<SubresourceState>{
91 }) |
92 Views::filter(
93 [=](const SubresourceState& state)
94 {
95 return (RHITextureAspectFlag(state.aspect) & range.layer.aspect) && state.mip >= mip_begin &&
96 state.mip <= mip_end && state.layer >= layer_begin && state.layer <= layer_end;
97 });
98 }
100 {
101 lastBufferState = {};
102 for (auto& sta : lastSubresourceStates)
103 sta.reset();
104 }
107 };
126}
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Definition Resource.hpp:48
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:169
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:144
RHIDeviceQueueType
Definition Common.hpp:107
static constexpr Handle kInvalidHandle
Definition Details.hpp:9
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
size_t ResourceHandle
Definition RenderPass.hpp:11
size_t PassHandle
Definition RenderPass.hpp:10
const size_t kTextureAspectCount
Definition RenderResource.hpp:11
RHITextureAspectFlag aspect
Definition Resource.hpp:119
RHITextureSubresourceLayer layer
Definition Resource.hpp:126
Pair< uint32_t, uint32_t > GetMipLevelRange() const
Definition Resource.hpp:130
Pair< uint32_t, uint32_t > GetArrayLayerRange() const
Definition Resource.hpp:134
Helper class containing runtime resources either imported, or created by the Renderer.
Definition RenderResource.hpp:112
Vector< RHIDeviceScopedHandle< RHIDeviceSampler > > samplers
Definition RenderResource.hpp:117
Vector< Variant< RHITextureScopedHandle< RHITextureView >, RHITextureHandle< RHITextureView > > > views
Definition RenderResource.hpp:116
Vector< Variant< RHIBuffer *, RHIDeviceHandle< RHIBuffer >, RHIDeviceScopedHandle< RHIBuffer >, RHITexture *, RHIDeviceHandle< RHITexture >, RHIDeviceScopedHandle< RHITexture > > > resources
Definition RenderResource.hpp:115
ExecuteResources(Allocator *allocator)
Definition RenderResource.hpp:118
void fit(ResourceHandle handle)
Definition RenderResource.hpp:119
RHIPipelineStage stage
Definition RenderResource.hpp:41
size_t lastProducedFrame
Definition RenderResource.hpp:35
PassHandle lastProducer
Definition RenderResource.hpp:33
RHIResourceAccess access
Definition RenderResource.hpp:40
bool executeTempTransitionFlag
Definition RenderResource.hpp:39
RHIDeviceQueueType lastOwnerQueue
Definition RenderResource.hpp:37
PassHandle producer
Definition RenderResource.hpp:31
void reset()
Definition RenderResource.hpp:42
RHIResourceAccess access
Definition RenderResource.hpp:67
RHIDeviceQueueType lastOwnerQueue
Definition RenderResource.hpp:64
void reset()
Definition RenderResource.hpp:70
bool executeTempTransitionFlag
Definition RenderResource.hpp:66
RHIPipelineStage stage
Definition RenderResource.hpp:68
RHITextureAspectFlagBits aspect
Definition RenderResource.hpp:55
RHITextureLayout layout
Definition RenderResource.hpp:69
PassHandle producer
Definition RenderResource.hpp:58
size_t lastProducedFrame
Definition RenderResource.hpp:62
PassHandle lastProducer
Definition RenderResource.hpp:60
RHITextureSubresourceRange ToRange() const
Definition RenderResource.cpp:3
size_t mip
Definition RenderResource.hpp:54
size_t layer
Definition RenderResource.hpp:54
Internal tracking information for a resource in the frame graph.
Definition RenderResource.hpp:16
Vector< SubresourceState > lastSubresourceStates
Definition RenderResource.hpp:82
auto GetLastSubresourceStateOf(RHITextureSubresourceRange const &range)
Definition RenderResource.hpp:83
bool hasGraphicsUsage
Definition RenderResource.hpp:21
String name
Definition RenderResource.hpp:18
void ResetStates()
Definition RenderResource.hpp:99
ResourceDefinition desc
Definition RenderResource.hpp:19
uint32_t textureMips
Definition RenderResource.hpp:51
uint32_t textureLayers
Definition RenderResource.hpp:51
bool hasComputeUsage
Definition RenderResource.hpp:20
struct Foundation::RenderCore::TrackedResource::BufferState lastBufferState
ResourceHandle handle
Definition RenderResource.hpp:17