Skip to content

Commit

Permalink
Add structured and typed buffers to the render graph
Browse files Browse the repository at this point in the history
  • Loading branch information
pierremoreau committed Sep 25, 2020
1 parent d187a2e commit 1df7851
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
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
12 changes: 9 additions & 3 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,7 +106,7 @@ namespace Falcor
Type getType() const { return mType; }
Visibility getVisibility() const { return mVisibility; }

bool isBuffer() const { return mType == Type::RawBuffer; }
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 @@ -117,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 @@ -156,6 +160,8 @@ namespace Falcor
switch (t)
{
t2s(RawBuffer);
t2s(StructuredBuffer);
t2s(TypedBuffer);
t2s(Texture1D);
t2s(Texture2D);
t2s(Texture3D);
Expand Down
7 changes: 7 additions & 0 deletions Source/Falcor/RenderGraph/ResourceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace Falcor
}
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

0 comments on commit 1df7851

Please sign in to comment.