mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-14 08:30:50 +00:00
- there is no need to track a transfer family - yet another pointless detour thanks to vulkan-tutorial..
This commit is contained in:
parent
655b0c27de
commit
f7069c4ddc
7 changed files with 24 additions and 115 deletions
|
@ -271,7 +271,7 @@ void VkPostprocess::BeginFrame()
|
|||
if (!mDescriptorPool)
|
||||
{
|
||||
DescriptorPoolBuilder builder;
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 100);
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 200);
|
||||
builder.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 4);
|
||||
builder.setMaxSets(100);
|
||||
mDescriptorPool = builder.create(GetVulkanFrameBuffer()->device);
|
||||
|
@ -370,20 +370,12 @@ VkPPTexture::VkPPTexture(PPTexture *texture)
|
|||
barrier1.addImage(Image.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
barrier1.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
Layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
if (fb->device->transferFamily != fb->device->graphicsFamily)
|
||||
{
|
||||
PipelineBarrier transfer;
|
||||
transfer.addQueueTransfer(fb->device->transferFamily, fb->device->graphicsFamily, Image.get(), Layout);
|
||||
transfer.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
transfer.execute(fb->GetPreDrawCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PipelineBarrier barrier;
|
||||
barrier.addImage(Image.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
|
||||
barrier.execute(fb->GetPreDrawCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||
barrier.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||
Layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,6 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
|
|||
mStaging->Unmap();
|
||||
|
||||
fb->GetTransferCommands()->copyBuffer(mStaging.get(), mBuffer.get());
|
||||
|
||||
if (fb->device->transferFamily != fb->device->graphicsFamily)
|
||||
{
|
||||
PipelineBarrier transfer;
|
||||
transfer.addQueueTransfer(fb->device->transferFamily, fb->device->graphicsFamily, mBuffer.get(), VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
|
||||
transfer.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
transfer.execute(fb->GetPreDrawCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -86,22 +78,7 @@ void VKBuffer::SetSubData(size_t offset, size_t size, const void *data)
|
|||
memcpy(dst, data, size);
|
||||
mStaging->Unmap();
|
||||
|
||||
if (fb->device->transferFamily != fb->device->graphicsFamily)
|
||||
{
|
||||
PipelineBarrier transfer;
|
||||
transfer.addQueueTransfer(fb->device->graphicsFamily, fb->device->transferFamily, mBuffer.get(), VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_SHADER_READ_BIT, 0);
|
||||
transfer.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
}
|
||||
|
||||
fb->GetTransferCommands()->copyBuffer(mStaging.get(), mBuffer.get(), offset, offset, size);
|
||||
|
||||
if (fb->device->transferFamily != fb->device->graphicsFamily)
|
||||
{
|
||||
PipelineBarrier transfer;
|
||||
transfer.addQueueTransfer(fb->device->transferFamily, fb->device->graphicsFamily, mBuffer.get(), VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_SHADER_READ_BIT);
|
||||
transfer.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
transfer.execute(fb->GetPreDrawCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -120,6 +120,12 @@ void VulkanDevice::SelectPhysicalDevice()
|
|||
if (!CheckRequiredFeatures(info.Features))
|
||||
continue;
|
||||
|
||||
std::set<std::string> requiredExtensionSearch(EnabledDeviceExtensions.begin(), EnabledDeviceExtensions.end());
|
||||
for (const auto &ext : info.Extensions)
|
||||
requiredExtensionSearch.erase(ext.extensionName);
|
||||
if (!requiredExtensionSearch.empty())
|
||||
continue;
|
||||
|
||||
VulkanCompatibleDevice dev;
|
||||
dev.device = &AvailableDevices[idx];
|
||||
|
||||
|
@ -135,42 +141,22 @@ void VulkanDevice::SelectPhysicalDevice()
|
|||
}
|
||||
}
|
||||
|
||||
// Look for family that can do both graphics and transfer
|
||||
// The vulkan spec states that graphics and compute queues can always do transfer.
|
||||
// Furthermore the spec states that graphics queues always can do compute.
|
||||
// Last, the spec makes it OPTIONAL whether the VK_QUEUE_TRANSFER_BIT is set for such queues, but they MUST support transfer.
|
||||
//
|
||||
// In short: pick the first graphics queue family for everything.
|
||||
for (int i = 0; i < (int)info.QueueFamilies.size(); i++)
|
||||
{
|
||||
const auto &queueFamily = info.QueueFamilies[i];
|
||||
VkQueueFlags gpuFlags = (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_TRANSFER_BIT);
|
||||
if (queueFamily.queueCount > 0 && (queueFamily.queueFlags & gpuFlags) == gpuFlags)
|
||||
if (queueFamily.queueCount > 0 && (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT))
|
||||
{
|
||||
dev.graphicsFamily = i;
|
||||
dev.transferFamily = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// OK we didn't find any. Look for any match now.
|
||||
if (dev.graphicsFamily == -1)
|
||||
{
|
||||
for (int i = 0; i < (int)info.QueueFamilies.size(); i++)
|
||||
{
|
||||
const auto &queueFamily = info.QueueFamilies[i];
|
||||
if (queueFamily.queueCount > 0)
|
||||
{
|
||||
if (dev.graphicsFamily == -1 && (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT))
|
||||
dev.graphicsFamily = i;
|
||||
if (dev.transferFamily == -1 && (queueFamily.queueFlags & VK_QUEUE_TRANSFER_BIT))
|
||||
dev.transferFamily = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string> requiredExtensionSearch(EnabledDeviceExtensions.begin(), EnabledDeviceExtensions.end());
|
||||
for (const auto &ext : info.Extensions)
|
||||
requiredExtensionSearch.erase(ext.extensionName);
|
||||
if (!requiredExtensionSearch.empty())
|
||||
continue;
|
||||
|
||||
if (dev.graphicsFamily != -1 && dev.presentFamily != -1 && dev.transferFamily != -1)
|
||||
if (dev.graphicsFamily != -1 && dev.presentFamily != -1)
|
||||
{
|
||||
SupportedDevices.push_back(dev);
|
||||
}
|
||||
|
@ -213,7 +199,6 @@ void VulkanDevice::SelectPhysicalDevice()
|
|||
PhysicalDevice = *SupportedDevices[selected].device;
|
||||
graphicsFamily = SupportedDevices[selected].graphicsFamily;
|
||||
presentFamily = SupportedDevices[selected].presentFamily;
|
||||
transferFamily = SupportedDevices[selected].transferFamily;
|
||||
}
|
||||
|
||||
bool VulkanDevice::SupportsDeviceExtension(const char *ext) const
|
||||
|
@ -241,7 +226,6 @@ void VulkanDevice::CreateDevice()
|
|||
std::set<int> neededFamilies;
|
||||
neededFamilies.insert(graphicsFamily);
|
||||
neededFamilies.insert(presentFamily);
|
||||
neededFamilies.insert(transferFamily);
|
||||
|
||||
for (int index : neededFamilies)
|
||||
{
|
||||
|
@ -270,7 +254,6 @@ void VulkanDevice::CreateDevice()
|
|||
|
||||
vkGetDeviceQueue(device, graphicsFamily, 0, &graphicsQueue);
|
||||
vkGetDeviceQueue(device, presentFamily, 0, &presentQueue);
|
||||
vkGetDeviceQueue(device, transferFamily, 0, &transferQueue);
|
||||
}
|
||||
|
||||
void VulkanDevice::CreateSurface()
|
||||
|
|
|
@ -28,7 +28,6 @@ class VulkanCompatibleDevice
|
|||
public:
|
||||
VulkanPhysicalDevice *device = nullptr;
|
||||
int graphicsFamily = -1;
|
||||
int transferFamily = -1;
|
||||
int presentFamily = -1;
|
||||
};
|
||||
|
||||
|
@ -73,10 +72,8 @@ public:
|
|||
|
||||
VkQueue graphicsQueue = VK_NULL_HANDLE;
|
||||
VkQueue presentQueue = VK_NULL_HANDLE;
|
||||
VkQueue transferQueue = VK_NULL_HANDLE;
|
||||
|
||||
int graphicsFamily = -1;
|
||||
int transferFamily = -1;
|
||||
int presentFamily = -1;
|
||||
|
||||
private:
|
||||
|
|
|
@ -118,9 +118,7 @@ void VulkanFrameBuffer::InitializeState()
|
|||
maxuniformblock = device->PhysicalDevice.Properties.limits.maxUniformBufferRange;
|
||||
|
||||
mTransferSemaphore.reset(new VulkanSemaphore(device));
|
||||
mPreDrawSemaphore.reset(new VulkanSemaphore(device));
|
||||
mGraphicsCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily));
|
||||
mTransferCommandPool.reset(new VulkanCommandPool(device, device->transferFamily));
|
||||
mCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily));
|
||||
|
||||
mScreenBuffers.reset(new VkRenderBuffers());
|
||||
mSaveBuffers.reset(new VkRenderBuffers());
|
||||
|
@ -210,7 +208,6 @@ void VulkanFrameBuffer::Update()
|
|||
|
||||
mDrawCommands.reset();
|
||||
mTransferCommands.reset();
|
||||
mPreDrawCommands.reset();
|
||||
DeleteFrameObjects();
|
||||
|
||||
Finish.Unclock();
|
||||
|
@ -235,18 +232,6 @@ void VulkanFrameBuffer::SubmitCommands(bool finish)
|
|||
QueueSubmit submit;
|
||||
submit.addCommandBuffer(mTransferCommands.get());
|
||||
submit.addSignal(mTransferSemaphore.get());
|
||||
submit.execute(device, device->transferQueue);
|
||||
}
|
||||
|
||||
if (mPreDrawCommands)
|
||||
{
|
||||
mPreDrawCommands->end();
|
||||
|
||||
QueueSubmit submit;
|
||||
submit.addCommandBuffer(mPreDrawCommands.get());
|
||||
if (mTransferCommands)
|
||||
submit.addWait(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, mTransferSemaphore.get());
|
||||
submit.addSignal(mPreDrawSemaphore.get());
|
||||
submit.execute(device, device->graphicsQueue);
|
||||
}
|
||||
|
||||
|
@ -254,10 +239,10 @@ void VulkanFrameBuffer::SubmitCommands(bool finish)
|
|||
|
||||
QueueSubmit submit;
|
||||
submit.addCommandBuffer(mDrawCommands.get());
|
||||
if (mPreDrawCommands)
|
||||
submit.addWait(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, mPreDrawSemaphore.get());
|
||||
else if (mTransferCommands)
|
||||
if (mTransferCommands)
|
||||
{
|
||||
submit.addWait(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, mTransferSemaphore.get());
|
||||
}
|
||||
if (finish)
|
||||
{
|
||||
submit.addWait(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, mSwapChainImageAvailableSemaphore.get());
|
||||
|
@ -271,7 +256,6 @@ void VulkanFrameBuffer::SubmitCommands(bool finish)
|
|||
vkResetFences(device->device, 1, &mRenderFinishedFence->fence);
|
||||
mDrawCommands.reset();
|
||||
mTransferCommands.reset();
|
||||
mPreDrawCommands.reset();
|
||||
DeleteFrameObjects();
|
||||
}
|
||||
}
|
||||
|
@ -790,29 +774,18 @@ VulkanCommandBuffer *VulkanFrameBuffer::GetTransferCommands()
|
|||
{
|
||||
if (!mTransferCommands)
|
||||
{
|
||||
mTransferCommands = mTransferCommandPool->createBuffer();
|
||||
mTransferCommands = mCommandPool->createBuffer();
|
||||
mTransferCommands->SetDebugName("VulkanFrameBuffer.mTransferCommands");
|
||||
mTransferCommands->begin();
|
||||
}
|
||||
return mTransferCommands.get();
|
||||
}
|
||||
|
||||
VulkanCommandBuffer *VulkanFrameBuffer::GetPreDrawCommands()
|
||||
{
|
||||
if (!mPreDrawCommands)
|
||||
{
|
||||
mPreDrawCommands = mGraphicsCommandPool->createBuffer();
|
||||
mPreDrawCommands->SetDebugName("VulkanFrameBuffer.mPreDrawCommands");
|
||||
mPreDrawCommands->begin();
|
||||
}
|
||||
return mPreDrawCommands.get();
|
||||
}
|
||||
|
||||
VulkanCommandBuffer *VulkanFrameBuffer::GetDrawCommands()
|
||||
{
|
||||
if (!mDrawCommands)
|
||||
{
|
||||
mDrawCommands = mGraphicsCommandPool->createBuffer();
|
||||
mDrawCommands = mCommandPool->createBuffer();
|
||||
mDrawCommands->SetDebugName("VulkanFrameBuffer.mDrawCommands");
|
||||
mDrawCommands->begin();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ public:
|
|||
uint32_t presentImageIndex = 0;
|
||||
|
||||
VulkanCommandBuffer *GetTransferCommands();
|
||||
VulkanCommandBuffer *GetPreDrawCommands();
|
||||
VulkanCommandBuffer *GetDrawCommands();
|
||||
VkShaderManager *GetShaderManager() { return mShaderManager.get(); }
|
||||
VkSamplerManager *GetSamplerManager() { return mSamplerManager.get(); }
|
||||
|
@ -114,13 +113,10 @@ private:
|
|||
std::unique_ptr<VkRenderBuffers> mSaveBuffers;
|
||||
std::unique_ptr<VkPostprocess> mPostprocess;
|
||||
std::unique_ptr<VkRenderPassManager> mRenderPassManager;
|
||||
std::unique_ptr<VulkanCommandPool> mGraphicsCommandPool;
|
||||
std::unique_ptr<VulkanCommandPool> mTransferCommandPool;
|
||||
std::unique_ptr<VulkanCommandPool> mCommandPool;
|
||||
std::unique_ptr<VulkanCommandBuffer> mTransferCommands;
|
||||
std::unique_ptr<VulkanCommandBuffer> mPreDrawCommands;
|
||||
std::unique_ptr<VulkanCommandBuffer> mDrawCommands;
|
||||
std::unique_ptr<VulkanSemaphore> mTransferSemaphore;
|
||||
std::unique_ptr<VulkanSemaphore> mPreDrawSemaphore;
|
||||
std::unique_ptr<VkRenderState> mRenderState;
|
||||
|
||||
std::unique_ptr<VulkanSemaphore> mSwapChainImageAvailableSemaphore;
|
||||
|
|
|
@ -195,7 +195,7 @@ void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags)
|
|||
mImageView = viewbuilder.create(fb->device);
|
||||
mImageView->SetDebugName("VkHardwareTexture.mImageView");
|
||||
|
||||
auto cmdbuffer = fb->GetPreDrawCommands();
|
||||
auto cmdbuffer = fb->GetTransferCommands();
|
||||
|
||||
PipelineBarrier imageTransition;
|
||||
imageTransition.addImage(mImage.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, VK_ACCESS_SHADER_READ_BIT);
|
||||
|
@ -289,15 +289,6 @@ void VkHardwareTexture::GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer
|
|||
PipelineBarrier barrier2;
|
||||
barrier2.addImage(image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_ASPECT_COLOR_BIT, i - 1);
|
||||
barrier2.execute(cmdbuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
if (fb->device->transferFamily != fb->device->graphicsFamily)
|
||||
{
|
||||
PipelineBarrier transfer;
|
||||
transfer.addQueueTransfer(fb->device->transferFamily, fb->device->graphicsFamily, image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT, 0, GetMipLevels(image->width, image->height));
|
||||
transfer.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
transfer.execute(fb->GetPreDrawCommands(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
int VkHardwareTexture::GetMipLevels(int w, int h)
|
||||
|
@ -335,7 +326,7 @@ void VkHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
|
|||
mImageView = viewbuilder.create(fb->device);
|
||||
mImageView->SetDebugName("VkHardwareTexture.mImageView");
|
||||
|
||||
auto cmdbuffer = fb->GetPreDrawCommands();
|
||||
auto cmdbuffer = fb->GetTransferCommands();
|
||||
|
||||
PipelineBarrier imageTransition;
|
||||
imageTransition.addImage(mImage.get(), VK_IMAGE_LAYOUT_UNDEFINED, mImageLayout, 0, VK_ACCESS_SHADER_READ_BIT);
|
||||
|
|
Loading…
Reference in a new issue