Commit 0da99f52 by Alexis Hetu Committed by Alexis Hétu

Move Blitter ownership from Image to Device

The blitter has a cache which can allow us to reuse already used routines, so it should be kept in a central location. For that reason, the blitter ownership was moved from the Image object to the Device object. Bug b/117974925 Change-Id: I825853c381dcbc04701b1d9e7dfa376108294221 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/25728Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 15dff360
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "VkDebug.hpp" #include "VkDebug.hpp"
#include "VkDescriptorSetLayout.hpp" #include "VkDescriptorSetLayout.hpp"
#include "VkQueue.hpp" #include "VkQueue.hpp"
#include "Device/Blitter.hpp"
#include <new> // Must #include this to use "placement new" #include <new> // Must #include this to use "placement new"
...@@ -50,6 +51,8 @@ Device::Device(const Device::CreateInfo* info, void* mem) ...@@ -50,6 +51,8 @@ Device::Device(const Device::CreateInfo* info, void* mem)
// "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations." // "The ppEnabledLayerNames and enabledLayerCount members of VkDeviceCreateInfo are deprecated and their values must be ignored by implementations."
UNIMPLEMENTED(); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here. UNIMPLEMENTED(); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
} }
blitter = new sw::Blitter();
} }
void Device::destroy(const VkAllocationCallbacks* pAllocator) void Device::destroy(const VkAllocationCallbacks* pAllocator)
...@@ -60,6 +63,8 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator) ...@@ -60,6 +63,8 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator)
} }
vk::deallocate(queues, pAllocator); vk::deallocate(queues, pAllocator);
delete blitter;
} }
size_t Device::ComputeRequiredAllocationSize(const Device::CreateInfo* info) size_t Device::ComputeRequiredAllocationSize(const Device::CreateInfo* info)
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#include "VkObject.hpp" #include "VkObject.hpp"
namespace sw
{
class Blitter;
};
namespace vk namespace vk
{ {
...@@ -46,11 +51,13 @@ public: ...@@ -46,11 +51,13 @@ public:
VkPhysicalDevice getPhysicalDevice() const { return physicalDevice; } VkPhysicalDevice getPhysicalDevice() const { return physicalDevice; }
void updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, void updateDescriptorSets(uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites,
uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies); uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies);
sw::Blitter* getBlitter() const { return blitter; }
private: private:
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
Queue* queues = nullptr; Queue* queues = nullptr;
uint32_t queueCount = 0; uint32_t queueCount = 0;
sw::Blitter* blitter = nullptr;
}; };
using DispatchableDevice = DispatchableObject<Device, VkDevice>; using DispatchableDevice = DispatchableObject<Device, VkDevice>;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "VkDeviceMemory.hpp" #include "VkDeviceMemory.hpp"
#include "VkBuffer.hpp" #include "VkBuffer.hpp"
#include "VkDevice.hpp"
#include "VkImage.hpp" #include "VkImage.hpp"
#include "Device/Blitter.hpp" #include "Device/Blitter.hpp"
#include "Device/Surface.hpp" #include "Device/Surface.hpp"
...@@ -41,18 +42,17 @@ namespace ...@@ -41,18 +42,17 @@ namespace
namespace vk namespace vk
{ {
Image::Image(const VkImageCreateInfo* pCreateInfo, void* mem) : Image::Image(const Image::CreateInfo* pCreateInfo, void* mem) :
flags(pCreateInfo->flags), device(Cast(pCreateInfo->device)),
imageType(pCreateInfo->imageType), flags(pCreateInfo->pCreateInfo->flags),
format(pCreateInfo->format), imageType(pCreateInfo->pCreateInfo->imageType),
extent(pCreateInfo->extent), format(pCreateInfo->pCreateInfo->format),
mipLevels(pCreateInfo->mipLevels), extent(pCreateInfo->pCreateInfo->extent),
arrayLayers(pCreateInfo->arrayLayers), mipLevels(pCreateInfo->pCreateInfo->mipLevels),
samples(pCreateInfo->samples), arrayLayers(pCreateInfo->pCreateInfo->arrayLayers),
tiling(pCreateInfo->tiling) samples(pCreateInfo->pCreateInfo->samples),
tiling(pCreateInfo->pCreateInfo->tiling)
{ {
blitter = new sw::Blitter();
if (samples != VK_SAMPLE_COUNT_1_BIT) if (samples != VK_SAMPLE_COUNT_1_BIT)
{ {
UNIMPLEMENTED("Multisample images not yet supported"); UNIMPLEMENTED("Multisample images not yet supported");
...@@ -61,10 +61,9 @@ Image::Image(const VkImageCreateInfo* pCreateInfo, void* mem) : ...@@ -61,10 +61,9 @@ Image::Image(const VkImageCreateInfo* pCreateInfo, void* mem) :
void Image::destroy(const VkAllocationCallbacks* pAllocator) void Image::destroy(const VkAllocationCallbacks* pAllocator)
{ {
delete blitter;
} }
size_t Image::ComputeRequiredAllocationSize(const VkImageCreateInfo* pCreateInfo) size_t Image::ComputeRequiredAllocationSize(const Image::CreateInfo* pCreateInfo)
{ {
return 0; return 0;
} }
...@@ -495,7 +494,7 @@ void Image::blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter) ...@@ -495,7 +494,7 @@ void Image::blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter)
for(int i = 0; i < numSlices; i++) for(int i = 0; i < numSlices; i++)
{ {
blitter->blit(srcSurface, sRect, dstSurface, dRect, device->getBlitter()->blit(srcSurface, sRect, dstSurface, dRect,
{filter != VK_FILTER_NEAREST, srcAspect == VK_IMAGE_ASPECT_STENCIL_BIT, false}); {filter != VK_FILTER_NEAREST, srcAspect == VK_IMAGE_ASPECT_STENCIL_BIT, false});
sRect.slice++; sRect.slice++;
dRect.slice++; dRect.slice++;
...@@ -547,7 +546,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRang ...@@ -547,7 +546,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkImageSubresourceRang
{ {
const sw::SliceRect dRect(0, 0, mipLevelExtent.width, mipLevelExtent.height, s); const sw::SliceRect dRect(0, 0, mipLevelExtent.width, mipLevelExtent.height, s);
sw::Surface* surface = asSurface(aspect, mipLevel, layer); sw::Surface* surface = asSurface(aspect, mipLevel, layer);
blitter->clear(pixelData, format, surface, dRect, 0xF); device->getBlitter()->clear(pixelData, format, surface, dRect, 0xF);
delete surface; delete surface;
} }
} }
...@@ -574,7 +573,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, ...@@ -574,7 +573,7 @@ void Image::clear(void* pixelData, VkFormat format, const VkRect2D& renderArea,
{ {
dRect.slice = s; dRect.slice = s;
sw::Surface* surface = asSurface(aspect, 0, layer); sw::Surface* surface = asSurface(aspect, 0, layer);
blitter->clear(pixelData, format, surface, dRect, 0xF); device->getBlitter()->clear(pixelData, format, surface, dRect, 0xF);
delete surface; delete surface;
} }
} }
......
...@@ -19,23 +19,29 @@ ...@@ -19,23 +19,29 @@
namespace sw namespace sw
{ {
class Blitter;
class Surface; class Surface;
}; };
namespace vk namespace vk
{ {
class Device;
class DeviceMemory; class DeviceMemory;
class Image : public Object<Image, VkImage> class Image : public Object<Image, VkImage>
{ {
public: public:
Image(const VkImageCreateInfo* pCreateInfo, void* mem); struct CreateInfo
{
const VkImageCreateInfo* pCreateInfo;
const VkDevice device;
};
Image(const CreateInfo* pCreateInfo, void* mem);
~Image() = delete; ~Image() = delete;
void destroy(const VkAllocationCallbacks* pAllocator); void destroy(const VkAllocationCallbacks* pAllocator);
static size_t ComputeRequiredAllocationSize(const VkImageCreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const CreateInfo* pCreateInfo);
const VkMemoryRequirements getMemoryRequirements() const; const VkMemoryRequirements getMemoryRequirements() const;
void getSubresourceLayout(const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout) const; void getSubresourceLayout(const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout) const;
...@@ -77,6 +83,7 @@ private: ...@@ -77,6 +83,7 @@ private:
void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect); void clear(void* pixelData, VkFormat format, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
void clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect); void clear(void* pixelData, VkFormat format, const VkRect2D& renderArea, const VkImageSubresourceRange& subresourceRange, VkImageAspectFlagBits aspect);
const Device *const device = nullptr;
DeviceMemory* deviceMemory = nullptr; DeviceMemory* deviceMemory = nullptr;
VkDeviceSize memoryOffset = 0; VkDeviceSize memoryOffset = 0;
VkImageCreateFlags flags = 0; VkImageCreateFlags flags = 0;
...@@ -87,7 +94,6 @@ private: ...@@ -87,7 +94,6 @@ private:
uint32_t arrayLayers = 0; uint32_t arrayLayers = 0;
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT; VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;
sw::Blitter* blitter = nullptr;
}; };
static inline Image* Cast(VkImage object) static inline Image* Cast(VkImage object)
......
...@@ -906,7 +906,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreat ...@@ -906,7 +906,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreat
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
return vk::Image::Create(pAllocator, pCreateInfo, pImage); vk::Image::CreateInfo imageCreateInfo =
{
pCreateInfo,
device
};
return vk::Image::Create(pAllocator, &imageCreateInfo, pImage);
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator) VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
......
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