Change the folder structure of the vulkan backend to better reflect what is going on
This commit is contained in:
parent
4638cc44d2
commit
295eb252ab
37 changed files with 119 additions and 110 deletions
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
** Vulkan backend
|
||||
** Copyright (c) 2016-2020 Magnus Norddahl
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any damages
|
||||
** arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose,
|
||||
** including commercial applications, and to alter it and redistribute it
|
||||
** freely, subject to the following restrictions:
|
||||
**
|
||||
** 1. The origin of this software must not be misrepresented; you must not
|
||||
** claim that you wrote the original software. If you use this software
|
||||
** in a product, an acknowledgment in the product documentation would be
|
||||
** appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be
|
||||
** misrepresented as being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
**
|
||||
*/
|
||||
|
||||
#include <zvulkan/vulkanobjects.h>
|
||||
#include <zvulkan/vulkandevice.h>
|
||||
#include <zvulkan/vulkanbuilders.h>
|
||||
#include <zvulkan/vulkanswapchain.h>
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/renderer/vk_postprocess.h"
|
||||
#include "vk_framebuffer.h"
|
||||
|
||||
CVAR(Bool, vk_hdr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
CVAR(Bool, vk_exclusivefullscreen, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
||||
|
||||
VkFramebufferManager::VkFramebufferManager(VulkanRenderDevice* fb) : fb(fb)
|
||||
{
|
||||
SwapChain = VulkanSwapChainBuilder()
|
||||
.Create(fb->device.get());
|
||||
|
||||
SwapChainImageAvailableSemaphore = SemaphoreBuilder()
|
||||
.DebugName("SwapChainImageAvailableSemaphore")
|
||||
.Create(fb->device.get());
|
||||
|
||||
RenderFinishedSemaphore = SemaphoreBuilder()
|
||||
.DebugName("RenderFinishedSemaphore")
|
||||
.Create(fb->device.get());
|
||||
}
|
||||
|
||||
VkFramebufferManager::~VkFramebufferManager()
|
||||
{
|
||||
}
|
||||
|
||||
void VkFramebufferManager::AcquireImage()
|
||||
{
|
||||
bool exclusiveFullscreen = fb->IsFullscreen() && vk_exclusivefullscreen;
|
||||
if (SwapChain->Lost() || fb->GetClientWidth() != CurrentWidth || fb->GetClientHeight() != CurrentHeight || fb->GetVSync() != CurrentVSync || CurrentHdr != vk_hdr || CurrentExclusiveFullscreen != exclusiveFullscreen)
|
||||
{
|
||||
Framebuffers.clear();
|
||||
|
||||
CurrentWidth = fb->GetClientWidth();
|
||||
CurrentHeight = fb->GetClientHeight();
|
||||
CurrentVSync = fb->GetVSync();
|
||||
CurrentHdr = vk_hdr;
|
||||
CurrentExclusiveFullscreen = exclusiveFullscreen;
|
||||
|
||||
SwapChain->Create(CurrentWidth, CurrentHeight, CurrentVSync ? 2 : 3, CurrentVSync, CurrentHdr, CurrentExclusiveFullscreen);
|
||||
}
|
||||
|
||||
PresentImageIndex = SwapChain->AcquireImage(SwapChainImageAvailableSemaphore.get());
|
||||
if (PresentImageIndex != -1)
|
||||
{
|
||||
fb->GetPostprocess()->DrawPresentTexture(fb->mOutputLetterbox, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
void VkFramebufferManager::QueuePresent()
|
||||
{
|
||||
if (PresentImageIndex != -1)
|
||||
SwapChain->QueuePresent(PresentImageIndex, RenderFinishedSemaphore.get());
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "zvulkan/vulkanobjects.h"
|
||||
#include <array>
|
||||
#include <map>
|
||||
|
||||
class VulkanRenderDevice;
|
||||
enum class PPFilterMode;
|
||||
enum class PPWrapMode;
|
||||
|
||||
class VkFramebufferManager
|
||||
{
|
||||
public:
|
||||
VkFramebufferManager(VulkanRenderDevice* fb);
|
||||
~VkFramebufferManager();
|
||||
|
||||
void AcquireImage();
|
||||
void QueuePresent();
|
||||
|
||||
std::map<int, std::unique_ptr<VulkanFramebuffer>> Framebuffers;
|
||||
|
||||
std::shared_ptr<VulkanSwapChain> SwapChain;
|
||||
int PresentImageIndex = -1;
|
||||
|
||||
std::unique_ptr<VulkanSemaphore> SwapChainImageAvailableSemaphore;
|
||||
std::unique_ptr<VulkanSemaphore> RenderFinishedSemaphore;
|
||||
|
||||
private:
|
||||
VulkanRenderDevice* fb = nullptr;
|
||||
int CurrentWidth = 0;
|
||||
int CurrentHeight = 0;
|
||||
bool CurrentVSync = false;
|
||||
bool CurrentHdr = false;
|
||||
bool CurrentExclusiveFullscreen = false;
|
||||
};
|
||||
|
|
@ -27,13 +27,13 @@
|
|||
#include "hw_renderstate.h"
|
||||
#include <zvulkan/vulkanobjects.h>
|
||||
#include <zvulkan/vulkanbuilders.h>
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "vulkan/textures/vk_samplers.h"
|
||||
#include "vulkan/vk_renderdevice.h"
|
||||
#include "vulkan/vk_postprocess.h"
|
||||
#include "vulkan/commands/vk_commandbuffer.h"
|
||||
#include "vulkan/samplers/vk_samplers.h"
|
||||
#include "vulkan/textures/vk_renderbuffers.h"
|
||||
#include "vulkan/textures/vk_texture.h"
|
||||
#include "vulkan/renderer/vk_descriptorset.h"
|
||||
#include "vulkan/renderer/vk_postprocess.h"
|
||||
#include "vulkan/descriptorsets/vk_descriptorset.h"
|
||||
#include "vulkan/shaders/vk_shader.h"
|
||||
#include "vk_hwtexture.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include "zvulkan/vulkanobjects.h"
|
||||
#include "zvulkan/vulkanbuilders.h"
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "vulkan/renderer/vk_renderpass.h"
|
||||
#include "vulkan/vk_renderdevice.h"
|
||||
#include "vulkan/commands/vk_commandbuffer.h"
|
||||
#include "vulkan/pipelines/vk_renderpass.h"
|
||||
|
||||
class VkTextureImage
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
#include "vk_pptexture.h"
|
||||
#include "vk_texture.h"
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "vulkan/vk_renderdevice.h"
|
||||
#include "vulkan/commands/vk_commandbuffer.h"
|
||||
|
||||
VkPPTexture::VkPPTexture(VulkanRenderDevice* fb, PPTexture *texture) : fb(fb)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@
|
|||
*/
|
||||
|
||||
#include "vk_renderbuffers.h"
|
||||
#include "vulkan/renderer/vk_postprocess.h"
|
||||
#include "vulkan/vk_postprocess.h"
|
||||
#include "vulkan/vk_renderdevice.h"
|
||||
#include "vulkan/textures/vk_texture.h"
|
||||
#include "vulkan/textures/vk_framebuffer.h"
|
||||
#include "vulkan/framebuffers/vk_framebuffer.h"
|
||||
#include "vulkan/shaders/vk_shader.h"
|
||||
#include "vulkan/commands/vk_commandbuffer.h"
|
||||
#include <zvulkan/vulkanswapchain.h>
|
||||
#include <zvulkan/vulkanbuilders.h>
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "hw_cvars.h"
|
||||
|
||||
VkRenderBuffers::VkRenderBuffers(VulkanRenderDevice* fb) : fb(fb)
|
||||
|
|
|
|||
|
|
@ -1,189 +0,0 @@
|
|||
/*
|
||||
** Vulkan backend
|
||||
** Copyright (c) 2016-2020 Magnus Norddahl
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any damages
|
||||
** arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose,
|
||||
** including commercial applications, and to alter it and redistribute it
|
||||
** freely, subject to the following restrictions:
|
||||
**
|
||||
** 1. The origin of this software must not be misrepresented; you must not
|
||||
** claim that you wrote the original software. If you use this software
|
||||
** in a product, an acknowledgment in the product documentation would be
|
||||
** appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be
|
||||
** misrepresented as being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
**
|
||||
*/
|
||||
|
||||
#include <zvulkan/vulkanobjects.h>
|
||||
#include <zvulkan/vulkandevice.h>
|
||||
#include <zvulkan/vulkanbuilders.h>
|
||||
#include "c_cvars.h"
|
||||
#include "v_video.h"
|
||||
#include "hw_cvars.h"
|
||||
#include "vulkan/system/vk_renderdevice.h"
|
||||
#include "vulkan/system/vk_commandbuffer.h"
|
||||
#include "vk_samplers.h"
|
||||
#include "hw_material.h"
|
||||
#include "i_interface.h"
|
||||
#include "hwrenderer/postprocessing/hw_postprocess.h"
|
||||
|
||||
struct VkTexFilter
|
||||
{
|
||||
VkFilter minFilter;
|
||||
VkFilter magFilter;
|
||||
VkSamplerMipmapMode mipfilter;
|
||||
bool mipmapping;
|
||||
};
|
||||
|
||||
static VkTexFilter TexFilter[] =
|
||||
{
|
||||
{VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST, false},
|
||||
{VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST, true},
|
||||
{VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST, false},
|
||||
{VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST, true},
|
||||
{VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_LINEAR, true},
|
||||
{VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_LINEAR, true},
|
||||
{VK_FILTER_LINEAR, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_LINEAR, true}
|
||||
};
|
||||
|
||||
struct VkTexClamp
|
||||
{
|
||||
VkSamplerAddressMode clamp_u;
|
||||
VkSamplerAddressMode clamp_v;
|
||||
};
|
||||
|
||||
static VkTexClamp TexClamp[] =
|
||||
{
|
||||
{ VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT },
|
||||
{ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT },
|
||||
{ VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE },
|
||||
{ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE },
|
||||
};
|
||||
|
||||
VkSamplerManager::VkSamplerManager(VulkanRenderDevice* fb) : fb(fb)
|
||||
{
|
||||
CreateHWSamplers();
|
||||
CreateShadowmapSampler();
|
||||
CreateLightmapSampler();
|
||||
}
|
||||
|
||||
VkSamplerManager::~VkSamplerManager()
|
||||
{
|
||||
}
|
||||
|
||||
void VkSamplerManager::ResetHWSamplers()
|
||||
{
|
||||
DeleteHWSamplers();
|
||||
CreateHWSamplers();
|
||||
}
|
||||
|
||||
void VkSamplerManager::CreateHWSamplers()
|
||||
{
|
||||
int filter = sysCallbacks.DisableTextureFilter && sysCallbacks.DisableTextureFilter()? 0 : gl_texture_filter;
|
||||
|
||||
for (int i = CLAMP_NONE; i <= CLAMP_XY; i++)
|
||||
{
|
||||
SamplerBuilder builder;
|
||||
builder.MagFilter(TexFilter[filter].magFilter);
|
||||
builder.MinFilter(TexFilter[filter].minFilter);
|
||||
builder.AddressMode(TexClamp[i].clamp_u, TexClamp[i].clamp_v, VK_SAMPLER_ADDRESS_MODE_REPEAT);
|
||||
builder.MipmapMode(TexFilter[filter].mipfilter);
|
||||
if (TexFilter[filter].mipmapping)
|
||||
{
|
||||
builder.Anisotropy(gl_texture_filter_anisotropic);
|
||||
builder.MaxLod(100.0f); // According to the spec this value is clamped so something high makes it usable for all textures.
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.MaxLod(0.25f);
|
||||
}
|
||||
builder.DebugName("VkSamplerManager.mSamplers");
|
||||
mSamplers[i] = builder.Create(fb->device.get());
|
||||
}
|
||||
|
||||
mSamplers[CLAMP_XY_NOMIP] = SamplerBuilder()
|
||||
.MagFilter(TexFilter[filter].magFilter)
|
||||
.MinFilter(TexFilter[filter].magFilter)
|
||||
.AddressMode(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT)
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_NEAREST)
|
||||
.MaxLod(0.25f)
|
||||
.DebugName("VkSamplerManager.mSamplers")
|
||||
.Create(fb->device.get());
|
||||
|
||||
for (int i = CLAMP_NOFILTER; i <= CLAMP_NOFILTER_XY; i++)
|
||||
{
|
||||
mSamplers[i] = SamplerBuilder()
|
||||
.MagFilter(VK_FILTER_NEAREST)
|
||||
.MinFilter(VK_FILTER_NEAREST)
|
||||
.AddressMode(TexClamp[i - CLAMP_NOFILTER].clamp_u, TexClamp[i - CLAMP_NOFILTER].clamp_v, VK_SAMPLER_ADDRESS_MODE_REPEAT)
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_NEAREST)
|
||||
.MaxLod(0.25f)
|
||||
.DebugName("VkSamplerManager.mSamplers")
|
||||
.Create(fb->device.get());
|
||||
}
|
||||
|
||||
// CAMTEX is repeating with texture filter and no mipmap
|
||||
mSamplers[CLAMP_CAMTEX] = SamplerBuilder()
|
||||
.MagFilter(TexFilter[filter].magFilter)
|
||||
.MinFilter(TexFilter[filter].magFilter)
|
||||
.AddressMode(VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT)
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_NEAREST)
|
||||
.MaxLod(0.25f)
|
||||
.DebugName("VkSamplerManager.mSamplers")
|
||||
.Create(fb->device.get());
|
||||
}
|
||||
|
||||
void VkSamplerManager::DeleteHWSamplers()
|
||||
{
|
||||
for (auto& sampler : mSamplers)
|
||||
{
|
||||
if (sampler)
|
||||
fb->GetCommands()->DrawDeleteList->Add(std::move(sampler));
|
||||
}
|
||||
}
|
||||
|
||||
VulkanSampler* VkSamplerManager::Get(PPFilterMode filter, PPWrapMode wrap)
|
||||
{
|
||||
int index = (((int)filter) << 1) | (int)wrap;
|
||||
auto& sampler = mPPSamplers[index];
|
||||
if (sampler)
|
||||
return sampler.get();
|
||||
|
||||
sampler = SamplerBuilder()
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_NEAREST)
|
||||
.MinFilter(filter == PPFilterMode::Nearest ? VK_FILTER_NEAREST : VK_FILTER_LINEAR)
|
||||
.MagFilter(filter == PPFilterMode::Nearest ? VK_FILTER_NEAREST : VK_FILTER_LINEAR)
|
||||
.AddressMode(wrap == PPWrapMode::Clamp ? VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE : VK_SAMPLER_ADDRESS_MODE_REPEAT)
|
||||
.DebugName("VkPostprocess.mSamplers")
|
||||
.Create(fb->device.get());
|
||||
|
||||
return sampler.get();
|
||||
}
|
||||
|
||||
void VkSamplerManager::CreateShadowmapSampler()
|
||||
{
|
||||
ShadowmapSampler = SamplerBuilder()
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_NEAREST)
|
||||
.MinFilter(VK_FILTER_NEAREST)
|
||||
.MagFilter(VK_FILTER_NEAREST)
|
||||
.AddressMode(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE)
|
||||
.DebugName("VkRenderBuffers.ShadowmapSampler")
|
||||
.Create(fb->device.get());
|
||||
}
|
||||
|
||||
void VkSamplerManager::CreateLightmapSampler()
|
||||
{
|
||||
LightmapSampler = SamplerBuilder()
|
||||
.MipmapMode(VK_SAMPLER_MIPMAP_MODE_LINEAR)
|
||||
.MinFilter(VK_FILTER_LINEAR)
|
||||
.MagFilter(VK_FILTER_LINEAR)
|
||||
.AddressMode(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE)
|
||||
.DebugName("VkRenderBuffers.LightmapSampler")
|
||||
.Create(fb->device.get());
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "zvulkan/vulkanobjects.h"
|
||||
#include <array>
|
||||
|
||||
class VulkanRenderDevice;
|
||||
enum class PPFilterMode;
|
||||
enum class PPWrapMode;
|
||||
|
||||
class VkSamplerManager
|
||||
{
|
||||
public:
|
||||
VkSamplerManager(VulkanRenderDevice* fb);
|
||||
~VkSamplerManager();
|
||||
|
||||
void ResetHWSamplers();
|
||||
|
||||
VulkanSampler *Get(int no) const { return mSamplers[no].get(); }
|
||||
VulkanSampler* Get(PPFilterMode filter, PPWrapMode wrap);
|
||||
|
||||
std::unique_ptr<VulkanSampler> ShadowmapSampler;
|
||||
std::unique_ptr<VulkanSampler> LightmapSampler;
|
||||
|
||||
private:
|
||||
void CreateHWSamplers();
|
||||
void DeleteHWSamplers();
|
||||
void CreateShadowmapSampler();
|
||||
void CreateLightmapSampler();
|
||||
|
||||
VulkanRenderDevice* fb = nullptr;
|
||||
std::array<std::unique_ptr<VulkanSampler>, NUMSAMPLERS> mSamplers;
|
||||
std::array<std::unique_ptr<VulkanSampler>, 4> mPPSamplers;
|
||||
};
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
#include "vk_hwtexture.h"
|
||||
#include "vk_pptexture.h"
|
||||
#include "vk_renderbuffers.h"
|
||||
#include "vulkan/renderer/vk_postprocess.h"
|
||||
#include "vulkan/vk_postprocess.h"
|
||||
#include "hw_cvars.h"
|
||||
|
||||
VkTextureManager::VkTextureManager(VulkanRenderDevice* fb) : fb(fb)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue