Commit 0c73680a by Nicolas Capens Committed by Nicolas Capens

Allow additional info to be passed to object's Create functions

This is particularly useful for passing extension info structures to the object's constructor. Bug: b/132437008 Bug: b/116336664 Change-Id: I10592f5ddeb8efa52f34ebd4dfd14150b6964eab Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31612 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent f6535a39
...@@ -36,12 +36,11 @@ namespace ...@@ -36,12 +36,11 @@ namespace
namespace vk namespace vk
{ {
Device::Device(const Device::CreateInfo* info, void* mem) Device::Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice *physicalDevice)
: physicalDevice(info->pPhysicalDevice), : physicalDevice(physicalDevice),
queues(reinterpret_cast<Queue*>(mem)), queues(reinterpret_cast<Queue*>(mem)),
enabledExtensionCount(info->pCreateInfo->enabledExtensionCount) enabledExtensionCount(pCreateInfo->enabledExtensionCount)
{ {
const auto* pCreateInfo = info->pCreateInfo;
for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
{ {
const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i]; const VkDeviceQueueCreateInfo& queueCreateInfo = pCreateInfo->pQueueCreateInfos[i];
...@@ -87,15 +86,15 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator) ...@@ -87,15 +86,15 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator)
delete blitter; delete blitter;
} }
size_t Device::ComputeRequiredAllocationSize(const Device::CreateInfo* info) size_t Device::ComputeRequiredAllocationSize(const VkDeviceCreateInfo* pCreateInfo)
{ {
uint32_t queueCount = 0; uint32_t queueCount = 0;
for(uint32_t i = 0; i < info->pCreateInfo->queueCreateInfoCount; i++) for(uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++)
{ {
queueCount += info->pCreateInfo->pQueueCreateInfos[i].queueCount; queueCount += pCreateInfo->pQueueCreateInfos[i].queueCount;
} }
return (sizeof(Queue) * queueCount) + (info->pCreateInfo->enabledExtensionCount * sizeof(ExtensionName)); return (sizeof(Queue) * queueCount) + (pCreateInfo->enabledExtensionCount * sizeof(ExtensionName));
} }
bool Device::hasExtension(const char* extensionName) const bool Device::hasExtension(const char* extensionName) const
......
...@@ -25,23 +25,18 @@ namespace sw ...@@ -25,23 +25,18 @@ namespace sw
namespace vk namespace vk
{ {
class PhysicalDevice;
class Queue; class Queue;
class Device class Device
{ {
public: public:
struct CreateInfo
{
const VkDeviceCreateInfo* pCreateInfo;
VkPhysicalDevice pPhysicalDevice;
};
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_DEVICE; } static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_DEVICE; }
Device(const CreateInfo* info, void* mem); Device(const VkDeviceCreateInfo* pCreateInfo, void* mem, PhysicalDevice *physicalDevice);
void destroy(const VkAllocationCallbacks* pAllocator); void destroy(const VkAllocationCallbacks* pAllocator);
static size_t ComputeRequiredAllocationSize(const CreateInfo* info); static size_t ComputeRequiredAllocationSize(const VkDeviceCreateInfo* pCreateInfo);
bool hasExtension(const char* extensionName) const; bool hasExtension(const char* extensionName) const;
VkQueue getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const; VkQueue getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex) const;
...@@ -49,13 +44,13 @@ public: ...@@ -49,13 +44,13 @@ public:
VkResult waitIdle(); VkResult waitIdle();
void getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo, void getDescriptorSetLayoutSupport(const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
VkDescriptorSetLayoutSupport* pSupport) const; VkDescriptorSetLayoutSupport* pSupport) const;
VkPhysicalDevice getPhysicalDevice() const { return physicalDevice; } PhysicalDevice *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; } sw::Blitter* getBlitter() const { return blitter; }
private: private:
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; PhysicalDevice *physicalDevice = nullptr;
Queue* queues = nullptr; Queue* queues = nullptr;
uint32_t queueCount = 0; uint32_t queueCount = 0;
sw::Blitter* blitter = nullptr; sw::Blitter* blitter = nullptr;
......
...@@ -53,24 +53,23 @@ namespace ...@@ -53,24 +53,23 @@ namespace
namespace vk namespace vk
{ {
Image::Image(const Image::CreateInfo* pCreateInfo, void* mem) : Image::Image(const VkImageCreateInfo* pCreateInfo, void* mem, Device *device) :
device(Cast(pCreateInfo->device)), device(device),
flags(pCreateInfo->pCreateInfo->flags), flags(pCreateInfo->flags),
imageType(pCreateInfo->pCreateInfo->imageType), imageType(pCreateInfo->imageType),
format(pCreateInfo->pCreateInfo->format), format(pCreateInfo->format),
extent(pCreateInfo->pCreateInfo->extent), extent(pCreateInfo->extent),
mipLevels(pCreateInfo->pCreateInfo->mipLevels), mipLevels(pCreateInfo->mipLevels),
arrayLayers(pCreateInfo->pCreateInfo->arrayLayers), arrayLayers(pCreateInfo->arrayLayers),
samples(pCreateInfo->pCreateInfo->samples), samples(pCreateInfo->samples),
tiling(pCreateInfo->pCreateInfo->tiling), tiling(pCreateInfo->tiling),
usage(pCreateInfo->pCreateInfo->usage) usage(pCreateInfo->usage)
{ {
if(format.isCompressed()) if(format.isCompressed())
{ {
VkImageCreateInfo imageCreateInfo = *(pCreateInfo->pCreateInfo); VkImageCreateInfo compressedImageCreateInfo = *pCreateInfo;
imageCreateInfo.format = format.getDecompressedFormat(); compressedImageCreateInfo.format = format.getDecompressedFormat();
Image::CreateInfo createInfo = { &imageCreateInfo, pCreateInfo->device }; decompressedImage = new (mem) Image(&compressedImageCreateInfo, nullptr, device);
decompressedImage = new (mem) Image(&createInfo, nullptr);
} }
} }
...@@ -82,9 +81,9 @@ void Image::destroy(const VkAllocationCallbacks* pAllocator) ...@@ -82,9 +81,9 @@ void Image::destroy(const VkAllocationCallbacks* pAllocator)
} }
} }
size_t Image::ComputeRequiredAllocationSize(const Image::CreateInfo* pCreateInfo) size_t Image::ComputeRequiredAllocationSize(const VkImageCreateInfo* pCreateInfo)
{ {
return Format(pCreateInfo->pCreateInfo->format).isCompressed() ? sizeof(Image) : 0; return Format(pCreateInfo->format).isCompressed() ? sizeof(Image) : 0;
} }
const VkMemoryRequirements Image::getMemoryRequirements() const const VkMemoryRequirements Image::getMemoryRequirements() const
......
...@@ -27,16 +27,10 @@ class DeviceMemory; ...@@ -27,16 +27,10 @@ class DeviceMemory;
class Image : public Object<Image, VkImage> class Image : public Object<Image, VkImage>
{ {
public: public:
struct CreateInfo Image(const VkImageCreateInfo* pCreateInfo, void* mem, Device *device);
{
const VkImageCreateInfo* pCreateInfo;
const VkDevice device;
};
Image(const CreateInfo* pCreateInfo, void* mem);
void destroy(const VkAllocationCallbacks* pAllocator); void destroy(const VkAllocationCallbacks* pAllocator);
static size_t ComputeRequiredAllocationSize(const CreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkImageCreateInfo* 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;
......
...@@ -18,13 +18,10 @@ ...@@ -18,13 +18,10 @@
namespace vk namespace vk
{ {
Instance::Instance(const CreateInfo* pCreateInfo, void* mem) Instance::Instance(const VkInstanceCreateInfo* pCreateInfo, void* mem, VkPhysicalDevice physicalDevice)
: physicalDevice(physicalDevice),
physicalDeviceCount(physicalDevice ? 1 : 0)
{ {
if(pCreateInfo->pPhysicalDevice)
{
physicalDevice = pCreateInfo->pPhysicalDevice;
physicalDeviceCount = 1;
}
} }
void Instance::destroy(const VkAllocationCallbacks* pAllocator) void Instance::destroy(const VkAllocationCallbacks* pAllocator)
......
...@@ -23,28 +23,23 @@ namespace vk ...@@ -23,28 +23,23 @@ namespace vk
class Instance class Instance
{ {
public: public:
struct CreateInfo
{
const VkInstanceCreateInfo* pCreateInfo;
VkPhysicalDevice pPhysicalDevice;
};
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE; } static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE; }
Instance(const CreateInfo* pCreateInfo, void* mem); Instance(const VkInstanceCreateInfo* pCreateInfo, void* mem, VkPhysicalDevice physicalDevice);
void destroy(const VkAllocationCallbacks* pAllocator); void destroy(const VkAllocationCallbacks* pAllocator);
static size_t ComputeRequiredAllocationSize(const CreateInfo*) { return 0; } static size_t ComputeRequiredAllocationSize(const VkInstanceCreateInfo*) { return 0; }
uint32_t getPhysicalDeviceCount() const; uint32_t getPhysicalDeviceCount() const;
void getPhysicalDevices(uint32_t pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) const; void getPhysicalDevices(uint32_t pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) const;
uint32_t getPhysicalDeviceGroupCount() const; uint32_t getPhysicalDeviceGroupCount() const;
void getPhysicalDeviceGroups(uint32_t pPhysicalDeviceGroupCount, void getPhysicalDeviceGroups(uint32_t pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const; VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) const;
private: private:
uint32_t physicalDeviceCount = 0;
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
uint32_t physicalDeviceGroupCount = 1; const uint32_t physicalDeviceCount = 0;
const uint32_t physicalDeviceGroupCount = 1;
}; };
using DispatchableInstance = DispatchableObject<Instance, VkInstance>; using DispatchableInstance = DispatchableObject<Instance, VkInstance>;
......
...@@ -28,8 +28,8 @@ namespace vk ...@@ -28,8 +28,8 @@ namespace vk
// For use in the placement new to make it verbose that we're allocating an object using device memory // For use in the placement new to make it verbose that we're allocating an object using device memory
static constexpr VkAllocationCallbacks* DEVICE_MEMORY = nullptr; static constexpr VkAllocationCallbacks* DEVICE_MEMORY = nullptr;
template<typename T, typename VkT, typename CreateInfo> template<typename T, typename VkT, typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject) static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
{ {
*outObject = VK_NULL_HANDLE; *outObject = VK_NULL_HANDLE;
...@@ -51,7 +51,7 @@ static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo ...@@ -51,7 +51,7 @@ static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;
} }
auto object = new (objectMemory) T(pCreateInfo, memory); auto object = new (objectMemory) T(pCreateInfo, memory, extendedInfo...);
if(!object) if(!object)
{ {
...@@ -75,10 +75,10 @@ public: ...@@ -75,10 +75,10 @@ public:
void destroy(const VkAllocationCallbacks* pAllocator) {} // Method defined by objects to delete their content, if necessary void destroy(const VkAllocationCallbacks* pAllocator) {} // Method defined by objects to delete their content, if necessary
template<typename CreateInfo> template<typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject) static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
{ {
return vk::Create<T, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject); return vk::Create<T, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject, extendedInfo...);
} }
static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_OBJECT; } static constexpr VkSystemAllocationScope GetAllocationScope() { return VK_SYSTEM_ALLOCATION_SCOPE_OBJECT; }
...@@ -102,6 +102,7 @@ class DispatchableObject ...@@ -102,6 +102,7 @@ class DispatchableObject
VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC }; VK_LOADER_DATA loaderData = { ICD_LOADER_MAGIC };
T object; T object;
public: public:
static constexpr VkSystemAllocationScope GetAllocationScope() { return T::GetAllocationScope(); } static constexpr VkSystemAllocationScope GetAllocationScope() { return T::GetAllocationScope(); }
...@@ -110,6 +111,8 @@ public: ...@@ -110,6 +111,8 @@ public:
{ {
} }
~DispatchableObject() = delete;
void destroy(const VkAllocationCallbacks* pAllocator) void destroy(const VkAllocationCallbacks* pAllocator)
{ {
object.destroy(pAllocator); object.destroy(pAllocator);
...@@ -121,10 +124,10 @@ public: ...@@ -121,10 +124,10 @@ public:
ASSERT(false); ASSERT(false);
} }
template<typename CreateInfo> template<typename CreateInfo, typename... ExtendedInfo>
static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject) static VkResult Create(const VkAllocationCallbacks* pAllocator, const CreateInfo* pCreateInfo, VkT* outObject, ExtendedInfo... extendedInfo)
{ {
return vk::Create<DispatchableObject<T, VkT>, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject); return vk::Create<DispatchableObject<T, VkT>, VkT, CreateInfo>(pAllocator, pCreateInfo, outObject, extendedInfo...);
} }
template<typename CreateInfo> template<typename CreateInfo>
......
...@@ -177,13 +177,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCre ...@@ -177,13 +177,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCre
return result; return result;
} }
vk::Instance::CreateInfo info = result = vk::DispatchableInstance::Create(pAllocator, pCreateInfo, pInstance, physicalDevice);
{
pCreateInfo,
physicalDevice
};
result = vk::DispatchableInstance::Create(pAllocator, &info, pInstance);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vk::destroy(physicalDevice, pAllocator); vk::destroy(physicalDevice, pAllocator);
...@@ -479,13 +473,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, c ...@@ -479,13 +473,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, c
(void)queueFamilyPropertyCount; // Silence unused variable warning (void)queueFamilyPropertyCount; // Silence unused variable warning
} }
vk::Device::CreateInfo deviceCreateInfo = return vk::DispatchableDevice::Create(pAllocator, pCreateInfo, pDevice, vk::Cast(physicalDevice));
{
pCreateInfo,
physicalDevice
};
return vk::DispatchableDevice::Create(pAllocator, &deviceCreateInfo, pDevice);
} }
VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
...@@ -687,7 +675,7 @@ VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment(VkDevice pDevice, VkDevic ...@@ -687,7 +675,7 @@ VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment(VkDevice pDevice, VkDevic
auto memory = vk::Cast(pMemory); auto memory = vk::Cast(pMemory);
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
const auto& memoryProperties = vk::Cast(vk::Cast(pDevice)->getPhysicalDevice())->getMemoryProperties(); const auto& memoryProperties = vk::Cast(pDevice)->getPhysicalDevice()->getMemoryProperties();
uint32_t typeIndex = memory->getMemoryTypeIndex(); uint32_t typeIndex = memory->getMemoryTypeIndex();
ASSERT(typeIndex < memoryProperties.memoryTypeCount); ASSERT(typeIndex < memoryProperties.memoryTypeCount);
ASSERT(memoryProperties.memoryTypes[typeIndex].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT); ASSERT(memoryProperties.memoryTypes[typeIndex].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT);
...@@ -997,13 +985,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreat ...@@ -997,13 +985,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(VkDevice device, const VkImageCreat
extensionCreateInfo = extensionCreateInfo->pNext; extensionCreateInfo = extensionCreateInfo->pNext;
} }
vk::Image::CreateInfo imageCreateInfo = VkResult result = vk::Image::Create(pAllocator, pCreateInfo, pImage, vk::Cast(device));
{
pCreateInfo,
device
};
VkResult result = vk::Image::Create(pAllocator, &imageCreateInfo, pImage);
#ifdef __ANDROID__ #ifdef __ANDROID__
if (swapchainImage) if (swapchainImage)
...@@ -1479,7 +1461,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRende ...@@ -1479,7 +1461,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRende
// pViewMask is a 32 bit value. If maxFramebufferLayers > 32, it's impossible // pViewMask is a 32 bit value. If maxFramebufferLayers > 32, it's impossible
// for pViewMask to contain a bit at an illegal position // for pViewMask to contain a bit at an illegal position
// Note: Verify pViewMask values instead if we hit this assert // Note: Verify pViewMask values instead if we hit this assert
ASSERT(vk::Cast(vk::Cast(device)->getPhysicalDevice())->getProperties().limits.maxFramebufferLayers >= 32); ASSERT(vk::Cast(device)->getPhysicalDevice()->getProperties().limits.maxFramebufferLayers >= 32);
} }
break; break;
default: default:
......
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