diff --git a/CHANGELOG b/CHANGELOG index 88edd079..cc08e7fa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +- replace IDevice::getFormatSupportedResourceStates with IDevice::getFormatSupport +- rename TextureDesc::allowedStates -> TextureDesc::usage and introduce TextureUsage enum +- rename BufferDesc::allowedStates -> BufferDesc::usage and introduce BufferUsage enum - rename IQueryPool::Desc -> QueryPoolDesc, add label to QueryPoolDesc - rename IFence::Desc -> FenceDesc, add label to FenceDesc - implement dynamic rendering in Vulkan diff --git a/YONGQUESTIONS.txt b/YONGQUESTIONS.txt new file mode 100644 index 00000000..37484706 --- /dev/null +++ b/YONGQUESTIONS.txt @@ -0,0 +1,10 @@ + +Pipeline refactor +- can we remove runtime specialization? we have to! +- specialize() doesn't lead to a program layout that can be used + +Shader program +- can we always create shader program from a "linked program" +- we cannot just have a single linked program passed in +- d3d12 has support for "libraries" where we have individual entry points with different specializations +- how should the interface to create shader programs look like? diff --git a/include/slang-rhi.h b/include/slang-rhi.h index 96d58016..46caa093 100644 --- a/include/slang-rhi.h +++ b/include/slang-rhi.h @@ -26,6 +26,18 @@ #define SLANG_RHI_API #endif +// clang-format off +/// Implement logical operators on a class enum for making it usable as a flags enum. +#define SLANG_RHI_ENUM_CLASS_OPERATORS(e_) \ + inline e_ operator& (e_ a, e_ b) { return static_cast(static_cast(a)& static_cast(b)); } \ + inline e_ operator| (e_ a, e_ b) { return static_cast(static_cast(a)| static_cast(b)); } \ + inline e_& operator|= (e_& a, e_ b) { a = a | b; return a; }; \ + inline e_& operator&= (e_& a, e_ b) { a = a & b; return a; }; \ + inline e_ operator~ (e_ a) { return static_cast(~static_cast(a)); } \ + inline bool is_set(e_ val, e_ flag) { return (val & flag) != static_cast(0); } \ + inline void flip_bit(e_& val, e_ flag) { val = is_set(val, flag) ? (val & (~flag)) : (val | flag); } +// clang-format on + // Needed for building on cygwin with gcc #undef Always #undef None @@ -266,6 +278,27 @@ struct FormatInfo GfxCount blockHeight; }; +enum class FormatSupport +{ + None = 0x0, + + Buffer = 0x1, + IndexBuffer = 0x2, + VertexBuffer = 0x4, + + Texture = 0x8, + DepthStencil = 0x10, + RenderTarget = 0x20, + Blendable = 0x40, + + ShaderLoad = 0x80, + ShaderSample = 0x100, + ShaderUavLoad = 0x200, + ShaderUavStore = 0x400, + ShaderAtomic = 0x800, +}; +SLANG_RHI_ENUM_CLASS_OPERATORS(FormatSupport); + enum class InputSlotClass { PerVertex, @@ -313,42 +346,6 @@ enum class ResourceState AccelerationStructureBuildInput, PixelShaderResource, NonPixelShaderResource, - _Count -}; - -struct ResourceStateSet -{ -public: - void add(ResourceState state) { m_bitFields |= (1LL << (uint32_t)state); } - template - void add(ResourceState s, TResourceState... states) - { - add(s); - add(states...); - } - bool contains(ResourceState state) const { return (m_bitFields & (1LL << (uint32_t)state)) != 0; } - ResourceStateSet() - : m_bitFields(0) - { - } - ResourceStateSet(const ResourceStateSet& other) = default; - ResourceStateSet(ResourceState state) { add(state); } - template - ResourceStateSet(TResourceState... states) - { - add(states...); - } - - ResourceStateSet operator&(const ResourceStateSet& that) const - { - ResourceStateSet result; - result.m_bitFields = this->m_bitFields & that.m_bitFields; - return result; - } - -private: - uint64_t m_bitFields = 0; - void add() {} }; /// Describes how memory for the resource should be allocated for CPU access. @@ -467,6 +464,23 @@ struct MemoryRange uint64_t size; }; +enum class BufferUsage +{ + None = 0, + VertexBuffer = 0x1, + IndexBuffer = 0x2, + ConstantBuffer = 0x4, + ShaderResource = 0x8, + UnorderedAccess = 0x10, + IndirectArgument = 0x20, + CopySource = 0x40, + CopyDestination = 0x80, + AccelerationStructure = 0x100, + AccelerationStructureBuildInput = 0x200, + ShaderTable = 0x400, +}; +SLANG_RHI_ENUM_CLASS_OPERATORS(BufferUsage); + struct BufferDesc { /// Total size in bytes. @@ -478,8 +492,8 @@ struct BufferDesc MemoryType memoryType = MemoryType::DeviceLocal; + BufferUsage usage = BufferUsage::None; ResourceState defaultState = ResourceState::Undefined; - ResourceStateSet allowedStates = ResourceStateSet(); bool isShared = false; @@ -522,6 +536,22 @@ struct BufferRange Size size; }; +enum class TextureUsage +{ + None = 0x0, + ShaderResource = 0x1, + UnorderedAccess = 0x2, + RenderTarget = 0x4, + DepthRead = 0x8, + DepthWrite = 0x10, + Present = 0x20, + CopySource = 0x40, + CopyDestination = 0x80, + ResolveSource = 0x100, + ResolveDestination = 0x200, +}; +SLANG_RHI_ENUM_CLASS_OPERATORS(TextureUsage); + enum class TextureType { Texture1D, ///< A 1d texture @@ -625,9 +655,11 @@ struct Extents struct TextureDesc { TextureType type = TextureType::Texture2D; - ResourceState defaultState = ResourceState::Undefined; - ResourceStateSet allowedStates = ResourceStateSet(); + MemoryType memoryType = MemoryType::DeviceLocal; + + TextureUsage usage = TextureUsage::None; + ResourceState defaultState = ResourceState::Undefined; bool isShared = false; Extents size; @@ -2122,8 +2154,7 @@ class IDevice : public ISlangUnknown virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) = 0; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) = 0; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) = 0; virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession) = 0; diff --git a/src/cuda/cuda-device.cpp b/src/cuda/cuda-device.cpp index d69ce0c6..b48df5e7 100644 --- a/src/cuda/cuda-device.cpp +++ b/src/cuda/cuda-device.cpp @@ -700,7 +700,7 @@ DeviceImpl::createTexture(const TextureDesc& desc, const SubresourceData* initDa // time we create a resource, and then allocate the surface or // texture objects as part of view creation. // - if (desc.allowedStates.contains(ResourceState::UnorderedAccess)) + if (is_set(desc.usage, TextureUsage::UnorderedAccess)) { // On CUDA surfaces only support a single MIP map SLANG_RHI_ASSERT(desc.numMipLevels == 1); diff --git a/src/d3d11/d3d11-device.cpp b/src/d3d11/d3d11-device.cpp index 2fd3299c..1f40d3e2 100644 --- a/src/d3d11/d3d11-device.cpp +++ b/src/d3d11/d3d11-device.cpp @@ -496,7 +496,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat return SLANG_FAIL; } - const int bindFlags = _calcResourceBindFlags(srcDesc.allowedStates); + const int bindFlags = _calcResourceBindFlags(srcDesc.usage); // Set up the initialize data std::vector subRes; @@ -609,7 +609,7 @@ Result DeviceImpl::createBuffer(const BufferDesc& descIn, const void* initData, { BufferDesc srcDesc = fixupBufferDesc(descIn); - auto d3dBindFlags = _calcResourceBindFlags(srcDesc.allowedStates); + auto d3dBindFlags = _calcResourceBindFlags(srcDesc.usage); size_t alignedSizeInBytes = srcDesc.size; @@ -636,7 +636,7 @@ Result DeviceImpl::createBuffer(const BufferDesc& descIn, const void* initData, bufferDesc.Usage = D3D11_USAGE_DEFAULT; // If written by CPU, make it dynamic - if (descIn.memoryType == MemoryType::Upload && !descIn.allowedStates.contains(ResourceState::UnorderedAccess)) + if (descIn.memoryType == MemoryType::Upload && !is_set(descIn.usage, BufferUsage::UnorderedAccess)) { bufferDesc.Usage = D3D11_USAGE_DYNAMIC; } diff --git a/src/d3d11/d3d11-helper-functions.cpp b/src/d3d11/d3d11-helper-functions.cpp index 81b8089e..33a42dbc 100644 --- a/src/d3d11/d3d11-helper-functions.cpp +++ b/src/d3d11/d3d11-helper-functions.cpp @@ -18,44 +18,36 @@ bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op) #endif } -D3D11_BIND_FLAG calcResourceFlag(ResourceState state) +int _calcResourceBindFlags(BufferUsage usage) { - switch (state) - { - case ResourceState::VertexBuffer: - return D3D11_BIND_VERTEX_BUFFER; - case ResourceState::IndexBuffer: - return D3D11_BIND_INDEX_BUFFER; - case ResourceState::ConstantBuffer: - return D3D11_BIND_CONSTANT_BUFFER; - case ResourceState::StreamOutput: - return D3D11_BIND_STREAM_OUTPUT; - case ResourceState::RenderTarget: - return D3D11_BIND_RENDER_TARGET; - case ResourceState::DepthRead: - case ResourceState::DepthWrite: - return D3D11_BIND_DEPTH_STENCIL; - case ResourceState::UnorderedAccess: - return D3D11_BIND_UNORDERED_ACCESS; - case ResourceState::ShaderResource: - case ResourceState::PixelShaderResource: - case ResourceState::NonPixelShaderResource: - return D3D11_BIND_SHADER_RESOURCE; - default: - return D3D11_BIND_FLAG(0); - } + int flags = 0; + if (is_set(usage, BufferUsage::VertexBuffer)) + flags |= D3D11_BIND_VERTEX_BUFFER; + if (is_set(usage, BufferUsage::IndexBuffer)) + flags |= D3D11_BIND_INDEX_BUFFER; + if (is_set(usage, BufferUsage::ConstantBuffer)) + flags |= D3D11_BIND_CONSTANT_BUFFER; + if (is_set(usage, BufferUsage::ShaderResource)) + flags |= D3D11_BIND_SHADER_RESOURCE; + if (is_set(usage, BufferUsage::UnorderedAccess)) + flags |= D3D11_BIND_UNORDERED_ACCESS; + return flags; } -int _calcResourceBindFlags(ResourceStateSet allowedStates) +int _calcResourceBindFlags(TextureUsage usage) { - int dstFlags = 0; - for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++) - { - auto state = (ResourceState)i; - if (allowedStates.contains(state)) - dstFlags |= calcResourceFlag(state); - } - return dstFlags; + int flags = 0; + if (is_set(usage, TextureUsage::RenderTarget)) + flags |= D3D11_BIND_RENDER_TARGET; + if (is_set(usage, TextureUsage::DepthRead)) + flags |= D3D11_BIND_DEPTH_STENCIL; + if (is_set(usage, TextureUsage::DepthWrite)) + flags |= D3D11_BIND_DEPTH_STENCIL; + if (is_set(usage, TextureUsage::ShaderResource)) + flags |= D3D11_BIND_SHADER_RESOURCE; + if (is_set(usage, TextureUsage::UnorderedAccess)) + flags |= D3D11_BIND_UNORDERED_ACCESS; + return flags; } int _calcResourceAccessFlags(MemoryType memType) diff --git a/src/d3d11/d3d11-helper-functions.h b/src/d3d11/d3d11-helper-functions.h index 1c6d30d1..d8a5bbe8 100644 --- a/src/d3d11/d3d11-helper-functions.h +++ b/src/d3d11/d3d11-helper-functions.h @@ -242,8 +242,8 @@ struct BindingOffset : SimpleBindingOffset bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op); -D3D11_BIND_FLAG calcResourceFlag(ResourceState state); -int _calcResourceBindFlags(ResourceStateSet allowedStates); +int _calcResourceBindFlags(BufferUsage usage); +int _calcResourceBindFlags(TextureUsage usage); int _calcResourceAccessFlags(MemoryType memType); D3D11_FILTER_TYPE translateFilterMode(TextureFilteringMode mode); diff --git a/src/d3d11/d3d11-shader-object.cpp b/src/d3d11/d3d11-shader-object.cpp index d1e956c1..2fe48106 100644 --- a/src/d3d11/d3d11-shader-object.cpp +++ b/src/d3d11/d3d11-shader-object.cpp @@ -245,8 +245,8 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded( ComPtr buffer; BufferDesc bufferDesc = {}; bufferDesc.size = specializedOrdinaryDataSize; + bufferDesc.usage = BufferUsage::ConstantBuffer | BufferUsage::CopyDestination; bufferDesc.defaultState = ResourceState::ConstantBuffer; - bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination); bufferDesc.memoryType = MemoryType::Upload; SLANG_RETURN_ON_FAIL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); m_ordinaryDataBuffer = static_cast(buffer.get()); diff --git a/src/d3d11/d3d11-swap-chain.cpp b/src/d3d11/d3d11-swap-chain.cpp index 94bb0db3..6bcd029b 100644 --- a/src/d3d11/d3d11-swap-chain.cpp +++ b/src/d3d11/d3d11-swap-chain.cpp @@ -27,9 +27,8 @@ void SwapchainImpl::createSwapchainBufferImages() imageDesc.size.height = m_desc.height; imageDesc.size.depth = 1; imageDesc.format = m_desc.format; + imageDesc.usage = TextureUsage::Present | TextureUsage::CopyDestination | TextureUsage::RenderTarget; imageDesc.defaultState = ResourceState::Present; - imageDesc.allowedStates = - ResourceStateSet(ResourceState::Present, ResourceState::CopyDestination, ResourceState::RenderTarget); RefPtr image = new TextureImpl(imageDesc); image->m_resource = d3dResource; for (GfxIndex i = 0; i < m_desc.imageCount; i++) diff --git a/src/d3d12/d3d12-device.cpp b/src/d3d12/d3d12-device.cpp index babcc32f..3af83348 100644 --- a/src/d3d12/d3d12-device.cpp +++ b/src/d3d12/d3d12-device.cpp @@ -1255,7 +1255,7 @@ Result DeviceImpl::createBuffer(const BufferDesc& descIn, const void* initData, D3D12_RESOURCE_DESC bufferDesc; initBufferDesc(descIn.size, bufferDesc); - bufferDesc.Flags |= calcResourceFlags(srcDesc.allowedStates); + bufferDesc.Flags |= calcResourceFlags(srcDesc.usage); const D3D12_RESOURCE_STATES initialState = buffer->m_defaultState; SLANG_RETURN_ON_FAIL(createBuffer( @@ -1584,49 +1584,42 @@ Result DeviceImpl::createTextureView(ITexture* texture, IResourceView::Desc cons return SLANG_OK; } -Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +Result DeviceImpl::getFormatSupport(Format format, FormatSupport* outFormatSupport) { - D3D12_FEATURE_DATA_FORMAT_SUPPORT support; - support.Format = D3DUtil::getMapFormat(format); - SLANG_RETURN_ON_FAIL(m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &support, sizeof(support))); - - ResourceStateSet allowedStates; - - auto dxgi1 = support.Support1; - if (dxgi1 & D3D12_FORMAT_SUPPORT1_BUFFER) - allowedStates.add(ResourceState::ConstantBuffer); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER) - allowedStates.add(ResourceState::VertexBuffer); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_IA_INDEX_BUFFER) - allowedStates.add(ResourceState::IndexBuffer); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SO_BUFFER) - allowedStates.add(ResourceState::StreamOutput); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE1D) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE2D) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE3D) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURECUBE) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_LOAD) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE_COMPARISON) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER_COMPARISON) - allowedStates.add(ResourceState::ShaderResource); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET) - allowedStates.add(ResourceState::RenderTarget); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL) - allowedStates.add(ResourceState::DepthWrite); - if (dxgi1 & D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW) - allowedStates.add(ResourceState::UnorderedAccess); - - *outStates = allowedStates; + D3D12_FEATURE_DATA_FORMAT_SUPPORT featureData; + featureData.Format = D3DUtil::getMapFormat(format); + SLANG_RETURN_ON_FAIL(m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &featureData, sizeof(featureData)) + ); + + FormatSupport support = FormatSupport::None; + + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_BUFFER) + support = support | FormatSupport::Buffer; + if (featureData.Support1 & (D3D12_FORMAT_SUPPORT1_TEXTURE1D | D3D12_FORMAT_SUPPORT1_TEXTURE2D | + D3D12_FORMAT_SUPPORT1_TEXTURE3D | D3D12_FORMAT_SUPPORT1_TEXTURECUBE)) + support = support | FormatSupport::Texture; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL) + support = support | FormatSupport::DepthStencil; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET) + support = support | FormatSupport::RenderTarget; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_BLENDABLE) + support = support | FormatSupport::Blendable; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_IA_INDEX_BUFFER) + support = support | FormatSupport::IndexBuffer; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER) + support = support | FormatSupport::VertexBuffer; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_LOAD) + support = support | FormatSupport::ShaderLoad; + if (featureData.Support1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE) + support = support | FormatSupport::ShaderSample; + if (featureData.Support2 & D3D12_FORMAT_SUPPORT2_UAV_ATOMIC_ADD) + support = support | FormatSupport::ShaderAtomic; + if (featureData.Support2 & D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD) + support = support | FormatSupport::ShaderUavLoad; + if (featureData.Support2 & D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE) + support = support | FormatSupport::ShaderUavStore; + + *outFormatSupport = support; return SLANG_OK; } diff --git a/src/d3d12/d3d12-device.h b/src/d3d12/d3d12-device.h index f8818416..f0021825 100644 --- a/src/d3d12/d3d12-device.h +++ b/src/d3d12/d3d12-device.h @@ -99,8 +99,7 @@ class DeviceImpl : public RendererBase public: virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override; virtual SLANG_NO_THROW Result SLANG_MCALL createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override; diff --git a/src/d3d12/d3d12-helper-functions.cpp b/src/d3d12/d3d12-helper-functions.cpp index 6747bb89..30dbbbd2 100644 --- a/src/d3d12/d3d12-helper-functions.cpp +++ b/src/d3d12/d3d12-helper-functions.cpp @@ -32,33 +32,28 @@ bool isSupportedNVAPIOp(ID3D12Device* dev, uint32_t op) #endif } -D3D12_RESOURCE_FLAGS calcResourceFlag(ResourceState state) +D3D12_RESOURCE_FLAGS calcResourceFlags(BufferUsage usage) { - switch (state) - { - case ResourceState::RenderTarget: - return D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; - case ResourceState::DepthRead: - case ResourceState::DepthWrite: - return D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; - case ResourceState::UnorderedAccess: - case ResourceState::AccelerationStructure: - return D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; - default: - return D3D12_RESOURCE_FLAG_NONE; - } + int flags = D3D12_RESOURCE_FLAG_NONE; + if (is_set(usage, BufferUsage::UnorderedAccess)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + if (is_set(usage, BufferUsage::AccelerationStructure)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + return (D3D12_RESOURCE_FLAGS)flags; } -D3D12_RESOURCE_FLAGS calcResourceFlags(ResourceStateSet states) +D3D12_RESOURCE_FLAGS calcResourceFlags(TextureUsage usage) { - int dstFlags = 0; - for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++) - { - auto state = (ResourceState)i; - if (states.contains(state)) - dstFlags |= calcResourceFlag(state); - } - return (D3D12_RESOURCE_FLAGS)dstFlags; + int flags = D3D12_RESOURCE_FLAG_NONE; + if (is_set(usage, TextureUsage::RenderTarget)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + if (is_set(usage, TextureUsage::DepthRead)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + if (is_set(usage, TextureUsage::DepthWrite)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + if (is_set(usage, TextureUsage::UnorderedAccess)) + flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + return (D3D12_RESOURCE_FLAGS)flags; } D3D12_RESOURCE_DIMENSION calcResourceDimension(TextureType type) @@ -363,12 +358,12 @@ Result initTextureDesc(D3D12_RESOURCE_DESC& resourceDesc, const TextureDesc& src resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; - resourceDesc.Flags |= calcResourceFlags(srcDesc.allowedStates); + resourceDesc.Flags |= calcResourceFlags(srcDesc.usage); resourceDesc.Alignment = 0; - if (isDepthFormat(srcDesc.format) && (srcDesc.allowedStates.contains(ResourceState::ShaderResource) || - srcDesc.allowedStates.contains(ResourceState::UnorderedAccess))) + if (isDepthFormat(srcDesc.format) && + (is_set(srcDesc.usage, TextureUsage::ShaderResource) || is_set(srcDesc.usage, TextureUsage::UnorderedAccess))) { resourceDesc.Format = getTypelessFormatFromDepthFormat(srcDesc.format); } diff --git a/src/d3d12/d3d12-helper-functions.h b/src/d3d12/d3d12-helper-functions.h index 11c53696..548bd5d3 100644 --- a/src/d3d12/d3d12-helper-functions.h +++ b/src/d3d12/d3d12-helper-functions.h @@ -38,8 +38,8 @@ struct BindingContext bool isSupportedNVAPIOp(ID3D12Device* dev, uint32_t op); -D3D12_RESOURCE_FLAGS calcResourceFlag(ResourceState state); -D3D12_RESOURCE_FLAGS calcResourceFlags(ResourceStateSet states); +D3D12_RESOURCE_FLAGS calcResourceFlags(BufferUsage usage); +D3D12_RESOURCE_FLAGS calcResourceFlags(TextureUsage usage); D3D12_RESOURCE_DIMENSION calcResourceDimension(TextureType type); DXGI_FORMAT getTypelessFormatFromDepthFormat(Format format); diff --git a/src/d3d12/d3d12-query.cpp b/src/d3d12/d3d12-query.cpp index 179fdbd6..5bb86933 100644 --- a/src/d3d12/d3d12-query.cpp +++ b/src/d3d12/d3d12-query.cpp @@ -124,7 +124,7 @@ Result PlainBufferProxyQueryPoolImpl::init(const QueryPoolDesc& desc, DeviceImpl bufferDesc.elementSize = 0; bufferDesc.size = desc.count * stride; bufferDesc.format = Format::Unknown; - bufferDesc.allowedStates.add(ResourceState::UnorderedAccess); + bufferDesc.usage = BufferUsage::UnorderedAccess; SLANG_RETURN_ON_FAIL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); m_buffer = static_cast(buffer.get()); m_queryType = desc.type; diff --git a/src/d3d12/d3d12-shader-table.cpp b/src/d3d12/d3d12-shader-table.cpp index dd9ff1fa..e3e54f6a 100644 --- a/src/d3d12/d3d12-shader-table.cpp +++ b/src/d3d12/d3d12-shader-table.cpp @@ -30,7 +30,7 @@ RefPtr ShaderTableImpl::createDeviceBuffer( BufferDesc bufferDesc = {}; bufferDesc.memoryType = MemoryType::DeviceLocal; bufferDesc.defaultState = ResourceState::General; - bufferDesc.allowedStates.add(ResourceState::NonPixelShaderResource); + bufferDesc.usage = BufferUsage::ShaderTable; bufferDesc.size = tableSize; m_device->createBuffer(bufferDesc, nullptr, buffer.writeRef()); diff --git a/src/d3d12/d3d12-swap-chain.cpp b/src/d3d12/d3d12-swap-chain.cpp index 0de05213..f7636917 100644 --- a/src/d3d12/d3d12-swap-chain.cpp +++ b/src/d3d12/d3d12-swap-chain.cpp @@ -39,8 +39,7 @@ void SwapchainImpl::createSwapchainBufferImages() ComPtr d3dResource; m_swapChain->GetBuffer(i, IID_PPV_ARGS(d3dResource.writeRef())); TextureDesc imageDesc = {}; - imageDesc.allowedStates = - ResourceStateSet(ResourceState::Present, ResourceState::RenderTarget, ResourceState::CopyDestination); + imageDesc.usage = TextureUsage::Present | TextureUsage::RenderTarget | TextureUsage::CopyDestination; imageDesc.type = TextureType::Texture2D; imageDesc.arraySize = 0; imageDesc.format = m_desc.format; diff --git a/src/debug-layer/debug-device.cpp b/src/debug-layer/debug-device.cpp index 2aaa277a..a285806e 100644 --- a/src/debug-layer/debug-device.cpp +++ b/src/debug-layer/debug-device.cpp @@ -47,10 +47,10 @@ Result DebugDevice::getFeatures(const char** outFeatures, Size bufferSize, GfxCo return baseObject->getFeatures(outFeatures, bufferSize, outFeatureCount); } -Result DebugDevice::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +Result DebugDevice::getFormatSupport(Format format, FormatSupport* outFormatSupport) { SLANG_RHI_API_FUNC; - return baseObject->getFormatSupportedResourceStates(format, outStates); + return baseObject->getFormatSupport(format, outFormatSupport); } DebugDevice::DebugDevice() diff --git a/src/debug-layer/debug-device.h b/src/debug-layer/debug-device.h index 8f12fc73..fb80b2fd 100644 --- a/src/debug-layer/debug-device.h +++ b/src/debug-layer/debug-device.h @@ -18,8 +18,7 @@ class DebugDevice : public DebugObject virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* feature) override; virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) override; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override; virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession) override; virtual SLANG_NO_THROW Result SLANG_MCALL diff --git a/src/metal/metal-device.cpp b/src/metal/metal-device.cpp index 44292b6f..9f8fa8fa 100644 --- a/src/metal/metal-device.cpp +++ b/src/metal/metal-device.cpp @@ -374,15 +374,15 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat } MTL::TextureUsage textureUsage = MTL::TextureUsageUnknown; - if (desc.allowedStates.contains(ResourceState::RenderTarget)) + if (is_set(desc.usage, TextureUsage::RenderTarget)) { textureUsage |= MTL::TextureUsageRenderTarget; } - if (desc.allowedStates.contains(ResourceState::ShaderResource)) + if (is_set(desc.usage, TextureUsage::ShaderResource)) { textureUsage |= MTL::TextureUsageShaderRead; } - if (desc.allowedStates.contains(ResourceState::UnorderedAccess)) + if (is_set(desc.usage, TextureUsage::UnorderedAccess)) { textureUsage |= MTL::TextureUsageShaderRead; textureUsage |= MTL::TextureUsageShaderWrite; @@ -590,30 +590,26 @@ Result DeviceImpl::createTextureView(ITexture* texture, IResourceView::Desc cons return SLANG_OK; } -Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +Result DeviceImpl::getFormatSupport(Format format, FormatSupport* outFormatSupport) { AUTORELEASEPOOL // TODO - add table based on https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf - ResourceStateSet allowedStates; - allowedStates.add(ResourceState::VertexBuffer); - allowedStates.add(ResourceState::IndexBuffer); - allowedStates.add(ResourceState::ConstantBuffer); - allowedStates.add(ResourceState::ShaderResource); - allowedStates.add(ResourceState::UnorderedAccess); - allowedStates.add(ResourceState::RenderTarget); - allowedStates.add(ResourceState::DepthRead); - allowedStates.add(ResourceState::DepthWrite); - allowedStates.add(ResourceState::Present); - allowedStates.add(ResourceState::IndirectArgument); - allowedStates.add(ResourceState::CopySource); - allowedStates.add(ResourceState::ResolveSource); - allowedStates.add(ResourceState::CopyDestination); - allowedStates.add(ResourceState::ResolveDestination); - allowedStates.add(ResourceState::AccelerationStructure); - allowedStates.add(ResourceState::AccelerationStructureBuildInput); - - *outStates = allowedStates; + FormatSupport support = FormatSupport::None; + support |= FormatSupport::Buffer; + support |= FormatSupport::IndexBuffer; + support |= FormatSupport::VertexBuffer; + support |= FormatSupport::Texture; + support |= FormatSupport::DepthStencil; + support |= FormatSupport::RenderTarget; + support |= FormatSupport::Blendable; + support |= FormatSupport::ShaderLoad; + support |= FormatSupport::ShaderSample; + support |= FormatSupport::ShaderUavLoad; + support |= FormatSupport::ShaderUavStore; + support |= FormatSupport::ShaderAtomic; + + *outFormatSupport = support; return SLANG_OK; } diff --git a/src/metal/metal-device.h b/src/metal/metal-device.h index b73d94eb..eaa5b3b9 100644 --- a/src/metal/metal-device.h +++ b/src/metal/metal-device.h @@ -15,8 +15,7 @@ class DeviceImpl : public RendererBase public: // Renderer implementation virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override; virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override; virtual SLANG_NO_THROW Result SLANG_MCALL diff --git a/src/metal/metal-shader-object.cpp b/src/metal/metal-shader-object.cpp index c631cbdc..489d0e14 100644 --- a/src/metal/metal-shader-object.cpp +++ b/src/metal/metal-shader-object.cpp @@ -256,8 +256,8 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(DeviceImpl* de ComPtr buffer; BufferDesc bufferDesc = {}; bufferDesc.size = ordinaryDataSize; + bufferDesc.usage = BufferUsage::ConstantBuffer | BufferUsage::CopyDestination; bufferDesc.defaultState = ResourceState::ConstantBuffer; - bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination); bufferDesc.memoryType = MemoryType::Upload; SLANG_RETURN_ON_FAIL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); m_ordinaryDataBuffer = static_cast(buffer.get()); @@ -351,8 +351,8 @@ BufferImpl* ShaderObjectImpl::_ensureArgumentBufferUpToDate(DeviceImpl* device, ComPtr buffer; BufferDesc bufferDesc = {}; bufferDesc.size = typeLayout->getSize(); + bufferDesc.usage = BufferUsage::ConstantBuffer | BufferUsage::CopyDestination; bufferDesc.defaultState = ResourceState::ConstantBuffer; - bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination); bufferDesc.memoryType = MemoryType::Upload; SLANG_RETURN_NULL_ON_FAIL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); m_argumentBuffer = static_cast(buffer.get()); diff --git a/src/metal/metal-swap-chain.cpp b/src/metal/metal-swap-chain.cpp index 1d8d0982..cd02622d 100644 --- a/src/metal/metal-swap-chain.cpp +++ b/src/metal/metal-swap-chain.cpp @@ -22,12 +22,8 @@ void SwapchainImpl::createImages() for (GfxCount i = 0; i < m_desc.imageCount; ++i) { TextureDesc imageDesc = {}; - imageDesc.allowedStates = ResourceStateSet( - ResourceState::Present, - ResourceState::RenderTarget, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + imageDesc.usage = TextureUsage::Present | TextureUsage::RenderTarget | TextureUsage::CopyDestination | + TextureUsage::CopySource; imageDesc.type = TextureType::Texture2D; imageDesc.arraySize = 0; imageDesc.format = m_desc.format; diff --git a/src/renderer-shared.cpp b/src/renderer-shared.cpp index 43914c57..5c75d545 100644 --- a/src/renderer-shared.cpp +++ b/src/renderer-shared.cpp @@ -349,30 +349,23 @@ SLANG_NO_THROW bool SLANG_MCALL RendererBase::hasFeature(const char* featureName ); } -Result RendererBase::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +Result RendererBase::getFormatSupport(Format format, FormatSupport* outFormatSupport) { SLANG_UNUSED(format); - outStates->add(ResourceState::AccelerationStructure); - outStates->add(ResourceState::AccelerationStructureBuildInput); - outStates->add(ResourceState::ConstantBuffer); - outStates->add(ResourceState::CopyDestination); - outStates->add(ResourceState::CopySource); - outStates->add(ResourceState::DepthRead); - outStates->add(ResourceState::DepthWrite); - outStates->add(ResourceState::IndexBuffer); - outStates->add(ResourceState::IndirectArgument); - outStates->add(ResourceState::PreInitialized); - outStates->add(ResourceState::Present); - outStates->add(ResourceState::RenderTarget); - outStates->add(ResourceState::ResolveDestination); - outStates->add(ResourceState::ResolveSource); - outStates->add(ResourceState::ShaderResource); - outStates->add(ResourceState::PixelShaderResource); - outStates->add(ResourceState::NonPixelShaderResource); - outStates->add(ResourceState::StreamOutput); - outStates->add(ResourceState::Undefined); - outStates->add(ResourceState::UnorderedAccess); - outStates->add(ResourceState::VertexBuffer); + FormatSupport support = FormatSupport::None; + support |= FormatSupport::Buffer; + support |= FormatSupport::IndexBuffer; + support |= FormatSupport::VertexBuffer; + support |= FormatSupport::Texture; + support |= FormatSupport::DepthStencil; + support |= FormatSupport::RenderTarget; + support |= FormatSupport::Blendable; + support |= FormatSupport::ShaderLoad; + support |= FormatSupport::ShaderSample; + support |= FormatSupport::ShaderUavLoad; + support |= FormatSupport::ShaderUavStore; + support |= FormatSupport::ShaderAtomic; + *outFormatSupport = support; return SLANG_OK; } @@ -766,7 +759,7 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView( { // Create structured buffer resource if it has not been created. BufferDesc desc = {}; - desc.allowedStates = ResourceStateSet(ResourceState::ShaderResource, ResourceState::UnorderedAccess); + desc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess; desc.defaultState = ResourceState::ShaderResource; desc.elementSize = (int)elementLayout->getSize(); desc.format = Format::Unknown; diff --git a/src/renderer-shared.h b/src/renderer-shared.h index bf04789a..cb733500 100644 --- a/src/renderer-shared.h +++ b/src/renderer-shared.h @@ -1064,8 +1064,7 @@ class RendererBase : public IDevice, public ComObject virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) SLANG_OVERRIDE; virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* featureName) SLANG_OVERRIDE; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override; virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession) SLANG_OVERRIDE; virtual SLANG_NO_THROW Result SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) SLANG_OVERRIDE; IDevice* getInterface(const Guid& guid); diff --git a/src/resource-desc-utils.cpp b/src/resource-desc-utils.cpp index 8d7c12b1..91444169 100644 --- a/src/resource-desc-utils.cpp +++ b/src/resource-desc-utils.cpp @@ -5,7 +5,6 @@ namespace rhi { BufferDesc fixupBufferDesc(const BufferDesc& desc) { BufferDesc result = desc; - result.allowedStates.add(result.defaultState); return result; } @@ -14,7 +13,6 @@ TextureDesc fixupTextureDesc(const TextureDesc& desc) TextureDesc rs = desc; if (desc.numMipLevels == 0) rs.numMipLevels = calcNumMipLevels(desc.type, desc.size); - rs.allowedStates.add(rs.defaultState); return rs; } diff --git a/src/simple-transient-resource-heap.h b/src/simple-transient-resource-heap.h index 44ddde12..828a3f56 100644 --- a/src/simple-transient-resource-heap.h +++ b/src/simple-transient-resource-heap.h @@ -21,7 +21,7 @@ class SimpleTransientResourceHeap : public TransientResourceHeapBase { m_device = device; BufferDesc bufferDesc = {}; - bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination); + bufferDesc.usage = BufferUsage::ConstantBuffer | BufferUsage::CopyDestination; bufferDesc.defaultState = ResourceState::ConstantBuffer; bufferDesc.size = desc.constantBufferSize; bufferDesc.memoryType = MemoryType::Upload; diff --git a/src/transient-resource-heap-base.h b/src/transient-resource-heap-base.h index c81e671f..136d6e5d 100644 --- a/src/transient-resource-heap-base.h +++ b/src/transient-resource-heap-base.h @@ -23,7 +23,7 @@ class StagingBufferPool TDevice* m_device; MemoryType m_memoryType; uint32_t m_alignment; - ResourceStateSet m_allowedStates; + BufferUsage m_usage; std::vector m_pages; std::vector> m_largeAllocations; @@ -33,12 +33,12 @@ class StagingBufferPool const size_t kStagingBufferDefaultPageSize = 16 * 1024 * 1024; - void init(TDevice* device, MemoryType memoryType, uint32_t alignment, ResourceStateSet allowedStates) + void init(TDevice* device, MemoryType memoryType, uint32_t alignment, BufferUsage usage) { m_device = device; m_memoryType = memoryType; m_alignment = alignment; - m_allowedStates = allowedStates; + m_usage = usage; } static size_t alignUp(size_t value, uint32_t alignment) { return (value + alignment - 1) / alignment * alignment; } @@ -57,8 +57,8 @@ class StagingBufferPool ComPtr bufferPtr; BufferDesc bufferDesc; + bufferDesc.usage = m_usage; bufferDesc.defaultState = ResourceState::General; - bufferDesc.allowedStates = m_allowedStates; bufferDesc.memoryType = m_memoryType; bufferDesc.size = pageSize; SLANG_RETURN_ON_FAIL(m_device->createBuffer(bufferDesc, nullptr, bufferPtr.writeRef())); @@ -73,8 +73,8 @@ class StagingBufferPool { ComPtr bufferPtr; BufferDesc bufferDesc; + bufferDesc.usage = m_usage; bufferDesc.defaultState = ResourceState::General; - bufferDesc.allowedStates = m_allowedStates; bufferDesc.memoryType = m_memoryType; bufferDesc.size = size; SLANG_RETURN_ON_FAIL(m_device->createBuffer(bufferDesc, nullptr, bufferPtr.writeRef())); @@ -143,22 +143,14 @@ class TransientResourceHeapBaseImpl : public TransientResourceHeapBase device, MemoryType::Upload, 256, - ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopySource, ResourceState::CopyDestination) + BufferUsage::ConstantBuffer | BufferUsage::CopySource | BufferUsage::CopyDestination ); - m_uploadBufferPool.init( - device, - MemoryType::Upload, - 256, - ResourceStateSet(ResourceState::CopySource, ResourceState::CopyDestination) - ); + m_uploadBufferPool + .init(device, MemoryType::Upload, 256, BufferUsage::CopySource | BufferUsage::CopyDestination); - m_readbackBufferPool.init( - device, - MemoryType::ReadBack, - 256, - ResourceStateSet(ResourceState::CopySource, ResourceState::CopyDestination) - ); + m_readbackBufferPool + .init(device, MemoryType::ReadBack, 256, BufferUsage::CopySource | BufferUsage::CopyDestination); m_version = getVersionCounter(); getVersionCounter()++; diff --git a/src/vulkan/vk-device.cpp b/src/vulkan/vk-device.cpp index 14242e01..64863714 100644 --- a/src/vulkan/vk-device.cpp +++ b/src/vulkan/vk-device.cpp @@ -1455,7 +1455,7 @@ Result DeviceImpl::getTextureAllocationInfo(const TextureDesc& descIn, Size* out imageInfo.format = format; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; - imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, nullptr); + imageInfo.usage = _calcImageUsageFlags(desc.usage, desc.memoryType, nullptr); imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount; @@ -1541,7 +1541,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat imageInfo.format = format; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; - imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, initData); + imageInfo.usage = _calcImageUsageFlags(desc.usage, desc.memoryType, initData); imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; imageInfo.samples = (VkSampleCountFlagBits)desc.sampleCount; @@ -1868,16 +1868,6 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat } Result DeviceImpl::createBuffer(const BufferDesc& descIn, const void* initData, IBuffer** outBuffer) -{ - return createBufferImpl(descIn, 0, initData, outBuffer); -} - -Result DeviceImpl::createBufferImpl( - const BufferDesc& descIn, - VkBufferUsageFlags additionalUsageFlag, - const void* initData, - IBuffer** outBuffer -) { BufferDesc desc = fixupBufferDesc(descIn); @@ -1885,12 +1875,12 @@ Result DeviceImpl::createBufferImpl( VkMemoryPropertyFlags reqMemoryProperties = 0; - VkBufferUsageFlags usage = _calcBufferUsageFlags(desc.allowedStates) | additionalUsageFlag; + VkBufferUsageFlags usage = _calcBufferUsageFlags(desc.usage); if (m_api.m_extendedFeatures.vulkan12Features.bufferDeviceAddress) { usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; } - if (desc.allowedStates.contains(ResourceState::ShaderResource) && + if (is_set(desc.usage, BufferUsage::ShaderResource) && m_api.m_extendedFeatures.accelerationStructureFeatures.accelerationStructure) { usage |= VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR; @@ -1900,7 +1890,7 @@ Result DeviceImpl::createBufferImpl( usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; } - if (desc.allowedStates.contains(ResourceState::ConstantBuffer) || desc.memoryType == MemoryType::Upload || + if (is_set(desc.usage, BufferUsage::ConstantBuffer) || desc.memoryType == MemoryType::Upload || desc.memoryType == MemoryType::ReadBack) { reqMemoryProperties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; @@ -2115,105 +2105,46 @@ Result DeviceImpl::createTextureView(ITexture* texture, IResourceView::Desc cons return SLANG_OK; } -Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +Result DeviceImpl::getFormatSupport(Format format, FormatSupport* outFormatSupport) { - // TODO: Add variables to VkDevice to track supported surface presentable formats - VkFormat vkFormat = VulkanUtil::getVkFormat(format); - VkFormatProperties supportedProperties = {}; - m_api.vkGetPhysicalDeviceFormatProperties(m_api.m_physicalDevice, vkFormat, &supportedProperties); + VkFormatProperties props = {}; + m_api.vkGetPhysicalDeviceFormatProperties(m_api.m_physicalDevice, vkFormat, &props); - std::set presentableFormats; - // TODO: enable this once we have VK_GOOGLE_surfaceless_query. -#if 0 - std::vector surfaceFormats; + FormatSupport support = FormatSupport::None; - uint32_t surfaceFormatCount = 0; - m_api.vkGetPhysicalDeviceSurfaceFormatsKHR( - m_api.m_physicalDevice, VK_NULL_HANDLE, &surfaceFormatCount, nullptr); + if (props.bufferFeatures) + support = support | FormatSupport::Buffer; - surfaceFormats.resize(surfaceFormatCount); - m_api.vkGetPhysicalDeviceSurfaceFormatsKHR(m_api.m_physicalDevice, VK_NULL_HANDLE, &surfaceFormatCount, surfaceFormats.data()); - for (auto surfaceFormat : surfaceFormats) + if (format == Format::R32_UINT || format == Format::R16_UINT) { - presentableFormats.emplace(surfaceFormat.format); + // There is no explicit bit in vk::FormatFeatureFlags for index buffers + support = support | FormatSupport::IndexBuffer; } -#else - // Until we have a solution to query presentable formats without needing a surface, - // hard code presentable formats that is supported by most drivers. - presentableFormats.emplace(VK_FORMAT_R8G8B8A8_UNORM); - presentableFormats.emplace(VK_FORMAT_B8G8R8A8_UNORM); - presentableFormats.emplace(VK_FORMAT_R8G8B8A8_SRGB); - presentableFormats.emplace(VK_FORMAT_B8G8R8A8_SRGB); -#endif - ResourceStateSet allowedStates; - // TODO: Currently only supports VK_IMAGE_TILING_OPTIMAL - auto imageFeatures = supportedProperties.optimalTilingFeatures; - auto bufferFeatures = supportedProperties.bufferFeatures; - // PreInitialized - Only supported for VK_IMAGE_TILING_LINEAR - // VertexBuffer - if (bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) - allowedStates.add(ResourceState::VertexBuffer); - // IndexBuffer - Without extensions, Vulkan only supports two formats for index buffers. - switch (format) - { - case Format::R32_UINT: - case Format::R16_UINT: - allowedStates.add(ResourceState::IndexBuffer); - break; - default: - break; + if (props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) + support = support | FormatSupport::VertexBuffer; + + if (props.optimalTilingFeatures) + support = support | FormatSupport::Texture; + + if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + support = support | FormatSupport::DepthStencil; + + if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) + support = support | FormatSupport::RenderTarget; + + if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) + support = support | FormatSupport::Blendable; + + if ((props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) || + (props.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)) + { + support = support | FormatSupport::ShaderLoad; } - // ConstantBuffer - allowedStates.add(ResourceState::ConstantBuffer); - // StreamOutput - TODO: Requires VK_EXT_transform_feedback - // ShaderResource - if (imageFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) - allowedStates.add(ResourceState::ShaderResource); - if (bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) - allowedStates.add(ResourceState::ShaderResource); - // UnorderedAccess - if (imageFeatures & (VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT)) - allowedStates.add(ResourceState::UnorderedAccess); - if (bufferFeatures & - (VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT)) - allowedStates.add(ResourceState::UnorderedAccess); - // RenderTarget - if (imageFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) - allowedStates.add(ResourceState::RenderTarget); - // DepthRead, DepthWrite - if (imageFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) - { - allowedStates.add(ResourceState::DepthRead); - allowedStates.add(ResourceState::DepthWrite); - } - // Present - if (presentableFormats.count(vkFormat)) - allowedStates.add(ResourceState::Present); - // IndirectArgument - allowedStates.add(ResourceState::IndirectArgument); - // CopySource, ResolveSource - if (imageFeatures & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT) - { - allowedStates.add(ResourceState::CopySource); - allowedStates.add(ResourceState::ResolveSource); - } - // CopyDestination, ResolveDestination - if (imageFeatures & VK_FORMAT_FEATURE_TRANSFER_DST_BIT) - { - allowedStates.add(ResourceState::CopyDestination); - allowedStates.add(ResourceState::ResolveDestination); - } - // AccelerationStructure - if (bufferFeatures & VK_FORMAT_FEATURE_ACCELERATION_STRUCTURE_VERTEX_BUFFER_BIT_KHR) - { - allowedStates.add(ResourceState::AccelerationStructure); - allowedStates.add(ResourceState::AccelerationStructureBuildInput); - } - - *outStates = allowedStates; + + *outFormatSupport = support; return SLANG_OK; } diff --git a/src/vulkan/vk-device.h b/src/vulkan/vk-device.h index b0e6a718..21225d8e 100644 --- a/src/vulkan/vk-device.h +++ b/src/vulkan/vk-device.h @@ -14,8 +14,7 @@ class DeviceImpl : public RendererBase // Renderer implementation Result initVulkanInstanceAndDevice(const NativeHandle* handles, bool useValidationLayer); virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override; - virtual SLANG_NO_THROW Result SLANG_MCALL - getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override; + virtual SLANG_NO_THROW Result SLANG_MCALL getFormatSupport(Format format, FormatSupport* outFormatSupport) override; virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override; virtual SLANG_NO_THROW Result SLANG_MCALL @@ -26,12 +25,6 @@ class DeviceImpl : public RendererBase createTexture(const TextureDesc& desc, const SubresourceData* initData, ITexture** outTexture) override; virtual SLANG_NO_THROW Result SLANG_MCALL createBuffer(const BufferDesc& desc, const void* initData, IBuffer** outBuffer) override; - SLANG_NO_THROW Result SLANG_MCALL createBufferImpl( - const BufferDesc& desc, - VkBufferUsageFlags additionalUsageFlag, - const void* initData, - IBuffer** outBuffer - ); virtual SLANG_NO_THROW Result SLANG_MCALL createBufferFromNativeHandle(NativeHandle handle, const BufferDesc& srcDesc, IBuffer** outBuffer) override; virtual SLANG_NO_THROW Result SLANG_MCALL createSampler(SamplerDesc const& desc, ISampler** outSampler) override; diff --git a/src/vulkan/vk-helper-functions.cpp b/src/vulkan/vk-helper-functions.cpp index 3b40e0f5..de7eda06 100644 --- a/src/vulkan/vk-helper-functions.cpp +++ b/src/vulkan/vk-helper-functions.cpp @@ -212,56 +212,32 @@ VkAccessFlags translateAccelerationStructureAccessFlag(AccessFlag access) return result; } -VkBufferUsageFlagBits _calcBufferUsageFlags(ResourceState state) +VkBufferUsageFlagBits _calcBufferUsageFlags(BufferUsage usage) { - switch (state) - { - case ResourceState::VertexBuffer: - return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - case ResourceState::IndexBuffer: - return VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - case ResourceState::ConstantBuffer: - return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - case ResourceState::StreamOutput: - return VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT; - case ResourceState::RenderTarget: - case ResourceState::DepthRead: - case ResourceState::DepthWrite: - { - SLANG_RHI_ASSERT_FAILURE("Invalid resource state for buffer resource."); - return VkBufferUsageFlagBits(0); - } - case ResourceState::UnorderedAccess: - return (VkBufferUsageFlagBits)(VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); - case ResourceState::ShaderResource: - case ResourceState::NonPixelShaderResource: - case ResourceState::PixelShaderResource: - return (VkBufferUsageFlagBits)(VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); - case ResourceState::CopySource: - return VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - case ResourceState::CopyDestination: - return VK_BUFFER_USAGE_TRANSFER_DST_BIT; - case ResourceState::AccelerationStructure: - return VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR; - case ResourceState::IndirectArgument: - return VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; - case ResourceState::AccelerationStructureBuildInput: - return VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR; - default: - return VkBufferUsageFlagBits(0); - } -} - -VkBufferUsageFlagBits _calcBufferUsageFlags(ResourceStateSet states) -{ - int dstFlags = 0; - for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++) - { - auto state = (ResourceState)i; - if (states.contains(state)) - dstFlags |= _calcBufferUsageFlags(state); - } - return VkBufferUsageFlagBits(dstFlags); + int flags = 0; + if (is_set(usage, BufferUsage::VertexBuffer)) + flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + if (is_set(usage, BufferUsage::IndexBuffer)) + flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + if (is_set(usage, BufferUsage::ConstantBuffer)) + flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + if (is_set(usage, BufferUsage::ShaderResource)) + flags |= (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); + if (is_set(usage, BufferUsage::UnorderedAccess)) + flags |= (VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT); + if (is_set(usage, BufferUsage::IndirectArgument)) + flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; + if (is_set(usage, BufferUsage::CopySource)) + flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + if (is_set(usage, BufferUsage::CopyDestination)) + flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; + if (is_set(usage, BufferUsage::AccelerationStructure)) + flags |= VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR; + if (is_set(usage, BufferUsage::AccelerationStructureBuildInput)) + flags |= VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR; + if (is_set(usage, BufferUsage::ShaderTable)) + flags |= VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR; + return VkBufferUsageFlagBits(flags); } VkImageUsageFlagBits _calcImageUsageFlags(ResourceState state) @@ -328,28 +304,42 @@ VkImageViewType _calcImageViewType(TextureType type, const TextureDesc& desc) return VK_IMAGE_VIEW_TYPE_MAX_ENUM; } -VkImageUsageFlagBits _calcImageUsageFlags(ResourceStateSet states) +VkImageUsageFlagBits _calcImageUsageFlags(TextureUsage usage) { - int dstFlags = 0; - for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++) - { - auto state = (ResourceState)i; - if (states.contains(state)) - dstFlags |= _calcImageUsageFlags(state); - } - return VkImageUsageFlagBits(dstFlags); + int flags = 0; + if (is_set(usage, TextureUsage::ShaderResource)) + flags |= VK_IMAGE_USAGE_SAMPLED_BIT; + if (is_set(usage, TextureUsage::UnorderedAccess)) + flags |= VK_IMAGE_USAGE_STORAGE_BIT; + if (is_set(usage, TextureUsage::RenderTarget)) + flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + if (is_set(usage, TextureUsage::DepthRead)) + flags |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + if (is_set(usage, TextureUsage::DepthWrite)) + flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + if (is_set(usage, TextureUsage::Present)) + flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + if (is_set(usage, TextureUsage::CopySource)) + flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + if (is_set(usage, TextureUsage::CopyDestination)) + flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + if (is_set(usage, TextureUsage::ResolveSource)) + flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + if (is_set(usage, TextureUsage::ResolveDestination)) + flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + return VkImageUsageFlagBits(flags); } -VkImageUsageFlags _calcImageUsageFlags(ResourceStateSet states, MemoryType memoryType, const void* initData) +VkImageUsageFlags _calcImageUsageFlags(TextureUsage usage, MemoryType memoryType, const void* initData) { - VkImageUsageFlags usage = _calcImageUsageFlags(states); + VkImageUsageFlags flags = _calcImageUsageFlags(usage); if (memoryType == MemoryType::Upload || initData) { - usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; } - return usage; + return flags; } VkAccessFlags calcAccessFlagsFromImageLayout(VkImageLayout layout) diff --git a/src/vulkan/vk-helper-functions.h b/src/vulkan/vk-helper-functions.h index 2c41c183..0cb5e8c4 100644 --- a/src/vulkan/vk-helper-functions.h +++ b/src/vulkan/vk-helper-functions.h @@ -155,12 +155,11 @@ VkAccessFlagBits calcAccessFlags(ResourceState state); VkPipelineStageFlagBits calcPipelineStageFlags(ResourceState state, bool src); VkAccessFlags translateAccelerationStructureAccessFlag(AccessFlag access); -VkBufferUsageFlagBits _calcBufferUsageFlags(ResourceState state); -VkBufferUsageFlagBits _calcBufferUsageFlags(ResourceStateSet states); +VkBufferUsageFlagBits _calcBufferUsageFlags(BufferUsage usage); VkImageUsageFlagBits _calcImageUsageFlags(ResourceState state); VkImageViewType _calcImageViewType(TextureType type, const TextureDesc& desc); -VkImageUsageFlagBits _calcImageUsageFlags(ResourceStateSet states); -VkImageUsageFlags _calcImageUsageFlags(ResourceStateSet states, MemoryType memoryType, const void* initData); +VkImageUsageFlagBits _calcImageUsageFlags(TextureUsage usage); +VkImageUsageFlags _calcImageUsageFlags(TextureUsage usage, MemoryType memoryType, const void* initData); VkAccessFlags calcAccessFlagsFromImageLayout(VkImageLayout layout); VkPipelineStageFlags calcPipelineStageFlagsFromImageLayout(VkImageLayout layout); diff --git a/src/vulkan/vk-shader-table.cpp b/src/vulkan/vk-shader-table.cpp index c654a2b1..1ede9983 100644 --- a/src/vulkan/vk-shader-table.cpp +++ b/src/vulkan/vk-shader-table.cpp @@ -28,11 +28,10 @@ RefPtr ShaderTableImpl::createDeviceBuffer( ComPtr buffer; BufferDesc bufferDesc = {}; bufferDesc.memoryType = MemoryType::DeviceLocal; + bufferDesc.usage = BufferUsage::ShaderTable | BufferUsage::CopyDestination; bufferDesc.defaultState = ResourceState::General; - bufferDesc.allowedStates = ResourceStateSet(ResourceState::General, ResourceState::CopyDestination); bufferDesc.size = tableSize; - static_cast(m_device) - ->createBufferImpl(bufferDesc, VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR, nullptr, buffer.writeRef()); + static_cast(m_device)->createBuffer(bufferDesc, nullptr, buffer.writeRef()); TransientResourceHeapImpl* transientHeapImpl = static_cast(transientHeap); diff --git a/src/vulkan/vk-swap-chain.cpp b/src/vulkan/vk-swap-chain.cpp index 694fb554..7cb73350 100644 --- a/src/vulkan/vk-swap-chain.cpp +++ b/src/vulkan/vk-swap-chain.cpp @@ -149,8 +149,7 @@ Result SwapchainImpl::createSwapchainAndImages() for (GfxIndex i = 0; i < m_desc.imageCount; i++) { TextureDesc imageDesc = {}; - imageDesc.allowedStates = - ResourceStateSet(ResourceState::Present, ResourceState::RenderTarget, ResourceState::CopyDestination); + imageDesc.usage = TextureUsage::Present | TextureUsage::RenderTarget | TextureUsage::CopyDestination; imageDesc.type = TextureType::Texture2D; imageDesc.arraySize = 0; imageDesc.format = m_desc.format; diff --git a/tests/test-buffer-barrier.cpp b/tests/test-buffer-barrier.cpp index 298c0f54..600f5fdd 100644 --- a/tests/test-buffer-barrier.cpp +++ b/tests/test-buffer-barrier.cpp @@ -32,12 +32,11 @@ void createFloatBuffer( bufferDesc.size = elementCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.defaultState = unorderedAccess ? ResourceState::UnorderedAccess : ResourceState::ShaderResource; bufferDesc.memoryType = MemoryType::DeviceLocal; - bufferDesc.allowedStates = - ResourceStateSet(ResourceState::ShaderResource, ResourceState::CopyDestination, ResourceState::CopySource); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::CopyDestination | BufferUsage::CopySource; if (unorderedAccess) - bufferDesc.allowedStates.add(ResourceState::UnorderedAccess); + bufferDesc.usage |= BufferUsage::UnorderedAccess; + bufferDesc.defaultState = unorderedAccess ? ResourceState::UnorderedAccess : ResourceState::ShaderResource; REQUIRE_CALL(device->createBuffer(bufferDesc, (void*)initialData, outBuffer.buffer.writeRef())); diff --git a/tests/test-clear-texture.cpp b/tests/test-clear-texture.cpp index 68214ad3..26691903 100644 --- a/tests/test-clear-texture.cpp +++ b/tests/test-clear-texture.cpp @@ -19,9 +19,8 @@ void testClearTexture(GpuTestContext* ctx, DeviceType deviceType) srcTexDesc.size.width = 4; srcTexDesc.size.height = 4; srcTexDesc.size.depth = 1; + srcTexDesc.usage = TextureUsage::RenderTarget | TextureUsage::CopySource | TextureUsage::CopyDestination; srcTexDesc.defaultState = ResourceState::RenderTarget; - srcTexDesc.allowedStates = - ResourceStateSet(ResourceState::RenderTarget, ResourceState::CopySource, ResourceState::CopyDestination); srcTexDesc.format = Format::R32G32B32A32_FLOAT; ComPtr srcTexture; diff --git a/tests/test-compute-smoke.cpp b/tests/test-compute-smoke.cpp index ceabff8e..d841c274 100644 --- a/tests/test-compute-smoke.cpp +++ b/tests/test-compute-smoke.cpp @@ -27,12 +27,8 @@ void testComputeSmoke(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-compute-trivial.cpp b/tests/test-compute-trivial.cpp index fea1a240..a9eb8d44 100644 --- a/tests/test-compute-trivial.cpp +++ b/tests/test-compute-trivial.cpp @@ -27,12 +27,8 @@ void testComputeTrivial(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-copy-texture.cpp b/tests/test-copy-texture.cpp index 63369c3c..052ea20a 100644 --- a/tests/test-copy-texture.cpp +++ b/tests/test-copy-texture.cpp @@ -73,13 +73,12 @@ struct BaseCopyTextureTest srcTexDesc.numMipLevels = srcTextureInfo->mipLevelCount; srcTexDesc.arraySize = srcTextureInfo->arrayLayerCount; srcTexDesc.size = srcTextureInfo->extents; - srcTexDesc.defaultState = ResourceState::ShaderResource; - srcTexDesc.allowedStates = ResourceStateSet(ResourceState::ShaderResource, ResourceState::CopySource); + srcTexDesc.usage = TextureUsage::ShaderResource | TextureUsage::CopySource; if (srcTextureInfo->format == Format::D32_FLOAT || srcTextureInfo->format == Format::D16_UNORM) { - srcTexDesc.allowedStates.add(ResourceState::DepthWrite); - srcTexDesc.allowedStates.add(ResourceState::DepthRead); + srcTexDesc.usage |= (TextureUsage::DepthWrite | TextureUsage::DepthRead); } + srcTexDesc.defaultState = ResourceState::ShaderResource; srcTexDesc.format = srcTextureInfo->format; REQUIRE_CALL(device->createTexture(srcTexDesc, srcTextureInfo->subresourceDatas.data(), srcTexture.writeRef())); @@ -89,14 +88,12 @@ struct BaseCopyTextureTest dstTexDesc.numMipLevels = dstTextureInfo->mipLevelCount; dstTexDesc.arraySize = dstTextureInfo->arrayLayerCount; dstTexDesc.size = dstTextureInfo->extents; - dstTexDesc.defaultState = ResourceState::CopyDestination; - dstTexDesc.allowedStates = - ResourceStateSet(ResourceState::ShaderResource, ResourceState::CopyDestination, ResourceState::CopySource); + dstTexDesc.usage = TextureUsage::ShaderResource | TextureUsage::CopyDestination | TextureUsage::CopySource; if (dstTextureInfo->format == Format::D32_FLOAT || dstTextureInfo->format == Format::D16_UNORM) { - dstTexDesc.allowedStates.add(ResourceState::DepthWrite); - dstTexDesc.allowedStates.add(ResourceState::DepthRead); + dstTexDesc.usage |= (TextureUsage::DepthWrite | TextureUsage::DepthRead); } + dstTexDesc.defaultState = ResourceState::CopyDestination; dstTexDesc.format = dstTextureInfo->format; REQUIRE_CALL(device->createTexture(dstTexDesc, dstTextureInfo->subresourceDatas.data(), dstTexture.writeRef())); @@ -110,12 +107,8 @@ struct BaseCopyTextureTest bufferDesc.size = bufferCopyExtents.height * bufferCopyExtents.depth * alignedRowStride; bufferDesc.format = Format::Unknown; bufferDesc.elementSize = 0; - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::CopyDestination; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-create-buffer-from-handle.cpp b/tests/test-create-buffer-from-handle.cpp index 7b9ed448..db64c909 100644 --- a/tests/test-create-buffer-from-handle.cpp +++ b/tests/test-create-buffer-from-handle.cpp @@ -27,12 +27,8 @@ void testCreateBufferFromHandle(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-existing-device-handle.cpp b/tests/test-existing-device-handle.cpp index a8185c97..aa602dbf 100644 --- a/tests/test-existing-device-handle.cpp +++ b/tests/test-existing-device-handle.cpp @@ -44,12 +44,8 @@ void testExistingDeviceHandle(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-formats.cpp b/tests/test-formats.cpp index 07f61525..b15b8168 100644 --- a/tests/test-formats.cpp +++ b/tests/test-formats.cpp @@ -38,17 +38,13 @@ Format convertTypelessFormat(Format format) void setUpAndRunTest( IDevice* device, + ComPtr transientHeap, ComPtr texView, ComPtr bufferView, const char* entryPoint, ComPtr sampler = nullptr ) { - ComPtr transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; - REQUIRE_CALL(device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); - ComPtr shaderProgram; slang::ProgramLayout* slangReflection; REQUIRE_CALL(loadComputeProgram(device, shaderProgram, "test-formats", entryPoint, slangReflection)); @@ -99,6 +95,7 @@ ComPtr createTexView(IDevice* device, Extents size, Format format texDesc.numMipLevels = mips; texDesc.arraySize = 1; texDesc.size = size; + texDesc.usage = TextureUsage::ShaderResource; texDesc.defaultState = ResourceState::ShaderResource; texDesc.format = format; @@ -120,12 +117,8 @@ ComPtr createBuffer(IDevice* device, int size, void* initialData) bufferDesc.size = size * sizeof(T); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(T); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; @@ -148,6 +141,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) { ComPtr device = createTestingDevice(ctx, deviceType); + ComPtr transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + REQUIRE_CALL(device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + bool isSwiftShader = isSwiftShaderDevice(device); SamplerDesc samplerDesc; @@ -183,7 +181,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 32, 0}; auto texView = createTexView(device, size, Format::R32G32B32A32_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -191,7 +189,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R32G32B32A32_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -206,7 +204,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 24, 0}; auto texView = createTexView(device, size, Format::R32G32B32_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat3"); compareComputeResult( device, floatResults, @@ -214,7 +212,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R32G32B32_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat3"); compareComputeResult( device, floatResults, @@ -227,11 +225,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R32G32_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f}); texView = createTexView(device, size, Format::R32G32_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f}); } @@ -240,11 +238,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R32_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.5f, 0.25f}); texView = createTexView(device, size, Format::R32_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.5f, 0.25f}); } @@ -254,7 +252,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R16G16B16A16_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -262,7 +260,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R16G16B16A16_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -275,11 +273,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R16G16_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f}); texView = createTexView(device, size, Format::R16G16_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f}); } @@ -288,11 +286,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R16_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.5f, 0.25f}); texView = createTexView(device, size, Format::R16_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.5f, 0.25f}); } @@ -301,7 +299,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 32, 0}; auto texView = createTexView(device, size, Format::R32G32B32A32_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint4"); compareComputeResult( device, uintResults, @@ -316,7 +314,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 24, 0}; auto texView = createTexView(device, size, Format::R32G32B32_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint3"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint3"); compareComputeResult( device, uintResults, @@ -329,7 +327,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R32G32_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint2"); compareComputeResult(device, uintResults, std::array{255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u}); } @@ -338,7 +336,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R32_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint"); compareComputeResult(device, uintResults, std::array{255u, 0u, 127u, 73u}); } @@ -347,7 +345,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R16G16B16A16_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint4"); compareComputeResult( device, uintResults, @@ -360,7 +358,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R16G16_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint2"); compareComputeResult(device, uintResults, std::array{255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u}); } @@ -369,7 +367,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R16_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint"); compareComputeResult(device, uintResults, std::array{255u, 0u, 127u, 73u}); } @@ -378,7 +376,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R8G8B8A8_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint4"); compareComputeResult( device, uintResults, @@ -391,7 +389,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R8G8_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint2"); compareComputeResult(device, uintResults, std::array{255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u}); } @@ -400,7 +398,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 2, 0}; auto texView = createTexView(device, size, Format::R8_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint"); compareComputeResult(device, uintResults, std::array{255u, 0u, 127u, 73u}); } @@ -409,7 +407,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 32, 0}; auto texView = createTexView(device, size, Format::R32G32B32A32_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt4"); compareComputeResult( device, intResults, @@ -424,7 +422,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 24, 0}; auto texView = createTexView(device, size, Format::R32G32B32_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt3"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt3"); compareComputeResult(device, intResults, std::array{255, 0, 0, 0, 255, 0, 0, 0, 255, 127, 127, 127}); } @@ -433,7 +431,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R32G32_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt2"); compareComputeResult(device, intResults, std::array{255, 0, 0, 255, 255, 255, 127, 127}); } @@ -442,7 +440,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R32_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt"); compareComputeResult(device, intResults, std::array{255, 0, 127, 73}); } @@ -451,7 +449,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R16G16B16A16_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt4"); compareComputeResult( device, intResults, @@ -464,7 +462,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R16G16_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt2"); compareComputeResult(device, intResults, std::array{255, 0, 0, 255, 255, 255, 127, 127}); } @@ -473,7 +471,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R16_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt"); compareComputeResult(device, intResults, std::array{255, 0, 127, 73}); } @@ -482,7 +480,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R8G8B8A8_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt4"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt4"); compareComputeResult( device, intResults, @@ -495,7 +493,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R8G8_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt2"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt2"); compareComputeResult(device, intResults, std::array{127, 0, 0, 127, 127, 127, 73, 73}); } @@ -504,7 +502,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 2, 0}; auto texView = createTexView(device, size, Format::R8_SINT, &subData); - setUpAndRunTest(device, texView, intBufferView, "copyTexInt"); + setUpAndRunTest(device, transientHeap, texView, intBufferView, "copyTexInt"); compareComputeResult(device, intResults, std::array{127, 0, 73, 25}); } @@ -514,7 +512,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R16G16B16A16_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -544,7 +542,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R16G16_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult( device, floatResults, @@ -557,7 +555,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R16_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.499992371f, 0.249988556f}); } @@ -568,7 +566,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R8G8B8A8_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -593,7 +591,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R8G8B8A8_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -618,7 +616,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R8G8B8A8_UNORM_SRGB, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -650,7 +648,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R8G8_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult( device, floatResults, @@ -658,7 +656,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R8G8_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult( device, floatResults, @@ -673,11 +671,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 2, 0}; auto texView = createTexView(device, size, Format::R8_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.498039216f, 0.247058824f}); texView = createTexView(device, size, Format::R8_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.498039216f, 0.247058824f}); } @@ -688,7 +686,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::B8G8R8A8_TYPELESS, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -713,7 +711,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::B8G8R8A8_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -738,7 +736,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::B8G8R8A8_UNORM_SRGB, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -768,7 +766,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, size, Format::R16G16B16A16_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -781,7 +779,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R16G16_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f}); } @@ -790,7 +788,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R16_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, -1.0f, 0.0f}); } @@ -799,7 +797,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R8G8B8A8_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -812,7 +810,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::R8G8_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat2"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f}); } @@ -821,7 +819,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 2, 0}; auto texView = createTexView(device, size, Format::R8_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat"); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, -1.0f, 0.0f}); } @@ -832,7 +830,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::B4G4R4A4_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -864,7 +862,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 4, 0}; auto texView = createTexView(device, size, Format::B5G6R5_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat3"); compareComputeResult( device, floatResults, @@ -872,7 +870,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::B5G5R5A1_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -902,7 +900,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R9G9B9E5_SHAREDEXP, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat3"); compareComputeResult( device, floatResults, @@ -917,7 +915,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R10G10B10A2_TYPELESS, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint4"); compareComputeResult( device, uintResults, @@ -925,7 +923,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R10G10B10A2_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat4"); compareComputeResult( device, floatResults, @@ -950,7 +948,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, size, Format::R10G10B10A2_UINT, &subData); - setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4"); + setUpAndRunTest(device, transientHeap, texView, uintBufferView, "copyTexUint4"); compareComputeResult( device, uintResults, @@ -963,7 +961,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, size, Format::R11G11B10_FLOAT, &subData); - setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3"); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "copyTexFloat3"); compareComputeResult( device, floatResults, @@ -988,11 +986,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) size.depth = 1; auto texView = createTexView(device, size, Format::BC1_UNORM, subData, 2); - setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleMips", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.517647088f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); texView = createTexView(device, size, Format::BC1_UNORM_SRGB, subData, 2); - setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleMips", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.230468750f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); } @@ -1003,11 +1001,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC2_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.517647088f, 1.0f}); texView = createTexView(device, bcSize, Format::BC2_UNORM_SRGB, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.230468750f, 1.0f}); } @@ -1018,11 +1016,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC3_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.517647088f, 1.0f}); texView = createTexView(device, bcSize, Format::BC3_UNORM_SRGB, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0f, 0.230468750f, 1.0f}); } @@ -1033,11 +1031,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 8, 0}; auto texView = createTexView(device, bcSize, Format::BC4_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.498039216f, 0.0f, 0.0f, 1.0f}); texView = createTexView(device, bcSize, Format::BC4_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{1.0f, 0.0f, 0.0f, 1.0f}); } @@ -1048,7 +1046,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC5_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult( device, floatResults, @@ -1056,7 +1054,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) ); texView = createTexView(device, bcSize, Format::BC5_SNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}); } @@ -1068,7 +1066,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC6H_UF16, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.336669922f, 0.911132812f, 2.13867188f, 1.0f}); } @@ -1079,7 +1077,7 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC6H_SF16, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.336914062f, 0.910644531f, 2.14062500f, 1.0f}); } @@ -1090,11 +1088,11 @@ void testFormats(GpuTestContext* ctx, DeviceType deviceType) SubresourceData subData = {(void*)texData, 16, 0}; auto texView = createTexView(device, bcSize, Format::BC7_UNORM, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.101960786f, 0.0f, 1.0f}); texView = createTexView(device, bcSize, Format::BC7_UNORM_SRGB, &subData); - setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler); + setUpAndRunTest(device, transientHeap, texView, floatBufferView, "sampleTex", sampler); compareComputeResult(device, floatResults, std::array{0.0f, 0.0103149414f, 0.0f, 1.0f}); } } diff --git a/tests/test-instanced-draw.cpp b/tests/test-instanced-draw.cpp index 30bfebb4..a535f711 100644 --- a/tests/test-instanced-draw.cpp +++ b/tests/test-instanced-draw.cpp @@ -51,8 +51,8 @@ static ComPtr createVertexBuffer(IDevice* device) { BufferDesc vertexBufferDesc; vertexBufferDesc.size = kVertexCount * sizeof(Vertex); + vertexBufferDesc.usage = BufferUsage::VertexBuffer; vertexBufferDesc.defaultState = ResourceState::VertexBuffer; - vertexBufferDesc.allowedStates = ResourceState::VertexBuffer; ComPtr vertexBuffer = device->createBuffer(vertexBufferDesc, &kVertexData[0]); REQUIRE(vertexBuffer != nullptr); return vertexBuffer; @@ -62,8 +62,8 @@ static ComPtr createInstanceBuffer(IDevice* device) { BufferDesc instanceBufferDesc; instanceBufferDesc.size = kInstanceCount * sizeof(Instance); + instanceBufferDesc.usage = BufferUsage::VertexBuffer; instanceBufferDesc.defaultState = ResourceState::VertexBuffer; - instanceBufferDesc.allowedStates = ResourceState::VertexBuffer; ComPtr instanceBuffer = device->createBuffer(instanceBufferDesc, &kInstanceData[0]); REQUIRE(instanceBuffer != nullptr); return instanceBuffer; @@ -73,8 +73,8 @@ static ComPtr createIndexBuffer(IDevice* device) { BufferDesc indexBufferDesc; indexBufferDesc.size = kIndexCount * sizeof(uint32_t); + indexBufferDesc.usage = BufferUsage::IndexBuffer; indexBufferDesc.defaultState = ResourceState::IndexBuffer; - indexBufferDesc.allowedStates = ResourceState::IndexBuffer; ComPtr indexBuffer = device->createBuffer(indexBufferDesc, &kIndexData[0]); REQUIRE(indexBuffer != nullptr); return indexBuffer; @@ -89,8 +89,8 @@ static ComPtr createColorBuffer(IDevice* device) colorBufferDesc.size.depth = 1; colorBufferDesc.numMipLevels = 1; colorBufferDesc.format = format; + colorBufferDesc.usage = TextureUsage::RenderTarget | TextureUsage::CopySource; colorBufferDesc.defaultState = ResourceState::RenderTarget; - colorBufferDesc.allowedStates = {ResourceState::RenderTarget, ResourceState::CopySource}; ComPtr colorBuffer = device->createTexture(colorBufferDesc, nullptr); REQUIRE(colorBuffer != nullptr); return colorBuffer; @@ -349,8 +349,8 @@ struct DrawIndirectTest : BaseDrawTest BufferDesc indirectBufferDesc; indirectBufferDesc.size = sizeof(IndirectArgData); + indirectBufferDesc.usage = BufferUsage::IndirectArgument; indirectBufferDesc.defaultState = ResourceState::IndirectArgument; - indirectBufferDesc.allowedStates = ResourceState::IndirectArgument; ComPtr indirectBuffer = device->createBuffer(indirectBufferDesc, &kIndirectData); REQUIRE(indirectBuffer != nullptr); return indirectBuffer; @@ -433,8 +433,8 @@ struct DrawIndexedIndirectTest : BaseDrawTest BufferDesc indirectBufferDesc; indirectBufferDesc.size = sizeof(IndexedIndirectArgData); + indirectBufferDesc.usage = BufferUsage::IndirectArgument; indirectBufferDesc.defaultState = ResourceState::IndirectArgument; - indirectBufferDesc.allowedStates = ResourceState::IndirectArgument; ComPtr indexBuffer = device->createBuffer(indirectBufferDesc, &kIndexedIndirectData); REQUIRE(indexBuffer != nullptr); return indexBuffer; diff --git a/tests/test-link-time-constant.cpp b/tests/test-link-time-constant.cpp index 58bfc315..88d07072 100644 --- a/tests/test-link-time-constant.cpp +++ b/tests/test-link-time-constant.cpp @@ -94,12 +94,8 @@ void testLinkTimeConstant(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-link-time-default.cpp b/tests/test-link-time-default.cpp index 2c9b9f65..aed55706 100644 --- a/tests/test-link-time-default.cpp +++ b/tests/test-link-time-default.cpp @@ -133,12 +133,8 @@ void testLinkTimeDefault(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-link-time-options.cpp b/tests/test-link-time-options.cpp index 975716b2..87489bf2 100644 --- a/tests/test-link-time-options.cpp +++ b/tests/test-link-time-options.cpp @@ -82,12 +82,8 @@ void testLinkTimeOptions(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-link-time-type.cpp b/tests/test-link-time-type.cpp index c2d6db38..9b8711cc 100644 --- a/tests/test-link-time-type.cpp +++ b/tests/test-link-time-type.cpp @@ -121,12 +121,8 @@ void testLinkTimeType(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-mutable-shader-object.cpp b/tests/test-mutable-shader-object.cpp index 7435cf16..9009a385 100644 --- a/tests/test-mutable-shader-object.cpp +++ b/tests/test-mutable-shader-object.cpp @@ -28,12 +28,8 @@ void testMutableShaderObject(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = sizeof(initialData); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-native-handle.cpp b/tests/test-native-handle.cpp index 213e1b5d..50dc6ee4 100644 --- a/tests/test-native-handle.cpp +++ b/tests/test-native-handle.cpp @@ -18,12 +18,8 @@ void testNativeHandleBuffer(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; @@ -63,6 +59,7 @@ void testNativeHandleTexture(GpuTestContext* ctx, DeviceType deviceType) desc.size.width = 1; desc.size.height = 1; desc.size.depth = 1; + desc.usage = TextureUsage::UnorderedAccess; desc.defaultState = ResourceState::UnorderedAccess; desc.format = Format::R16G16B16A16_FLOAT; diff --git a/tests/test-nested-parameter-block.cpp b/tests/test-nested-parameter-block.cpp index aa3f8d0a..25f6e530 100644 --- a/tests/test-nested-parameter-block.cpp +++ b/tests/test-nested-parameter-block.cpp @@ -11,12 +11,8 @@ ComPtr createBuffer(IDevice* device, uint32_t data, ResourceState defau bufferDesc.size = sizeof(initialData); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(uint32_t) * 4; - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = defaultState; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-precompiled-module-2.cpp b/tests/test-precompiled-module-2.cpp index d0bcfc93..8adb0e34 100644 --- a/tests/test-precompiled-module-2.cpp +++ b/tests/test-precompiled-module-2.cpp @@ -127,12 +127,7 @@ void precompiledModule2TestImplCommon(IDevice* device, UnitTestContext* context, bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = gfx::Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-precompiled-module-cache.cpp b/tests/test-precompiled-module-cache.cpp index 5ee649d4..7f52a38c 100644 --- a/tests/test-precompiled-module-cache.cpp +++ b/tests/test-precompiled-module-cache.cpp @@ -155,12 +155,7 @@ void precompiledModuleCacheTestImpl(IDevice* device, UnitTestContext* context) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = gfx::Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-precompiled-module.cpp b/tests/test-precompiled-module.cpp index e1d1d5c6..20cc8518 100644 --- a/tests/test-precompiled-module.cpp +++ b/tests/test-precompiled-module.cpp @@ -89,12 +89,7 @@ void testPrecompiledModule(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-ray-tracing.cpp b/tests/test-ray-tracing.cpp index aa765c2f..4941869f 100644 --- a/tests/test-ray-tracing.cpp +++ b/tests/test-ray-tracing.cpp @@ -115,8 +115,8 @@ struct BaseRayTracingTest resultTextureDesc.size.width = width; resultTextureDesc.size.height = height; resultTextureDesc.size.depth = 1; + resultTextureDesc.usage = TextureUsage::UnorderedAccess | TextureUsage::CopySource; resultTextureDesc.defaultState = ResourceState::UnorderedAccess; - resultTextureDesc.allowedStates = {ResourceState::UnorderedAccess, ResourceState::CopySource}; resultTextureDesc.format = Format::R32G32B32A32_FLOAT; resultTexture = device->createTexture(resultTextureDesc); IResourceView::Desc resultUAVDesc = {}; @@ -133,18 +133,21 @@ struct BaseRayTracingTest BufferDesc vertexBufferDesc; vertexBufferDesc.size = kVertexCount * sizeof(Vertex); + vertexBufferDesc.usage = BufferUsage::ShaderResource; vertexBufferDesc.defaultState = ResourceState::ShaderResource; vertexBuffer = device->createBuffer(vertexBufferDesc, &kVertexData[0]); REQUIRE(vertexBuffer != nullptr); BufferDesc indexBufferDesc; indexBufferDesc.size = kIndexCount * sizeof(int32_t); + indexBufferDesc.usage = BufferUsage::ShaderResource; indexBufferDesc.defaultState = ResourceState::ShaderResource; indexBuffer = device->createBuffer(indexBufferDesc, &kIndexData[0]); REQUIRE(indexBuffer != nullptr); BufferDesc transformBufferDesc; transformBufferDesc.size = sizeof(float) * 12; + transformBufferDesc.usage = BufferUsage::ShaderResource; transformBufferDesc.defaultState = ResourceState::ShaderResource; float transformData[12] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}; transformBuffer = device->createBuffer(transformBufferDesc, &transformData); @@ -183,10 +186,12 @@ struct BaseRayTracingTest )); // Allocate buffers for acceleration structure. BufferDesc asDraftBufferDesc; + asDraftBufferDesc.usage = BufferUsage::AccelerationStructure; asDraftBufferDesc.defaultState = ResourceState::AccelerationStructure; asDraftBufferDesc.size = (size_t)accelerationStructurePrebuildInfo.resultDataMaxSize; ComPtr draftBuffer = device->createBuffer(asDraftBufferDesc); BufferDesc scratchBufferDesc; + scratchBufferDesc.usage = BufferUsage::UnorderedAccess; scratchBufferDesc.defaultState = ResourceState::UnorderedAccess; scratchBufferDesc.size = (size_t)accelerationStructurePrebuildInfo.scratchDataSize; ComPtr scratchBuffer = device->createBuffer(scratchBufferDesc); @@ -226,6 +231,7 @@ struct BaseRayTracingTest uint64_t compactedSize = 0; compactedSizeQuery->getResult(0, 1, &compactedSize); BufferDesc asBufferDesc; + asBufferDesc.usage = BufferUsage::AccelerationStructure; asBufferDesc.defaultState = ResourceState::AccelerationStructure; asBufferDesc.size = (size_t)compactedSize; BLASBuffer = device->createBuffer(asBufferDesc); @@ -259,6 +265,7 @@ struct BaseRayTracingTest BufferDesc instanceBufferDesc; instanceBufferDesc.size = instanceDescs.size() * sizeof(IAccelerationStructure::InstanceDesc); + instanceBufferDesc.usage = BufferUsage::ShaderResource; instanceBufferDesc.defaultState = ResourceState::ShaderResource; instanceBuffer = device->createBuffer(instanceBufferDesc, instanceDescs.data()); REQUIRE(instanceBuffer != nullptr); @@ -276,11 +283,13 @@ struct BaseRayTracingTest )); BufferDesc asBufferDesc; + asBufferDesc.usage = BufferUsage::AccelerationStructure; asBufferDesc.defaultState = ResourceState::AccelerationStructure; asBufferDesc.size = (size_t)accelerationStructurePrebuildInfo.resultDataMaxSize; TLASBuffer = device->createBuffer(asBufferDesc); BufferDesc scratchBufferDesc; + scratchBufferDesc.usage = BufferUsage::UnorderedAccess; scratchBufferDesc.defaultState = ResourceState::UnorderedAccess; scratchBufferDesc.size = (size_t)accelerationStructurePrebuildInfo.scratchDataSize; ComPtr scratchBuffer = device->createBuffer(scratchBufferDesc); diff --git a/tests/test-resolve-resource-tests.cpp b/tests/test-resolve-resource-tests.cpp index bfbc64e4..d974abc2 100644 --- a/tests/test-resolve-resource-tests.cpp +++ b/tests/test-resolve-resource-tests.cpp @@ -44,8 +44,8 @@ static ComPtr createVertexBuffer(IDevice* device) { BufferDesc vertexBufferDesc; vertexBufferDesc.size = kVertexCount * sizeof(Vertex); + vertexBufferDesc.usage = BufferUsage::VertexBuffer; vertexBufferDesc.defaultState = ResourceState::VertexBuffer; - vertexBufferDesc.allowedStates = ResourceState::VertexBuffer; ComPtr vertexBuffer = device->createBuffer(vertexBufferDesc, &kVertexData[0]); REQUIRE(vertexBuffer != nullptr); return vertexBuffer; @@ -91,8 +91,8 @@ struct BaseResolveResourceTest msaaTexDesc.numMipLevels = dstTextureInfo.numMipLevels; msaaTexDesc.arraySize = dstTextureInfo.arraySize; msaaTexDesc.size = dstTextureInfo.extent; + msaaTexDesc.usage = TextureUsage::RenderTarget | TextureUsage::ResolveSource; msaaTexDesc.defaultState = ResourceState::RenderTarget; - msaaTexDesc.allowedStates = ResourceStateSet(ResourceState::RenderTarget, ResourceState::ResolveSource); msaaTexDesc.format = format; msaaTexDesc.sampleCount = 4; @@ -103,8 +103,8 @@ struct BaseResolveResourceTest dstTexDesc.numMipLevels = dstTextureInfo.numMipLevels; dstTexDesc.arraySize = dstTextureInfo.arraySize; dstTexDesc.size = dstTextureInfo.extent; + dstTexDesc.usage = TextureUsage::ResolveDestination | TextureUsage::CopySource; dstTexDesc.defaultState = ResourceState::ResolveDestination; - dstTexDesc.allowedStates = ResourceStateSet(ResourceState::ResolveDestination, ResourceState::CopySource); dstTexDesc.format = format; REQUIRE_CALL(device->createTexture(dstTexDesc, dstTextureInfo.initData, dstTexture.writeRef())); diff --git a/tests/test-resource-states.cpp b/tests/test-resource-states.cpp new file mode 100644 index 00000000..7f8aee40 --- /dev/null +++ b/tests/test-resource-states.cpp @@ -0,0 +1,171 @@ +#include "testing.h" + +#include + +using namespace rhi; +using namespace rhi::testing; + +void testBufferResourceStates(GpuTestContext* ctx, DeviceType deviceType) +{ + ComPtr device = createTestingDevice(ctx, deviceType); + + ComPtr transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + REQUIRE_CALL(device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + + ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; + auto queue = device->createCommandQueue(queueDesc); + + BufferUsage bufferUsage = BufferUsage::VertexBuffer | BufferUsage::IndexBuffer | BufferUsage::ConstantBuffer | + BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | + BufferUsage::IndirectArgument | BufferUsage::CopySource | BufferUsage::CopyDestination | + // BufferUsage::AccelerationStructure | BufferUsage::AccelerationStructureBuildInput | + BufferUsage::ShaderTable; + + std::set allowedStates = { + ResourceState::VertexBuffer, + ResourceState::IndexBuffer, + ResourceState::ConstantBuffer, + ResourceState::ShaderResource, + ResourceState::UnorderedAccess, + ResourceState::IndirectArgument, + ResourceState::CopySource, + ResourceState::CopyDestination, + // ResourceState::AccelerationStructure, + // ResourceState::AccelerationStructureBuildInput, + ResourceState::PixelShaderResource, + ResourceState::NonPixelShaderResource, + }; + + BufferDesc bufferDesc = {}; + bufferDesc.size = 256; + bufferDesc.format = Format::Unknown; + bufferDesc.elementSize = sizeof(float); + bufferDesc.usage = bufferUsage; + bufferDesc.memoryType = MemoryType::DeviceLocal; + ComPtr buffer; + REQUIRE_CALL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); + + auto commandBuffer = transientHeap->createCommandBuffer(); + auto encoder = commandBuffer->encodeResourceCommands(); + + ResourceState currentState = buffer->getDesc()->defaultState; + + for (ResourceState state : allowedStates) + { + encoder->bufferBarrier(buffer, currentState, state); + currentState = state; + } + + encoder->endEncoding(); + commandBuffer->close(); + queue->executeCommandBuffer(commandBuffer); + queue->waitOnHost(); +} + +void testTextureResourceStates(GpuTestContext* ctx, DeviceType deviceType) +{ + ComPtr device = createTestingDevice(ctx, deviceType); + + ComPtr transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + REQUIRE_CALL(device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + + ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; + auto queue = device->createCommandQueue(queueDesc); + + for (uint32_t i = 1; i < (uint32_t)Format::_Count; ++i) + { + auto format = (Format)i; + FormatInfo info; + rhiGetFormatInfo(format, &info); + FormatSupport formatSupport; + REQUIRE_CALL(device->getFormatSupport(format, &formatSupport)); + + if (!is_set(formatSupport, FormatSupport::Texture)) + continue; + + TextureUsage textureUsage = TextureUsage::CopySource | TextureUsage::CopyDestination | + TextureUsage::ResolveSource | TextureUsage::ResolveDestination; + + std::set allowedStates = { + ResourceState::ResolveSource, + ResourceState::ResolveDestination, + ResourceState::CopySource, + ResourceState::CopyDestination + }; + + if (is_set(formatSupport, FormatSupport::RenderTarget)) + { + textureUsage |= TextureUsage::RenderTarget; + allowedStates.insert(ResourceState::RenderTarget); + } + if (is_set(formatSupport, FormatSupport::DepthStencil)) + { + textureUsage |= (TextureUsage::DepthRead | TextureUsage::DepthWrite); + allowedStates.insert(ResourceState::DepthRead); + allowedStates.insert(ResourceState::DepthWrite); + } + if (is_set(formatSupport, FormatSupport::ShaderLoad) || is_set(formatSupport, FormatSupport::ShaderSample)) + { + textureUsage |= TextureUsage::ShaderResource; + allowedStates.insert(ResourceState::ShaderResource); + } + if (is_set(formatSupport, FormatSupport::ShaderUavLoad) || is_set(formatSupport, FormatSupport::ShaderUavStore)) + { + textureUsage |= TextureUsage::UnorderedAccess; + allowedStates.insert(ResourceState::UnorderedAccess); + } + + TextureDesc texDesc = {}; + texDesc.type = TextureType::Texture2D; + texDesc.format = format; + texDesc.size = Extents{4, 4, 1}; + texDesc.numMipLevels = 1; + texDesc.arraySize = 1; + texDesc.usage = textureUsage; + texDesc.memoryType = MemoryType::DeviceLocal; + ComPtr texture; + REQUIRE_CALL(device->createTexture(texDesc, nullptr, texture.writeRef())); + + auto commandBuffer = transientHeap->createCommandBuffer(); + auto encoder = commandBuffer->encodeResourceCommands(); + + ResourceState currentState = texture->getDesc()->defaultState; + + for (ResourceState state : allowedStates) + { + encoder->textureBarrier(texture, currentState, state); + currentState = state; + } + + encoder->endEncoding(); + commandBuffer->close(); + queue->executeCommandBuffer(commandBuffer); + queue->waitOnHost(); + } +} + +TEST_CASE("buffer-resource-states") +{ + runGpuTests( + testBufferResourceStates, + { + DeviceType::D3D12, + DeviceType::Vulkan, + } + ); +} + +TEST_CASE("texture-resource-states") +{ + runGpuTests( + testTextureResourceStates, + { + DeviceType::D3D12, + DeviceType::Vulkan, + } + ); +} diff --git a/tests/test-root-mutable-shader-object.cpp b/tests/test-root-mutable-shader-object.cpp index 61611e8d..eed15b19 100644 --- a/tests/test-root-mutable-shader-object.cpp +++ b/tests/test-root-mutable-shader-object.cpp @@ -28,12 +28,8 @@ void testRootMutableShaderObject(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = sizeof(initialData); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-root-shader-parameter.cpp b/tests/test-root-shader-parameter.cpp index b03d4b23..6c28307d 100644 --- a/tests/test-root-shader-parameter.cpp +++ b/tests/test-root-shader-parameter.cpp @@ -10,12 +10,8 @@ static ComPtr createBuffer(IDevice* device, uint32_t content) bufferDesc.size = sizeof(uint32_t); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-sampler-array.cpp b/tests/test-sampler-array.cpp index 74ee8545..02260422 100644 --- a/tests/test-sampler-array.cpp +++ b/tests/test-sampler-array.cpp @@ -10,12 +10,8 @@ static ComPtr createBuffer(IDevice* device, uint32_t content) bufferDesc.size = sizeof(uint32_t); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; @@ -66,8 +62,8 @@ void testSamplerArray(GpuTestContext* ctx, DeviceType deviceType) textureDesc.size.depth = 1; textureDesc.numMipLevels = 2; textureDesc.memoryType = MemoryType::DeviceLocal; + textureDesc.usage = TextureUsage::ShaderResource | TextureUsage::CopyDestination; textureDesc.defaultState = ResourceState::ShaderResource; - textureDesc.allowedStates.add(ResourceState::CopyDestination); uint32_t data[] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; SubresourceData subResourceData[2] = {{data, 8, 16}, {data, 8, 16}}; REQUIRE_CALL(device->createTexture(textureDesc, subResourceData, texture.writeRef())); diff --git a/tests/test-shader-cache.cpp b/tests/test-shader-cache.cpp index 372b173d..227beecd 100644 --- a/tests/test-shader-cache.cpp +++ b/tests/test-shader-cache.cpp @@ -222,12 +222,8 @@ struct ShaderCacheTest bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; @@ -710,8 +706,8 @@ struct ShaderCacheTestGraphics : ShaderCacheTest BufferDesc vertexBufferDesc; vertexBufferDesc.size = sizeof(vertices); + vertexBufferDesc.usage = BufferUsage::VertexBuffer; vertexBufferDesc.defaultState = ResourceState::VertexBuffer; - vertexBufferDesc.allowedStates = ResourceState::VertexBuffer; ComPtr vertexBuffer = device->createBuffer(vertexBufferDesc, vertices); REQUIRE(vertexBuffer != nullptr); return vertexBuffer; @@ -726,8 +722,8 @@ struct ShaderCacheTestGraphics : ShaderCacheTest colorBufferDesc.size.depth = 1; colorBufferDesc.numMipLevels = 1; colorBufferDesc.format = format; + colorBufferDesc.usage = TextureUsage::RenderTarget | TextureUsage::CopySource; colorBufferDesc.defaultState = ResourceState::RenderTarget; - colorBufferDesc.allowedStates = {ResourceState::RenderTarget, ResourceState::CopySource}; ComPtr colorBuffer = device->createTexture(colorBufferDesc, nullptr); REQUIRE(colorBuffer != nullptr); return colorBuffer; diff --git a/tests/test-shared-buffer.cpp b/tests/test-shared-buffer.cpp index aa3cf3f2..396eeaff 100644 --- a/tests/test-shared-buffer.cpp +++ b/tests/test-shared-buffer.cpp @@ -17,12 +17,8 @@ void testSharedBuffer(GpuTestContext* ctx, DeviceType deviceType) bufferDesc.size = numberCount * sizeof(float); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; bufferDesc.isShared = true; diff --git a/tests/test-shared-texture.cpp b/tests/test-shared-texture.cpp index 1e270ada..d55d43cf 100644 --- a/tests/test-shared-texture.cpp +++ b/tests/test-shared-texture.cpp @@ -67,13 +67,9 @@ static ComPtr createTexture(IDevice* device, Extents extents, Format f texDesc.numMipLevels = 1; texDesc.arraySize = 1; texDesc.size = extents; + texDesc.usage = TextureUsage::ShaderResource | TextureUsage::UnorderedAccess | TextureUsage::CopyDestination | + TextureUsage::CopySource; texDesc.defaultState = ResourceState::UnorderedAccess; - texDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); texDesc.format = format; texDesc.isShared = true; @@ -100,12 +96,8 @@ ComPtr createBuffer(IDevice* device, int size, void* initialData) bufferDesc.size = size * sizeof(T); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(T); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; diff --git a/tests/test-supported-resource-states.cpp b/tests/test-supported-resource-states.cpp deleted file mode 100644 index 09892b72..00000000 --- a/tests/test-supported-resource-states.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "testing.h" - -#if SLANG_WINDOWS_FAMILY -#include -#endif - -using namespace rhi; -using namespace rhi::testing; - -struct SupportedResourceStatesTest -{ - IDevice* device; - - ResourceStateSet formatSupportedStates; - ResourceStateSet textureAllowedStates; - ResourceStateSet bufferAllowedStates; - - ComPtr texture; - ComPtr buffer; - - SupportedResourceStatesTest(IDevice* device) - : device(device) - { - } - - Format convertTypelessFormat(Format format) - { - switch (format) - { - case Format::R32G32B32A32_TYPELESS: - return Format::R32G32B32A32_FLOAT; - case Format::R32G32B32_TYPELESS: - return Format::R32G32B32_FLOAT; - case Format::R32G32_TYPELESS: - return Format::R32G32_FLOAT; - case Format::R32_TYPELESS: - return Format::R32_FLOAT; - case Format::R16G16B16A16_TYPELESS: - return Format::R16G16B16A16_FLOAT; - case Format::R16G16_TYPELESS: - return Format::R16G16_FLOAT; - case Format::R16_TYPELESS: - return Format::R16_FLOAT; - case Format::R8G8B8A8_TYPELESS: - return Format::R8G8B8A8_UNORM; - case Format::R8G8_TYPELESS: - return Format::R8G8_UNORM; - case Format::R8_TYPELESS: - return Format::R8_UNORM; - case Format::B8G8R8A8_TYPELESS: - return Format::B8G8R8A8_UNORM; - case Format::R10G10B10A2_TYPELESS: - return Format::R10G10B10A2_UINT; - default: - return Format::Unknown; - } - } - - void transitionResourceStates(IDevice* device) - { - ComPtr transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; - REQUIRE_CALL(device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); - - ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; - auto queue = device->createCommandQueue(queueDesc); - - auto commandBuffer = transientHeap->createCommandBuffer(); - auto encoder = commandBuffer->encodeResourceCommands(); - ResourceState currentTextureState = texture->getDesc()->defaultState; - ResourceState currentBufferState = buffer->getDesc()->defaultState; - - for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; ++i) - { - auto nextState = (ResourceState)i; - if (formatSupportedStates.contains(nextState)) - { - if (bufferAllowedStates.contains(nextState)) - { - encoder->bufferBarrier(buffer, currentBufferState, nextState); - currentBufferState = nextState; - } - if (textureAllowedStates.contains(nextState)) - { - encoder->textureBarrier(texture, currentTextureState, nextState); - currentTextureState = nextState; - } - } - } - encoder->endEncoding(); - commandBuffer->close(); - queue->executeCommandBuffer(commandBuffer); - queue->waitOnHost(); - } - - void run() - { - // Skip Format::Unknown - for (uint32_t i = 1; i < (uint32_t)Format::_Count; ++i) - { - auto baseFormat = (Format)i; - FormatInfo info; - rhiGetFormatInfo(baseFormat, &info); - // Ignore 3-channel textures for now since validation layer seem to report unsupported errors there. - if (info.channelCount == 3) - continue; - - auto format = rhiIsTypelessFormat(baseFormat) ? convertTypelessFormat(baseFormat) : baseFormat; - REQUIRE_CALL(device->getFormatSupportedResourceStates(format, &formatSupportedStates)); - - textureAllowedStates.add( - ResourceState::RenderTarget, - ResourceState::DepthRead, - ResourceState::DepthWrite, - ResourceState::Present, - ResourceState::ResolveSource, - ResourceState::ResolveDestination, - ResourceState::Undefined, - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopySource, - ResourceState::CopyDestination - ); - - bufferAllowedStates.add( - ResourceState::VertexBuffer, - ResourceState::IndexBuffer, - ResourceState::ConstantBuffer, - ResourceState::StreamOutput, - ResourceState::IndirectArgument, - ResourceState::AccelerationStructure, - ResourceState::Undefined, - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopySource, - ResourceState::CopyDestination - ); - - ResourceState currentState = ResourceState::CopySource; - Extents extent; - extent.width = 4; - extent.height = 4; - extent.depth = 1; - - TextureDesc texDesc = {}; - texDesc.type = TextureType::Texture2D; - texDesc.numMipLevels = 1; - texDesc.arraySize = 1; - texDesc.size = extent; - texDesc.defaultState = currentState; - texDesc.allowedStates = formatSupportedStates & textureAllowedStates; - texDesc.memoryType = MemoryType::DeviceLocal; - texDesc.format = format; - - REQUIRE_CALL(device->createTexture(texDesc, nullptr, texture.writeRef())); - - BufferDesc bufferDesc = {}; - bufferDesc.size = 256; - bufferDesc.format = Format::Unknown; - bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = formatSupportedStates & bufferAllowedStates; - bufferDesc.defaultState = currentState; - bufferDesc.memoryType = MemoryType::DeviceLocal; - - REQUIRE_CALL(device->createBuffer(bufferDesc, nullptr, buffer.writeRef())); - - transitionResourceStates(device); - } - } -}; - -void testSupportedResourceStates(GpuTestContext* ctx, DeviceType deviceType) -{ - ComPtr device = createTestingDevice(ctx, deviceType); - SupportedResourceStatesTest test(device); - test.run(); -} - -TEST_CASE("supported-resource-states") -{ - runGpuTests( - testSupportedResourceStates, - { - DeviceType::D3D12, - DeviceType::Vulkan, - } - ); -} diff --git a/tests/test-texture-types.cpp b/tests/test-texture-types.cpp index dcf73eff..195a568f 100644 --- a/tests/test-texture-types.cpp +++ b/tests/test-texture-types.cpp @@ -47,6 +47,23 @@ struct BaseTextureViewTest this->textureInfo->textureType = type; } + TextureUsage getTextureUsageForViewType(IResourceView::Type type) + { + switch (type) + { + case IResourceView::Type::RenderTarget: + return TextureUsage::RenderTarget; + case IResourceView::Type::DepthStencil: + return TextureUsage::DepthWrite; + case IResourceView::Type::ShaderResource: + return TextureUsage::ShaderResource; + case IResourceView::Type::UnorderedAccess: + return TextureUsage::UnorderedAccess; + default: + return TextureUsage::None; + } + } + ResourceState getDefaultResourceStateForViewType(IResourceView::Type type) { switch (type) @@ -127,9 +144,9 @@ struct ShaderAndUnorderedTests : BaseTextureViewTest textureDesc.numMipLevels = textureInfo->mipLevelCount; textureDesc.arraySize = textureInfo->arrayLayerCount; textureDesc.size = textureInfo->extents; + textureDesc.usage = + getTextureUsageForViewType(viewType) | TextureUsage::CopySource | TextureUsage::CopyDestination; textureDesc.defaultState = getDefaultResourceStateForViewType(viewType); - textureDesc.allowedStates = - ResourceStateSet(textureDesc.defaultState, ResourceState::CopySource, ResourceState::CopyDestination); textureDesc.format = textureInfo->format; REQUIRE_CALL(device->createTexture(textureDesc, textureInfo->subresourceDatas.data(), texture.writeRef())); @@ -150,9 +167,8 @@ struct ShaderAndUnorderedTests : BaseTextureViewTest textureDesc.size.width * textureDesc.size.height * textureDesc.size.depth * texelSize * sizeof(uint32_t); bufferDesc.format = Format::Unknown; bufferDesc.elementSize = sizeof(uint32_t); + bufferDesc.usage = BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; - bufferDesc.allowedStates = - ResourceStateSet(bufferDesc.defaultState, ResourceState::CopyDestination, ResourceState::CopySource); bufferDesc.memoryType = MemoryType::DeviceLocal; REQUIRE_CALL(device->createBuffer(bufferDesc, nullptr, resultsBuffer.writeRef())); @@ -353,8 +369,8 @@ struct RenderTargetTests : BaseTextureViewTest { BufferDesc vertexBufferDesc; vertexBufferDesc.size = kVertexCount * sizeof(Vertex); + vertexBufferDesc.usage = BufferUsage::VertexBuffer; vertexBufferDesc.defaultState = ResourceState::VertexBuffer; - vertexBufferDesc.allowedStates = ResourceState::VertexBuffer; vertexBuffer = device->createBuffer(vertexBufferDesc, &kVertexData[0]); REQUIRE(vertexBuffer != nullptr); @@ -373,9 +389,9 @@ struct RenderTargetTests : BaseTextureViewTest sampledTexDesc.numMipLevels = textureInfo->mipLevelCount; sampledTexDesc.arraySize = textureInfo->arrayLayerCount; sampledTexDesc.size = textureInfo->extents; + sampledTexDesc.usage = + getTextureUsageForViewType(viewType) | TextureUsage::ResolveSource | TextureUsage::CopySource; sampledTexDesc.defaultState = getDefaultResourceStateForViewType(viewType); - sampledTexDesc.allowedStates = - ResourceStateSet(sampledTexDesc.defaultState, ResourceState::ResolveSource, ResourceState::CopySource); sampledTexDesc.format = textureInfo->format; sampledTexDesc.sampleCount = sampleCount; @@ -388,8 +404,8 @@ struct RenderTargetTests : BaseTextureViewTest texDesc.numMipLevels = textureInfo->mipLevelCount; texDesc.arraySize = textureInfo->arrayLayerCount; texDesc.size = textureInfo->extents; + texDesc.usage = TextureUsage::ResolveDestination | TextureUsage::CopySource; texDesc.defaultState = ResourceState::ResolveDestination; - texDesc.allowedStates = ResourceStateSet(ResourceState::ResolveDestination, ResourceState::CopySource); texDesc.format = textureInfo->format; REQUIRE_CALL(device->createTexture(texDesc, textureInfo->subresourceDatas.data(), texture.writeRef())); diff --git a/tests/test-uint16-structured-buffer.cpp b/tests/test-uint16-structured-buffer.cpp index 2f2a1d6c..6188de14 100644 --- a/tests/test-uint16-structured-buffer.cpp +++ b/tests/test-uint16-structured-buffer.cpp @@ -29,12 +29,8 @@ void testUint16StructuredBuffer(GpuTestContext* ctx, DeviceType deviceType) // Note: we don't specify any element size here, and rhi should be able to derive the // correct element size from the reflection infomation. bufferDesc.elementSize = 0; - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource - ); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | BufferUsage::CopyDestination | + BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal;