vulkan: simplify function calls

This commit is contained in:
scribam 2022-10-06 18:02:01 +02:00 committed by flyinghead
parent d22fa54f7b
commit 8426bcad27
20 changed files with 289 additions and 360 deletions

View File

@ -57,14 +57,14 @@ public:
void EndFrame() void EndFrame()
{ {
std::vector<vk::CommandBuffer> commandBuffers = vk::uniqueToRaw(inFlightBuffers[index]); std::vector<vk::CommandBuffer> commandBuffers = vk::uniqueToRaw(inFlightBuffers[index]);
VulkanContext::Instance()->SubmitCommandBuffers((u32)commandBuffers.size(), commandBuffers.data(), *fences[index]); VulkanContext::Instance()->SubmitCommandBuffers(commandBuffers, *fences[index]);
} }
void BeginFrame() void BeginFrame()
{ {
index = (index + 1) % chainSize; index = (index + 1) % chainSize;
VulkanContext::Instance()->GetDevice().waitForFences(1, &fences[index].get(), true, UINT64_MAX); VulkanContext::Instance()->GetDevice().waitForFences(fences[index].get(), true, UINT64_MAX);
VulkanContext::Instance()->GetDevice().resetFences(1, &fences[index].get()); VulkanContext::Instance()->GetDevice().resetFences(fences[index].get());
std::vector<vk::UniqueCommandBuffer>& inFlight = inFlightBuffers[index]; std::vector<vk::UniqueCommandBuffer>& inFlight = inFlightBuffers[index];
std::vector<vk::UniqueCommandBuffer>& freeBuf = freeBuffers[index]; std::vector<vk::UniqueCommandBuffer>& freeBuf = freeBuffers[index];
std::move(inFlight.begin(), inFlight.end(), std::back_inserter(freeBuf)); std::move(inFlight.begin(), inFlight.end(), std::back_inserter(freeBuf));

View File

@ -213,5 +213,5 @@ vk::UniqueShaderModule ShaderCompiler::Compile(vk::ShaderStageFlagBits shaderSta
verify(ok); verify(ok);
return VulkanContext::Instance()->GetDevice().createShaderModuleUnique return VulkanContext::Instance()->GetDevice().createShaderModuleUnique
(vk::ShaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), shaderSPV.size() * sizeof(unsigned int), shaderSPV.data())); (vk::ShaderModuleCreateInfo(vk::ShaderModuleCreateFlags(), shaderSPV));
} }

View File

@ -45,7 +45,7 @@ public:
{ {
std::vector<vk::DescriptorSetLayout> layouts(allocChunk, layout); std::vector<vk::DescriptorSetLayout> layouts(allocChunk, layout);
descSets = VulkanContext::Instance()->GetDevice().allocateDescriptorSetsUnique( descSets = VulkanContext::Instance()->GetDevice().allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo(VulkanContext::Instance()->GetDescriptorPool(), (u32)layouts.size(), &layouts[0])); vk::DescriptorSetAllocateInfo(VulkanContext::Instance()->GetDescriptorPool(), layouts));
} }
descSetsInFlight[index].emplace_back(std::move(descSets.back())); descSetsInFlight[index].emplace_back(std::move(descSets.back()));
descSets.pop_back(); descSets.pop_back();
@ -99,7 +99,7 @@ public:
{ {
std::vector<vk::DescriptorSetLayout> layouts(allocChunk, layout); std::vector<vk::DescriptorSetLayout> layouts(allocChunk, layout);
descSets = VulkanContext::Instance()->GetDevice().allocateDescriptorSetsUnique( descSets = VulkanContext::Instance()->GetDevice().allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo(VulkanContext::Instance()->GetDescriptorPool(), (u32)layouts.size(), &layouts[0])); vk::DescriptorSetAllocateInfo(VulkanContext::Instance()->GetDescriptorPool(), layouts));
} }
descSetsInFlight[index].emplace_back(std::move(descSets.back())); descSetsInFlight[index].emplace_back(std::move(descSets.back()));
descSets.pop_back(); descSets.pop_back();

View File

@ -210,7 +210,7 @@ void Drawer::DrawModVols(const vk::CommandBuffer& cmdBuffer, int first, int coun
return; return;
vk::Buffer buffer = GetMainBuffer(0)->buffer.get(); vk::Buffer buffer = GetMainBuffer(0)->buffer.get();
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offsets.modVolOffset); cmdBuffer.bindVertexBuffers(0, buffer, offsets.modVolOffset);
SetScissor(cmdBuffer, baseScissor); SetScissor(cmdBuffer, baseScissor);
ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first]; ModifierVolumeParam* params = &pvrrc.global_param_mvo.head()[first];
@ -249,8 +249,7 @@ void Drawer::DrawModVols(const vk::CommandBuffer& cmdBuffer, int first, int coun
mod_base = -1; mod_base = -1;
} }
} }
const vk::DeviceSize offset = 0; cmdBuffer.bindVertexBuffers(0, buffer, {0});
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offset);
std::array<float, 5> pushConstants = { 1 - FPU_SHAD_SCALE.scale_factor / 256.f, 0, 0, 0, 0 }; std::array<float, 5> pushConstants = { 1 - FPU_SHAD_SCALE.scale_factor / 256.f, 0, 0, 0, 0 };
cmdBuffer.pushConstants<float>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants); cmdBuffer.pushConstants<float>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
@ -327,9 +326,8 @@ bool Drawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
descriptorSets.bindPerFrameDescriptorSets(cmdBuffer); descriptorSets.bindPerFrameDescriptorSets(cmdBuffer);
// Bind vertex and index buffers // Bind vertex and index buffers
const vk::DeviceSize zeroOffset[] = { 0 };
const vk::Buffer buffer = GetMainBuffer(0)->buffer.get(); const vk::Buffer buffer = GetMainBuffer(0)->buffer.get();
cmdBuffer.bindVertexBuffers(0, 1, &buffer, zeroOffset); cmdBuffer.bindVertexBuffers(0, buffer, {0});
cmdBuffer.bindIndexBuffer(buffer, offsets.indexOffset, vk::IndexType::eUint32); cmdBuffer.bindIndexBuffer(buffer, offsets.indexOffset, vk::IndexType::eUint32);
// Make sure to push constants even if not used // Make sure to push constants even if not used
@ -458,17 +456,17 @@ vk::CommandBuffer TextureDrawer::BeginRenderPass()
setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal); setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal);
vk::ImageView imageViews[] = { std::array<vk::ImageView, 2> imageViews = {
colorImageView, colorImageView,
depthAttachment->GetImageView(), depthAttachment->GetImageView(),
}; };
framebuffers.resize(GetContext()->GetSwapChainSize()); framebuffers.resize(GetContext()->GetSwapChainSize());
framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(),
rttPipelineManager->GetRenderPass(), ARRAY_SIZE(imageViews), imageViews, widthPow2, heightPow2, 1)); rttPipelineManager->GetRenderPass(), imageViews, widthPow2, heightPow2, 1));
const vk::ClearValue clear_colors[] = { vk::ClearColorValue(std::array<float, 4> { 0.f, 0.f, 0.f, 1.f }), vk::ClearDepthStencilValue { 0.f, 0 } }; const std::array<vk::ClearValue, 2> clear_colors = { vk::ClearColorValue(std::array<float, 4> { 0.f, 0.f, 0.f, 1.f }), vk::ClearDepthStencilValue { 0.f, 0 } };
commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(rttPipelineManager->GetRenderPass(), *framebuffers[GetCurrentImage()], commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(rttPipelineManager->GetRenderPass(), *framebuffers[GetCurrentImage()],
vk::Rect2D( { 0, 0 }, { width, height }), 2, clear_colors), vk::SubpassContents::eInline); vk::Rect2D( { 0, 0 }, { width, height }), clear_colors), vk::SubpassContents::eInline);
commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)upscaledWidth, (float)upscaledHeight, 1.0f, 0.0f)); commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)upscaledWidth, (float)upscaledHeight, 1.0f, 0.0f));
u32 minX = pvrrc.fb_X_CLIP.min; u32 minX = pvrrc.fb_X_CLIP.min;
u32 minY = pvrrc.fb_Y_CLIP.min; u32 minY = pvrrc.fb_Y_CLIP.min;
@ -490,7 +488,7 @@ void TextureDrawer::EndRenderPass()
if (config::RenderToTextureBuffer) if (config::RenderToTextureBuffer)
{ {
vk::BufferImageCopy copyRegion(0, clippedWidth, clippedHeight, vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1), vk::Offset3D(0, 0, 0), vk::BufferImageCopy copyRegion(0, clippedWidth, clippedHeight, vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1), vk::Offset3D(0, 0, 0),
vk::Extent3D(vk::Extent2D(clippedWidth, clippedHeight), 1)); vk::Extent3D(clippedWidth, clippedHeight, 1));
currentCommandBuffer.copyImageToBuffer(colorAttachment->GetImage(), vk::ImageLayout::eTransferSrcOptimal, currentCommandBuffer.copyImageToBuffer(colorAttachment->GetImage(), vk::ImageLayout::eTransferSrcOptimal,
*colorAttachment->GetBufferData()->buffer, copyRegion); *colorAttachment->GetBufferData()->buffer, copyRegion);
@ -513,7 +511,7 @@ void TextureDrawer::EndRenderPass()
if (config::RenderToTextureBuffer) if (config::RenderToTextureBuffer)
{ {
vk::Fence fence = commandPool->GetCurrentFence(); vk::Fence fence = commandPool->GetCurrentFence();
GetContext()->GetDevice().waitForFences(1, &fence, true, UINT64_MAX); GetContext()->GetDevice().waitForFences(fence, true, UINT64_MAX);
u16 *dst = (u16 *)&vram[textureAddr]; u16 *dst = (u16 *)&vram[textureAddr];
@ -555,7 +553,7 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan
if (!renderPassLoad) if (!renderPassLoad)
{ {
vk::AttachmentDescription attachmentDescriptions[] = { std::array<vk::AttachmentDescription, 2> attachmentDescriptions = {
// Color attachment // Color attachment
vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetColorFormat(), vk::SampleCountFlagBits::e1, vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetColorFormat(), vk::SampleCountFlagBits::e1,
vk::AttachmentLoadOp::eLoad, vk::AttachmentStoreOp::eStore, vk::AttachmentLoadOp::eLoad, vk::AttachmentStoreOp::eStore,
@ -570,27 +568,25 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan
vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal); vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal);
vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal); vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal);
vk::SubpassDescription subpasses[] = { vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
0, nullptr,
1, &colorReference,
nullptr, nullptr,
&depthReference), colorReference,
}; nullptr,
&depthReference);
std::vector<vk::SubpassDependency> dependencies; vk::SubpassDependency dependency(0, VK_SUBPASS_EXTERNAL, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eFragmentShader,
dependencies.emplace_back(0, VK_SUBPASS_EXTERNAL, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eFragmentShader,
vk::AccessFlagBits::eColorAttachmentWrite, vk::AccessFlagBits::eShaderRead,vk::DependencyFlagBits::eByRegion); vk::AccessFlagBits::eColorAttachmentWrite, vk::AccessFlagBits::eShaderRead,vk::DependencyFlagBits::eByRegion);
renderPassLoad = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), renderPassLoad = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(),
ARRAY_SIZE(attachmentDescriptions), attachmentDescriptions, attachmentDescriptions,
ARRAY_SIZE(subpasses), subpasses, subpass,
dependencies.size(), dependencies.data())); dependency));
attachmentDescriptions[0].loadOp = vk::AttachmentLoadOp::eClear; attachmentDescriptions[0].loadOp = vk::AttachmentLoadOp::eClear;
renderPassClear = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), renderPassClear = GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(),
ARRAY_SIZE(attachmentDescriptions), attachmentDescriptions, attachmentDescriptions,
ARRAY_SIZE(subpasses), subpasses, subpass,
dependencies.size(), dependencies.data())); dependency));
} }
size_t size = GetSwapChainSize(); size_t size = GetSwapChainSize();
if (colorAttachments.size() > size) if (colorAttachments.size() > size)
@ -602,7 +598,7 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan
} }
else else
{ {
vk::ImageView attachments[] = { std::array<vk::ImageView, 2> attachments = {
nullptr, nullptr,
depthAttachment->GetImageView(), depthAttachment->GetImageView(),
}; };
@ -614,7 +610,7 @@ void ScreenDrawer::Init(SamplerManager *samplerManager, ShaderManager *shaderMan
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled); vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled);
attachments[0] = colorAttachments.back()->GetImageView(); attachments[0] = colorAttachments.back()->GetImageView();
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), *renderPassLoad, vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), *renderPassLoad,
ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1); attachments, viewport.width, viewport.height, 1);
framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo)); framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo));
transitionNeeded.push_back(true); transitionNeeded.push_back(true);
clearNeeded.push_back(true); clearNeeded.push_back(true);
@ -642,9 +638,9 @@ vk::CommandBuffer ScreenDrawer::BeginRenderPass()
vk::RenderPass renderPass = clearNeeded[GetCurrentImage()] ? *renderPassClear : *renderPassLoad; vk::RenderPass renderPass = clearNeeded[GetCurrentImage()] ? *renderPassClear : *renderPassLoad;
clearNeeded[GetCurrentImage()] = false; clearNeeded[GetCurrentImage()] = false;
const vk::ClearValue clear_colors[] = { vk::ClearColorValue(std::array<float, 4> { 0.f, 0.f, 0.f, 1.f }), vk::ClearDepthStencilValue { 0.f, 0 } }; const std::array<vk::ClearValue, 2> clear_colors = { vk::ClearColorValue(std::array<float, 4> { 0.f, 0.f, 0.f, 1.f }), vk::ClearDepthStencilValue { 0.f, 0 } };
commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(renderPass, *framebuffers[GetCurrentImage()], commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(renderPass, *framebuffers[GetCurrentImage()],
vk::Rect2D( { 0, 0 }, viewport), 2, clear_colors), vk::SubpassContents::eInline); vk::Rect2D( { 0, 0 }, viewport), clear_colors), vk::SubpassContents::eInline);
commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)viewport.width, (float)viewport.height, 1.0f, 0.0f)); commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)viewport.width, (float)viewport.height, 1.0f, 0.0f));
matrices.CalcMatrices(&pvrrc, viewport.width, viewport.height); matrices.CalcMatrices(&pvrrc, viewport.width, viewport.height);

View File

@ -62,13 +62,13 @@ public:
{ {
static vk::DescriptorBufferInfo pixelBufferInfo({}, 0, VK_WHOLE_SIZE); static vk::DescriptorBufferInfo pixelBufferInfo({}, 0, VK_WHOLE_SIZE);
pixelBufferInfo.buffer = *pixelBuffer->buffer; pixelBufferInfo.buffer = *pixelBuffer->buffer;
writeDescSets.emplace_back(descSet, 7, 0, 1, vk::DescriptorType::eStorageBuffer, nullptr, &pixelBufferInfo, nullptr); writeDescSets.emplace_back(descSet, 7, 0, vk::DescriptorType::eStorageBuffer, nullptr, pixelBufferInfo);
static vk::DescriptorBufferInfo pixelCounterBufferInfo({}, 0, 4); static vk::DescriptorBufferInfo pixelCounterBufferInfo({}, 0, 4);
pixelCounterBufferInfo.buffer = *pixelCounter->buffer; pixelCounterBufferInfo.buffer = *pixelCounter->buffer;
writeDescSets.emplace_back(descSet, 8, 0, 1, vk::DescriptorType::eStorageBuffer, nullptr, &pixelCounterBufferInfo, nullptr); writeDescSets.emplace_back(descSet, 8, 0, vk::DescriptorType::eStorageBuffer, nullptr, pixelCounterBufferInfo);
static vk::DescriptorBufferInfo abufferPointerInfo({}, 0, VK_WHOLE_SIZE); static vk::DescriptorBufferInfo abufferPointerInfo({}, 0, VK_WHOLE_SIZE);
abufferPointerInfo.buffer = *abufferPointer->buffer; abufferPointerInfo.buffer = *abufferPointer->buffer;
writeDescSets.emplace_back(descSet, 9, 0, 1, vk::DescriptorType::eStorageBuffer, nullptr, &abufferPointerInfo, nullptr); writeDescSets.emplace_back(descSet, 9, 0, vk::DescriptorType::eStorageBuffer, nullptr, abufferPointerInfo);
} }
void OnNewFrame(vk::CommandBuffer commandBuffer) void OnNewFrame(vk::CommandBuffer commandBuffer)
@ -85,7 +85,7 @@ public:
void ResetPixelCounter(vk::CommandBuffer commandBuffer) void ResetPixelCounter(vk::CommandBuffer commandBuffer)
{ {
vk::BufferCopy copy(0, 0, sizeof(int)); vk::BufferCopy copy(0, 0, sizeof(int));
commandBuffer.copyBuffer(*pixelCounterReset->buffer, *pixelCounter->buffer, 1, &copy); commandBuffer.copyBuffer(*pixelCounterReset->buffer, *pixelCounter->buffer, copy);
} }
void Term() void Term()

View File

