Skip to content

Commit 1df7851

Browse files
committed
Add structured and typed buffers to the render graph
1 parent d187a2e commit 1df7851

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

Source/Falcor/RenderGraph/RenderPassReflection.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ namespace Falcor
4242
return *this;
4343
}
4444

45+
RenderPassReflection::Field& RenderPassReflection::Field::structuredBuffer(uint32_t elementCount, uint32_t structureSize)
46+
{
47+
mType = Type::StructuredBuffer;
48+
mWidth = elementCount;
49+
mHeight = structureSize;
50+
mDepth = mArraySize = mMipCount = 0;
51+
return *this;
52+
}
53+
54+
RenderPassReflection::Field& RenderPassReflection::Field::typedBuffer(uint32_t elementCount)
55+
{
56+
mType = Type::TypedBuffer;
57+
mWidth = elementCount;
58+
mHeight = mDepth = mArraySize = mMipCount = 0;
59+
return *this;
60+
}
61+
4562
RenderPassReflection::Field& RenderPassReflection::Field::texture1D(uint32_t width, uint32_t mipCount, uint32_t arraySize)
4663
{
4764
mType = Type::Texture1D;
@@ -93,6 +110,12 @@ namespace Falcor
93110
case RenderPassReflection::Field::Type::RawBuffer:
94111
if(height > 0 || depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be either 0");
95112
return rawBuffer(width);
113+
case RenderPassReflection::Field::Type::StructuredBuffer:
114+
if (depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - depth, sampleCount for " + to_string(type) + " must be 0");
115+
return structuredBuffer(width, height);
116+
case RenderPassReflection::Field::Type::TypedBuffer:
117+
if (height > 0 || depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be 0");
118+
return typedBuffer(width);
96119
case RenderPassReflection::Field::Type::Texture1D:
97120
if (height > 1 || depth > 1 || sampleCount > 1) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be either 0 or 1");
98121
return texture1D(width, mipCount, arraySize);

Source/Falcor/RenderGraph/RenderPassReflection.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace Falcor
6363
Texture3D,
6464
TextureCube,
6565
RawBuffer,
66+
StructuredBuffer,
67+
TypedBuffer,
6668
};
6769

6870
Field(const std::string& name, const std::string& desc, Visibility v);
@@ -75,6 +77,8 @@ namespace Falcor
7577
static const uint32_t kMaxMipLevels = Texture::kMaxPossible;
7678

7779
Field& rawBuffer(uint32_t size);
80+
Field& structuredBuffer(uint32_t elementCount, uint32_t structureSize);
81+
Field& typedBuffer(uint32_t elementCount);
7882
Field& texture1D(uint32_t width = 0, uint32_t mipCount = 1, uint32_t arraySize = 1);
7983
Field& texture2D(uint32_t width = 0, uint32_t height = 0, uint32_t sampleCount = 1, uint32_t mipCount = 1, uint32_t arraySize = 1);
8084
Field& texture3D(uint32_t width = 0, uint32_t height = 0, uint32_t depth = 0, uint32_t arraySize = 1);
@@ -102,7 +106,7 @@ namespace Falcor
102106
Type getType() const { return mType; }
103107
Visibility getVisibility() const { return mVisibility; }
104108

105-
bool isBuffer() const { return mType == Type::RawBuffer; }
109+
bool isBuffer() const { return mType == Type::RawBuffer || mType == Type::StructuredBuffer || mType == Type::TypedBuffer; }
106110

107111
/** Overwrite previously unknown/unspecified fields with specified ones.
108112
If a property is specified both in the current object, as well as the other field, an error will be logged and the current field will be undefined
@@ -117,8 +121,8 @@ namespace Falcor
117121
Type mType = Type::Texture2D;
118122
std::string mName; ///< The field's name
119123
std::string mDesc; ///< A description of the field
120-
uint32_t mWidth = 0; ///< For texture, the width. For buffers, the size in bytes. 0 means don't care - the pass will use whatever is bound (the RenderGraph will use the window size if this field is 0)
121-
uint32_t mHeight = 0; ///< 0 means don't care - the pass will use whatever is bound (the RenderGraph will use the window size if this field is 0)
124+
uint32_t mWidth = 0; ///< For texture, the width. For raw buffer, the size in bytes. For typed or structured buffer, the numer of elements. 0 means don't care - the pass will use whatever is bound (the RenderGraph will use the window size if this field is 0)
125+
uint32_t mHeight = 0; ///< For texture, the height. For structured buffer, the structure size. 0 means don't care - the pass will use whatever is bound (the RenderGraph will use the window size if this field is 0)
122126
uint32_t mDepth = 0; ///< 0 means don't care - the pass will use whatever is bound (the RenderGraph will use the window size if this field is 0)
123127
uint32_t mSampleCount = 1; ///< 0 means don't care - the pass will use whatever is bound
124128
uint32_t mMipCount = 1; ///< The required mip-level count. Only valid for textures
@@ -156,6 +160,8 @@ namespace Falcor
156160
switch (t)
157161
{
158162
t2s(RawBuffer);
163+
t2s(StructuredBuffer);
164+
t2s(TypedBuffer);
159165
t2s(Texture1D);
160166
t2s(Texture2D);
161167
t2s(Texture3D);

Source/Falcor/RenderGraph/ResourceCache.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ namespace Falcor
143143
}
144144
else // *Buffer
145145
{
146+
if (field.getType() == RenderPassReflection::Field::Type::TypedBuffer) format = field.getFormat() == ResourceFormat::Unknown ? params.format : field.getFormat();
146147
if (resolveBindFlags) bindFlags = Resource::BindFlags::UnorderedAccess | Resource::BindFlags::ShaderResource;
147148
}
148149
Resource::SharedPtr pResource;
@@ -152,6 +153,12 @@ namespace Falcor
152153
case RenderPassReflection::Field::Type::RawBuffer:
153154
pResource = Buffer::create(width, bindFlags, Buffer::CpuAccess::None);
154155
break;
156+
case RenderPassReflection::Field::Type::StructuredBuffer:
157+
pResource = Buffer::createStructured(height, width, bindFlags, Buffer::CpuAccess::None);
158+
break;
159+
case RenderPassReflection::Field::Type::TypedBuffer:
160+
pResource = Buffer::createTyped(format, width, bindFlags, Buffer::CpuAccess::None);
161+
break;
155162
case RenderPassReflection::Field::Type::Texture1D:
156163
pResource = Texture::create1D(width, format, arraySize, mipLevels, nullptr, bindFlags);
157164
break;

0 commit comments

Comments
 (0)