diff --git a/Source/Falcor/RenderGraph/RenderPassReflection.cpp b/Source/Falcor/RenderGraph/RenderPassReflection.cpp index 274fbf255..3b035c364 100644 --- a/Source/Falcor/RenderGraph/RenderPassReflection.cpp +++ b/Source/Falcor/RenderGraph/RenderPassReflection.cpp @@ -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; @@ -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); diff --git a/Source/Falcor/RenderGraph/RenderPassReflection.h b/Source/Falcor/RenderGraph/RenderPassReflection.h index 9aca10187..b10f747c5 100644 --- a/Source/Falcor/RenderGraph/RenderPassReflection.h +++ b/Source/Falcor/RenderGraph/RenderPassReflection.h @@ -63,6 +63,8 @@ namespace Falcor Texture3D, TextureCube, RawBuffer, + StructuredBuffer, + TypedBuffer, }; Field(const std::string& name, const std::string& desc, Visibility v); @@ -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); @@ -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 */ @@ -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 @@ -155,6 +161,8 @@ namespace Falcor switch (t) { t2s(RawBuffer); + t2s(StructuredBuffer); + t2s(TypedBuffer); t2s(Texture1D); t2s(Texture2D); t2s(Texture3D); @@ -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: diff --git a/Source/Falcor/RenderGraph/ResourceCache.cpp b/Source/Falcor/RenderGraph/ResourceCache.cpp index f3e18c0a8..896e5ebb3 100644 --- a/Source/Falcor/RenderGraph/ResourceCache.cpp +++ b/Source/Falcor/RenderGraph/ResourceCache.cpp @@ -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) @@ -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; @@ -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;