A bit more clang-format

This commit is contained in:
Jasmine Iwanek
2022-11-19 08:49:04 -05:00
parent b04dd8cc8b
commit 3fe4f75108
223 changed files with 8047 additions and 7456 deletions

View File

@@ -35,11 +35,10 @@
#include <QFile>
#include "qt_vulkanrenderer.hpp"
#if QT_CONFIG(vulkan)
#include <QVulkanFunctions>
# include <QVulkanFunctions>
extern "C"
{
#include <86box/86box.h>
extern "C" {
# include <86box/86box.h>
}
// Use a triangle strip to get a quad.
@@ -58,7 +57,8 @@ static float vertexData[] = { // Y up, front = CW
static const int UNIFORM_DATA_SIZE = 16 * sizeof(float);
static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign)
static inline VkDeviceSize
aligned(VkDeviceSize v, VkDeviceSize byteAlign)
{
return (v + byteAlign - 1) & ~(byteAlign - 1);
}
@@ -68,7 +68,8 @@ VulkanRenderer2::VulkanRenderer2(QVulkanWindow *w)
{
}
VkShaderModule VulkanRenderer2::createShader(const QString &name)
VkShaderModule
VulkanRenderer2::createShader(const QString &name)
{
QFile file(name);
if (!file.open(QIODevice::ReadOnly)) {
@@ -80,11 +81,11 @@ VkShaderModule VulkanRenderer2::createShader(const QString &name)
VkShaderModuleCreateInfo shaderInfo;
memset(&shaderInfo, 0, sizeof(shaderInfo));
shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
shaderInfo.codeSize = blob.size();
shaderInfo.pCode = reinterpret_cast<const uint32_t *>(blob.constData());
shaderInfo.pCode = reinterpret_cast<const uint32_t *>(blob.constData());
VkShaderModule shaderModule;
VkResult err = m_devFuncs->vkCreateShaderModule(m_window->device(), &shaderInfo, nullptr, &shaderModule);
VkResult err = m_devFuncs->vkCreateShaderModule(m_window->device(), &shaderInfo, nullptr, &shaderModule);
if (err != VK_SUCCESS) {
qWarning("Failed to create shader module: %d", err);
return VK_NULL_HANDLE;
@@ -93,13 +94,14 @@ VkShaderModule VulkanRenderer2::createShader(const QString &name)
return shaderModule;
}
bool VulkanRenderer2::createTexture()
bool
VulkanRenderer2::createTexture()
{
QImage img(2048, 2048, QImage::Format_RGBA8888_Premultiplied);
img.fill(QColor(0, 0, 0));
QVulkanFunctions *f = m_window->vulkanInstance()->functions();
VkDevice dev = m_window->device();
QVulkanFunctions *f = m_window->vulkanInstance()->functions();
VkDevice dev = m_window->device();
m_texFormat = VK_FORMAT_B8G8R8A8_UNORM;
@@ -108,7 +110,7 @@ bool VulkanRenderer2::createTexture()
// tiling format.
VkFormatProperties props;
f->vkGetPhysicalDeviceFormatProperties(m_window->physicalDevice(), m_texFormat, &props);
const bool canSampleLinear = (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
const bool canSampleLinear = (props.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
const bool canSampleOptimal = (props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
if (!canSampleLinear && !canSampleOptimal) {
qWarning("Neither linear nor optimal image sampling is supported for RGBA8");
@@ -146,14 +148,14 @@ bool VulkanRenderer2::createTexture()
VkImageViewCreateInfo viewInfo;
memset(&viewInfo, 0, sizeof(viewInfo));
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
viewInfo.image = m_texImage;
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
viewInfo.format = m_texFormat;
viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
viewInfo.image = m_texImage;
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
viewInfo.format = m_texFormat;
viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
viewInfo.subresourceRange.levelCount = viewInfo.subresourceRange.layerCount = 1;
@@ -168,24 +170,25 @@ bool VulkanRenderer2::createTexture()
return true;
}
bool VulkanRenderer2::createTextureImage(const QSize &size, VkImage *image, VkDeviceMemory *mem,
VkImageTiling tiling, VkImageUsageFlags usage, uint32_t memIndex)
bool
VulkanRenderer2::createTextureImage(const QSize &size, VkImage *image, VkDeviceMemory *mem,
VkImageTiling tiling, VkImageUsageFlags usage, uint32_t memIndex)
{
VkDevice dev = m_window->device();
VkImageCreateInfo imageInfo;
memset(&imageInfo, 0, sizeof(imageInfo));
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = m_texFormat;
imageInfo.extent.width = size.width();
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = m_texFormat;
imageInfo.extent.width = size.width();
imageInfo.extent.height = size.height();
imageInfo.extent.depth = 1;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.tiling = tiling;
imageInfo.usage = usage;
imageInfo.extent.depth = 1;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.tiling = tiling;
imageInfo.usage = usage;
imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
VkResult err = m_devFuncs->vkCreateImage(dev, &imageInfo, nullptr, image);
@@ -230,7 +233,8 @@ bool VulkanRenderer2::createTextureImage(const QSize &size, VkImage *image, VkDe
return true;
}
bool VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDeviceMemory memory)
bool
VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDeviceMemory memory)
{
VkDevice dev = m_window->device();
@@ -242,7 +246,7 @@ bool VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDevic
VkSubresourceLayout layout;
m_devFuncs->vkGetImageSubresourceLayout(dev, image, &subres, &layout);
uchar *p;
uchar *p;
VkResult err = m_devFuncs->vkMapMemory(dev, memory, layout.offset, layout.size, 0, reinterpret_cast<void **>(&p));
if (err != VK_SUCCESS) {
qWarning("Failed to map memory for linear image: %d", err);
@@ -259,7 +263,8 @@ bool VulkanRenderer2::writeLinearImage(const QImage &img, VkImage image, VkDevic
return true;
}
void VulkanRenderer2::ensureTexture()
void
VulkanRenderer2::ensureTexture()
{
if (!m_texLayoutPending && !m_texStagingPending)
return;
@@ -269,24 +274,24 @@ void VulkanRenderer2::ensureTexture()
VkImageMemoryBarrier barrier;
memset(&barrier, 0, sizeof(barrier));
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1;
if (m_texLayoutPending) {
m_texLayoutPending = false;
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
barrier.image = m_texImage;
barrier.image = m_texImage;
m_devFuncs->vkCmdPipelineBarrier(cb,
VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VkDevice dev = m_window->device();
@@ -301,38 +306,38 @@ void VulkanRenderer2::ensureTexture()
VkResult err = m_devFuncs->vkMapMemory(dev, m_texMem, layout.offset, layout.size, 0, reinterpret_cast<void **>(&mappedPtr));
if (err != VK_SUCCESS) {
qWarning("Failed to map memory for linear image: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
imagePitch = layout.rowPitch;
if (qobject_cast<VulkanWindowRenderer*>(m_window)) {
emit qobject_cast<VulkanWindowRenderer*>(m_window)->rendererInitialized();
if (qobject_cast<VulkanWindowRenderer *>(m_window)) {
emit qobject_cast<VulkanWindowRenderer *>(m_window)->rendererInitialized();
}
} else {
m_texStagingPending = false;
if (!m_texStagingTransferLayout) {
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
barrier.image = m_texStaging;
barrier.image = m_texStaging;
m_devFuncs->vkCmdPipelineBarrier(cb,
VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.srcAccessMask = 0;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.image = m_texImage;
barrier.image = m_texImage;
m_devFuncs->vkCmdPipelineBarrier(cb,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VkDevice dev = m_window->device();
@@ -347,12 +352,12 @@ void VulkanRenderer2::ensureTexture()
VkResult err = m_devFuncs->vkMapMemory(dev, m_texStagingMem, layout.offset, layout.size, 0, reinterpret_cast<void **>(&mappedPtr));
if (err != VK_SUCCESS) {
qWarning("Failed to map memory for linear image: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
imagePitch = layout.rowPitch;
if (qobject_cast<VulkanWindowRenderer*>(m_window)) {
emit qobject_cast<VulkanWindowRenderer*>(m_window)->rendererInitialized();
if (qobject_cast<VulkanWindowRenderer *>(m_window)) {
emit qobject_cast<VulkanWindowRenderer *>(m_window)->rendererInitialized();
}
m_texStagingTransferLayout = true;
@@ -364,26 +369,27 @@ void VulkanRenderer2::ensureTexture()
copyInfo.srcSubresource.layerCount = 1;
copyInfo.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copyInfo.dstSubresource.layerCount = 1;
copyInfo.extent.width = m_texSize.width();
copyInfo.extent.height = m_texSize.height();
copyInfo.extent.depth = 1;
copyInfo.extent.width = m_texSize.width();
copyInfo.extent.height = m_texSize.height();
copyInfo.extent.depth = 1;
m_devFuncs->vkCmdCopyImage(cb, m_texStaging, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
m_texImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copyInfo);
m_texImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copyInfo);
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
barrier.image = m_texImage;
barrier.image = m_texImage;
m_devFuncs->vkCmdPipelineBarrier(cb,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
}
}
void VulkanRenderer2::updateSamplers()
void
VulkanRenderer2::updateSamplers()
{
static int cur_video_filter_method = -1;
@@ -400,52 +406,53 @@ void VulkanRenderer2::updateSamplers()
for (int i = 0; i < m_window->concurrentFrameCount(); i++) {
VkWriteDescriptorSet descWrite[2];
memset(descWrite, 0, sizeof(descWrite));
descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[0].dstSet = m_descSet[i];
descWrite[0].dstBinding = 0;
descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[0].dstSet = m_descSet[i];
descWrite[0].dstBinding = 0;
descWrite[0].descriptorCount = 1;
descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descWrite[0].pBufferInfo = &m_uniformBufInfo[i];
descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descWrite[0].pBufferInfo = &m_uniformBufInfo[i];
descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[1].dstSet = m_descSet[i];
descWrite[1].dstBinding = 1;
descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[1].dstSet = m_descSet[i];
descWrite[1].dstBinding = 1;
descWrite[1].descriptorCount = 1;
descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descWrite[1].pImageInfo = &descImageInfo;
descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descWrite[1].pImageInfo = &descImageInfo;
m_devFuncs->vkUpdateDescriptorSets(m_window->device(), 2, descWrite, 0, nullptr);
}
}
}
void VulkanRenderer2::initResources()
void
VulkanRenderer2::initResources()
{
qDebug("initResources");
VkDevice dev = m_window->device();
m_devFuncs = m_window->vulkanInstance()->deviceFunctions(dev);
m_devFuncs = m_window->vulkanInstance()->deviceFunctions(dev);
// The setup is similar to hellovulkantriangle. The difference is the
// presence of a second vertex attribute (texcoord), a sampler, and that we
// need blending.
const int concurrentFrameCount = m_window->concurrentFrameCount();
const VkPhysicalDeviceLimits *pdevLimits = &m_window->physicalDeviceProperties()->limits;
const VkDeviceSize uniAlign = pdevLimits->minUniformBufferOffsetAlignment;
const int concurrentFrameCount = m_window->concurrentFrameCount();
const VkPhysicalDeviceLimits *pdevLimits = &m_window->physicalDeviceProperties()->limits;
const VkDeviceSize uniAlign = pdevLimits->minUniformBufferOffsetAlignment;
qDebug("uniform buffer offset alignment is %u", (uint) uniAlign);
VkBufferCreateInfo bufInfo;
memset(&bufInfo, 0, sizeof(bufInfo));
bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
// Our internal layout is vertex, uniform, uniform, ... with each uniform buffer start offset aligned to uniAlign.
const VkDeviceSize vertexAllocSize = aligned(sizeof(vertexData), uniAlign);
const VkDeviceSize vertexAllocSize = aligned(sizeof(vertexData), uniAlign);
const VkDeviceSize uniformAllocSize = aligned(UNIFORM_DATA_SIZE, uniAlign);
bufInfo.size = vertexAllocSize + concurrentFrameCount * uniformAllocSize;
bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
bufInfo.size = vertexAllocSize + concurrentFrameCount * uniformAllocSize;
bufInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
VkResult err = m_devFuncs->vkCreateBuffer(dev, &bufInfo, nullptr, &m_buf);
if (err != VK_SUCCESS) {
qWarning("Failed to create buffer: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
VkMemoryRequirements memReq;
@@ -461,20 +468,20 @@ void VulkanRenderer2::initResources()
err = m_devFuncs->vkAllocateMemory(dev, &memAllocInfo, nullptr, &m_bufMem);
if (err != VK_SUCCESS) {
qWarning("Failed to allocate memory: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
err = m_devFuncs->vkBindBufferMemory(dev, m_buf, m_bufMem, 0);
if (err != VK_SUCCESS) {
qWarning("Failed to bind buffer memory: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
quint8 *p;
err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0, memReq.size, 0, reinterpret_cast<void **>(&p));
if (err != VK_SUCCESS) {
qWarning("Failed to map memory: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
memcpy(p, vertexData, sizeof(vertexData));
QMatrix4x4 ident;
@@ -484,7 +491,7 @@ void VulkanRenderer2::initResources()
memcpy(p + offset, ident.constData(), 16 * sizeof(float));
m_uniformBufInfo[i].buffer = m_buf;
m_uniformBufInfo[i].offset = offset;
m_uniformBufInfo[i].range = uniformAllocSize;
m_uniformBufInfo[i].range = uniformAllocSize;
}
m_devFuncs->vkUnmapMemory(dev, m_bufMem);
@@ -494,93 +501,86 @@ void VulkanRenderer2::initResources()
VK_VERTEX_INPUT_RATE_VERTEX
};
VkVertexInputAttributeDescription vertexAttrDesc[] = {
{ // position
0, // location
0, // binding
VK_FORMAT_R32G32B32_SFLOAT,
0
},
{// position
0, // location
0, // binding
VK_FORMAT_R32G32B32_SFLOAT,
0 },
{ // texcoord
1,
0,
VK_FORMAT_R32G32_SFLOAT,
3 * sizeof(float)
}
1,
0,
VK_FORMAT_R32G32_SFLOAT,
3 * sizeof(float)}
};
VkPipelineVertexInputStateCreateInfo vertexInputInfo;
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputInfo.pNext = nullptr;
vertexInputInfo.flags = 0;
vertexInputInfo.vertexBindingDescriptionCount = 1;
vertexInputInfo.pVertexBindingDescriptions = &vertexBindingDesc;
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputInfo.pNext = nullptr;
vertexInputInfo.flags = 0;
vertexInputInfo.vertexBindingDescriptionCount = 1;
vertexInputInfo.pVertexBindingDescriptions = &vertexBindingDesc;
vertexInputInfo.vertexAttributeDescriptionCount = 2;
vertexInputInfo.pVertexAttributeDescriptions = vertexAttrDesc;
vertexInputInfo.pVertexAttributeDescriptions = vertexAttrDesc;
// Sampler.
VkSamplerCreateInfo samplerInfo;
memset(&samplerInfo, 0, sizeof(samplerInfo));
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
samplerInfo.maxAnisotropy = 1.0f;
samplerInfo.maxLod = 0.25;
err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_sampler);
samplerInfo.maxLod = 0.25;
err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_sampler);
if (err != VK_SUCCESS) {
qWarning("Failed to create sampler: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_linearSampler);
err = m_devFuncs->vkCreateSampler(dev, &samplerInfo, nullptr, &m_linearSampler);
if (err != VK_SUCCESS) {
qWarning("Failed to create sampler: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
// Texture.
if (!createTexture()) {
qWarning("Failed to create texture");
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
// Set up descriptor set and its layout.
VkDescriptorPoolSize descPoolSizes[2] = {
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32_t(concurrentFrameCount) },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32_t(concurrentFrameCount) }
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32_t(concurrentFrameCount)},
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32_t(concurrentFrameCount)}
};
VkDescriptorPoolCreateInfo descPoolInfo;
memset(&descPoolInfo, 0, sizeof(descPoolInfo));
descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
descPoolInfo.maxSets = concurrentFrameCount;
descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
descPoolInfo.maxSets = concurrentFrameCount;
descPoolInfo.poolSizeCount = 2;
descPoolInfo.pPoolSizes = descPoolSizes;
err = m_devFuncs->vkCreateDescriptorPool(dev, &descPoolInfo, nullptr, &m_descPool);
descPoolInfo.pPoolSizes = descPoolSizes;
err = m_devFuncs->vkCreateDescriptorPool(dev, &descPoolInfo, nullptr, &m_descPool);
if (err != VK_SUCCESS) {
qWarning("Failed to create descriptor pool: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
VkDescriptorSetLayoutBinding layoutBinding[2] =
{
{
0, // binding
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1, // descriptorCount
VK_SHADER_STAGE_VERTEX_BIT,
nullptr
},
{
1, // binding
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1, // descriptorCount
VK_SHADER_STAGE_FRAGMENT_BIT,
nullptr
}
VkDescriptorSetLayoutBinding layoutBinding[2] = {
{0, // binding
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1, // descriptorCount
VK_SHADER_STAGE_VERTEX_BIT,
nullptr},
{ 1, // binding
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1, // descriptorCount
VK_SHADER_STAGE_FRAGMENT_BIT,
nullptr}
};
VkDescriptorSetLayoutCreateInfo descLayoutInfo = {
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
@@ -592,7 +592,7 @@ void VulkanRenderer2::initResources()
err = m_devFuncs->vkCreateDescriptorSetLayout(dev, &descLayoutInfo, nullptr, &m_descSetLayout);
if (err != VK_SUCCESS) {
qWarning("Failed to create descriptor set layout: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
for (int i = 0; i < concurrentFrameCount; ++i) {
@@ -606,17 +606,17 @@ void VulkanRenderer2::initResources()
err = m_devFuncs->vkAllocateDescriptorSets(dev, &descSetAllocInfo, &m_descSet[i]);
if (err != VK_SUCCESS) {
qWarning("Failed to allocate descriptor set: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
VkWriteDescriptorSet descWrite[2];
memset(descWrite, 0, sizeof(descWrite));
descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[0].dstSet = m_descSet[i];
descWrite[0].dstBinding = 0;
descWrite[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[0].dstSet = m_descSet[i];
descWrite[0].dstBinding = 0;
descWrite[0].descriptorCount = 1;
descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descWrite[0].pBufferInfo = &m_uniformBufInfo[i];
descWrite[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descWrite[0].pBufferInfo = &m_uniformBufInfo[i];
VkDescriptorImageInfo descImageInfo = {
video_filter_method == 1 ? m_linearSampler : m_sampler,
@@ -624,12 +624,12 @@ void VulkanRenderer2::initResources()
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
};
descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[1].dstSet = m_descSet[i];
descWrite[1].dstBinding = 1;
descWrite[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrite[1].dstSet = m_descSet[i];
descWrite[1].dstBinding = 1;
descWrite[1].descriptorCount = 1;
descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descWrite[1].pImageInfo = &descImageInfo;
descWrite[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descWrite[1].pImageInfo = &descImageInfo;
m_devFuncs->vkUpdateDescriptorSets(dev, 2, descWrite, 0, nullptr);
}
@@ -638,60 +638,60 @@ void VulkanRenderer2::initResources()
VkPipelineCacheCreateInfo pipelineCacheInfo;
memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo));
pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
err = m_devFuncs->vkCreatePipelineCache(dev, &pipelineCacheInfo, nullptr, &m_pipelineCache);
err = m_devFuncs->vkCreatePipelineCache(dev, &pipelineCacheInfo, nullptr, &m_pipelineCache);
if (err != VK_SUCCESS) {
qWarning("Failed to create pipeline cache: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
// Pipeline layout
VkPipelineLayoutCreateInfo pipelineLayoutInfo;
memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo));
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.setLayoutCount = 1;
pipelineLayoutInfo.pSetLayouts = &m_descSetLayout;
err = m_devFuncs->vkCreatePipelineLayout(dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
pipelineLayoutInfo.pSetLayouts = &m_descSetLayout;
err = m_devFuncs->vkCreatePipelineLayout(dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
if (err != VK_SUCCESS) {
qWarning("Failed to create pipeline layout: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
// Shaders
/*
#version 440
/*
#version 440
layout(location = 0) in vec4 position;
layout(location = 1) in vec2 texcoord;
layout(location = 0) in vec4 position;
layout(location = 1) in vec2 texcoord;
layout(location = 0) out vec2 v_texcoord;
layout(location = 0) out vec2 v_texcoord;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
} ubuf;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
} ubuf;
out gl_PerVertex { vec4 gl_Position; };
out gl_PerVertex { vec4 gl_Position; };
void main()
{
v_texcoord = texcoord;
gl_Position = ubuf.mvp * position;
}
*/
void main()
{
v_texcoord = texcoord;
gl_Position = ubuf.mvp * position;
}
*/
VkShaderModule vertShaderModule = createShader(QStringLiteral(":/texture_vert.spv"));
/*
#version 440
/*
#version 440
layout(location = 0) in vec2 v_texcoord;
layout(location = 0) in vec2 v_texcoord;
layout(location = 0) out vec4 fragColor;
layout(location = 0) out vec4 fragColor;
layout(binding = 1) uniform sampler2D tex;
layout(binding = 1) uniform sampler2D tex;
void main()
{
fragColor = texture(tex, v_texcoord);
}
*/
void main()
{
fragColor = texture(tex, v_texcoord);
}
*/
VkShaderModule fragShaderModule = createShader(QStringLiteral(":/texture_frag.spv"));
// Graphics pipeline
@@ -720,46 +720,46 @@ void main()
}
};
pipelineInfo.stageCount = 2;
pipelineInfo.pStages = shaderStages;
pipelineInfo.pStages = shaderStages;
pipelineInfo.pVertexInputState = &vertexInputInfo;
VkPipelineInputAssemblyStateCreateInfo ia;
memset(&ia, 0, sizeof(ia));
ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
ia.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
ia.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
pipelineInfo.pInputAssemblyState = &ia;
// The viewport and scissor will be set dynamically via vkCmdSetViewport/Scissor.
// This way the pipeline does not need to be touched when resizing the window.
VkPipelineViewportStateCreateInfo vp;
memset(&vp, 0, sizeof(vp));
vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
vp.viewportCount = 1;
vp.scissorCount = 1;
vp.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
vp.viewportCount = 1;
vp.scissorCount = 1;
pipelineInfo.pViewportState = &vp;
VkPipelineRasterizationStateCreateInfo rs;
memset(&rs, 0, sizeof(rs));
rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rs.polygonMode = VK_POLYGON_MODE_FILL;
rs.cullMode = VK_CULL_MODE_BACK_BIT;
rs.frontFace = VK_FRONT_FACE_CLOCKWISE;
rs.lineWidth = 1.0f;
rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rs.polygonMode = VK_POLYGON_MODE_FILL;
rs.cullMode = VK_CULL_MODE_BACK_BIT;
rs.frontFace = VK_FRONT_FACE_CLOCKWISE;
rs.lineWidth = 1.0f;
pipelineInfo.pRasterizationState = &rs;
VkPipelineMultisampleStateCreateInfo ms;
memset(&ms, 0, sizeof(ms));
ms.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
ms.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
pipelineInfo.pMultisampleState = &ms;
VkPipelineDepthStencilStateCreateInfo ds;
memset(&ds, 0, sizeof(ds));
ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
ds.depthTestEnable = VK_TRUE;
ds.depthWriteEnable = VK_TRUE;
ds.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
ds.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
ds.depthTestEnable = VK_TRUE;
ds.depthWriteEnable = VK_TRUE;
ds.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.pDepthStencilState = &ds;
VkPipelineColorBlendStateCreateInfo cb;
@@ -768,33 +768,33 @@ void main()
// assume pre-multiplied alpha, blend, write out all of rgba
VkPipelineColorBlendAttachmentState att;
memset(&att, 0, sizeof(att));
att.colorWriteMask = 0xF;
att.blendEnable = VK_TRUE;
att.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
att.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
att.colorBlendOp = VK_BLEND_OP_ADD;
att.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
att.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
att.alphaBlendOp = VK_BLEND_OP_ADD;
cb.attachmentCount = 1;
cb.pAttachments = &att;
att.colorWriteMask = 0xF;
att.blendEnable = VK_TRUE;
att.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
att.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
att.colorBlendOp = VK_BLEND_OP_ADD;
att.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
att.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
att.alphaBlendOp = VK_BLEND_OP_ADD;
cb.attachmentCount = 1;
cb.pAttachments = &att;
pipelineInfo.pColorBlendState = &cb;
VkDynamicState dynEnable[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
VkDynamicState dynEnable[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
VkPipelineDynamicStateCreateInfo dyn;
memset(&dyn, 0, sizeof(dyn));
dyn.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dyn.dynamicStateCount = sizeof(dynEnable) / sizeof(VkDynamicState);
dyn.pDynamicStates = dynEnable;
dyn.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dyn.dynamicStateCount = sizeof(dynEnable) / sizeof(VkDynamicState);
dyn.pDynamicStates = dynEnable;
pipelineInfo.pDynamicState = &dyn;
pipelineInfo.layout = m_pipelineLayout;
pipelineInfo.layout = m_pipelineLayout;
pipelineInfo.renderPass = m_window->defaultRenderPass();
err = m_devFuncs->vkCreateGraphicsPipelines(dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline);
if (err != VK_SUCCESS) {
qWarning("Failed to create graphics pipeline: %d", err);
return emit qobject_cast<VulkanWindowRenderer*>(m_window)->errorInitializing();
return emit qobject_cast<VulkanWindowRenderer *>(m_window)->errorInitializing();
}
if (vertShaderModule)
@@ -807,7 +807,8 @@ void main()
pclog("Vulkan driver version: %d.%d.%d\n", VK_VERSION_MAJOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_MINOR(m_window->physicalDeviceProperties()->driverVersion), VK_VERSION_PATCH(m_window->physicalDeviceProperties()->driverVersion));
}
void VulkanRenderer2::initSwapChainResources()
void
VulkanRenderer2::initSwapChainResources()
{
qDebug("initSwapChainResources");
@@ -815,12 +816,14 @@ void VulkanRenderer2::initSwapChainResources()
m_proj = m_window->clipCorrectionMatrix(); // adjust for Vulkan-OpenGL clip space differences
}
void VulkanRenderer2::releaseSwapChainResources()
void
VulkanRenderer2::releaseSwapChainResources()
{
qDebug("releaseSwapChainResources");
}
void VulkanRenderer2::releaseResources()
void
VulkanRenderer2::releaseResources()
{
qDebug("releaseResources");
@@ -897,85 +900,88 @@ void VulkanRenderer2::releaseResources()
}
}
void VulkanRenderer2::startNextFrame()
void
VulkanRenderer2::startNextFrame()
{
VkDevice dev = m_window->device();
VkCommandBuffer cb = m_window->currentCommandBuffer();
const QSize sz = m_window->swapChainImageSize();
VkDevice dev = m_window->device();
VkCommandBuffer cb = m_window->currentCommandBuffer();
const QSize sz = m_window->swapChainImageSize();
updateSamplers();
// Add the necessary barriers and do the host-linear -> device-optimal copy, if not yet done.
ensureTexture();
VkClearColorValue clearColor = {{ 0, 0, 0, 1 }};
VkClearColorValue clearColor = {
{0, 0, 0, 1}
};
VkClearDepthStencilValue clearDS = { 1, 0 };
VkClearValue clearValues[2];
VkClearValue clearValues[2];
memset(clearValues, 0, sizeof(clearValues));
clearValues[0].color = clearColor;
clearValues[0].color = clearColor;
clearValues[1].depthStencil = clearDS;
VkRenderPassBeginInfo rpBeginInfo;
memset(&rpBeginInfo, 0, sizeof(rpBeginInfo));
rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpBeginInfo.renderPass = m_window->defaultRenderPass();
rpBeginInfo.framebuffer = m_window->currentFramebuffer();
rpBeginInfo.renderArea.extent.width = sz.width();
rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpBeginInfo.renderPass = m_window->defaultRenderPass();
rpBeginInfo.framebuffer = m_window->currentFramebuffer();
rpBeginInfo.renderArea.extent.width = sz.width();
rpBeginInfo.renderArea.extent.height = sz.height();
rpBeginInfo.clearValueCount = 2;
rpBeginInfo.pClearValues = clearValues;
VkCommandBuffer cmdBuf = m_window->currentCommandBuffer();
rpBeginInfo.clearValueCount = 2;
rpBeginInfo.pClearValues = clearValues;
VkCommandBuffer cmdBuf = m_window->currentCommandBuffer();
m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
quint8 *p;
quint8 *p;
VkResult err = m_devFuncs->vkMapMemory(dev, m_bufMem, m_uniformBufInfo[m_window->currentFrame()].offset,
UNIFORM_DATA_SIZE, 0, reinterpret_cast<void **>(&p));
UNIFORM_DATA_SIZE, 0, reinterpret_cast<void **>(&p));
if (err != VK_SUCCESS)
qFatal("Failed to map memory: %d", err);
QMatrix4x4 m = m_proj;
//m.rotate(m_rotation, 0, 0, 1);
// m.rotate(m_rotation, 0, 0, 1);
memcpy(p, m.constData(), 16 * sizeof(float));
m_devFuncs->vkUnmapMemory(dev, m_bufMem);
p = nullptr;
// Second pass for texture coordinates.
err = m_devFuncs->vkMapMemory(dev, m_bufMem, 0,
sizeof(vertexData), 0, reinterpret_cast<void **>(&p));
sizeof(vertexData), 0, reinterpret_cast<void **>(&p));
if (err != VK_SUCCESS)
qFatal("Failed to map memory: %d", err);
float* floatData = (float*)p;
auto source = qobject_cast<VulkanWindowRenderer*>(m_window)->source;
auto destination = qobject_cast<VulkanWindowRenderer*>(m_window)->destination;
floatData[3] = (float)source.x() / 2048.f;
floatData[9] = (float)(source.y()) / 2048.f;
floatData[8] = (float)source.x() / 2048.f;
floatData[4] = (float)(source.y() + source.height()) / 2048.f;
floatData[13] = (float)(source.x() + source.width()) / 2048.f;
floatData[19] = (float)(source.y()) / 2048.f;
floatData[18] = (float)(source.x() + source.width()) / 2048.f;
floatData[14] = (float)(source.y() + source.height()) / 2048.f;
float *floatData = (float *) p;
auto source = qobject_cast<VulkanWindowRenderer *>(m_window)->source;
auto destination = qobject_cast<VulkanWindowRenderer *>(m_window)->destination;
floatData[3] = (float) source.x() / 2048.f;
floatData[9] = (float) (source.y()) / 2048.f;
floatData[8] = (float) source.x() / 2048.f;
floatData[4] = (float) (source.y() + source.height()) / 2048.f;
floatData[13] = (float) (source.x() + source.width()) / 2048.f;
floatData[19] = (float) (source.y()) / 2048.f;
floatData[18] = (float) (source.x() + source.width()) / 2048.f;
floatData[14] = (float) (source.y() + source.height()) / 2048.f;
m_devFuncs->vkUnmapMemory(dev, m_bufMem);
m_devFuncs->vkCmdBindPipeline(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline);
m_devFuncs->vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1,
&m_descSet[m_window->currentFrame()], 0, nullptr);
&m_descSet[m_window->currentFrame()], 0, nullptr);
VkDeviceSize vbOffset = 0;
m_devFuncs->vkCmdBindVertexBuffers(cb, 0, 1, &m_buf, &vbOffset);
VkViewport viewport;
viewport.x = destination.x() * m_window->devicePixelRatio();
viewport.y = destination.y() * m_window->devicePixelRatio();
viewport.width = destination.width() * m_window->devicePixelRatio();
viewport.height = destination.height() * m_window->devicePixelRatio();
viewport.x = destination.x() * m_window->devicePixelRatio();
viewport.y = destination.y() * m_window->devicePixelRatio();
viewport.width = destination.width() * m_window->devicePixelRatio();
viewport.height = destination.height() * m_window->devicePixelRatio();
viewport.minDepth = 0;
viewport.maxDepth = 1;
m_devFuncs->vkCmdSetViewport(cb, 0, 1, &viewport);
VkRect2D scissor;
scissor.offset.x = viewport.x;
scissor.offset.y = viewport.y;
scissor.extent.width = viewport.width;
scissor.offset.x = viewport.x;
scissor.offset.y = viewport.y;
scissor.extent.width = viewport.width;
scissor.extent.height = viewport.height;
m_devFuncs->vkCmdSetScissor(cb, 0, 1, &scissor);
@@ -984,20 +990,20 @@ void VulkanRenderer2::startNextFrame()
m_devFuncs->vkCmdEndRenderPass(cmdBuf);
if (m_texStagingTransferLayout) {
VkImageMemoryBarrier barrier{};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
VkImageMemoryBarrier barrier {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.levelCount = barrier.subresourceRange.layerCount = 1;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
barrier.image = m_texImage;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
barrier.image = m_texImage;
m_devFuncs->vkCmdPipelineBarrier(cb,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr,
1, &barrier);
m_texStagingPending = true;
}