@ -134,7 +134,7 @@ void OITDrawer::DrawModifierVolumes(const vk::CommandBuffer& cmdBuffer, int firs
return; return;
vk::Buffer buffer = GetMainBuffer(0)->buffer.get(); vk::Buffer buffer = GetMainBuffer(0)->buffer.get();
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offsets.modVolOffset); cmdBuffer.bindVertexBuffers(0, buffer, offsets.modVolOffset);
SetScissor(cmdBuffer, baseScissor); SetScissor(cmdBuffer, baseScissor);
const ModifierVolumeParam *params = &modVolParams[first]; const ModifierVolumeParam *params = &modVolParams[first];
@ -203,8 +203,7 @@ void OITDrawer::DrawModifierVolumes(const vk::CommandBuffer& cmdBuffer, int firs
} }
} }
} }
const vk::DeviceSize offset = 0; cmdBuffer.bindVertexBuffers(0, buffer, {0});
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offset);
} }
void OITDrawer::UploadMainBuffer(const OITDescriptorSets::VertexShaderUniforms& vertexUniforms, void OITDrawer::UploadMainBuffer(const OITDescriptorSets::VertexShaderUniforms& vertexUniforms,
@ -294,8 +293,7 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
descriptorSets.updateColorInputDescSet(1, colorAttachments[1]->GetImageView()); descriptorSets.updateColorInputDescSet(1, colorAttachments[1]->GetImageView());
// Bind vertex and index buffers // Bind vertex and index buffers
const vk::DeviceSize zeroOffset[] = { 0 }; cmdBuffer.bindVertexBuffers(0, mainBuffer, {0});
cmdBuffer.bindVertexBuffers(0, 1, &mainBuffer, zeroOffset);
cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32); cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32);
// Make sure to push constants even if not used // Make sure to push constants even if not used
@ -338,7 +336,7 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
targetFramebuffer = GetFinalFramebuffer(); targetFramebuffer = GetFinalFramebuffer();
cmdBuffer.beginRenderPass( cmdBuffer.beginRenderPass(
vk::RenderPassBeginInfo(pipelineManager->GetRenderPass(initialPass, finalPass), vk::RenderPassBeginInfo(pipelineManager->GetRenderPass(initialPass, finalPass),
targetFramebuffer, viewport, clear_colors.size(), clear_colors.data()), targetFramebuffer, viewport, clear_colors),
vk::SubpassContents::eInline); vk::SubpassContents::eInline);
if (!pvrrc.isRTT && (FB_R_CTRL.fb_enable == 0 || VO_CONTROL.blank_video == 1)) if (!pvrrc.isRTT && (FB_R_CTRL.fb_enable == 0 || VO_CONTROL.blank_video == 1))
@ -394,7 +392,7 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
vk::MemoryBarrier memoryBarrier(vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eShaderRead); vk::MemoryBarrier memoryBarrier(vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eShaderRead);
cmdBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eFragmentShader, cmdBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eFragmentShader,
vk::DependencyFlagBits::eByRegion, 1, &memoryBarrier, 0, nullptr, 0, nullptr); vk::DependencyFlagBits::eByRegion, memoryBarrier, nullptr, nullptr);
firstFrameAfterInit = false; firstFrameAfterInit = false;
} }
// Tr modifier volumes // Tr modifier volumes
@ -414,7 +412,7 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
if (!finalPass) if (!finalPass)
{ {
// Re-bind vertex and index buffers // Re-bind vertex and index buffers
cmdBuffer.bindVertexBuffers(0, 1, &mainBuffer, zeroOffset); cmdBuffer.bindVertexBuffers(0, mainBuffer, {0});
cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32); cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32);
// Tr depth-only pass // Tr depth-only pass
@ -458,14 +456,14 @@ void OITDrawer::MakeBuffers(int width, int height)
} }
needDepthTransition = true; needDepthTransition = true;
vk::ImageView attachments[] = { std::array<vk::ImageView, 4> attachments = {
colorAttachments[1]->GetImageView(), colorAttachments[1]->GetImageView(),
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachments[0]->GetImageView(), depthAttachments[0]->GetImageView(),
depthAttachments[1]->GetImageView(), depthAttachments[1]->GetImageView(),
}; };
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true), vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true),
ARRAY_SIZE(attachments), attachments, maxWidth, maxHeight, 1); attachments, maxWidth, maxHeight, 1);
tempFramebuffers[0] = GetContext()->GetDevice().createFramebufferUnique(createInfo); tempFramebuffers[0] = GetContext()->GetDevice().createFramebufferUnique(createInfo);
attachments[0] = attachments[1]; attachments[0] = attachments[1];
attachments[1] = colorAttachments[1]->GetImageView(); attachments[1] = colorAttachments[1]->GetImageView();
@ -489,14 +487,14 @@ void OITScreenDrawer::MakeFramebuffers(const vk::Extent2D& viewport)
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()))); new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())));
finalColorAttachments.back()->Init(viewport.width, viewport.height, GetContext()->GetColorFormat(), finalColorAttachments.back()->Init(viewport.width, viewport.height, GetContext()->GetColorFormat(),
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled); vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled);
vk::ImageView attachments[] = { std::array<vk::ImageView, 4> attachments = {
finalColorAttachments.back()->GetImageView(), finalColorAttachments.back()->GetImageView(),
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachments[0]->GetImageView(), depthAttachments[0]->GetImageView(),
depthAttachments[1]->GetImageView(), depthAttachments[1]->GetImageView(),
}; };
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true), vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true),
ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1); attachments, viewport.width, viewport.height, 1);
framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo)); framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo));
transitionNeeded.push_back(true); transitionNeeded.push_back(true);
clearNeeded.push_back(true); clearNeeded.push_back(true);
@ -582,7 +580,7 @@ vk::CommandBuffer OITTextureDrawer::NewFrame()
setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal); setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal);
vk::ImageView imageViews[] = { std::array<vk::ImageView, 4> imageViews = {
colorImageView, colorImageView,
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachments[0]->GetImageView(), depthAttachments[0]->GetImageView(),
@ -590,7 +588,7 @@ vk::CommandBuffer OITTextureDrawer::NewFrame()
}; };
framebuffers.resize(GetSwapChainSize()); framebuffers.resize(GetSwapChainSize());
framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(),
rttPipelineManager->GetRenderPass(true, true), ARRAY_SIZE(imageViews), imageViews, widthPow2, heightPow2, 1)); rttPipelineManager->GetRenderPass(true, true), imageViews, widthPow2, heightPow2, 1));
commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)upscaledWidth, (float)upscaledHeight, 1.0f, 0.0f)); commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)upscaledWidth, (float)upscaledHeight, 1.0f, 0.0f));
u32 minX = pvrrc.fb_X_CLIP.min; u32 minX = pvrrc.fb_X_CLIP.min;
@ -638,7 +636,7 @@ void OITTextureDrawer::EndFrame()
if (config::RenderToTextureBuffer) if (config::RenderToTextureBuffer)
{ {
vk::Fence fence = commandPool->GetCurrentFence(); vk::Fence fence = commandPool->GetCurrentFence();
GetContext()->GetDevice().waitForFences(1, &fence, true, UINT64_MAX); GetContext()->GetDevice().waitForFences(fence, true, UINT64_MAX);
u16 *dst = (u16 *)&vram[textureAddr]; u16 *dst = (u16 *)&vram[textureAddr];

View File

@ -131,8 +131,7 @@ void OITPipelineManager::CreatePipeline(u32 listType, bool autosort, const PolyP
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
@ -161,15 +160,14 @@ void OITPipelineManager::CreatePipeline(u32 listType, bool autosort, const PolyP
params.divPosZ = divPosZ; params.divPosZ = divPosZ;
vk::ShaderModule fragment_module = shaderManager->GetFragmentShader(params); vk::ShaderModule fragment_module = shaderManager->GetFragmentShader(params);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -237,26 +235,24 @@ void OITPipelineManager::CreateFinalPipeline()
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
vk::ShaderModule vertex_module = shaderManager->GetFinalVertexShader(); vk::ShaderModule vertex_module = shaderManager->GetFinalVertexShader();
vk::ShaderModule fragment_module = shaderManager->GetFinalShader(); vk::ShaderModule fragment_module = shaderManager->GetFinalShader();
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -312,26 +308,24 @@ void OITPipelineManager::CreateClearPipeline()
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
vk::ShaderModule vertex_module = shaderManager->GetFinalVertexShader(); vk::ShaderModule vertex_module = shaderManager->GetFinalVertexShader();
vk::ShaderModule fragment_module = shaderManager->GetClearShader(); vk::ShaderModule fragment_module = shaderManager->GetClearShader();
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -353,21 +347,13 @@ void OITPipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, boo
{ {
verify(mode != ModVolMode::Final); verify(mode != ModVolMode::Final);
static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = static const vk::VertexInputBindingDescription vertexBindingDescription(0, sizeof(float) * 3);
{ static const vk::VertexInputAttributeDescription vertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0); // pos
{ 0, sizeof(float) * 3 },
};
static const vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[] =
{
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0), // pos
};
// Vertex input state // Vertex input state
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vk::PipelineVertexInputStateCreateFlags(),
ARRAY_SIZE(vertexBindingDescriptions), vertexBindingDescription,
vertexBindingDescriptions, vertexInputAttributeDescription);
ARRAY_SIZE(vertexInputAttributeDescriptions),
vertexInputAttributeDescriptions);
// Input assembly state // Input assembly state
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(),
vk::PrimitiveTopology::eTriangleList); vk::PrimitiveTopology::eTriangleList);
@ -433,26 +419,24 @@ void OITPipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, boo
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(OITShaderManager::ModVolShaderParams{ naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation }); vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(OITShaderManager::ModVolShaderParams{ naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation });
vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation); vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -463,8 +447,7 @@ void OITPipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, boo
&pipelineColorBlendStateCreateInfo, // pColorBlendState &pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState &pipelineDynamicStateCreateInfo, // pDynamicState
*pipelineLayout, // layout *pipelineLayout, // layout
renderPasses->GetRenderPass(true, true), // renderPass renderPasses->GetRenderPass(true, true) // renderPass
0 // subpass
); );
modVolPipelines[hash(mode, cullMode, naomi2)] = modVolPipelines[hash(mode, cullMode, naomi2)] =
@ -476,21 +459,13 @@ void OITPipelineManager::CreateTrModVolPipeline(ModVolMode mode, int cullMode, b
{ {
verify(mode != ModVolMode::Final); verify(mode != ModVolMode::Final);
static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = static const vk::VertexInputBindingDescription vertexBindingDescription(0, sizeof(float) * 3);
{ static const vk::VertexInputAttributeDescription vertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0); // pos
{ 0, sizeof(float) * 3 },
};
static const vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[] =
{
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0), // pos
};
// Vertex input state // Vertex input state
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vk::PipelineVertexInputStateCreateFlags(),
ARRAY_SIZE(vertexBindingDescriptions), vertexBindingDescription,
vertexBindingDescriptions, vertexInputAttributeDescription);
ARRAY_SIZE(vertexInputAttributeDescriptions),
vertexInputAttributeDescriptions);
// Input assembly state // Input assembly state
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(),
vk::PrimitiveTopology::eTriangleList); vk::PrimitiveTopology::eTriangleList);
@ -528,27 +503,25 @@ void OITPipelineManager::CreateTrModVolPipeline(ModVolMode mode, int cullMode, b
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
bool divPosZ = !settings.platform.isNaomi2() && config::NativeDepthInterpolation; bool divPosZ = !settings.platform.isNaomi2() && config::NativeDepthInterpolation;
vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(OITShaderManager::ModVolShaderParams{ naomi2, divPosZ }); vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(OITShaderManager::ModVolShaderParams{ naomi2, divPosZ });
vk::ShaderModule fragment_module = shaderManager->GetTrModVolShader(OITShaderManager::TrModVolShaderParams{ mode, divPosZ }); vk::ShaderModule fragment_module = shaderManager->GetTrModVolShader(OITShaderManager::TrModVolShaderParams{ mode, divPosZ });
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState

View File

@ -102,8 +102,8 @@ public:
bufferInfos.emplace_back(buffer, fragmentUniformOffset, sizeof(FragmentShaderUniforms)); bufferInfos.emplace_back(buffer, fragmentUniformOffset, sizeof(FragmentShaderUniforms));
std::vector<vk::WriteDescriptorSet> writeDescriptorSets; std::vector<vk::WriteDescriptorSet> writeDescriptorSets;
writeDescriptorSets.emplace_back(perFrameDescSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfos[0], nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 0, 0, vk::DescriptorType::eUniformBuffer, nullptr, bufferInfos[0]);
writeDescriptorSets.emplace_back(perFrameDescSet, 1, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfos[1], nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 1, 0, vk::DescriptorType::eUniformBuffer, nullptr, bufferInfos[1]);
if (fogImageView) if (fogImageView)
{ {
TSP fogTsp = {}; TSP fogTsp = {};
@ -113,7 +113,7 @@ public:
vk::Sampler fogSampler = samplerManager->GetSampler(fogTsp); vk::Sampler fogSampler = samplerManager->GetSampler(fogTsp);
static vk::DescriptorImageInfo imageInfo; static vk::DescriptorImageInfo imageInfo;
imageInfo = { fogSampler, fogImageView, vk::ImageLayout::eShaderReadOnlyOptimal }; imageInfo = { fogSampler, fogImageView, vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perFrameDescSet, 2, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 2, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
} }
if (paletteImageView) if (paletteImageView)
{ {
@ -124,18 +124,18 @@ public:
vk::Sampler palSampler = samplerManager->GetSampler(palTsp); vk::Sampler palSampler = samplerManager->GetSampler(palTsp);
static vk::DescriptorImageInfo imageInfo; static vk::DescriptorImageInfo imageInfo;
imageInfo = { palSampler, paletteImageView, vk::ImageLayout::eShaderReadOnlyOptimal }; imageInfo = { palSampler, paletteImageView, vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perFrameDescSet, 6, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 6, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
} }
if (polyParamsSize > 0) if (polyParamsSize > 0)
{ {
static vk::DescriptorBufferInfo polyParamsBufferInfo; static vk::DescriptorBufferInfo polyParamsBufferInfo;
polyParamsBufferInfo = vk::DescriptorBufferInfo(buffer, polyParamsOffset, polyParamsSize); polyParamsBufferInfo = vk::DescriptorBufferInfo(buffer, polyParamsOffset, polyParamsSize);
writeDescriptorSets.emplace_back(perFrameDescSet, 3, 0, 1, vk::DescriptorType::eStorageBuffer, nullptr, &polyParamsBufferInfo, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 3, 0, vk::DescriptorType::eStorageBuffer, nullptr, polyParamsBufferInfo);
} }
vk::DescriptorImageInfo stencilImageInfo(vk::Sampler(), stencilImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal); vk::DescriptorImageInfo stencilImageInfo(vk::Sampler(), stencilImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
writeDescriptorSets.emplace_back(perFrameDescSet, 4, 0, 1, vk::DescriptorType::eInputAttachment, &stencilImageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 4, 0, vk::DescriptorType::eInputAttachment, stencilImageInfo);
vk::DescriptorImageInfo depthImageInfo(vk::Sampler(), depthImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal); vk::DescriptorImageInfo depthImageInfo(vk::Sampler(), depthImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
writeDescriptorSets.emplace_back(perFrameDescSet, 5, 0, 1, vk::DescriptorType::eInputAttachment, &depthImageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 5, 0, vk::DescriptorType::eInputAttachment, depthImageInfo);
oitBuffers->updateDescriptorSet(perFrameDescSet, writeDescriptorSets); oitBuffers->updateDescriptorSet(perFrameDescSet, writeDescriptorSets);
getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
@ -147,9 +147,9 @@ public:
colorInputDescSets[index] = colorInputAlloc.alloc(); colorInputDescSets[index] = colorInputAlloc.alloc();
vk::DescriptorImageInfo colorImageInfo(vk::Sampler(), colorImageView, vk::ImageLayout::eShaderReadOnlyOptimal); vk::DescriptorImageInfo colorImageInfo(vk::Sampler(), colorImageView, vk::ImageLayout::eShaderReadOnlyOptimal);
vk::WriteDescriptorSet writeDescriptorSet(colorInputDescSets[index], 0, 0, 1, vk::DescriptorType::eInputAttachment, &colorImageInfo, nullptr, nullptr); vk::WriteDescriptorSet writeDescriptorSet(colorInputDescSets[index], 0, 0, vk::DescriptorType::eInputAttachment, colorImageInfo);
getContext()->GetDevice().updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSet, nullptr);
} }
void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const PolyParam& poly, int polyNumber, vk::Buffer buffer, void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const PolyParam& poly, int polyNumber, vk::Buffer buffer,
@ -167,14 +167,14 @@ public:
{ {
imageInfo0 = vk::DescriptorImageInfo{ samplerManager->GetSampler(poly.tsp), ((Texture *)poly.texture)->GetReadOnlyImageView(), imageInfo0 = vk::DescriptorImageInfo{ samplerManager->GetSampler(poly.tsp), ((Texture *)poly.texture)->GetReadOnlyImageView(),
vk::ImageLayout::eShaderReadOnlyOptimal }; vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perPolyDescSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo0, nullptr, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 0, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo0);
} }
vk::DescriptorImageInfo imageInfo1; vk::DescriptorImageInfo imageInfo1;
if (poly.texture1 != nullptr) if (poly.texture1 != nullptr)
{ {
imageInfo1 = vk::DescriptorImageInfo{ samplerManager->GetSampler(poly.tsp1), ((Texture *)poly.texture1)->GetReadOnlyImageView(), imageInfo1 = vk::DescriptorImageInfo{ samplerManager->GetSampler(poly.tsp1), ((Texture *)poly.texture1)->GetReadOnlyImageView(),
vk::ImageLayout::eShaderReadOnlyOptimal }; vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perPolyDescSet, 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo1, nullptr, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo1);
} }
vk::DescriptorBufferInfo uniBufferInfo; vk::DescriptorBufferInfo uniBufferInfo;
@ -184,7 +184,7 @@ public:
const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment(); const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment();
size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment); size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment);
uniBufferInfo = vk::DescriptorBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) }; uniBufferInfo = vk::DescriptorBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) };
writeDescriptorSets.emplace_back(perPolyDescSet, 2, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniBufferInfo, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 2, 0, vk::DescriptorType::eUniformBuffer, nullptr, uniBufferInfo);
size = sizeof(N2LightModel) + align(sizeof(N2LightModel), uniformAlignment); size = sizeof(N2LightModel) + align(sizeof(N2LightModel), uniformAlignment);
// light at index 0 is no light // light at index 0 is no light
@ -192,7 +192,7 @@ public:
lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset + (poly.lightModel - pvrrc.lightModels.head() + 1) * size, sizeof(N2LightModel) }; lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset + (poly.lightModel - pvrrc.lightModels.head() + 1) * size, sizeof(N2LightModel) };
else else
lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset, sizeof(N2LightModel) }; lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset, sizeof(N2LightModel) };
writeDescriptorSets.emplace_back(perPolyDescSet, 3, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &lightBufferInfo, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 3, 0, vk::DescriptorType::eUniformBuffer, nullptr, lightBufferInfo);
} }
getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
@ -200,7 +200,7 @@ public:
} }
else else
perPolyDescSet = it->second; perPolyDescSet = it->second;
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, 1, &perPolyDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, perPolyDescSet, nullptr);
} }
void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const ModifierVolumeParam& mvParam, int polyNumber, vk::Buffer buffer, vk::DeviceSize uniformOffset) void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const ModifierVolumeParam& mvParam, int polyNumber, vk::Buffer buffer, vk::DeviceSize uniformOffset)
@ -216,24 +216,24 @@ public:
const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment(); const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment();
size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment); size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment);
vk::DescriptorBufferInfo uniBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) }; vk::DescriptorBufferInfo uniBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) };
vk::WriteDescriptorSet writeDescriptorSet(perPolyDescSet, 2, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniBufferInfo, nullptr); vk::WriteDescriptorSet writeDescriptorSet(perPolyDescSet, 2, 0, vk::DescriptorType::eUniformBuffer, nullptr, uniBufferInfo);
getContext()->GetDevice().updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSet, nullptr);
perPolyDescSets[&mvParam] = perPolyDescSet; perPolyDescSets[&mvParam] = perPolyDescSet;
} }
else else
perPolyDescSet = it->second; perPolyDescSet = it->second;
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, 1, &perPolyDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, perPolyDescSet, nullptr);
} }
void bindPerFrameDescriptorSets(vk::CommandBuffer cmdBuffer) void bindPerFrameDescriptorSets(vk::CommandBuffer cmdBuffer)
{ {
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, 1, &perFrameDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, perFrameDescSet, nullptr);
} }
void bindColorInputDescSet(vk::CommandBuffer cmdBuffer, int index) void bindColorInputDescSet(vk::CommandBuffer cmdBuffer, int index)
{ {
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 2, 1, &colorInputDescSets[index], 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 2, colorInputDescSets[index], nullptr);
} }
void nextFrame() void nextFrame()
@ -283,45 +283,43 @@ public:
{ {
vk::Device device = GetContext()->GetDevice(); vk::Device device = GetContext()->GetDevice();
// Descriptor set and pipeline layout // Descriptor set and pipeline layout
vk::DescriptorSetLayoutBinding perFrameBindings[] = { std::array<vk::DescriptorSetLayoutBinding, 10> perFrameBindings = {
{ 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // vertex uniforms vk::DescriptorSetLayoutBinding(0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // vertex uniforms
{ 1, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // fragment uniforms vk::DescriptorSetLayoutBinding(1, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eFragment), // fragment uniforms
{ 2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// fog texture vk::DescriptorSetLayoutBinding(2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment),// fog texture
{ 3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // Tr poly params vk::DescriptorSetLayoutBinding(3, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment), // Tr poly params
{ 4, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment }, // stencil input attachment vk::DescriptorSetLayoutBinding(4, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment), // stencil input attachment
{ 5, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment }, // depth input attachment vk::DescriptorSetLayoutBinding(5, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment), // depth input attachment
{ 6, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// palette texture vk::DescriptorSetLayoutBinding(6, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment),// palette texture
// OIT buffers // OIT buffers
{ 7, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // pixel buffer vk::DescriptorSetLayoutBinding(7, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment), // pixel buffer
{ 8, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // pixel counter vk::DescriptorSetLayoutBinding(8, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment), // pixel counter
{ 9, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // a-buffer pointers vk::DescriptorSetLayoutBinding(9, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eFragment), // a-buffer pointers
}; };
perFrameLayout = device.createDescriptorSetLayoutUnique( perFrameLayout = device.createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perFrameBindings), perFrameBindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), perFrameBindings));
vk::DescriptorSetLayoutBinding colorInputBindings[] = { vk::DescriptorSetLayoutBinding colorInputBinding(0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment); // color input attachment
{ 0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment }, // color input attachment
};
colorInputLayout = device.createDescriptorSetLayoutUnique( colorInputLayout = device.createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(colorInputBindings), colorInputBindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), colorInputBinding));
vk::DescriptorSetLayoutBinding perPolyBindings[] = { std::array<vk::DescriptorSetLayoutBinding, 4> perPolyBindings = {
{ 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment }, // texture 0 vk::DescriptorSetLayoutBinding(0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment), // texture 0
{ 1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment }, // texture 1 (for 2-volume mode) vk::DescriptorSetLayoutBinding(1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment), // texture 1 (for 2-volume mode)
{ 2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // Naomi2 uniforms vk::DescriptorSetLayoutBinding(2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // Naomi2 uniforms
{ 3, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // Naomi2 lights vk::DescriptorSetLayoutBinding(3, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // Naomi2 lights
}; };
perPolyLayout = device.createDescriptorSetLayoutUnique( perPolyLayout = device.createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perPolyBindings), perPolyBindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), perPolyBindings));
vk::PushConstantRange pushConstants[] = { std::array<vk::PushConstantRange, 2> pushConstants = {
vk::PushConstantRange(vk::ShaderStageFlagBits::eFragment, 0, sizeof(OITDescriptorSets::PushConstants)), vk::PushConstantRange(vk::ShaderStageFlagBits::eFragment, 0, sizeof(OITDescriptorSets::PushConstants)),
vk::PushConstantRange(vk::ShaderStageFlagBits::eVertex, sizeof(OITDescriptorSets::PushConstants), sizeof(OITDescriptorSets::VtxPushConstants)), vk::PushConstantRange(vk::ShaderStageFlagBits::eVertex, sizeof(OITDescriptorSets::PushConstants), sizeof(OITDescriptorSets::VtxPushConstants)),
}; };
vk::DescriptorSetLayout layouts[] = { *perFrameLayout, *perPolyLayout, *colorInputLayout }; std::array<vk::DescriptorSetLayout, 3> layouts = { *perFrameLayout, *perPolyLayout, *colorInputLayout };
pipelineLayout = device.createPipelineLayoutUnique( pipelineLayout = device.createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), ARRAY_SIZE(layouts), layouts, ARRAY_SIZE(pushConstants), pushConstants)); vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), layouts, pushConstants));
} }
pipelines.clear(); pipelines.clear();

View File

@ -22,7 +22,7 @@
vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last) vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
{ {
vk::AttachmentDescription attachmentDescriptions[] = { std::array<vk::AttachmentDescription, 4> attachmentDescriptions = {
// Swap chain image // Swap chain image
GetAttachment0Description(initial, last), GetAttachment0Description(initial, last),
// OP+PT color attachment // OP+PT color attachment
@ -52,23 +52,23 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
vk::AttachmentReference depthReference2(3, vk::ImageLayout::eDepthStencilAttachmentOptimal); vk::AttachmentReference depthReference2(3, vk::ImageLayout::eDepthStencilAttachmentOptimal);
vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal); vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal);
vk::SubpassDescription subpasses[] = { std::array<vk::SubpassDescription, 3> subpasses = {
// Depth and modvol pass FIXME subpass 0 shouldn't reference the color attachment // Depth and modvol pass FIXME subpass 0 shouldn't reference the color attachment
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
0, nullptr, nullptr,
1, &colorReference, colorReference,
nullptr, nullptr,
&depthReference), &depthReference),
// Color pass // Color pass
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
1, &depthReadOnlyRef, depthReadOnlyRef,
1, &colorReference, colorReference,
nullptr, nullptr,
&depthReference2), &depthReference2),
// Final pass // Final pass
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
1, &colorInput, colorInput,
1, &swapChainReference, swapChainReference,
nullptr, nullptr,
&depthReference2), // depth-only Tr pass when continuation &depthReference2), // depth-only Tr pass when continuation
}; };
@ -99,8 +99,8 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
vk::DependencyFlagBits::eByRegion); vk::DependencyFlagBits::eByRegion);
return GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), return GetContext()->GetDevice().createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(),
ARRAY_SIZE(attachmentDescriptions), attachmentDescriptions, attachmentDescriptions,
ARRAY_SIZE(subpasses), subpasses, subpasses,
dependencies.size(), dependencies.data())); dependencies));
} }

View File

@ -188,7 +188,7 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport,
} }
#endif #endif
vk::Viewport viewport(x, y, w, h); vk::Viewport viewport(x, y, w, h);
commandBuffer.setViewport(0, 1, &viewport); commandBuffer.setViewport(0, viewport);
commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(x, y), vk::Extent2D(w, h))); commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(x, y), vk::Extent2D(w, h)));
drawers[i]->Draw(commandBuffer, vmuTextures[i]->GetImageView(), vtx, true, color); drawers[i]->Draw(commandBuffer, vmuTextures[i]->GetImageView(), vtx, true, color);
@ -219,7 +219,7 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport,
x -= w / 2; x -= w / 2;
y -= h / 2; y -= h / 2;
vk::Viewport viewport(x, y, w, h); vk::Viewport viewport(x, y, w, h);
commandBuffer.setViewport(0, 1, &viewport); commandBuffer.setViewport(0, viewport);
commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(std::max(0.f, x), std::max(0.f, y)), commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(std::max(0.f, x), std::max(0.f, y)),
vk::Extent2D(w, h))); vk::Extent2D(w, h)));
u32 color = config::CrosshairColor[i]; u32 color = config::CrosshairColor[i];

View File

