Commit 5822882b by Chris Forbes

Specialize descriptor contents for storage images

Bug: b/130768731 Test: dEQP-VK.image.* Change-Id: Iebea846a5fe611aa4ad769e2fb7c636ddb5dbc4d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29408Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent ac07ed82
...@@ -270,6 +270,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -270,6 +270,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<ClInclude Include="$(SolutionDir)src\Vulkan\Version.h" /> <ClInclude Include="$(SolutionDir)src\Vulkan\Version.h" />
<ClCompile Include="$(SolutionDir)src\Vulkan\VkBuffer.cpp" /> <ClCompile Include="$(SolutionDir)src\Vulkan\VkBuffer.cpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkBuffer.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkBuffer.hpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkBufferView.cpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkBufferView.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkBufferView.hpp" />
<ClCompile Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.cpp" /> <ClCompile Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.cpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.hpp" />
......
...@@ -118,6 +118,9 @@ ...@@ -118,6 +118,9 @@
<ClCompile Include="$(SolutionDir)src\Vulkan\VkBuffer.cpp"> <ClCompile Include="$(SolutionDir)src\Vulkan\VkBuffer.cpp">
<Filter>src\Vulkan</Filter> <Filter>src\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)src\Vulkan\VkBufferView.cpp">
<Filter>src\Vulkan</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.cpp"> <ClCompile Include="$(SolutionDir)src\Vulkan\VkCommandBuffer.cpp">
<Filter>src\Vulkan</Filter> <Filter>src\Vulkan</Filter>
</ClCompile> </ClCompile>
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "SamplerCore.hpp" #include "SamplerCore.hpp"
#include "System/Math.hpp" #include "System/Math.hpp"
#include "Vulkan/VkBuffer.hpp" #include "Vulkan/VkBuffer.hpp"
#include "Vulkan/VkBufferView.hpp"
#include "Vulkan/VkDebug.hpp" #include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkDescriptorSet.hpp" #include "Vulkan/VkDescriptorSet.hpp"
#include "Vulkan/VkPipelineLayout.hpp" #include "Vulkan/VkPipelineLayout.hpp"
...@@ -280,7 +281,7 @@ namespace sw ...@@ -280,7 +281,7 @@ namespace sw
auto &d = memberDecorations[targetId]; auto &d = memberDecorations[targetId];
if (memberIndex >= d.size()) if (memberIndex >= d.size())
d.resize(memberIndex + 1); // on demand; exact size would require another pass... d.resize(memberIndex + 1); // on demand; exact size would require another pass...
d[memberIndex].Apply(decoration, value); d[memberIndex].Apply(decoration, value);
if (decoration == spv::DecorationCentroid) if (decoration == spv::DecorationCentroid)
......
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "VkBufferView.hpp"
#include "VkBuffer.hpp"
#include "VkFormat.h"
namespace vk
{
BufferView::BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem) :
buffer(pCreateInfo->buffer), format(pCreateInfo->format), offset(pCreateInfo->offset)
{
if (pCreateInfo->range == VK_WHOLE_SIZE)
{
range = Cast(pCreateInfo->buffer)->getSize() - offset;
}
else
{
range = pCreateInfo->range - offset;
}
}
void * BufferView::getPointer() const
{
return Cast(buffer)->getOffsetPointer(offset);
}
}
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define VK_BUFFER_VIEW_HPP_ #define VK_BUFFER_VIEW_HPP_
#include "VkObject.hpp" #include "VkObject.hpp"
#include "VkFormat.h"
namespace vk namespace vk
{ {
...@@ -23,11 +24,7 @@ namespace vk ...@@ -23,11 +24,7 @@ namespace vk
class BufferView : public Object<BufferView, VkBufferView> class BufferView : public Object<BufferView, VkBufferView>
{ {
public: public:
BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem) : BufferView(const VkBufferViewCreateInfo* pCreateInfo, void* mem);
buffer(pCreateInfo->buffer), format(pCreateInfo->format), offset(pCreateInfo->offset), range(pCreateInfo->range)
{
}
~BufferView() = delete; ~BufferView() = delete;
static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo* pCreateInfo) static size_t ComputeRequiredAllocationSize(const VkBufferViewCreateInfo* pCreateInfo)
...@@ -35,6 +32,9 @@ public: ...@@ -35,6 +32,9 @@ public:
return 0; return 0;
} }
void *getPointer() const;
uint32_t getElementCount() const { return range / Format(format).bytes(); }
private: private:
VkBuffer buffer; VkBuffer buffer;
VkFormat format; VkFormat format;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "VkDescriptorSet.hpp" #include "VkDescriptorSet.hpp"
#include "VkSampler.hpp" #include "VkSampler.hpp"
#include "VkImageView.hpp" #include "VkImageView.hpp"
#include "VkBufferView.hpp"
#include "System/Types.hpp" #include "System/Types.hpp"
#include <algorithm> #include <algorithm>
...@@ -95,10 +96,11 @@ size_t DescriptorSetLayout::GetDescriptorSize(VkDescriptorType type) ...@@ -95,10 +96,11 @@ size_t DescriptorSetLayout::GetDescriptorSize(VkDescriptorType type)
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
return sizeof(SampledImageDescriptor); return sizeof(SampledImageDescriptor);
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
return sizeof(StorageImageDescriptor);
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
return sizeof(VkDescriptorImageInfo); return sizeof(VkDescriptorImageInfo);
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
return sizeof(VkBufferView); return sizeof(VkBufferView);
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
...@@ -244,19 +246,18 @@ const uint8_t* DescriptorSetLayout::GetInputData(const VkWriteDescriptorSet& wri ...@@ -244,19 +246,18 @@ const uint8_t* DescriptorSetLayout::GetInputData(const VkWriteDescriptorSet& wri
case VK_DESCRIPTOR_TYPE_SAMPLER: case VK_DESCRIPTOR_TYPE_SAMPLER:
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pImageInfo); return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pImageInfo);
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pTexelBufferView); return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pTexelBufferView);
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pBufferInfo); return reinterpret_cast<const uint8_t*>(writeDescriptorSet.pBufferInfo);
break; case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
ASSERT("descriptorType has custom handling");
default: default:
UNIMPLEMENTED("descriptorType"); UNIMPLEMENTED("descriptorType");
return nullptr; return nullptr;
...@@ -432,6 +433,32 @@ void DescriptorSetLayout::WriteDescriptorSet(const VkWriteDescriptorSet& writeDe ...@@ -432,6 +433,32 @@ void DescriptorSetLayout::WriteDescriptorSet(const VkWriteDescriptorSet& writeDe
} }
} }
} }
else if (writeDescriptorSet.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for(uint32_t i = 0; i < writeDescriptorSet.descriptorCount; i++)
{
auto imageView = vk::Cast(writeDescriptorSet.pImageInfo[i].imageView);
descriptor[i].ptr = imageView->getOffsetPointer({0, 0, 0}, VK_IMAGE_ASPECT_COLOR_BIT);
descriptor[i].extent = imageView->getMipLevelExtent(0);
descriptor[i].rowPitchBytes = imageView->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].slicePitchBytes = imageView->slicePitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
descriptor[i].arrayLayers = imageView->getSubresourceRange().layerCount;
}
}
else if (writeDescriptorSet.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
{
auto descriptor = reinterpret_cast<StorageImageDescriptor *>(memToWrite);
for (uint32_t i = 0; i < writeDescriptorSet.descriptorCount; i++)
{
auto bufferView = vk::Cast(writeDescriptorSet.pTexelBufferView[i]);
descriptor[i].ptr = bufferView->getPointer();
descriptor[i].extent = {bufferView->getElementCount(), 1, 1};
descriptor[i].rowPitchBytes = 0;
descriptor[i].slicePitchBytes = 0;
descriptor[i].arrayLayers = 1;
}
}
else else
{ {
// If the dstBinding has fewer than descriptorCount array elements remaining // If the dstBinding has fewer than descriptorCount array elements remaining
......
...@@ -36,6 +36,15 @@ struct SampledImageDescriptor ...@@ -36,6 +36,15 @@ struct SampledImageDescriptor
sw::Texture texture; sw::Texture texture;
}; };
struct StorageImageDescriptor
{
void *ptr;
VkExtent3D extent;
int rowPitchBytes;
int slicePitchBytes;
int arrayLayers;
};
class DescriptorSetLayout : public Object<DescriptorSetLayout, VkDescriptorSetLayout> class DescriptorSetLayout : public Object<DescriptorSetLayout, VkDescriptorSetLayout>
{ {
public: public:
......
...@@ -103,7 +103,7 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a ...@@ -103,7 +103,7 @@ void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags a
if(!format.isCompatible(image->getFormat())) if(!format.isCompatible(image->getFormat()))
{ {
UNIMPLEMENTED("incompatible formats"); UNIMPLEMENTED("incompatible formats");
} }
VkImageSubresourceRange sr; VkImageSubresourceRange sr;
sr.aspectMask = aspectMask; sr.aspectMask = aspectMask;
......
...@@ -110,6 +110,7 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy ...@@ -110,6 +110,7 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy
<ClCompile Include="libVulkan.cpp" /> <ClCompile Include="libVulkan.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="VkBuffer.cpp" /> <ClCompile Include="VkBuffer.cpp" />
<ClCompile Include="VkBufferView.cpp" />
<ClCompile Include="VkCommandBuffer.cpp" /> <ClCompile Include="VkCommandBuffer.cpp" />
<ClCompile Include="VkCommandPool.cpp" /> <ClCompile Include="VkCommandPool.cpp" />
<ClCompile Include="VkDebug.cpp" /> <ClCompile Include="VkDebug.cpp" />
......
...@@ -174,6 +174,9 @@ ...@@ -174,6 +174,9 @@
<ClCompile Include="VkBuffer.cpp"> <ClCompile Include="VkBuffer.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkBufferView.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkCommandBuffer.cpp"> <ClCompile Include="VkCommandBuffer.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment