diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-02-03 16:08:13 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 16:08:13 -0800 |
| commit | e586610a3752eb9325ff688d6245ab20bb635a81 (patch) | |
| tree | bd22daed7e32c83d83cab08f91d1097f72894128 /tools/gfx/vulkan/render-vk.cpp | |
| parent | 3aaa586c90a688e035e2941a2e0327bd96a681cb (diff) | |
Added Vulkan implementation of getFormatSupportedResourceStates() (#2108)
* Prelim work on getFormatSupportedResourceStates
* Mostly extended getFormatSupportedResourceStates to cover currently existing resource states, no testing included yet
Co-authored-by: Theresa Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools/gfx/vulkan/render-vk.cpp')
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index ed0fa7bb4..2dcc38a5c 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -60,6 +60,8 @@ public: // Renderer implementation Result initVulkanInstanceAndDevice(const InteropHandle* 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 createTransientResourceHeap( const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override; @@ -7956,6 +7958,78 @@ Result VKDevice::createTextureView(ITextureResource* texture, IResourceView::Des return SLANG_OK; } +// TODO: Buffer vs texture specific? +Result VKDevice::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) +{ + VkFormatProperties supportedProperties; + m_api.vkGetPhysicalDeviceFormatProperties(m_api.m_physicalDevice, VulkanUtil::getVkFormat(format), &supportedProperties); + + 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; + } + // 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 - TODO: Requires VK_GOOGLE_surfaceless_query and calling vkGetPhysicalDeviceSurfaceFormatsKHR + // 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); + // General - VK_IMAGE_LAYOUT_GENERAL supports all types of device access. Should only be set if everything else + // is included? + allowedStates.add(ResourceState::General); + + *outStates = allowedStates; + return SLANG_OK; +} + Result VKDevice::createBufferView(IBufferResource* buffer, IResourceView::Desc const& desc, IResourceView** outView) { auto resourceImpl = (BufferResourceImpl*) buffer; @@ -8463,7 +8537,7 @@ Result VKDevice::createGraphicsPipelineState(const GraphicsPipelineStateDesc& in colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlending.logicOpEnable = VK_FALSE; // TODO: D3D12 has per attachment logic op (and both have way more than one op) colorBlending.logicOp = VK_LOGIC_OP_COPY; - colorBlending.attachmentCount = (targetCount == 0) ? 1 : targetCount; + colorBlending.attachmentCount = (uint32_t)colorBlendAttachments.getCount(); colorBlending.pAttachments = colorBlendAttachments.getBuffer(); colorBlending.blendConstants[0] = 0.0f; colorBlending.blendConstants[1] = 0.0f; |