@ -38,20 +38,12 @@ void PipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, bool n
} }
else else
{ {
static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = static const vk::VertexInputBindingDescription vertexBindingDescription(0, sizeof(float) * 3);
{ static const vk::VertexInputAttributeDescription vertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0); // pos
{ 0, sizeof(float) * 3 },
};
static const vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[] =
{
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32B32Sfloat, 0), // pos
};
pipelineVertexInputStateCreateInfo = vk::PipelineVertexInputStateCreateInfo( pipelineVertexInputStateCreateInfo = vk::PipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vk::PipelineVertexInputStateCreateFlags(),
ARRAY_SIZE(vertexBindingDescriptions), vertexBindingDescription,
vertexBindingDescriptions, vertexInputAttributeDescription);
ARRAY_SIZE(vertexInputAttributeDescriptions),
vertexInputAttributeDescriptions);
pipelineInputAssemblyStateCreateInfo = vk::PipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(), pipelineInputAssemblyStateCreateInfo = vk::PipelineInputAssemblyStateCreateInfo(vk::PipelineInputAssemblyStateCreateFlags(),
vk::PrimitiveTopology::eTriangleList); vk::PrimitiveTopology::eTriangleList);
} }
@ -130,27 +122,25 @@ void PipelineManager::CreateModVolPipeline(ModVolMode mode, int cullMode, bool n
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
ModVolShaderParams shaderParams { naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation }; ModVolShaderParams shaderParams { naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation };
vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(shaderParams); vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(shaderParams);
vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation); vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -234,27 +224,25 @@ void PipelineManager::CreateDepthPassPipeline(int cullMode, bool naomi2)
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
ModVolShaderParams shaderParams { naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation }; ModVolShaderParams shaderParams { naomi2, !settings.platform.isNaomi2() && config::NativeDepthInterpolation };
vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(shaderParams); vk::ShaderModule vertex_module = shaderManager->GetModVolVertexShader(shaderParams);
vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation); vk::ShaderModule fragment_module = shaderManager->GetModVolShader(!settings.platform.isNaomi2() && config::NativeDepthInterpolation);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -386,8 +374,7 @@ void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const Pol
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
@ -413,15 +400,14 @@ void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const Pol
params.divPosZ = divPosZ; params.divPosZ = divPosZ;
vk::ShaderModule fragment_module = shaderManager->GetFragmentShader(params); vk::ShaderModule fragment_module = shaderManager->GetFragmentShader(params);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertex_module, "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragment_module, "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -442,21 +428,15 @@ void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const Pol
void OSDPipeline::CreatePipeline() void OSDPipeline::CreatePipeline()
{ {
// Vertex input state // Vertex input state
static const vk::VertexInputBindingDescription vertexBindingDescriptions[] = static const vk::VertexInputBindingDescription vertexInputBindingDescription(0, sizeof(OSDVertex));
{ static const std::array<vk::VertexInputAttributeDescription, 3> vertexInputAttributeDescriptions = {
{ 0, sizeof(OSDVertex) },
};
static const vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[] =
{
vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32Sfloat, offsetof(OSDVertex, x)), // pos vk::VertexInputAttributeDescription(0, 0, vk::Format::eR32G32Sfloat, offsetof(OSDVertex, x)), // pos
vk::VertexInputAttributeDescription(1, 0, vk::Format::eR8G8B8A8Uint, offsetof(OSDVertex, r)), // color vk::VertexInputAttributeDescription(1, 0, vk::Format::eR8G8B8A8Uint, offsetof(OSDVertex, r)), // color
vk::VertexInputAttributeDescription(2, 0, vk::Format::eR32G32Sfloat, offsetof(OSDVertex, u)), // tex coord vk::VertexInputAttributeDescription(2, 0, vk::Format::eR32G32Sfloat, offsetof(OSDVertex, u)), // tex coord
}; };
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vk::PipelineVertexInputStateCreateFlags(),
ARRAY_SIZE(vertexBindingDescriptions), vertexInputBindingDescription,
vertexBindingDescriptions,
ARRAY_SIZE(vertexInputAttributeDescriptions),
vertexInputAttributeDescriptions); vertexInputAttributeDescriptions);
// Input assembly state // Input assembly state
@ -490,24 +470,21 @@ void OSDPipeline::CreatePipeline()
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), ARRAY_SIZE(dynamicStates), vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
dynamicStates);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, shaderManager->GetOSDVertexShader(), "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, shaderManager->GetOSDVertexShader(), "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, shaderManager->GetOSDFragmentShader(), "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, shaderManager->GetOSDFragmentShader(), "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&vertexInputStateCreateInfo, // pVertexInputState &vertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -518,8 +495,7 @@ void OSDPipeline::CreatePipeline()
&pipelineColorBlendStateCreateInfo, // pColorBlendState &pipelineColorBlendStateCreateInfo, // pColorBlendState
&pipelineDynamicStateCreateInfo, // pDynamicState &pipelineDynamicStateCreateInfo, // pDynamicState
*pipelineLayout, // layout *pipelineLayout, // layout
renderPass, // renderPass renderPass // renderPass
0 // subpass
); );
pipeline = GetContext()->GetDevice().createGraphicsPipelineUnique(GetContext()->GetPipelineCache(), graphicsPipelineCreateInfo).value; pipeline = GetContext()->GetDevice().createGraphicsPipelineUnique(GetContext()->GetPipelineCache(), graphicsPipelineCreateInfo).value;

View File

@ -49,8 +49,8 @@ public:
bufferInfos.emplace_back(buffer, fragmentUniformOffset, sizeof(FragmentShaderUniforms)); bufferInfos.emplace_back(buffer, fragmentUniformOffset, sizeof(FragmentShaderUniforms));
std::vector<vk::WriteDescriptorSet> writeDescriptorSets; std::vector<vk::WriteDescriptorSet> writeDescriptorSets;
writeDescriptorSets.emplace_back(perFrameDescSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfos[0], nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 0, 0, vk::DescriptorType::eUniformBuffer, nullptr, bufferInfos[0]);
writeDescriptorSets.emplace_back(perFrameDescSet, 1, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfos[1], nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 1, 0, vk::DescriptorType::eUniformBuffer, nullptr, bufferInfos[1]);
if (fogImageView) if (fogImageView)
{ {
TSP fogTsp = {}; TSP fogTsp = {};
@ -60,7 +60,7 @@ public:
vk::Sampler fogSampler = samplerManager->GetSampler(fogTsp); vk::Sampler fogSampler = samplerManager->GetSampler(fogTsp);
static vk::DescriptorImageInfo imageInfo; static vk::DescriptorImageInfo imageInfo;
imageInfo = { fogSampler, fogImageView, vk::ImageLayout::eShaderReadOnlyOptimal }; imageInfo = { fogSampler, fogImageView, vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perFrameDescSet, 2, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 2, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
} }
if (paletteImageView) if (paletteImageView)
{ {
@ -71,7 +71,7 @@ public:
vk::Sampler palSampler = samplerManager->GetSampler(palTsp); vk::Sampler palSampler = samplerManager->GetSampler(palTsp);
static vk::DescriptorImageInfo imageInfo; static vk::DescriptorImageInfo imageInfo;
imageInfo = { palSampler, paletteImageView, vk::ImageLayout::eShaderReadOnlyOptimal }; imageInfo = { palSampler, paletteImageView, vk::ImageLayout::eShaderReadOnlyOptimal };
writeDescriptorSets.emplace_back(perFrameDescSet, 3, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perFrameDescSet, 3, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
} }
getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
} }
@ -91,7 +91,7 @@ public:
{ {
imageInfo = vk::DescriptorImageInfo(samplerManager->GetSampler(poly.tsp), imageInfo = vk::DescriptorImageInfo(samplerManager->GetSampler(poly.tsp),
((Texture *)poly.texture)->GetReadOnlyImageView(), vk::ImageLayout::eShaderReadOnlyOptimal); ((Texture *)poly.texture)->GetReadOnlyImageView(), vk::ImageLayout::eShaderReadOnlyOptimal);
writeDescriptorSets.emplace_back(perPolyDescSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 0, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
} }
vk::DescriptorBufferInfo uniBufferInfo; vk::DescriptorBufferInfo uniBufferInfo;
@ -101,7 +101,7 @@ public:
const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment(); const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment();
size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment); size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment);
uniBufferInfo = vk::DescriptorBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) }; uniBufferInfo = vk::DescriptorBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) };
writeDescriptorSets.emplace_back(perPolyDescSet, 2, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniBufferInfo, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 2, 0, vk::DescriptorType::eUniformBuffer, nullptr, uniBufferInfo);
size = sizeof(N2LightModel) + align(sizeof(N2LightModel), uniformAlignment); size = sizeof(N2LightModel) + align(sizeof(N2LightModel), uniformAlignment);
// light at index 0 is no light // light at index 0 is no light
@ -109,7 +109,7 @@ public:
lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset + (poly.lightModel - pvrrc.lightModels.head() + 1) * size, sizeof(N2LightModel) }; lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset + (poly.lightModel - pvrrc.lightModels.head() + 1) * size, sizeof(N2LightModel) };
else else
lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset, sizeof(N2LightModel) }; lightBufferInfo = vk::DescriptorBufferInfo{ buffer, lightOffset, sizeof(N2LightModel) };
writeDescriptorSets.emplace_back(perPolyDescSet, 3, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &lightBufferInfo, nullptr); writeDescriptorSets.emplace_back(perPolyDescSet, 3, 0, vk::DescriptorType::eUniformBuffer, nullptr, lightBufferInfo);
} }
getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
@ -117,7 +117,7 @@ public:
} }
else else
perPolyDescSet = it->second; perPolyDescSet = it->second;
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, 1, &perPolyDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, perPolyDescSet, nullptr);
} }
void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const ModifierVolumeParam& mvParam, int polyNumber, vk::Buffer buffer, void bindPerPolyDescriptorSets(vk::CommandBuffer cmdBuffer, const ModifierVolumeParam& mvParam, int polyNumber, vk::Buffer buffer,
@ -134,19 +134,19 @@ public:
const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment(); const vk::DeviceSize uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment();
size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment); size_t size = sizeof(N2VertexShaderUniforms) + align(sizeof(N2VertexShaderUniforms), uniformAlignment);
vk::DescriptorBufferInfo uniBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) }; vk::DescriptorBufferInfo uniBufferInfo{ buffer, uniformOffset + polyNumber * size, sizeof(N2VertexShaderUniforms) };
vk::WriteDescriptorSet writeDescriptorSet(perPolyDescSet, 2, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniBufferInfo, nullptr); vk::WriteDescriptorSet writeDescriptorSet(perPolyDescSet, 2, 0, vk::DescriptorType::eUniformBuffer, nullptr, uniBufferInfo);
getContext()->GetDevice().updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr); getContext()->GetDevice().updateDescriptorSets(writeDescriptorSet, nullptr);
perPolyDescSets[&mvParam] = perPolyDescSet; perPolyDescSets[&mvParam] = perPolyDescSet;
} }
else else
perPolyDescSet = it->second; perPolyDescSet = it->second;
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, 1, &perPolyDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 1, perPolyDescSet, nullptr);
} }
void bindPerFrameDescriptorSets(vk::CommandBuffer cmdBuffer) void bindPerFrameDescriptorSets(vk::CommandBuffer cmdBuffer)
{ {
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, 1, &perFrameDescSet, 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipelineLayout, 0, perFrameDescSet, nullptr);
} }
void nextFrame() void nextFrame()
@ -187,25 +187,25 @@ public:
if (!perFrameLayout) if (!perFrameLayout)
{ {
// Descriptor set and pipeline layout // Descriptor set and pipeline layout
vk::DescriptorSetLayoutBinding perFrameBindings[] = { std::array<vk::DescriptorSetLayoutBinding, 4> perFrameBindings = {
{ 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // vertex uniforms vk::DescriptorSetLayoutBinding(0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // vertex uniforms
{ 1, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // fragment uniforms vk::DescriptorSetLayoutBinding(1, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eFragment), // fragment uniforms
{ 2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// fog texture vk::DescriptorSetLayoutBinding(2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment),// fog texture
{ 3, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// palette texture vk::DescriptorSetLayoutBinding(3, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment),// palette texture
}; };
vk::DescriptorSetLayoutBinding perPolyBindings[] = { std::array<vk::DescriptorSetLayoutBinding, 3> perPolyBindings = {
{ 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// texture vk::DescriptorSetLayoutBinding(0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment),// texture
{ 2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // Naomi2 uniforms vk::DescriptorSetLayoutBinding(2, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // Naomi2 uniforms
{ 3, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // Naomi2 lights vk::DescriptorSetLayoutBinding(3, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex), // Naomi2 lights
}; };
perFrameLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique( perFrameLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perFrameBindings), perFrameBindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), perFrameBindings));
perPolyLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique( perPolyLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perPolyBindings), perPolyBindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), perPolyBindings));
vk::DescriptorSetLayout layouts[] = { *perFrameLayout, *perPolyLayout }; std::array<vk::DescriptorSetLayout, 2> layouts = { *perFrameLayout, *perPolyLayout };
vk::PushConstantRange pushConstant(vk::ShaderStageFlagBits::eFragment, 0, 24); vk::PushConstantRange pushConstant(vk::ShaderStageFlagBits::eFragment, 0, 24);
pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique( pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), ARRAY_SIZE(layouts), layouts, 1, &pushConstant)); vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), layouts, pushConstant));
} }
if (this->renderPass != renderPass) if (this->renderPass != renderPass)
@ -350,7 +350,7 @@ public:
}; };
vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal); vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal);
vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal); vk::AttachmentReference depthReference(1, vk::ImageLayout::eDepthStencilAttachmentOptimal);
vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 0, nullptr, 1, &colorReference, nullptr, &depthReference); vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, nullptr, colorReference, nullptr, &depthReference);
vk::SubpassDependency dependencies[] { vk::SubpassDependency dependencies[] {
vk::SubpassDependency(VK_SUBPASS_EXTERNAL, 0, vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::SubpassDependency(VK_SUBPASS_EXTERNAL, 0, vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eColorAttachmentOutput,
vk::AccessFlagBits::eShaderRead, vk::AccessFlagBits::eColorAttachmentWrite), vk::AccessFlagBits::eShaderRead, vk::AccessFlagBits::eColorAttachmentWrite),
@ -388,13 +388,11 @@ public:
this->shaderManager = shaderManager; this->shaderManager = shaderManager;
if (!pipelineLayout) if (!pipelineLayout)
{ {
vk::DescriptorSetLayoutBinding bindings[] = { vk::DescriptorSetLayoutBinding binding(0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment); // texture
{ 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// texture
};
descSetLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique( descSetLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(bindings), bindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), binding));
pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique( pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descSetLayout.get())); vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), descSetLayout.get()));
} }
if (!sampler) if (!sampler)
{ {
@ -412,12 +410,11 @@ public:
if (!descriptorSet) if (!descriptorSet)
{ {
descriptorSet = std::move(GetContext()->GetDevice().allocateDescriptorSetsUnique( descriptorSet = std::move(GetContext()->GetDevice().allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo(GetContext()->GetDescriptorPool(), 1, &descSetLayout.get())).front()); vk::DescriptorSetAllocateInfo(GetContext()->GetDescriptorPool(), descSetLayout.get())).front());
} }
vk::DescriptorImageInfo imageInfo(*sampler, imageView, vk::ImageLayout::eShaderReadOnlyOptimal); vk::DescriptorImageInfo imageInfo(*sampler, imageView, vk::ImageLayout::eShaderReadOnlyOptimal);
std::vector<vk::WriteDescriptorSet> writeDescriptorSets; vk::WriteDescriptorSet writeDescriptorSet(*descriptorSet, 0, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
writeDescriptorSets.emplace_back(*descriptorSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); GetContext()->GetDevice().updateDescriptorSets(writeDescriptorSet, nullptr);
GetContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
} }
vk::Pipeline GetPipeline() vk::Pipeline GetPipeline()
@ -429,7 +426,7 @@ public:
void BindDescriptorSets(vk::CommandBuffer cmdBuffer) const void BindDescriptorSets(vk::CommandBuffer cmdBuffer) const
{ {
cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, 1, &descriptorSet.get(), 0, nullptr); cmdBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipelineLayout, 0, descriptorSet.get(), nullptr);
} }
private: private:

