From 8d75e5b4ae98cc4baceb34b56952af6f39b7dfa6 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 23 Nov 2017 11:35:40 -0800 Subject: [PATCH] Member rename: src/backend/vulkan --- src/backend/vulkan/BufferUploader.cpp | 28 ++-- src/backend/vulkan/BufferUploader.h | 4 +- src/backend/vulkan/BufferVk.cpp | 32 ++-- src/backend/vulkan/BufferVk.h | 8 +- src/backend/vulkan/MemoryAllocator.cpp | 38 ++--- src/backend/vulkan/MemoryAllocator.h | 10 +- src/backend/vulkan/VulkanBackend.cpp | 196 ++++++++++++------------- src/backend/vulkan/VulkanBackend.h | 40 +++-- 8 files changed, 177 insertions(+), 179 deletions(-) diff --git a/src/backend/vulkan/BufferUploader.cpp b/src/backend/vulkan/BufferUploader.cpp index f91bb38655..ef798acf65 100644 --- a/src/backend/vulkan/BufferUploader.cpp +++ b/src/backend/vulkan/BufferUploader.cpp @@ -23,11 +23,11 @@ namespace backend { namespace vulkan { BufferUploader::BufferUploader(Device* device) - : device(device) { + : mDevice(device) { } BufferUploader::~BufferUploader() { - ASSERT(buffersToDelete.Empty()); + ASSERT(mBuffersToDelete.Empty()); } void BufferUploader::BufferSubData(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size, const void* data) { @@ -45,19 +45,19 @@ namespace vulkan { createInfo.pQueueFamilyIndices = 0; VkBuffer stagingBuffer = VK_NULL_HANDLE; - if (device->fn.CreateBuffer(device->GetVkDevice(), &createInfo, nullptr, &stagingBuffer) != VK_SUCCESS) { + if (mDevice->fn.CreateBuffer(mDevice->GetVkDevice(), &createInfo, nullptr, &stagingBuffer) != VK_SUCCESS) { ASSERT(false); } VkMemoryRequirements requirements; - device->fn.GetBufferMemoryRequirements(device->GetVkDevice(), stagingBuffer, &requirements); + mDevice->fn.GetBufferMemoryRequirements(mDevice->GetVkDevice(), stagingBuffer, &requirements); DeviceMemoryAllocation allocation; - if (!device->GetMemoryAllocator()->Allocate(requirements, true, &allocation)) { + if (!mDevice->GetMemoryAllocator()->Allocate(requirements, true, &allocation)) { ASSERT(false); } - if (device->fn.BindBufferMemory(device->GetVkDevice(), stagingBuffer, allocation.GetMemory(), + if (mDevice->fn.BindBufferMemory(mDevice->GetVkDevice(), stagingBuffer, allocation.GetMemory(), allocation.GetMemoryOffset()) != VK_SUCCESS) { ASSERT(false); } @@ -67,7 +67,7 @@ namespace vulkan { memcpy(allocation.GetMappedPointer(), data, size); // Enqueue host write -> transfer src barrier and copy command - VkCommandBuffer commands = device->GetPendingCommandBuffer(); + VkCommandBuffer commands = mDevice->GetPendingCommandBuffer(); VkMemoryBarrier barrier; barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; @@ -75,7 +75,7 @@ namespace vulkan { barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; - device->fn.CmdPipelineBarrier(commands, + mDevice->fn.CmdPipelineBarrier(commands, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &barrier, 0, nullptr, @@ -85,19 +85,19 @@ namespace vulkan { copy.srcOffset = 0; copy.dstOffset = offset; copy.size = size; - device->fn.CmdCopyBuffer(commands, stagingBuffer, buffer, 1, ©); + mDevice->fn.CmdCopyBuffer(commands, stagingBuffer, buffer, 1, ©); // TODO(cwallez@chromium.org): Buffers must be deleted before the memory. // This happens to work for now, but is fragile. - device->GetMemoryAllocator()->Free(&allocation); - buffersToDelete.Enqueue(stagingBuffer, device->GetSerial()); + mDevice->GetMemoryAllocator()->Free(&allocation); + mBuffersToDelete.Enqueue(stagingBuffer, mDevice->GetSerial()); } void BufferUploader::Tick(Serial completedSerial) { - for (VkBuffer buffer : buffersToDelete.IterateUpTo(completedSerial)) { - device->fn.DestroyBuffer(device->GetVkDevice(), buffer, nullptr); + for (VkBuffer buffer : mBuffersToDelete.IterateUpTo(completedSerial)) { + mDevice->fn.DestroyBuffer(mDevice->GetVkDevice(), buffer, nullptr); } - buffersToDelete.ClearUpTo(completedSerial); + mBuffersToDelete.ClearUpTo(completedSerial); } } diff --git a/src/backend/vulkan/BufferUploader.h b/src/backend/vulkan/BufferUploader.h index ba3c2ef986..7adc9499cc 100644 --- a/src/backend/vulkan/BufferUploader.h +++ b/src/backend/vulkan/BufferUploader.h @@ -33,8 +33,8 @@ namespace vulkan { void Tick(Serial completedSerial); private: - Device* device = nullptr; - SerialQueue buffersToDelete; + Device* mDevice = nullptr; + SerialQueue mBuffersToDelete; }; } diff --git a/src/backend/vulkan/BufferVk.cpp b/src/backend/vulkan/BufferVk.cpp index 0c2c91ff2f..f777ca71e8 100644 --- a/src/backend/vulkan/BufferVk.cpp +++ b/src/backend/vulkan/BufferVk.cpp @@ -65,20 +65,20 @@ namespace vulkan { createInfo.queueFamilyIndexCount = 0; createInfo.pQueueFamilyIndices = 0; - if (device->fn.CreateBuffer(device->GetVkDevice(), &createInfo, nullptr, &handle) != VK_SUCCESS) { + if (device->fn.CreateBuffer(device->GetVkDevice(), &createInfo, nullptr, &mHandle) != VK_SUCCESS) { ASSERT(false); } VkMemoryRequirements requirements; - device->fn.GetBufferMemoryRequirements(device->GetVkDevice(), handle, &requirements); + device->fn.GetBufferMemoryRequirements(device->GetVkDevice(), mHandle, &requirements); bool requestMappable = (GetAllowedUsage() & (nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::MapWrite)) != 0; - if (!device->GetMemoryAllocator()->Allocate(requirements, requestMappable, &memoryAllocation)) { + if (!device->GetMemoryAllocator()->Allocate(requirements, requestMappable, &mMemoryAllocation)) { ASSERT(false); } - if (device->fn.BindBufferMemory(device->GetVkDevice(), handle, memoryAllocation.GetMemory(), - memoryAllocation.GetMemoryOffset()) != VK_SUCCESS) { + if (device->fn.BindBufferMemory(device->GetVkDevice(), mHandle, mMemoryAllocation.GetMemory(), + mMemoryAllocation.GetMemoryOffset()) != VK_SUCCESS) { ASSERT(false); } } @@ -86,11 +86,11 @@ namespace vulkan { Buffer::~Buffer() { Device* device = ToBackend(GetDevice()); - device->GetMemoryAllocator()->Free(&memoryAllocation); + device->GetMemoryAllocator()->Free(&mMemoryAllocation); - if (handle != VK_NULL_HANDLE) { - device->fn.DestroyBuffer(device->GetVkDevice(), handle, nullptr); - handle = VK_NULL_HANDLE; + if (mHandle != VK_NULL_HANDLE) { + device->fn.DestroyBuffer(device->GetVkDevice(), mHandle, nullptr); + mHandle = VK_NULL_HANDLE; } } @@ -100,11 +100,11 @@ namespace vulkan { void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) { BufferUploader* uploader = ToBackend(GetDevice())->GetBufferUploader(); - uploader->BufferSubData(handle, start * sizeof(uint32_t), count * sizeof(uint32_t), data); + uploader->BufferSubData(mHandle, start * sizeof(uint32_t), count * sizeof(uint32_t), data); } void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t /*count*/) { - const uint8_t* memory = memoryAllocation.GetMappedPointer(); + const uint8_t* memory = mMemoryAllocation.GetMappedPointer(); ASSERT(memory != nullptr); MapReadRequestTracker* tracker = ToBackend(GetDevice())->GetMapReadRequestTracker(); @@ -119,11 +119,11 @@ namespace vulkan { } MapReadRequestTracker::MapReadRequestTracker(Device* device) - : device(device) { + : mDevice(device) { } MapReadRequestTracker::~MapReadRequestTracker() { - ASSERT(inflightRequests.Empty()); + ASSERT(mInflightRequests.Empty()); } void MapReadRequestTracker::Track(Buffer* buffer, uint32_t mapSerial, const void* data) { @@ -132,14 +132,14 @@ namespace vulkan { request.mapSerial = mapSerial; request.data = data; - inflightRequests.Enqueue(std::move(request), device->GetSerial()); + mInflightRequests.Enqueue(std::move(request), mDevice->GetSerial()); } void MapReadRequestTracker::Tick(Serial finishedSerial) { - for (auto& request : inflightRequests.IterateUpTo(finishedSerial)) { + for (auto& request : mInflightRequests.IterateUpTo(finishedSerial)) { request.buffer->OnMapReadCommandSerialFinished(request.mapSerial, request.data); } - inflightRequests.ClearUpTo(finishedSerial); + mInflightRequests.ClearUpTo(finishedSerial); } } diff --git a/src/backend/vulkan/BufferVk.h b/src/backend/vulkan/BufferVk.h index d31cc507fa..f92d7f2491 100644 --- a/src/backend/vulkan/BufferVk.h +++ b/src/backend/vulkan/BufferVk.h @@ -39,8 +39,8 @@ namespace vulkan { void UnmapImpl() override; void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override; - VkBuffer handle = VK_NULL_HANDLE; - DeviceMemoryAllocation memoryAllocation; + VkBuffer mHandle = VK_NULL_HANDLE; + DeviceMemoryAllocation mMemoryAllocation; }; class MapReadRequestTracker { @@ -52,14 +52,14 @@ namespace vulkan { void Tick(Serial finishedSerial); private: - Device* device; + Device* mDevice; struct Request { Ref buffer; uint32_t mapSerial; const void* data; }; - SerialQueue inflightRequests; + SerialQueue mInflightRequests; }; } diff --git a/src/backend/vulkan/MemoryAllocator.cpp b/src/backend/vulkan/MemoryAllocator.cpp index a9d4708007..48107bbaa2 100644 --- a/src/backend/vulkan/MemoryAllocator.cpp +++ b/src/backend/vulkan/MemoryAllocator.cpp @@ -19,31 +19,31 @@ namespace backend { namespace vulkan { DeviceMemoryAllocation::~DeviceMemoryAllocation() { - ASSERT(memory == VK_NULL_HANDLE); + ASSERT(mMemory == VK_NULL_HANDLE); } VkDeviceMemory DeviceMemoryAllocation::GetMemory() const { - return memory; + return mMemory; } size_t DeviceMemoryAllocation::GetMemoryOffset() const { - return offset; + return mOffset; } uint8_t* DeviceMemoryAllocation::GetMappedPointer() const { - return mappedPointer; + return mMappedPointer; } MemoryAllocator::MemoryAllocator(Device* device) - :device(device) { + :mDevice(device) { } MemoryAllocator::~MemoryAllocator() { - ASSERT(releasedMemory.Empty()); + ASSERT(mReleasedMemory.Empty()); } bool MemoryAllocator::Allocate(VkMemoryRequirements requirements, bool mappable, DeviceMemoryAllocation* allocation) { - const VulkanDeviceInfo& info = device->GetDeviceInfo(); + const VulkanDeviceInfo& info = mDevice->GetDeviceInfo(); // Find a suitable memory type for this allocation int bestType = -1; @@ -95,37 +95,37 @@ namespace vulkan { allocateInfo.memoryTypeIndex = static_cast(bestType); VkDeviceMemory allocatedMemory = VK_NULL_HANDLE; - if (device->fn.AllocateMemory(device->GetVkDevice(), &allocateInfo, nullptr, &allocatedMemory) != VK_SUCCESS) { + if (mDevice->fn.AllocateMemory(mDevice->GetVkDevice(), &allocateInfo, nullptr, &allocatedMemory) != VK_SUCCESS) { return false; } void* mappedPointer = nullptr; if (mappable) { - if (device->fn.MapMemory(device->GetVkDevice(), allocatedMemory, 0, requirements.size, 0, + if (mDevice->fn.MapMemory(mDevice->GetVkDevice(), allocatedMemory, 0, requirements.size, 0, &mappedPointer) != VK_SUCCESS) { return false; } } - allocation->memory = allocatedMemory; - allocation->offset = 0; - allocation->mappedPointer = reinterpret_cast(mappedPointer); + allocation->mMemory = allocatedMemory; + allocation->mOffset = 0; + allocation->mMappedPointer = reinterpret_cast(mappedPointer); return true; } void MemoryAllocator::Free(DeviceMemoryAllocation* allocation) { - releasedMemory.Enqueue(allocation->memory, device->GetSerial()); - allocation->memory = VK_NULL_HANDLE; - allocation->offset = 0; - allocation->mappedPointer = nullptr; + mReleasedMemory.Enqueue(allocation->mMemory, mDevice->GetSerial()); + allocation->mMemory = VK_NULL_HANDLE; + allocation->mOffset = 0; + allocation->mMappedPointer = nullptr; } void MemoryAllocator::Tick(Serial finishedSerial) { - for (auto memory : releasedMemory.IterateUpTo(finishedSerial)) { - device->fn.FreeMemory(device->GetVkDevice(), memory, nullptr); + for (auto memory : mReleasedMemory.IterateUpTo(finishedSerial)) { + mDevice->fn.FreeMemory(mDevice->GetVkDevice(), memory, nullptr); } - releasedMemory.ClearUpTo(finishedSerial); + mReleasedMemory.ClearUpTo(finishedSerial); } } } diff --git a/src/backend/vulkan/MemoryAllocator.h b/src/backend/vulkan/MemoryAllocator.h index c1ddb4e08b..6c82d8b805 100644 --- a/src/backend/vulkan/MemoryAllocator.h +++ b/src/backend/vulkan/MemoryAllocator.h @@ -33,9 +33,9 @@ namespace vulkan { private: friend class MemoryAllocator; - VkDeviceMemory memory = VK_NULL_HANDLE; - size_t offset = 0; - uint8_t* mappedPointer = nullptr; + VkDeviceMemory mMemory = VK_NULL_HANDLE; + size_t mOffset = 0; + uint8_t* mMappedPointer = nullptr; }; class MemoryAllocator { @@ -49,8 +49,8 @@ namespace vulkan { void Tick(Serial finishedSerial); private: - Device* device = nullptr; - SerialQueue releasedMemory; + Device* mDevice = nullptr; + SerialQueue mReleasedMemory; }; } diff --git a/src/backend/vulkan/VulkanBackend.cpp b/src/backend/vulkan/VulkanBackend.cpp index 926de57e77..7bed353c1f 100644 --- a/src/backend/vulkan/VulkanBackend.cpp +++ b/src/backend/vulkan/VulkanBackend.cpp @@ -45,19 +45,19 @@ namespace vulkan { // Device Device::Device() { - if (!vulkanLib.Open(kVulkanLibName)) { + if (!mVulkanLib.Open(kVulkanLibName)) { ASSERT(false); return; } VulkanFunctions* functions = GetMutableFunctions(); - if (!functions->LoadGlobalProcs(vulkanLib)) { + if (!functions->LoadGlobalProcs(mVulkanLib)) { ASSERT(false); return; } - if (!GatherGlobalInfo(*this, &globalInfo)) { + if (!GatherGlobalInfo(*this, &mGlobalInfo)) { ASSERT(false); return; } @@ -67,9 +67,9 @@ namespace vulkan { ASSERT(false); return; } - *static_cast(&globalInfo) = usedGlobalKnobs; + *static_cast(&mGlobalInfo) = usedGlobalKnobs; - if (!functions->LoadInstanceProcs(instance, usedGlobalKnobs)) { + if (!functions->LoadInstanceProcs(mInstance, usedGlobalKnobs)) { ASSERT(false); return; } @@ -87,9 +87,9 @@ namespace vulkan { return; } // TODO(cwallez@chromium.org): Choose the physical device based on ??? - physicalDevice = physicalDevices[0]; + mPhysicalDevice = physicalDevices[0]; - if (!GatherDeviceInfo(*this, physicalDevice, &deviceInfo)) { + if (!GatherDeviceInfo(*this, mPhysicalDevice, &mDeviceInfo)) { ASSERT(false); return; } @@ -99,77 +99,77 @@ namespace vulkan { ASSERT(false); return; } - *static_cast(&deviceInfo) = usedDeviceKnobs; + *static_cast(&mDeviceInfo) = usedDeviceKnobs; - if (!functions->LoadDeviceProcs(vkDevice, usedDeviceKnobs)) { + if (!functions->LoadDeviceProcs(mVkDevice, usedDeviceKnobs)) { ASSERT(false); return; } GatherQueueFromDevice(); - mapReadRequestTracker = new MapReadRequestTracker(this); - memoryAllocator = new MemoryAllocator(this); - bufferUploader = new BufferUploader(this); + mMapReadRequestTracker = new MapReadRequestTracker(this); + mMemoryAllocator = new MemoryAllocator(this); + mBufferUploader = new BufferUploader(this); } Device::~Device() { // Immediately forget about all pending commands so we don't try to submit them in Tick - FreeCommands(&pendingCommands); + FreeCommands(&mPendingCommands); - if (fn.QueueWaitIdle(queue) != VK_SUCCESS) { + if (fn.QueueWaitIdle(mQueue) != VK_SUCCESS) { ASSERT(false); } CheckPassedFences(); - ASSERT(fencesInFlight.empty()); + ASSERT(mFencesInFlight.empty()); // Some operations might have been started since the last submit and waiting // on a serial that doesn't have a corresponding fence enqueued. Force all // operations to look as if they were completed (because they were). - completedSerial = nextSerial; + mCompletedSerial = mNextSerial; Tick(); - ASSERT(commandsInFlight.Empty()); - for (auto& commands : unusedCommands) { + ASSERT(mCommandsInFlight.Empty()); + for (auto& commands : mUnusedCommands) { FreeCommands(&commands); } - unusedCommands.clear(); + mUnusedCommands.clear(); - for (VkFence fence : unusedFences) { - fn.DestroyFence(vkDevice, fence, nullptr); + for (VkFence fence : mUnusedFences) { + fn.DestroyFence(mVkDevice, fence, nullptr); } - unusedFences.clear(); + mUnusedFences.clear(); - if (bufferUploader) { - delete bufferUploader; - bufferUploader = nullptr; + if (mBufferUploader) { + delete mBufferUploader; + mBufferUploader = nullptr; } - if (memoryAllocator) { - delete memoryAllocator; - memoryAllocator = nullptr; + if (mMemoryAllocator) { + delete mMemoryAllocator; + mMemoryAllocator = nullptr; } - if (mapReadRequestTracker) { - delete mapReadRequestTracker; - mapReadRequestTracker = nullptr; + if (mMapReadRequestTracker) { + delete mMapReadRequestTracker; + mMapReadRequestTracker = nullptr; } // VkQueues are destroyed when the VkDevice is destroyed - if (vkDevice != VK_NULL_HANDLE) { - fn.DestroyDevice(vkDevice, nullptr); - vkDevice = VK_NULL_HANDLE; + if (mVkDevice != VK_NULL_HANDLE) { + fn.DestroyDevice(mVkDevice, nullptr); + mVkDevice = VK_NULL_HANDLE; } - if (debugReportCallback != VK_NULL_HANDLE) { - fn.DestroyDebugReportCallbackEXT(instance, debugReportCallback, nullptr); - debugReportCallback = VK_NULL_HANDLE; + if (mDebugReportCallback != VK_NULL_HANDLE) { + fn.DestroyDebugReportCallbackEXT(mInstance, mDebugReportCallback, nullptr); + mDebugReportCallback = VK_NULL_HANDLE; } // VkPhysicalDevices are destroyed when the VkInstance is destroyed - if (instance != VK_NULL_HANDLE) { - fn.DestroyInstance(instance, nullptr); - instance = VK_NULL_HANDLE; + if (mInstance != VK_NULL_HANDLE) { + fn.DestroyInstance(mInstance, nullptr); + mInstance = VK_NULL_HANDLE; } } @@ -240,38 +240,38 @@ namespace vulkan { CheckPassedFences(); RecycleCompletedCommands(); - mapReadRequestTracker->Tick(completedSerial); - bufferUploader->Tick(completedSerial); - memoryAllocator->Tick(completedSerial); + mMapReadRequestTracker->Tick(mCompletedSerial); + mBufferUploader->Tick(mCompletedSerial); + mMemoryAllocator->Tick(mCompletedSerial); - if (pendingCommands.pool != VK_NULL_HANDLE) { + if (mPendingCommands.pool != VK_NULL_HANDLE) { SubmitPendingCommands(); } } const VulkanDeviceInfo& Device::GetDeviceInfo() const { - return deviceInfo; + return mDeviceInfo; } MapReadRequestTracker* Device::GetMapReadRequestTracker() const { - return mapReadRequestTracker; + return mMapReadRequestTracker; } MemoryAllocator* Device::GetMemoryAllocator() const { - return memoryAllocator; + return mMemoryAllocator; } BufferUploader* Device::GetBufferUploader() const { - return bufferUploader; + return mBufferUploader; } Serial Device::GetSerial() const { - return nextSerial; + return mNextSerial; } VkCommandBuffer Device::GetPendingCommandBuffer() { - if (pendingCommands.pool == VK_NULL_HANDLE) { - pendingCommands = GetUnusedCommands(); + if (mPendingCommands.pool == VK_NULL_HANDLE) { + mPendingCommands = GetUnusedCommands(); VkCommandBufferBeginInfo beginInfo; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -279,20 +279,20 @@ namespace vulkan { beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; beginInfo.pInheritanceInfo = nullptr; - if (fn.BeginCommandBuffer(pendingCommands.commandBuffer, &beginInfo) != VK_SUCCESS) { + if (fn.BeginCommandBuffer(mPendingCommands.commandBuffer, &beginInfo) != VK_SUCCESS) { ASSERT(false); } } - return pendingCommands.commandBuffer; + return mPendingCommands.commandBuffer; } void Device::SubmitPendingCommands() { - if (pendingCommands.pool == VK_NULL_HANDLE) { + if (mPendingCommands.pool == VK_NULL_HANDLE) { return; } - if (fn.EndCommandBuffer(pendingCommands.commandBuffer) != VK_SUCCESS) { + if (fn.EndCommandBuffer(mPendingCommands.commandBuffer) != VK_SUCCESS) { ASSERT(false); } @@ -303,27 +303,27 @@ namespace vulkan { submitInfo.pWaitSemaphores = nullptr; submitInfo.pWaitDstStageMask = 0; submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &pendingCommands.commandBuffer; + submitInfo.pCommandBuffers = &mPendingCommands.commandBuffer; submitInfo.signalSemaphoreCount = 0; submitInfo.pSignalSemaphores = 0; VkFence fence = GetUnusedFence(); - if (fn.QueueSubmit(queue, 1, &submitInfo, fence) != VK_SUCCESS) { + if (fn.QueueSubmit(mQueue, 1, &submitInfo, fence) != VK_SUCCESS) { ASSERT(false); } - commandsInFlight.Enqueue(pendingCommands, nextSerial); - pendingCommands = CommandPoolAndBuffer(); - fencesInFlight.emplace(fence, nextSerial); - nextSerial++; + mCommandsInFlight.Enqueue(mPendingCommands, mNextSerial); + mPendingCommands = CommandPoolAndBuffer(); + mFencesInFlight.emplace(fence, mNextSerial); + mNextSerial++; } VkInstance Device::GetInstance() const { - return instance; + return mInstance; } VkDevice Device::GetVkDevice() const { - return vkDevice; + return mVkDevice; } bool Device::CreateInstance(VulkanGlobalKnobs* usedKnobs) { @@ -331,11 +331,11 @@ namespace vulkan { std::vector extensionsToRequest; #if defined(NXT_ENABLE_ASSERTS) - if (globalInfo.standardValidation) { + if (mGlobalInfo.standardValidation) { layersToRequest.push_back(kLayerNameLunargStandardValidation); usedKnobs->standardValidation = true; } - if (globalInfo.debugReport) { + if (mGlobalInfo.debugReport) { extensionsToRequest.push_back(kExtensionNameExtDebugReport); usedKnobs->debugReport = true; } @@ -360,7 +360,7 @@ namespace vulkan { createInfo.enabledExtensionCount = static_cast(extensionsToRequest.size()); createInfo.ppEnabledExtensionNames = extensionsToRequest.data(); - if (fn.CreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) { + if (fn.CreateInstance(&createInfo, nullptr, &mInstance) != VK_SUCCESS) { return false; } @@ -373,7 +373,7 @@ namespace vulkan { std::vector extensionsToRequest; std::vector queuesToRequest; - if (deviceInfo.swapchain) { + if (mDeviceInfo.swapchain) { extensionsToRequest.push_back(kExtensionNameKhrSwapchain); usedKnobs->swapchain = true; } @@ -382,8 +382,8 @@ namespace vulkan { { constexpr uint32_t kUniversalFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT; int universalQueueFamily = -1; - for (unsigned int i = 0; i < deviceInfo.queueFamilies.size(); ++i) { - if ((deviceInfo.queueFamilies[i].queueFlags & kUniversalFlags) == kUniversalFlags) { + for (unsigned int i = 0; i < mDeviceInfo.queueFamilies.size(); ++i) { + if ((mDeviceInfo.queueFamilies[i].queueFlags & kUniversalFlags) == kUniversalFlags) { universalQueueFamily = i; break; } @@ -392,7 +392,7 @@ namespace vulkan { if (universalQueueFamily == -1) { return false; } - queueFamily = static_cast(universalQueueFamily); + mQueueFamily = static_cast(universalQueueFamily); } // Choose to create a single universal queue @@ -401,7 +401,7 @@ namespace vulkan { queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; queueCreateInfo.pNext = nullptr; queueCreateInfo.flags = 0; - queueCreateInfo.queueFamilyIndex = static_cast(queueFamily); + queueCreateInfo.queueFamilyIndex = static_cast(mQueueFamily); queueCreateInfo.queueCount = 1; queueCreateInfo.pQueuePriorities = &zero; @@ -420,7 +420,7 @@ namespace vulkan { createInfo.ppEnabledExtensionNames = extensionsToRequest.data(); createInfo.pEnabledFeatures = &usedKnobs->features; - if (fn.CreateDevice(physicalDevice, &createInfo, nullptr, &vkDevice) != VK_SUCCESS) { + if (fn.CreateDevice(mPhysicalDevice, &createInfo, nullptr, &mVkDevice) != VK_SUCCESS) { return false; } @@ -428,7 +428,7 @@ namespace vulkan { } void Device::GatherQueueFromDevice() { - fn.GetDeviceQueue(vkDevice, queueFamily, 0, &queue); + fn.GetDeviceQueue(mVkDevice, mQueueFamily, 0, &mQueue); } bool Device::RegisterDebugReport() { @@ -439,7 +439,7 @@ namespace vulkan { createInfo.pfnCallback = Device::OnDebugReportCallback; createInfo.pUserData = this; - if (fn.CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &debugReportCallback) != VK_SUCCESS) { + if (fn.CreateDebugReportCallbackEXT(mInstance, &createInfo, nullptr, &mDebugReportCallback) != VK_SUCCESS) { return false; } @@ -465,9 +465,9 @@ namespace vulkan { } VkFence Device::GetUnusedFence() { - if (!unusedFences.empty()) { - VkFence fence = unusedFences.back(); - unusedFences.pop_back(); + if (!mUnusedFences.empty()) { + VkFence fence = mUnusedFences.back(); + mUnusedFences.pop_back(); return fence; } @@ -477,7 +477,7 @@ namespace vulkan { createInfo.flags = 0; VkFence fence = VK_NULL_HANDLE; - if (fn.CreateFence(vkDevice, &createInfo, nullptr, &fence) != VK_SUCCESS) { + if (fn.CreateFence(mVkDevice, &createInfo, nullptr, &fence) != VK_SUCCESS) { ASSERT(false); } @@ -485,11 +485,11 @@ namespace vulkan { } void Device::CheckPassedFences() { - while (!fencesInFlight.empty()) { - VkFence fence = fencesInFlight.front().first; - Serial fenceSerial = fencesInFlight.front().second; + while (!mFencesInFlight.empty()) { + VkFence fence = mFencesInFlight.front().first; + Serial fenceSerial = mFencesInFlight.front().second; - VkResult result = fn.GetFenceStatus(vkDevice, fence); + VkResult result = fn.GetFenceStatus(mVkDevice, fence); ASSERT(result == VK_SUCCESS || result == VK_NOT_READY); // Fence are added in order, so we can stop searching as soon @@ -498,22 +498,22 @@ namespace vulkan { return; } - if (fn.ResetFences(vkDevice, 1, &fence) != VK_SUCCESS) { + if (fn.ResetFences(mVkDevice, 1, &fence) != VK_SUCCESS) { ASSERT(false); } - unusedFences.push_back(fence); + mUnusedFences.push_back(fence); - fencesInFlight.pop(); + mFencesInFlight.pop(); - ASSERT(fenceSerial > completedSerial); - completedSerial = fenceSerial; + ASSERT(fenceSerial > mCompletedSerial); + mCompletedSerial = fenceSerial; } } Device::CommandPoolAndBuffer Device::GetUnusedCommands() { - if (!unusedCommands.empty()) { - CommandPoolAndBuffer commands = unusedCommands.back(); - unusedCommands.pop_back(); + if (!mUnusedCommands.empty()) { + CommandPoolAndBuffer commands = mUnusedCommands.back(); + mUnusedCommands.pop_back(); return commands; } @@ -523,9 +523,9 @@ namespace vulkan { createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; createInfo.pNext = nullptr; createInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; - createInfo.queueFamilyIndex = queueFamily; + createInfo.queueFamilyIndex = mQueueFamily; - if (fn.CreateCommandPool(vkDevice, &createInfo, nullptr, &commands.pool) != VK_SUCCESS) { + if (fn.CreateCommandPool(mVkDevice, &createInfo, nullptr, &commands.pool) != VK_SUCCESS) { ASSERT(false); } @@ -536,7 +536,7 @@ namespace vulkan { allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.commandBufferCount = 1; - if (fn.AllocateCommandBuffers(vkDevice, &allocateInfo, &commands.commandBuffer) != VK_SUCCESS) { + if (fn.AllocateCommandBuffers(mVkDevice, &allocateInfo, &commands.commandBuffer) != VK_SUCCESS) { ASSERT(false); } @@ -544,18 +544,18 @@ namespace vulkan { } void Device::RecycleCompletedCommands() { - for (auto& commands : commandsInFlight.IterateUpTo(completedSerial)) { - if (fn.ResetCommandPool(vkDevice, commands.pool, 0) != VK_SUCCESS) { + for (auto& commands : mCommandsInFlight.IterateUpTo(mCompletedSerial)) { + if (fn.ResetCommandPool(mVkDevice, commands.pool, 0) != VK_SUCCESS) { ASSERT(false); } - unusedCommands.push_back(commands); + mUnusedCommands.push_back(commands); } - commandsInFlight.ClearUpTo(completedSerial); + mCommandsInFlight.ClearUpTo(mCompletedSerial); } void Device::FreeCommands(CommandPoolAndBuffer* commands) { if (commands->pool != VK_NULL_HANDLE) { - fn.DestroyCommandPool(vkDevice, commands->pool, nullptr); + fn.DestroyCommandPool(mVkDevice, commands->pool, nullptr); commands->pool = VK_NULL_HANDLE; } diff --git a/src/backend/vulkan/VulkanBackend.h b/src/backend/vulkan/VulkanBackend.h index 117182a505..8345e35a84 100644 --- a/src/backend/vulkan/VulkanBackend.h +++ b/src/backend/vulkan/VulkanBackend.h @@ -142,8 +142,6 @@ namespace vulkan { VkInstance GetInstance() const; VkDevice GetVkDevice() const; - void FakeSubmit(); - private: bool CreateInstance(VulkanGlobalKnobs* usedKnobs); bool CreateDevice(VulkanDeviceKnobs* usedKnobs); @@ -163,21 +161,21 @@ namespace vulkan { // the Device is allowed to mutate them through these private methods. VulkanFunctions* GetMutableFunctions(); - VulkanGlobalInfo globalInfo; - VulkanDeviceInfo deviceInfo; + VulkanGlobalInfo mGlobalInfo; + VulkanDeviceInfo mDeviceInfo; - DynamicLib vulkanLib; + DynamicLib mVulkanLib; - VkInstance instance = VK_NULL_HANDLE; - VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; - VkDevice vkDevice = VK_NULL_HANDLE; - uint32_t queueFamily = 0; - VkQueue queue = VK_NULL_HANDLE; - VkDebugReportCallbackEXT debugReportCallback = VK_NULL_HANDLE; + VkInstance mInstance = VK_NULL_HANDLE; + VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE; + VkDevice mVkDevice = VK_NULL_HANDLE; + uint32_t mQueueFamily = 0; + VkQueue mQueue = VK_NULL_HANDLE; + VkDebugReportCallbackEXT mDebugReportCallback = VK_NULL_HANDLE; - MapReadRequestTracker* mapReadRequestTracker = nullptr; - MemoryAllocator* memoryAllocator = nullptr; - BufferUploader* bufferUploader = nullptr; + MapReadRequestTracker* mMapReadRequestTracker = nullptr; + MemoryAllocator* mMemoryAllocator = nullptr; + BufferUploader* mBufferUploader = nullptr; VkFence GetUnusedFence(); void CheckPassedFences(); @@ -186,10 +184,10 @@ namespace vulkan { // This works only because we have a single queue. Each submit to a queue is associated // to a serial and a fence, such that when the fence is "ready" we know the operations // have finished. - std::queue> fencesInFlight; - std::vector unusedFences; - Serial nextSerial = 1; - Serial completedSerial = 0; + std::queue> mFencesInFlight; + std::vector mUnusedFences; + Serial mNextSerial = 1; + Serial mCompletedSerial = 0; struct CommandPoolAndBuffer { VkCommandPool pool = VK_NULL_HANDLE; @@ -200,9 +198,9 @@ namespace vulkan { void RecycleCompletedCommands(); void FreeCommands(CommandPoolAndBuffer* commands); - SerialQueue commandsInFlight; - std::vector unusedCommands; - CommandPoolAndBuffer pendingCommands; + SerialQueue mCommandsInFlight; + std::vector mUnusedCommands; + CommandPoolAndBuffer mPendingCommands; }; class Queue : public QueueBase {