Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support typed and structured buffers as render graph resources #262

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Source/Falcor/RenderGraph/RenderPassReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ namespace Falcor
return *this;
}

RenderPassReflection::Field& RenderPassReflection::Field::structuredBuffer(uint32_t elementCount, uint32_t structureSize)
{
mType = Type::StructuredBuffer;
mWidth = elementCount;
mHeight = structureSize;
mDepth = mArraySize = mMipCount = 0;
return *this;
}

RenderPassReflection::Field& RenderPassReflection::Field::typedBuffer(uint32_t elementCount)
{
mType = Type::TypedBuffer;
mWidth = elementCount;
mHeight = mDepth = mArraySize = mMipCount = 0;
return *this;
}

RenderPassReflection::Field& RenderPassReflection::Field::texture1D(uint32_t width, uint32_t mipCount, uint32_t arraySize)
{
mType = Type::Texture1D;
Expand Down Expand Up @@ -93,6 +110,12 @@ namespace Falcor
case RenderPassReflection::Field::Type::RawBuffer:
if(height > 0 || depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be either 0");
return rawBuffer(width);
case RenderPassReflection::Field::Type::StructuredBuffer:
if (depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - depth, sampleCount for " + to_string(type) + " must be 0");
return structuredBuffer(width, height);
case RenderPassReflection::Field::Type::TypedBuffer:
if (height > 0 || depth > 0 || sampleCount > 0) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be 0");
return typedBuffer(width);
case RenderPassReflection::Field::Type::Texture1D:
if (height > 1 || depth > 1 || sampleCount > 1) logWarning("RenderPassReflection::Field::resourceType - height, depth, sampleCount for " + to_string(type) + " must be either 0 or 1");
return texture1D(width, mipCount, arraySize);
Expand Down
14 changes: 12 additions & 2 deletions Source/Falcor/RenderGraph/RenderPassReflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace Falcor
Texture3D,
TextureCube,
RawBuffer,
StructuredBuffer,
TypedBuffer,
};

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

Field& rawBuffer(uint32_t size);
Field& structuredBuffer(uint32_t elementCount, uint32_t structureSize);
Field& typedBuffer(uint32_t elementCount);
Field& texture1D(uint32_t width = 0, uint32_t mipCount = 1, uint32_t arraySize = 1);
Field& texture2D(uint32_t width = 0, uint32_t height = 0, uint32_t sampleCount = 1, uint32_t mipCount = 1, uint32_t arraySize = 1);
Field& texture3D(uint32_t width = 0, uint32_t height = 0, uint32_t depth = 0, uint32_t arraySize = 1);
Expand Down Expand Up @@ -102,6 +106,8 @@ namespace Falcor
Type getType() const { return mType; }
Visibility getVisibility() const { return mVisibility; }

bool isBuffer() const { return mType == Type::RawBuffer || mType == Type::StructuredBuffer || mType == Type::TypedBuffer; }

/** Overwrite previously unknown/unspecified fields with specified ones.
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
*/
Expand All @@ -115,8 +121,8 @@ namespace Falcor
Type mType = Type::Texture2D;
std::string mName; ///< The field's name
std::string mDesc; ///< A description of the field
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)
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)
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)
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)
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)
uint32_t mSampleCount = 1; ///< 0 means don't care - the pass will use whatever is bound
uint32_t mMipCount = 1; ///< The required mip-level count. Only valid for textures
Expand Down Expand Up @@ -155,6 +161,8 @@ namespace Falcor
switch (t)
{
t2s(RawBuffer);
t2s(StructuredBuffer);
t2s(TypedBuffer);
t2s(Texture1D);
t2s(Texture2D);
t2s(Texture3D);
Expand All @@ -170,6 +178,8 @@ namespace Falcor
{
switch (t)
{
case Resource::Type::Buffer:
return RenderPassReflection::Field::Type::RawBuffer;
case Resource::Type::Texture1D:
return RenderPassReflection::Field::Type::Texture1D;
case Resource::Type::Texture2D:
Expand Down
11 changes: 9 additions & 2 deletions Source/Falcor/RenderGraph/ResourceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace Falcor

ResourceFormat format = ResourceFormat::Unknown;

if (field.getType() != RenderPassReflection::Field::Type::RawBuffer)
if (!field.isBuffer())
{
format = field.getFormat() == ResourceFormat::Unknown ? params.format : field.getFormat();
if (resolveBindFlags)
Expand All @@ -141,8 +141,9 @@ namespace Falcor
bindFlags |= mask;
}
}
else // RawBuffer
else // *Buffer
{
if (field.getType() == RenderPassReflection::Field::Type::TypedBuffer) format = field.getFormat() == ResourceFormat::Unknown ? params.format : field.getFormat();
if (resolveBindFlags) bindFlags = Resource::BindFlags::UnorderedAccess | Resource::BindFlags::ShaderResource;
}
Resource::SharedPtr pResource;
Expand All @@ -152,6 +153,12 @@ namespace Falcor
case RenderPassReflection::Field::Type::RawBuffer:
pResource = Buffer::create(width, bindFlags, Buffer::CpuAccess::None);
break;
case RenderPassReflection::Field::Type::StructuredBuffer:
pResource = Buffer::createStructured(height, width, bindFlags, Buffer::CpuAccess::None);
break;
case RenderPassReflection::Field::Type::TypedBuffer:
pResource = Buffer::createTyped(format, width, bindFlags, Buffer::CpuAccess::None);
break;
case RenderPassReflection::Field::Type::Texture1D:
pResource = Texture::create1D(width, format, arraySize, mipLevels, nullptr, bindFlags);
break;
Expand Down