View File

@ -82,23 +82,21 @@ void QuadPipeline::CreatePipeline()
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), ARRAY_SIZE(dynamicStates), dynamicStates); vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(vk::PipelineDynamicStateCreateFlags(), dynamicStates);
vk::PipelineShaderStageCreateInfo stages[] = { std::array<vk::PipelineShaderStageCreateInfo, 2> stages = {
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, shaderManager->GetQuadVertexShader(rotate), "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, shaderManager->GetQuadVertexShader(rotate), "main"),
{ vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, shaderManager->GetQuadFragmentShader(ignoreTexAlpha), "main" }, vk::PipelineShaderStageCreateInfo(vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, shaderManager->GetQuadFragmentShader(ignoreTexAlpha), "main"),
}; };
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
( (
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount stages, // stages
stages, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -121,14 +119,12 @@ void QuadPipeline::Init(ShaderManager *shaderManager, vk::RenderPass renderPass,
this->shaderManager = shaderManager; this->shaderManager = shaderManager;
if (!pipelineLayout) if (!pipelineLayout)
{ {
vk::DescriptorSetLayoutBinding bindings[] = { vk::DescriptorSetLayoutBinding binding(0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment); // texture
{ 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment }, // texture
};
descSetLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique( descSetLayout = GetContext()->GetDevice().createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(bindings), bindings)); vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), binding));
vk::PushConstantRange pushConstant(vk::ShaderStageFlagBits::eFragment, 0, 4 * sizeof(float)); vk::PushConstantRange pushConstant(vk::ShaderStageFlagBits::eFragment, 0, 4 * sizeof(float));
pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique( pipelineLayout = GetContext()->GetDevice().createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), 1, &descSetLayout.get(), 1, &pushConstant)); vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), descSetLayout.get(), pushConstant));
} }
if (!linearSampler) if (!linearSampler)
{ {
@ -179,16 +175,15 @@ void QuadDrawer::Draw(vk::CommandBuffer commandBuffer, vk::ImageView imageView,
{ {
vk::DescriptorSetLayout layout = pipeline->GetDescSetLayout(); vk::DescriptorSetLayout layout = pipeline->GetDescSetLayout();
descSet = std::move(context->GetDevice().allocateDescriptorSetsUnique( descSet = std::move(context->GetDevice().allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo(context->GetDescriptorPool(), 1, &layout)).front()); vk::DescriptorSetAllocateInfo(context->GetDescriptorPool(), layout)).front());
} }
if (imageView) if (imageView)
{ {
vk::DescriptorImageInfo imageInfo(nearestFilter ? pipeline->GetNearestSampler() : pipeline->GetLinearSampler(), imageView, vk::ImageLayout::eShaderReadOnlyOptimal); vk::DescriptorImageInfo imageInfo(nearestFilter ? pipeline->GetNearestSampler() : pipeline->GetLinearSampler(), imageView, vk::ImageLayout::eShaderReadOnlyOptimal);
std::vector<vk::WriteDescriptorSet> writeDescriptorSets; vk::WriteDescriptorSet writeDescriptorSet(*descSet, 0, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo);
writeDescriptorSets.emplace_back(*descSet, 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr); context->GetDevice().updateDescriptorSets(writeDescriptorSet, nullptr);
context->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);
} }
commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline->GetPipelineLayout(), 0, 1, &descSet.get(), 0, nullptr); commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline->GetPipelineLayout(), 0, descSet.get(), nullptr);
buffer->Update(vertices); buffer->Update(vertices);
buffer->Bind(commandBuffer); buffer->Bind(commandBuffer);

View File

@ -43,8 +43,7 @@ public:
void Bind(vk::CommandBuffer commandBuffer) void Bind(vk::CommandBuffer commandBuffer)
{ {
const vk::DeviceSize zero = 0; commandBuffer.bindVertexBuffers(0, buffer->buffer.get(), {0});
commandBuffer.bindVertexBuffers(0, 1, &buffer->buffer.get(), &zero);
} }
void Draw(vk::CommandBuffer commandBuffer) void Draw(vk::CommandBuffer commandBuffer)
{ {

View File

@ -234,7 +234,7 @@ void Texture::CreateImage(vk::ImageTiling tiling, const vk::ImageUsageFlags& usa
{ {
vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(extent, 1), mipmapLevels, 1, vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(extent, 1), mipmapLevels, 1,
vk::SampleCountFlagBits::e1, tiling, usage, vk::SampleCountFlagBits::e1, tiling, usage,
vk::SharingMode::eExclusive, 0, nullptr, initialLayout); vk::SharingMode::eExclusive, nullptr, initialLayout);
image = device.createImageUnique(imageCreateInfo); image = device.createImageUnique(imageCreateInfo);
VmaAllocationCreateInfo allocCreateInfo = { VmaAllocationCreateFlags(), needsStaging ? VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY : VmaMemoryUsage::VMA_MEMORY_USAGE_CPU_TO_GPU }; VmaAllocationCreateInfo allocCreateInfo = { VmaAllocationCreateFlags(), needsStaging ? VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY : VmaMemoryUsage::VMA_MEMORY_USAGE_CPU_TO_GPU };
@ -283,7 +283,7 @@ void Texture::SetImage(u32 srcSize, const void *srcData, bool isNew, bool genMip
} }
else if (!needsStaging) else if (!needsStaging)
{ {
vk::SubresourceLayout layout = device.getImageSubresourceLayout(*image, vk::ImageSubresource(vk::ImageAspectFlagBits::eColor, 0, 0)); vk::SubresourceLayout layout = device.getImageSubresourceLayout(*image, vk::ImageSubresource(vk::ImageAspectFlagBits::eColor));
if (layout.size != srcSize) if (layout.size != srcSize)
{ {
u8 *src = (u8 *)srcData; u8 *src = (u8 *)srcData;
@ -376,7 +376,7 @@ void Texture::GenerateMipmaps()
{ { vk::Offset3D(0, 0, 0), vk::Offset3D(mipWidth, mipHeight, 1) } }, { { vk::Offset3D(0, 0, 0), vk::Offset3D(mipWidth, mipHeight, 1) } },
vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, i, 0, 1), vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, i, 0, 1),
{ { vk::Offset3D(0, 0, 0), vk::Offset3D(std::max(mipWidth / 2, 1u), std::max(mipHeight / 2, 1u), 1) } }); { { vk::Offset3D(0, 0, 0), vk::Offset3D(std::max(mipWidth / 2, 1u), std::max(mipHeight / 2, 1u), 1) } });
commandBuffer.blitImage(*image, vk::ImageLayout::eTransferSrcOptimal, *image, vk::ImageLayout::eTransferDstOptimal, 1, &blit, vk::Filter::eLinear); commandBuffer.blitImage(*image, vk::ImageLayout::eTransferSrcOptimal, *image, vk::ImageLayout::eTransferDstOptimal, blit, vk::Filter::eLinear);
// Transition previous mipmap level from src optimal to shader read-only optimal // Transition previous mipmap level from src optimal to shader read-only optimal
barrier.oldLayout = vk::ImageLayout::eTransferSrcOptimal; barrier.oldLayout = vk::ImageLayout::eTransferSrcOptimal;
@ -410,7 +410,7 @@ void FramebufferAttachment::Init(u32 width, u32 height, vk::Format format, const
} }
vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(extent, 1), 1, 1, vk::SampleCountFlagBits::e1, vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, format, vk::Extent3D(extent, 1), 1, 1, vk::SampleCountFlagBits::e1,
vk::ImageTiling::eOptimal, usage, vk::ImageTiling::eOptimal, usage,
vk::SharingMode::eExclusive, 0, nullptr, vk::ImageLayout::eUndefined); vk::SharingMode::eExclusive, nullptr, vk::ImageLayout::eUndefined);
image = device.createImageUnique(imageCreateInfo); image = device.createImageUnique(imageCreateInfo);
VmaAllocationCreateInfo allocCreateInfo = { VmaAllocationCreateFlags(), VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY }; VmaAllocationCreateInfo allocCreateInfo = { VmaAllocationCreateFlags(), VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY };

View File

@ -234,22 +234,22 @@ bool VulkanContext::init(retro_hw_render_interface_vulkan *retro_render_if)
ShaderCompiler::Init(); ShaderCompiler::Init();
// Descriptor pool // Descriptor pool
vk::DescriptorPoolSize pool_sizes[] = std::array<vk::DescriptorPoolSize, 11> pool_sizes =
{ {
{ vk::DescriptorType::eSampler, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eSampler, 2),
{ vk::DescriptorType::eCombinedImageSampler, 40000 }, vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, 40000),
{ vk::DescriptorType::eSampledImage, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eSampledImage, 2),
{ vk::DescriptorType::eStorageImage, 12 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageImage, 12),
{ vk::DescriptorType::eUniformTexelBuffer, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformTexelBuffer, 2),
{ vk::DescriptorType::eStorageTexelBuffer, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageTexelBuffer, 2),
{ vk::DescriptorType::eUniformBuffer, 80000 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 80000),
{ vk::DescriptorType::eStorageBuffer, 50 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, 50),
{ vk::DescriptorType::eUniformBufferDynamic, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformBufferDynamic, 2),
{ vk::DescriptorType::eStorageBufferDynamic, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageBufferDynamic, 2),
{ vk::DescriptorType::eInputAttachment, 50 } vk::DescriptorPoolSize(vk::DescriptorType::eInputAttachment, 50)
}; };
descriptorPool = device.createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, descriptorPool = device.createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
40000, ARRAY_SIZE(pool_sizes), pool_sizes)); 40000, pool_sizes));
std::string cachePath = hostfs::getShaderCachePath("vulkan_pipeline.cache"); std::string cachePath = hostfs::getShaderCachePath("vulkan_pipeline.cache");
FILE *f = fopen(cachePath.c_str(), "rb"); FILE *f = fopen(cachePath.c_str(), "rb");

View File

@ -48,9 +48,9 @@ public:
int GetCurrentImageIndex() const { return retro_render_if->get_sync_index(retro_render_if->handle); } int GetCurrentImageIndex() const { return retro_render_if->get_sync_index(retro_render_if->handle); }
void WaitIdle() const { queue.waitIdle(); } void WaitIdle() const { queue.waitIdle(); }
void SubmitCommandBuffers(u32 bufferCount, vk::CommandBuffer *buffers, vk::Fence fence) { void SubmitCommandBuffers(const std::vector<vk::CommandBuffer> &buffers, vk::Fence fence) {
retro_render_if->lock_queue(retro_render_if->handle); retro_render_if->lock_queue(retro_render_if->handle);
queue.submit(vk::SubmitInfo(0, nullptr, nullptr, bufferCount, buffers, 0, nullptr), fence); queue.submit(vk::SubmitInfo(nullptr, nullptr, buffers, nullptr), fence);
retro_render_if->unlock_queue(retro_render_if->handle); retro_render_if->unlock_queue(retro_render_if->handle);
} }
vk::DeviceSize GetUniformBufferAlignment() const { return uniformBufferAlignment; } vk::DeviceSize GetUniformBufferAlignment() const { return uniformBufferAlignment; }

View File

@ -167,8 +167,7 @@ bool VulkanContext::InitInstance(const char** extensions, uint32_t extensions_co
layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
#endif #endif
#endif #endif
vk::InstanceCreateInfo instanceCreateInfo({}, &applicationInfo, layer_names.size(), layer_names.data(), vk::InstanceCreateInfo instanceCreateInfo({}, &applicationInfo, layer_names, vext);
vext.size(), vext.data());
// create a UniqueInstance // create a UniqueInstance
instance = vk::createInstanceUnique(instanceCreateInfo); instance = vk::createInstanceUnique(instanceCreateInfo);
@ -302,14 +301,14 @@ void VulkanContext::InitImgui()
if (ImGui::GetIO().Fonts->TexID == 0) if (ImGui::GetIO().Fonts->TexID == 0)
{ {
// Upload Fonts // Upload Fonts
device->resetFences(1, &(*drawFences.front())); device->resetFences(*drawFences.front());
device->resetCommandPool(*commandPools.front(), vk::CommandPoolResetFlagBits::eReleaseResources); device->resetCommandPool(*commandPools.front(), vk::CommandPoolResetFlagBits::eReleaseResources);
vk::CommandBuffer& commandBuffer = *commandBuffers.front(); vk::CommandBuffer& commandBuffer = *commandBuffers.front();
commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit)); commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
ImGui_ImplVulkan_CreateFontsTexture((VkCommandBuffer)commandBuffer); ImGui_ImplVulkan_CreateFontsTexture((VkCommandBuffer)commandBuffer);
commandBuffer.end(); commandBuffer.end();
vk::SubmitInfo submitInfo(0, nullptr, nullptr, 1, &commandBuffer); vk::SubmitInfo submitInfo(nullptr, nullptr, commandBuffer);
graphicsQueue.submit(1, &submitInfo, *drawFences.front()); graphicsQueue.submit(submitInfo, *drawFences.front());
device->waitIdle(); device->waitIdle();
ImGui_ImplVulkan_DestroyFontUploadObjects(); ImGui_ImplVulkan_DestroyFontUploadObjects();
@ -418,8 +417,8 @@ bool VulkanContext::InitDevice()
if (samplerAnisotropy) if (samplerAnisotropy)
features.samplerAnisotropy = true; features.samplerAnisotropy = true;
const char *layers[] = { "VK_LAYER_ARM_AGA" }; const char *layers[] = { "VK_LAYER_ARM_AGA" };
device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo, device = physicalDevice.createDeviceUnique(vk::DeviceCreateInfo(vk::DeviceCreateFlags(), deviceQueueCreateInfo,
0, layers, deviceExtensions.size(), &deviceExtensions[0], &features)); layers, deviceExtensions, &features));
#ifndef TARGET_IPHONE #ifndef TARGET_IPHONE
// This links entry points directly from the driver and isn't absolutely necessary // This links entry points directly from the driver and isn't absolutely necessary
@ -431,22 +430,22 @@ bool VulkanContext::InitDevice()
presentQueue = device->getQueue(presentQueueIndex, 0); presentQueue = device->getQueue(presentQueueIndex, 0);
// Descriptor pool // Descriptor pool
vk::DescriptorPoolSize pool_sizes[] = std::array<vk::DescriptorPoolSize, 11> pool_sizes =
{ {
{ vk::DescriptorType::eSampler, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eSampler, 2),
{ vk::DescriptorType::eCombinedImageSampler, 40000 }, vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, 40000),
{ vk::DescriptorType::eSampledImage, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eSampledImage, 2),
{ vk::DescriptorType::eStorageImage, 12 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageImage, 12),
{ vk::DescriptorType::eUniformTexelBuffer, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformTexelBuffer, 2),
{ vk::DescriptorType::eStorageTexelBuffer, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageTexelBuffer, 2),
{ vk::DescriptorType::eUniformBuffer, 80000 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, 80000),
{ vk::DescriptorType::eStorageBuffer, 100 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, 100),
{ vk::DescriptorType::eUniformBufferDynamic, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eUniformBufferDynamic, 2),
{ vk::DescriptorType::eStorageBufferDynamic, 2 }, vk::DescriptorPoolSize(vk::DescriptorType::eStorageBufferDynamic, 2),
{ vk::DescriptorType::eInputAttachment, 100 } vk::DescriptorPoolSize(vk::DescriptorType::eInputAttachment, 100)
}; };
descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
40000, ARRAY_SIZE(pool_sizes), pool_sizes)); 40000, pool_sizes));
std::string cachePath = hostfs::getShaderCachePath("vulkan_pipeline.cache"); std::string cachePath = hostfs::getShaderCachePath("vulkan_pipeline.cache");
@ -538,7 +537,7 @@ void VulkanContext::CreateSwapChain()
vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(GetSurface()); vk::SurfaceCapabilitiesKHR surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR(GetSurface());
DEBUG_LOG(RENDERER, "Surface capabilities: %d x %d, %s, image count: %d - %d", surfaceCapabilities.currentExtent.width, surfaceCapabilities.currentExtent.height, DEBUG_LOG(RENDERER, "Surface capabilities: %d x %d, %s, image count: %d - %d", surfaceCapabilities.currentExtent.width, surfaceCapabilities.currentExtent.height,
vk::to_string(surfaceCapabilities.currentTransform).c_str(), surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount); vk::to_string(surfaceCapabilities.currentTransform).c_str(), surfaceCapabilities.minImageCount, surfaceCapabilities.maxImageCount);
VkExtent2D swapchainExtent; vk::Extent2D swapchainExtent;
if (surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max()) if (surfaceCapabilities.currentExtent.width == std::numeric_limits<uint32_t>::max())
{ {
// If the surface size is undefined, the size is set to the size of the images requested. // If the surface size is undefined, the size is set to the size of the images requested.
@ -645,11 +644,11 @@ void VulkanContext::CreateSwapChain()
vk::ImageLayout::eUndefined, vk::ImageLayout::ePresentSrcKHR); vk::ImageLayout::eUndefined, vk::ImageLayout::ePresentSrcKHR);
vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal); vk::AttachmentReference colorReference(0, vk::ImageLayout::eColorAttachmentOptimal);
vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 0, nullptr, 1, &colorReference, vk::SubpassDescription subpass(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, nullptr, colorReference,
nullptr, nullptr); nullptr, nullptr);
renderPass = device->createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(), renderPass = device->createRenderPassUnique(vk::RenderPassCreateInfo(vk::RenderPassCreateFlags(),
1, &attachmentDescription, 1, &subpass)); attachmentDescription, subpass));
// Framebuffers, fences, semaphores // Framebuffers, fences, semaphores
@ -660,7 +659,7 @@ void VulkanContext::CreateSwapChain()
for (auto const& view : imageViews) for (auto const& view : imageViews)
{ {
framebuffers.push_back(device->createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), *renderPass, framebuffers.push_back(device->createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), *renderPass,
1, &view.get(), width, height, 1))); view.get(), width, height, 1)));
drawFences.push_back(device->createFenceUnique(vk::FenceCreateInfo(vk::FenceCreateFlagBits::eSignaled))); drawFences.push_back(device->createFenceUnique(vk::FenceCreateInfo(vk::FenceCreateFlagBits::eSignaled)));
renderCompleteSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo())); renderCompleteSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo()));
imageAcquiredSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo())); imageAcquiredSemaphores.push_back(device->createSemaphoreUnique(vk::SemaphoreCreateInfo()));
@ -771,8 +770,8 @@ void VulkanContext::NewFrame()
if (!IsValid()) if (!IsValid())
throw InvalidVulkanContext(); throw InvalidVulkanContext();
device->acquireNextImageKHR(*swapChain, UINT64_MAX, *imageAcquiredSemaphores[currentSemaphore], nullptr, &currentImage); device->acquireNextImageKHR(*swapChain, UINT64_MAX, *imageAcquiredSemaphores[currentSemaphore], nullptr, &currentImage);
device->waitForFences(1, &(*drawFences[currentImage]), true, UINT64_MAX); device->waitForFences(*drawFences[currentImage], true, UINT64_MAX);
device->resetFences(1, &(*drawFences[currentImage])); device->resetFences(*drawFences[currentImage]);
device->resetCommandPool(*commandPools[currentImage], vk::CommandPoolResetFlagBits::eReleaseResources); device->resetCommandPool(*commandPools[currentImage], vk::CommandPoolResetFlagBits::eReleaseResources);
vk::CommandBuffer commandBuffer = *commandBuffers[currentImage]; vk::CommandBuffer commandBuffer = *commandBuffers[currentImage];
commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit)); commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
@ -785,9 +784,9 @@ void VulkanContext::BeginRenderPass()
{ {
if (!IsValid()) if (!IsValid())
return; return;
const vk::ClearValue clear_colors[] = { getBorderColor(), vk::ClearDepthStencilValue{ 0.f, 0 } }; const std::array<vk::ClearValue, 2> clear_colors = { getBorderColor(), vk::ClearDepthStencilValue{ 0.f, 0 } };
vk::CommandBuffer commandBuffer = *commandBuffers[currentImage]; vk::CommandBuffer commandBuffer = *commandBuffers[currentImage];
commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(*renderPass, *framebuffers[currentImage], vk::Rect2D({0, 0}, {width, height}), 2, clear_colors), commandBuffer.beginRenderPass(vk::RenderPassBeginInfo(*renderPass, *framebuffers[currentImage], vk::Rect2D({0, 0}, {width, height}), clear_colors),
vk::SubpassContents::eInline); vk::SubpassContents::eInline);
} }
@ -798,14 +797,13 @@ void VulkanContext::EndFrame(vk::CommandBuffer overlayCmdBuffer)
vk::CommandBuffer commandBuffer = *commandBuffers[currentImage]; vk::CommandBuffer commandBuffer = *commandBuffers[currentImage];
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();
commandBuffer.end(); commandBuffer.end();
vk::PipelineStageFlags wait_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput; vk::PipelineStageFlags wait_stage(vk::PipelineStageFlagBits::eColorAttachmentOutput);
std::vector<vk::CommandBuffer> allCmdBuffers; std::vector<vk::CommandBuffer> allCmdBuffers;
if (overlayCmdBuffer) if (overlayCmdBuffer)
allCmdBuffers.push_back(overlayCmdBuffer); allCmdBuffers.push_back(overlayCmdBuffer);
allCmdBuffers.push_back(commandBuffer); allCmdBuffers.push_back(commandBuffer);
vk::SubmitInfo submitInfo(1, &(*imageAcquiredSemaphores[currentSemaphore]), &wait_stage, allCmdBuffers.size(),allCmdBuffers.data(), vk::SubmitInfo submitInfo(*imageAcquiredSemaphores[currentSemaphore], wait_stage, allCmdBuffers, *renderCompleteSemaphores[currentSemaphore]);
1, &(*renderCompleteSemaphores[currentSemaphore])); graphicsQueue.submit(submitInfo, *drawFences[currentImage]);
graphicsQueue.submit(1, &submitInfo, *drawFences[currentImage]);
verify(rendering); verify(rendering);
rendering = false; rendering = false;
renderDone = true; renderDone = true;
@ -872,7 +870,7 @@ void VulkanContext::DrawFrame(vk::ImageView imageView, const vk::Extent2D& exten
dx = width * (1 - renderAR / screenAR) / 2; dx = width * (1 - renderAR / screenAR) / 2;
vk::Viewport viewport(dx, dy, width - dx * 2, height - dy * 2); vk::Viewport viewport(dx, dy, width - dx * 2, height - dy * 2);
commandBuffer.setViewport(0, 1, &viewport); commandBuffer.setViewport(0, viewport);
commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(dx, dy), vk::Extent2D(width - dx * 2, height - dy * 2))); commandBuffer.setScissor(0, vk::Rect2D(vk::Offset2D(dx, dy), vk::Extent2D(width - dx * 2, height - dy * 2)));
if (config::Rotate90) if (config::Rotate90)
quadRotateDrawer->Draw(commandBuffer, imageView, vtx, config::TextureFiltering == 1); quadRotateDrawer->Draw(commandBuffer, imageView, vtx, config::TextureFiltering == 1);
@ -1003,7 +1001,7 @@ void VulkanContext::term()
#ifndef USE_SDL #ifndef USE_SDL
surface.reset(); surface.reset();
#else #else
::vkDestroySurfaceKHR((VkInstance)*instance, (VkSurfaceKHR)surface.release(), nullptr); instance->destroySurfaceKHR(surface.release());
#endif #endif
pipelineCache.reset(); pipelineCache.reset();
device.reset(); device.reset();
@ -1039,7 +1037,7 @@ void VulkanContext::DoSwapAutomation()
vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, vk::Format::eR8G8B8A8Unorm, vk::ImageCreateInfo imageCreateInfo(vk::ImageCreateFlags(), vk::ImageType::e2D, vk::Format::eR8G8B8A8Unorm,
vk::Extent3D(width, height, 1), 1, 1, vk::Extent3D(width, height, 1), 1, 1,
vk::SampleCountFlagBits::e1, vk::ImageTiling::eLinear, vk::ImageUsageFlagBits::eTransferDst, vk::SampleCountFlagBits::e1, vk::ImageTiling::eLinear, vk::ImageUsageFlagBits::eTransferDst,
vk::SharingMode::eExclusive, 0, nullptr, vk::ImageLayout::eUndefined); vk::SharingMode::eExclusive, nullptr, vk::ImageLayout::eUndefined);
vk::UniqueImage dstImage = device->createImageUnique(imageCreateInfo); vk::UniqueImage dstImage = device->createImageUnique(imageCreateInfo);
vk::MemoryRequirements memReq = device->getImageMemoryRequirements(*dstImage); vk::MemoryRequirements memReq = device->getImageMemoryRequirements(*dstImage);
@ -1099,8 +1097,8 @@ void VulkanContext::DoSwapAutomation()
vk::DependencyFlags(), nullptr, nullptr, barrier); vk::DependencyFlags(), nullptr, nullptr, barrier);
cmdBuffer->end(); cmdBuffer->end();
vk::PipelineStageFlags wait_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput; vk::PipelineStageFlags wait_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput;
vk::SubmitInfo submitInfo(0, nullptr, nullptr, 1, &cmdBuffer.get(), 0, nullptr); vk::SubmitInfo submitInfo(nullptr, nullptr, cmdBuffer.get(), nullptr);
graphicsQueue.submit(1, &submitInfo, nullptr); graphicsQueue.submit(submitInfo, nullptr);
graphicsQueue.waitIdle(); graphicsQueue.waitIdle();
vk::ImageSubresource subresource(vk::ImageAspectFlagBits::eColor, 0, 0); vk::ImageSubresource subresource(vk::ImageAspectFlagBits::eColor, 0, 0);
@ -1141,7 +1139,7 @@ bool VulkanContext::HasSurfaceDimensionChanged() const
{ {
vk::SurfaceCapabilitiesKHR surfaceCapabilities = vk::SurfaceCapabilitiesKHR surfaceCapabilities =
physicalDevice.getSurfaceCapabilitiesKHR(GetSurface()); physicalDevice.getSurfaceCapabilitiesKHR(GetSurface());
VkExtent2D swapchainExtent; vk::Extent2D swapchainExtent;
if (surfaceCapabilities.currentExtent.width == std::numeric_limits < uint32_t > ::max()) if (surfaceCapabilities.currentExtent.width == std::numeric_limits < uint32_t > ::max())
{ {
// If the surface size is undefined, the size is set to the size of the images requested. // If the surface size is undefined, the size is set to the size of the images requested.

View File

@ -104,9 +104,9 @@ public:
u32 GetVendorID() const { return vendorID; } u32 GetVendorID() const { return vendorID; }
vk::CommandBuffer PrepareOverlay(bool vmu, bool crosshair); vk::CommandBuffer PrepareOverlay(bool vmu, bool crosshair);
void DrawOverlay(float scaling, bool vmu, bool crosshair); void DrawOverlay(float scaling, bool vmu, bool crosshair);
void SubmitCommandBuffers(u32 bufferCount, vk::CommandBuffer *buffers, vk::Fence fence) { void SubmitCommandBuffers(const std::vector<vk::CommandBuffer> &buffers, vk::Fence fence) {
graphicsQueue.submit( graphicsQueue.submit(
vk::SubmitInfo(0, nullptr, nullptr, bufferCount, buffers), fence); vk::SubmitInfo(nullptr, nullptr, buffers), fence);
} }
bool hasPerPixel() override { return fragmentStoresAndAtomics; } bool hasPerPixel() override { return fragmentStoresAndAtomics; }
bool recreateSwapChainIfNeeded(); bool recreateSwapChainIfNeeded();

View File

@ -197,12 +197,11 @@ public:
osdPipeline.BindDescriptorSets(cmdBuffer); osdPipeline.BindDescriptorSets(cmdBuffer);
const vk::Viewport viewport(0, 0, (float)settings.display.width, (float)settings.display.height, 0, 1.f); const vk::Viewport viewport(0, 0, (float)settings.display.width, (float)settings.display.height, 0, 1.f);
cmdBuffer.setViewport(0, 1, &viewport); cmdBuffer.setViewport(0, viewport);
const vk::Rect2D scissor({ 0, 0 }, { (u32)settings.display.width, (u32)settings.display.height }); const vk::Rect2D scissor({ 0, 0 }, { (u32)settings.display.width, (u32)settings.display.height });
cmdBuffer.setScissor(0, 1, &scissor); cmdBuffer.setScissor(0, scissor);
osdBuffer->upload((u32)(osdVertices.size() * sizeof(OSDVertex)), osdVertices.data()); osdBuffer->upload((u32)(osdVertices.size() * sizeof(OSDVertex)), osdVertices.data());
const vk::DeviceSize zero = 0; cmdBuffer.bindVertexBuffers(0, osdBuffer->buffer.get(), {0});
cmdBuffer.bindVertexBuffers(0, 1, &osdBuffer->buffer.get(), &zero);
for (u32 i = 0; i < (u32)osdVertices.size(); i += 4) for (u32 i = 0; i < (u32)osdVertices.size(); i += 4)
cmdBuffer.draw(4, 1, i, 0); cmdBuffer.draw(4, 1, i, 0);
if (clear_screen) if (clear_screen)