Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
287db66914 | ||
|
22dea3c194 | ||
|
b7b458e4be | ||
|
ed699f1e2b |
@ -103,8 +103,8 @@ add_library(video_core STATIC
|
|||||||
renderer_vulkan/vk_blit_helper.h
|
renderer_vulkan/vk_blit_helper.h
|
||||||
renderer_vulkan/vk_common.cpp
|
renderer_vulkan/vk_common.cpp
|
||||||
renderer_vulkan/vk_common.h
|
renderer_vulkan/vk_common.h
|
||||||
renderer_vulkan/vk_descriptor_pool.cpp
|
renderer_vulkan/vk_descriptor_update.cpp
|
||||||
renderer_vulkan/vk_descriptor_pool.h
|
renderer_vulkan/vk_descriptor_update.h
|
||||||
renderer_vulkan/vk_graphics_pipeline.cpp
|
renderer_vulkan/vk_graphics_pipeline.cpp
|
||||||
renderer_vulkan/vk_graphics_pipeline.h
|
renderer_vulkan/vk_graphics_pipeline.h
|
||||||
renderer_vulkan/vk_master_semaphore.cpp
|
renderer_vulkan/vk_master_semaphore.cpp
|
||||||
|
@ -176,15 +176,23 @@ struct TexturingRegs {
|
|||||||
INSERT_PADDING_WORDS(0x9);
|
INSERT_PADDING_WORDS(0x9);
|
||||||
|
|
||||||
struct FullTextureConfig {
|
struct FullTextureConfig {
|
||||||
const bool enabled;
|
u32 enabled;
|
||||||
const TextureConfig config;
|
TextureConfig config;
|
||||||
const TextureFormat format;
|
TextureFormat format;
|
||||||
|
|
||||||
|
bool operator==(const FullTextureConfig& other) const noexcept {
|
||||||
|
return std::memcmp(this, &other, sizeof(other)) == 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const std::array<FullTextureConfig, 3> GetTextures() const {
|
static_assert(std::has_unique_object_representations_v<FullTextureConfig>);
|
||||||
|
|
||||||
|
using Textures = std::array<FullTextureConfig, 3>;
|
||||||
|
|
||||||
|
const Textures GetTextures() const {
|
||||||
return {{
|
return {{
|
||||||
{static_cast<bool>(main_config.texture0_enable), texture0, texture0_format},
|
{main_config.texture0_enable, texture0, texture0_format},
|
||||||
{static_cast<bool>(main_config.texture1_enable), texture1, texture1_format},
|
{main_config.texture1_enable, texture1, texture1_format},
|
||||||
{static_cast<bool>(main_config.texture2_enable), texture2, texture2_format},
|
{main_config.texture2_enable, texture2, texture2_format},
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,11 +389,11 @@ struct TexturingRegs {
|
|||||||
BitField<16, 2, u32> alpha_scale;
|
BitField<16, 2, u32> alpha_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline unsigned GetColorMultiplier() const {
|
inline u32 GetColorMultiplier() const {
|
||||||
return (color_scale < 3) ? (1 << color_scale) : 1;
|
return (color_scale < 3) ? (1 << color_scale) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned GetAlphaMultiplier() const {
|
inline u32 GetAlphaMultiplier() const {
|
||||||
return (alpha_scale < 3) ? (1 << alpha_scale) : 1;
|
return (alpha_scale < 3) ? (1 << alpha_scale) : 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
||||||
#include "video_core/renderer_opengl/pica_to_gl.h"
|
#include "video_core/renderer_opengl/pica_to_gl.h"
|
||||||
#include "video_core/renderer_opengl/renderer_opengl.h"
|
#include "video_core/renderer_opengl/renderer_opengl.h"
|
||||||
#include "video_core/shader/generator/glsl_shader_gen.h"
|
#include "video_core/shader/generator/shader_gen.h"
|
||||||
#include "video_core/texture/texture_decode.h"
|
#include "video_core/texture/texture_decode.h"
|
||||||
#include "video_core/video_core.h"
|
#include "video_core/video_core.h"
|
||||||
|
|
||||||
@ -576,10 +576,9 @@ void RasterizerOpenGL::BindTextureCube(const Pica::TexturingRegs::FullTextureCon
|
|||||||
|
|
||||||
Surface& surface = res_cache.GetTextureCube(config);
|
Surface& surface = res_cache.GetTextureCube(config);
|
||||||
Sampler& sampler = res_cache.GetSampler(texture.config);
|
Sampler& sampler = res_cache.GetSampler(texture.config);
|
||||||
|
state.texture_units[0].target = GL_TEXTURE_CUBE_MAP;
|
||||||
state.texture_cube_unit.texture_cube = surface.Handle();
|
state.texture_units[0].texture_2d = surface.Handle();
|
||||||
state.texture_cube_unit.sampler = sampler.Handle();
|
state.texture_units[0].sampler = sampler.Handle();
|
||||||
state.texture_units[0].texture_2d = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::BindMaterial(u32 texture_index, Surface& surface) {
|
void RasterizerOpenGL::BindMaterial(u32 texture_index, Surface& surface) {
|
||||||
@ -612,7 +611,8 @@ bool RasterizerOpenGL::IsFeedbackLoop(u32 texture_index, const Framebuffer* fram
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::UnbindSpecial() {
|
void RasterizerOpenGL::UnbindSpecial() {
|
||||||
state.texture_cube_unit.texture_cube = 0;
|
state.texture_units[0].texture_2d = 0;
|
||||||
|
state.texture_units[0].target = GL_TEXTURE_2D;
|
||||||
state.image_shadow_texture_px = 0;
|
state.image_shadow_texture_px = 0;
|
||||||
state.image_shadow_texture_nx = 0;
|
state.image_shadow_texture_nx = 0;
|
||||||
state.image_shadow_texture_py = 0;
|
state.image_shadow_texture_py = 0;
|
||||||
|
@ -50,11 +50,11 @@ OpenGLState::OpenGLState() {
|
|||||||
|
|
||||||
for (auto& texture_unit : texture_units) {
|
for (auto& texture_unit : texture_units) {
|
||||||
texture_unit.texture_2d = 0;
|
texture_unit.texture_2d = 0;
|
||||||
|
texture_unit.target = GL_TEXTURE_2D;
|
||||||
texture_unit.sampler = 0;
|
texture_unit.sampler = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_cube_unit.texture_cube = 0;
|
color_buffer.texture_2d = 0;
|
||||||
texture_cube_unit.sampler = 0;
|
|
||||||
|
|
||||||
texture_buffer_lut_lf.texture_buffer = 0;
|
texture_buffer_lut_lf.texture_buffer = 0;
|
||||||
texture_buffer_lut_rg.texture_buffer = 0;
|
texture_buffer_lut_rg.texture_buffer = 0;
|
||||||
@ -213,21 +213,13 @@ void OpenGLState::Apply() const {
|
|||||||
for (u32 i = 0; i < texture_units.size(); ++i) {
|
for (u32 i = 0; i < texture_units.size(); ++i) {
|
||||||
if (texture_units[i].texture_2d != cur_state.texture_units[i].texture_2d) {
|
if (texture_units[i].texture_2d != cur_state.texture_units[i].texture_2d) {
|
||||||
glActiveTexture(TextureUnits::PicaTexture(i).Enum());
|
glActiveTexture(TextureUnits::PicaTexture(i).Enum());
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_units[i].texture_2d);
|
glBindTexture(texture_units[i].target, texture_units[i].texture_2d);
|
||||||
}
|
}
|
||||||
if (texture_units[i].sampler != cur_state.texture_units[i].sampler) {
|
if (texture_units[i].sampler != cur_state.texture_units[i].sampler) {
|
||||||
glBindSampler(i, texture_units[i].sampler);
|
glBindSampler(i, texture_units[i].sampler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture_cube_unit.texture_cube != cur_state.texture_cube_unit.texture_cube) {
|
|
||||||
glActiveTexture(TextureUnits::TextureCube.Enum());
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cube_unit.texture_cube);
|
|
||||||
}
|
|
||||||
if (texture_cube_unit.sampler != cur_state.texture_cube_unit.sampler) {
|
|
||||||
glBindSampler(TextureUnits::TextureCube.id, texture_cube_unit.sampler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texture buffer LUTs
|
// Texture buffer LUTs
|
||||||
if (texture_buffer_lut_lf.texture_buffer != cur_state.texture_buffer_lut_lf.texture_buffer) {
|
if (texture_buffer_lut_lf.texture_buffer != cur_state.texture_buffer_lut_lf.texture_buffer) {
|
||||||
glActiveTexture(TextureUnits::TextureBufferLUT_LF.Enum());
|
glActiveTexture(TextureUnits::TextureBufferLUT_LF.Enum());
|
||||||
@ -368,8 +360,6 @@ OpenGLState& OpenGLState::ResetTexture(GLuint handle) {
|
|||||||
unit.texture_2d = 0;
|
unit.texture_2d = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (texture_cube_unit.texture_cube == handle)
|
|
||||||
texture_cube_unit.texture_cube = 0;
|
|
||||||
if (texture_buffer_lut_lf.texture_buffer == handle)
|
if (texture_buffer_lut_lf.texture_buffer == handle)
|
||||||
texture_buffer_lut_lf.texture_buffer = 0;
|
texture_buffer_lut_lf.texture_buffer = 0;
|
||||||
if (texture_buffer_lut_rg.texture_buffer == handle)
|
if (texture_buffer_lut_rg.texture_buffer == handle)
|
||||||
@ -399,9 +389,6 @@ OpenGLState& OpenGLState::ResetSampler(GLuint handle) {
|
|||||||
unit.sampler = 0;
|
unit.sampler = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (texture_cube_unit.sampler == handle) {
|
|
||||||
texture_cube_unit.sampler = 0;
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,11 @@ constexpr TextureUnit PicaTexture(int unit) {
|
|||||||
return TextureUnit{unit};
|
return TextureUnit{unit};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr TextureUnit TextureCube{6};
|
|
||||||
constexpr TextureUnit TextureBufferLUT_LF{3};
|
constexpr TextureUnit TextureBufferLUT_LF{3};
|
||||||
constexpr TextureUnit TextureBufferLUT_RG{4};
|
constexpr TextureUnit TextureBufferLUT_RG{4};
|
||||||
constexpr TextureUnit TextureBufferLUT_RGBA{5};
|
constexpr TextureUnit TextureBufferLUT_RGBA{5};
|
||||||
constexpr TextureUnit TextureNormalMap{7};
|
constexpr TextureUnit TextureNormalMap{6};
|
||||||
constexpr TextureUnit TextureColorBuffer{10};
|
constexpr TextureUnit TextureColorBuffer{7};
|
||||||
|
|
||||||
} // namespace TextureUnits
|
} // namespace TextureUnits
|
||||||
|
|
||||||
@ -95,15 +94,11 @@ public:
|
|||||||
// 3 texture units - one for each that is used in PICA fragment shader emulation
|
// 3 texture units - one for each that is used in PICA fragment shader emulation
|
||||||
struct TextureUnit {
|
struct TextureUnit {
|
||||||
GLuint texture_2d; // GL_TEXTURE_BINDING_2D
|
GLuint texture_2d; // GL_TEXTURE_BINDING_2D
|
||||||
|
GLenum target; // GL_TEXTURE_TARGET
|
||||||
GLuint sampler; // GL_SAMPLER_BINDING
|
GLuint sampler; // GL_SAMPLER_BINDING
|
||||||
};
|
};
|
||||||
std::array<TextureUnit, 3> texture_units;
|
std::array<TextureUnit, 3> texture_units;
|
||||||
|
|
||||||
struct {
|
|
||||||
GLuint texture_cube; // GL_TEXTURE_BINDING_CUBE_MAP
|
|
||||||
GLuint sampler; // GL_SAMPLER_BINDING
|
|
||||||
} texture_cube_unit;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
|
GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
|
||||||
} texture_buffer_lut_lf;
|
} texture_buffer_lut_lf;
|
||||||
|
@ -7,10 +7,8 @@
|
|||||||
#include "common/memory_detect.h"
|
#include "common/memory_detect.h"
|
||||||
#include "common/microprofile.h"
|
#include "common/microprofile.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/texture.h"
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/frontend/emu_window.h"
|
#include "core/frontend/emu_window.h"
|
||||||
#include "core/hw/gpu.h"
|
|
||||||
#include "core/hw/hw.h"
|
#include "core/hw/hw.h"
|
||||||
#include "core/hw/lcd.h"
|
#include "core/hw/lcd.h"
|
||||||
#include "video_core/renderer_vulkan/renderer_vulkan.h"
|
#include "video_core/renderer_vulkan/renderer_vulkan.h"
|
||||||
@ -21,7 +19,6 @@
|
|||||||
#include "video_core/host_shaders/vulkan_present_frag_spv.h"
|
#include "video_core/host_shaders/vulkan_present_frag_spv.h"
|
||||||
#include "video_core/host_shaders/vulkan_present_interlaced_frag_spv.h"
|
#include "video_core/host_shaders/vulkan_present_interlaced_frag_spv.h"
|
||||||
#include "video_core/host_shaders/vulkan_present_vert_spv.h"
|
#include "video_core/host_shaders/vulkan_present_vert_spv.h"
|
||||||
#include "vulkan/vulkan_format_traits.hpp"
|
|
||||||
|
|
||||||
#include <vk_mem_alloc.h>
|
#include <vk_mem_alloc.h>
|
||||||
|
|
||||||
@ -38,6 +35,7 @@ struct ScreenRectVertex {
|
|||||||
Common::Vec2f tex_coord;
|
Common::Vec2f tex_coord;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr u32 MAX_IN_FLIGHT_FRAMES = 10;
|
||||||
constexpr u32 VERTEX_BUFFER_SIZE = sizeof(ScreenRectVertex) * 8192;
|
constexpr u32 VERTEX_BUFFER_SIZE = sizeof(ScreenRectVertex) * 8192;
|
||||||
|
|
||||||
constexpr std::array<f32, 4 * 4> MakeOrthographicMatrix(u32 width, u32 height) {
|
constexpr std::array<f32, 4 * 4> MakeOrthographicMatrix(u32 width, u32 height) {
|
||||||
@ -49,16 +47,12 @@ constexpr std::array<f32, 4 * 4> MakeOrthographicMatrix(u32 width, u32 height) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static std::array<vk::DescriptorSetLayoutBinding, 1> PRESENT_BINDINGS = {{
|
|
||||||
{0, vk::DescriptorType::eCombinedImageSampler, 3, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
}};
|
|
||||||
|
|
||||||
RendererVulkan::RendererVulkan(Core::System& system, Frontend::EmuWindow& window,
|
RendererVulkan::RendererVulkan(Core::System& system, Frontend::EmuWindow& window,
|
||||||
Frontend::EmuWindow* secondary_window)
|
Frontend::EmuWindow* secondary_window)
|
||||||
: RendererBase{system, window, secondary_window}, memory{system.Memory()},
|
: RendererBase{system, window, secondary_window}, memory{system.Memory()},
|
||||||
instance{system.TelemetrySession(), window, Settings::values.physical_device.GetValue()},
|
instance{system.TelemetrySession(), window, Settings::values.physical_device.GetValue()},
|
||||||
scheduler{instance, renderpass_cache}, renderpass_cache{instance, scheduler}, pool{instance},
|
scheduler{instance, renderpass_cache}, renderpass_cache{instance, scheduler},
|
||||||
main_window{window, instance, scheduler},
|
pool{instance, scheduler.GetMasterSemaphore()}, main_window{window, instance, scheduler},
|
||||||
vertex_buffer{instance, scheduler, vk::BufferUsageFlagBits::eVertexBuffer,
|
vertex_buffer{instance, scheduler, vk::BufferUsageFlagBits::eVertexBuffer,
|
||||||
VERTEX_BUFFER_SIZE},
|
VERTEX_BUFFER_SIZE},
|
||||||
rasterizer{memory,
|
rasterizer{memory,
|
||||||
@ -69,10 +63,9 @@ RendererVulkan::RendererVulkan(Core::System& system, Frontend::EmuWindow& window
|
|||||||
scheduler,
|
scheduler,
|
||||||
pool,
|
pool,
|
||||||
renderpass_cache,
|
renderpass_cache,
|
||||||
main_window.ImageCount()},
|
main_window.ImageCount()} {
|
||||||
present_set_provider{instance, pool, PRESENT_BINDINGS} {
|
|
||||||
CompileShaders();
|
CompileShaders();
|
||||||
BuildLayouts();
|
BuildLayoutsAndDescriptors();
|
||||||
BuildPipelines();
|
BuildPipelines();
|
||||||
if (secondary_window) {
|
if (secondary_window) {
|
||||||
second_window = std::make_unique<PresentWindow>(*secondary_window, instance, scheduler);
|
second_window = std::make_unique<PresentWindow>(*secondary_window, instance, scheduler);
|
||||||
@ -80,17 +73,21 @@ RendererVulkan::RendererVulkan(Core::System& system, Frontend::EmuWindow& window
|
|||||||
}
|
}
|
||||||
|
|
||||||
RendererVulkan::~RendererVulkan() {
|
RendererVulkan::~RendererVulkan() {
|
||||||
vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
scheduler.Finish();
|
scheduler.Finish();
|
||||||
device.waitIdle();
|
device.waitIdle();
|
||||||
|
|
||||||
device.destroyShaderModule(present_vertex_shader);
|
device.destroyPipelineLayout(pipeline_layout);
|
||||||
for (u32 i = 0; i < PRESENT_PIPELINES; i++) {
|
device.destroyDescriptorSetLayout(descriptor_set_layout);
|
||||||
device.destroyPipeline(present_pipelines[i]);
|
device.destroyDescriptorUpdateTemplate(update_template);
|
||||||
device.destroyShaderModule(present_shaders[i]);
|
device.destroyShaderModule(vert_shader);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < NUM_PIPELINES; i++) {
|
||||||
|
device.destroyPipeline(pipelines[i]);
|
||||||
|
device.destroyShaderModule(frag_shaders[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& sampler : present_samplers) {
|
for (auto sampler : samplers) {
|
||||||
device.destroySampler(sampler);
|
device.destroySampler(sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +102,10 @@ void RendererVulkan::Sync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::PrepareRendertarget() {
|
void RendererVulkan::PrepareRendertarget() {
|
||||||
for (u32 i = 0; i < 3; i++) {
|
for (u32 i = 0; i < NUM_SCREENS; i++) {
|
||||||
const u32 fb_id = i == 2 ? 1 : 0;
|
const u32 fb_id = i == 2 ? 1 : 0;
|
||||||
const auto& framebuffer = GPU::g_regs.framebuffer_config[fb_id];
|
const auto& framebuffer = GPU::g_regs.framebuffer_config[fb_id];
|
||||||
|
auto& texture = screen_infos[i].texture;
|
||||||
|
|
||||||
// Main LCD (0): 0x1ED02204, Sub LCD (1): 0x1ED02A04
|
// Main LCD (0): 0x1ED02204, Sub LCD (1): 0x1ED02A04
|
||||||
u32 lcd_color_addr =
|
u32 lcd_color_addr =
|
||||||
@ -118,37 +116,31 @@ void RendererVulkan::PrepareRendertarget() {
|
|||||||
|
|
||||||
if (color_fill.is_enabled) {
|
if (color_fill.is_enabled) {
|
||||||
LoadColorToActiveVkTexture(color_fill.color_r, color_fill.color_g, color_fill.color_b,
|
LoadColorToActiveVkTexture(color_fill.color_r, color_fill.color_g, color_fill.color_b,
|
||||||
screen_infos[i].texture);
|
texture);
|
||||||
} else {
|
continue;
|
||||||
TextureInfo& texture = screen_infos[i].texture;
|
}
|
||||||
|
|
||||||
if (texture.width != framebuffer.width || texture.height != framebuffer.height ||
|
if (texture.width != framebuffer.width || texture.height != framebuffer.height ||
|
||||||
texture.format != framebuffer.color_format) {
|
texture.format != framebuffer.color_format) {
|
||||||
|
|
||||||
// Reallocate texture if the framebuffer size has changed.
|
|
||||||
// This is expected to not happen very often and hence should not be a
|
|
||||||
// performance problem.
|
|
||||||
ConfigureFramebufferTexture(texture, framebuffer);
|
ConfigureFramebufferTexture(texture, framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadFBToScreenInfo(framebuffer, screen_infos[i], i == 1);
|
LoadFBToScreenInfo(framebuffer, screen_infos[i], i == 1);
|
||||||
|
|
||||||
// Resize the texture in case the framebuffer size has changed
|
|
||||||
texture.width = framebuffer.width;
|
|
||||||
texture.height = framebuffer.height;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout& layout) {
|
void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout& layout) {
|
||||||
const auto sampler = present_samplers[!Settings::values.filter_mode.GetValue()];
|
const auto sampler = samplers[!Settings::values.filter_mode.GetValue()];
|
||||||
std::transform(screen_infos.begin(), screen_infos.end(), present_textures.begin(),
|
std::transform(screen_infos.begin(), screen_infos.end(), image_infos.begin(), [&](auto& info) {
|
||||||
[&](auto& info) {
|
return vk::DescriptorImageInfo{sampler, info.image_view, vk::ImageLayout::eGeneral};
|
||||||
return DescriptorData{vk::DescriptorImageInfo{sampler, info.image_view,
|
|
||||||
vk::ImageLayout::eGeneral}};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto descriptor_set = present_set_provider.Acquire(present_textures);
|
// Prepare the descriptor set with presentation images.
|
||||||
|
const auto descriptor_set = present_sets[frame->index];
|
||||||
|
const vk::Device device = instance.GetDevice();
|
||||||
|
device.updateDescriptorSetWithTemplate(descriptor_set, update_template, image_infos);
|
||||||
|
|
||||||
|
// Bind presentation pipeline, enter renderpass.
|
||||||
renderpass_cache.EndRendering();
|
renderpass_cache.EndRendering();
|
||||||
scheduler.Record([this, layout, frame, descriptor_set, renderpass = main_window.Renderpass(),
|
scheduler.Record([this, layout, frame, descriptor_set, renderpass = main_window.Renderpass(),
|
||||||
index = current_pipeline](vk::CommandBuffer cmdbuf) {
|
index = current_pipeline](vk::CommandBuffer cmdbuf) {
|
||||||
@ -170,12 +162,11 @@ void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout&
|
|||||||
cmdbuf.setScissor(0, scissor);
|
cmdbuf.setScissor(0, scissor);
|
||||||
|
|
||||||
const vk::ClearValue clear{.color = clear_color};
|
const vk::ClearValue clear{.color = clear_color};
|
||||||
const vk::PipelineLayout layout{*present_pipeline_layout};
|
|
||||||
const vk::RenderPassBeginInfo renderpass_begin_info = {
|
const vk::RenderPassBeginInfo renderpass_begin_info = {
|
||||||
.renderPass = renderpass,
|
.renderPass = renderpass,
|
||||||
.framebuffer = frame->framebuffer,
|
.framebuffer = frame->framebuffer,
|
||||||
.renderArea =
|
.renderArea =
|
||||||
vk::Rect2D{
|
{
|
||||||
.offset = {0, 0},
|
.offset = {0, 0},
|
||||||
.extent = {frame->width, frame->height},
|
.extent = {frame->width, frame->height},
|
||||||
},
|
},
|
||||||
@ -184,8 +175,9 @@ void RendererVulkan::PrepareDraw(Frame* frame, const Layout::FramebufferLayout&
|
|||||||
};
|
};
|
||||||
|
|
||||||
cmdbuf.beginRenderPass(renderpass_begin_info, vk::SubpassContents::eInline);
|
cmdbuf.beginRenderPass(renderpass_begin_info, vk::SubpassContents::eInline);
|
||||||
cmdbuf.bindPipeline(vk::PipelineBindPoint::eGraphics, present_pipelines[index]);
|
cmdbuf.bindPipeline(vk::PipelineBindPoint::eGraphics, pipelines[index]);
|
||||||
cmdbuf.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, layout, 0, descriptor_set, {});
|
cmdbuf.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline_layout, 0,
|
||||||
|
descriptor_set, {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,13 +231,13 @@ void RendererVulkan::LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& fram
|
|||||||
|
|
||||||
void RendererVulkan::CompileShaders() {
|
void RendererVulkan::CompileShaders() {
|
||||||
vk::Device device = instance.GetDevice();
|
vk::Device device = instance.GetDevice();
|
||||||
present_vertex_shader = CompileSPV(VULKAN_PRESENT_VERT_SPV, device);
|
vert_shader = CompileSPV(VULKAN_PRESENT_VERT_SPV, device);
|
||||||
present_shaders[0] = CompileSPV(VULKAN_PRESENT_FRAG_SPV, device);
|
frag_shaders[0] = CompileSPV(VULKAN_PRESENT_FRAG_SPV, device);
|
||||||
present_shaders[1] = CompileSPV(VULKAN_PRESENT_ANAGLYPH_FRAG_SPV, device);
|
frag_shaders[1] = CompileSPV(VULKAN_PRESENT_ANAGLYPH_FRAG_SPV, device);
|
||||||
present_shaders[2] = CompileSPV(VULKAN_PRESENT_INTERLACED_FRAG_SPV, device);
|
frag_shaders[2] = CompileSPV(VULKAN_PRESENT_INTERLACED_FRAG_SPV, device);
|
||||||
|
|
||||||
auto properties = instance.GetPhysicalDevice().getProperties();
|
const auto properties = instance.GetPhysicalDevice().getProperties();
|
||||||
for (std::size_t i = 0; i < present_samplers.size(); i++) {
|
for (std::size_t i = 0; i < samplers.size(); i++) {
|
||||||
const vk::Filter filter_mode = i == 0 ? vk::Filter::eLinear : vk::Filter::eNearest;
|
const vk::Filter filter_mode = i == 0 ? vk::Filter::eLinear : vk::Filter::eNearest;
|
||||||
const vk::SamplerCreateInfo sampler_info = {
|
const vk::SamplerCreateInfo sampler_info = {
|
||||||
.magFilter = filter_mode,
|
.magFilter = filter_mode,
|
||||||
@ -261,25 +253,59 @@ void RendererVulkan::CompileShaders() {
|
|||||||
.unnormalizedCoordinates = false,
|
.unnormalizedCoordinates = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
present_samplers[i] = device.createSampler(sampler_info);
|
samplers[i] = device.createSampler(sampler_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::BuildLayouts() {
|
void RendererVulkan::BuildLayoutsAndDescriptors() {
|
||||||
const vk::PushConstantRange push_range = {
|
const vk::PushConstantRange push_range = {
|
||||||
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
|
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.size = sizeof(PresentUniformData),
|
.size = sizeof(PresentUniformData),
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto descriptor_set_layout = present_set_provider.Layout();
|
const vk::DescriptorSetLayoutBinding binding = {
|
||||||
const vk::PipelineLayoutCreateInfo layout_info = {
|
.binding = 0,
|
||||||
|
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||||
|
.descriptorCount = 3,
|
||||||
|
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||||
|
};
|
||||||
|
|
||||||
|
const vk::DescriptorUpdateTemplateEntry update_entry = {
|
||||||
|
.dstBinding = 0,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = 3,
|
||||||
|
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||||
|
.offset = 0,
|
||||||
|
.stride = sizeof(vk::DescriptorImageInfo),
|
||||||
|
};
|
||||||
|
|
||||||
|
const vk::DescriptorSetLayoutCreateInfo layout_info = {
|
||||||
|
.bindingCount = 1,
|
||||||
|
.pBindings = &binding,
|
||||||
|
};
|
||||||
|
|
||||||
|
const vk::Device device = instance.GetDevice();
|
||||||
|
descriptor_set_layout = device.createDescriptorSetLayout(layout_info);
|
||||||
|
|
||||||
|
const vk::DescriptorUpdateTemplateCreateInfo template_info = {
|
||||||
|
.descriptorUpdateEntryCount = 1,
|
||||||
|
.pDescriptorUpdateEntries = &update_entry,
|
||||||
|
.templateType = vk::DescriptorUpdateTemplateType::eDescriptorSet,
|
||||||
|
.descriptorSetLayout = descriptor_set_layout,
|
||||||
|
};
|
||||||
|
update_template = device.createDescriptorUpdateTemplate(template_info);
|
||||||
|
|
||||||
|
const vk::PipelineLayoutCreateInfo pipeline_layout_info = {
|
||||||
.setLayoutCount = 1,
|
.setLayoutCount = 1,
|
||||||
.pSetLayouts = &descriptor_set_layout,
|
.pSetLayouts = &descriptor_set_layout,
|
||||||
.pushConstantRangeCount = 1,
|
.pushConstantRangeCount = 1,
|
||||||
.pPushConstantRanges = &push_range,
|
.pPushConstantRanges = &push_range,
|
||||||
};
|
};
|
||||||
present_pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info);
|
pipeline_layout = device.createPipelineLayout(pipeline_layout_info);
|
||||||
|
|
||||||
|
const u32 image_count = main_window.ImageCount();
|
||||||
|
present_sets = pool.Commit(descriptor_set_layout, image_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::BuildPipelines() {
|
void RendererVulkan::BuildPipelines() {
|
||||||
@ -370,16 +396,16 @@ void RendererVulkan::BuildPipelines() {
|
|||||||
.stencilTestEnable = false,
|
.stencilTestEnable = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (u32 i = 0; i < PRESENT_PIPELINES; i++) {
|
for (u32 i = 0; i < NUM_PIPELINES; i++) {
|
||||||
const std::array shader_stages = {
|
const std::array shader_stages = {
|
||||||
vk::PipelineShaderStageCreateInfo{
|
vk::PipelineShaderStageCreateInfo{
|
||||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||||
.module = present_vertex_shader,
|
.module = vert_shader,
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
},
|
},
|
||||||
vk::PipelineShaderStageCreateInfo{
|
vk::PipelineShaderStageCreateInfo{
|
||||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||||
.module = present_shaders[i],
|
.module = frag_shaders[i],
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -395,14 +421,14 @@ void RendererVulkan::BuildPipelines() {
|
|||||||
.pDepthStencilState = &depth_info,
|
.pDepthStencilState = &depth_info,
|
||||||
.pColorBlendState = &color_blending,
|
.pColorBlendState = &color_blending,
|
||||||
.pDynamicState = &dynamic_info,
|
.pDynamicState = &dynamic_info,
|
||||||
.layout = *present_pipeline_layout,
|
.layout = pipeline_layout,
|
||||||
.renderPass = main_window.Renderpass(),
|
.renderPass = main_window.Renderpass(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto [result, pipeline] =
|
const auto [result, pipeline] =
|
||||||
instance.GetDevice().createGraphicsPipeline({}, pipeline_info);
|
instance.GetDevice().createGraphicsPipeline({}, pipeline_info);
|
||||||
ASSERT_MSG(result == vk::Result::eSuccess, "Unable to build present pipelines");
|
ASSERT_MSG(result == vk::Result::eSuccess, "Unable to build present pipelines");
|
||||||
present_pipelines[i] = pipeline;
|
pipelines[i] = pipeline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,8 +442,7 @@ void RendererVulkan::ConfigureFramebufferTexture(TextureInfo& texture,
|
|||||||
vmaDestroyImage(instance.GetAllocator(), texture.image, texture.allocation);
|
vmaDestroyImage(instance.GetAllocator(), texture.image, texture.allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const VideoCore::PixelFormat pixel_format =
|
const auto pixel_format = VideoCore::PixelFormatFromGPUPixelFormat(framebuffer.color_format);
|
||||||
VideoCore::PixelFormatFromGPUPixelFormat(framebuffer.color_format);
|
|
||||||
const vk::Format format = instance.GetTraits(pixel_format).native;
|
const vk::Format format = instance.GetTraits(pixel_format).native;
|
||||||
const vk::ImageCreateInfo image_info = {
|
const vk::ImageCreateInfo image_info = {
|
||||||
.imageType = vk::ImageType::e2D,
|
.imageType = vk::ImageType::e2D,
|
||||||
@ -603,7 +628,7 @@ void RendererVulkan::DrawSingleScreen(u32 screen_id, float x, float y, float w,
|
|||||||
|
|
||||||
scheduler.Record([this, offset = offset, info = draw_info](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([this, offset = offset, info = draw_info](vk::CommandBuffer cmdbuf) {
|
||||||
const u32 first_vertex = static_cast<u32>(offset) / sizeof(ScreenRectVertex);
|
const u32 first_vertex = static_cast<u32>(offset) / sizeof(ScreenRectVertex);
|
||||||
cmdbuf.pushConstants(*present_pipeline_layout,
|
cmdbuf.pushConstants(pipeline_layout,
|
||||||
vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex,
|
vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex,
|
||||||
0, sizeof(info), &info);
|
0, sizeof(info), &info);
|
||||||
|
|
||||||
@ -676,7 +701,7 @@ void RendererVulkan::DrawSingleScreenStereo(u32 screen_id_l, u32 screen_id_r, fl
|
|||||||
|
|
||||||
scheduler.Record([this, offset = offset, info = draw_info](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([this, offset = offset, info = draw_info](vk::CommandBuffer cmdbuf) {
|
||||||
const u32 first_vertex = static_cast<u32>(offset) / sizeof(ScreenRectVertex);
|
const u32 first_vertex = static_cast<u32>(offset) / sizeof(ScreenRectVertex);
|
||||||
cmdbuf.pushConstants(*present_pipeline_layout,
|
cmdbuf.pushConstants(pipeline_layout,
|
||||||
vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex,
|
vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex,
|
||||||
0, sizeof(info), &info);
|
0, sizeof(info), &info);
|
||||||
|
|
||||||
@ -817,29 +842,7 @@ void RendererVulkan::DrawScreens(Frame* frame, const Layout::FramebufferLayout&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler.Record([image = frame->image](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([](vk::CommandBuffer cmdbuf) { cmdbuf.endRenderPass(); });
|
||||||
const vk::ImageMemoryBarrier render_barrier = {
|
|
||||||
.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
|
||||||
.dstAccessMask = vk::AccessFlagBits::eTransferRead,
|
|
||||||
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
|
|
||||||
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
|
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
||||||
.image = image,
|
|
||||||
.subresourceRange{
|
|
||||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
cmdbuf.endRenderPass();
|
|
||||||
cmdbuf.pipelineBarrier(vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
|
||||||
vk::PipelineStageFlagBits::eTransfer,
|
|
||||||
vk::DependencyFlagBits::eByRegion, {}, {}, render_barrier);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererVulkan::SwapBuffers() {
|
void RendererVulkan::SwapBuffers() {
|
||||||
@ -1032,8 +1035,7 @@ bool RendererVulkan::TryRenderScreenshotWithHostMemory() {
|
|||||||
.imageExtent = {width, height, 1},
|
.imageExtent = {width, height, 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
const vk::MemoryHostPointerPropertiesEXT import_properties =
|
const auto import_properties = device.getMemoryHostPointerPropertiesEXT(
|
||||||
device.getMemoryHostPointerPropertiesEXT(
|
|
||||||
vk::ExternalMemoryHandleTypeFlagBits::eHostAllocationEXT, aligned_pointer);
|
vk::ExternalMemoryHandleTypeFlagBits::eHostAllocationEXT, aligned_pointer);
|
||||||
|
|
||||||
if (!import_properties.memoryTypeBits) {
|
if (!import_properties.memoryTypeBits) {
|
||||||
@ -1051,8 +1053,7 @@ bool RendererVulkan::TryRenderScreenshotWithHostMemory() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vk::StructureChain<vk::MemoryAllocateInfo, vk::ImportMemoryHostPointerInfoEXT>
|
const vk::StructureChain allocation_chain = {
|
||||||
allocation_chain = {
|
|
||||||
vk::MemoryAllocateInfo{
|
vk::MemoryAllocateInfo{
|
||||||
.allocationSize = aligned_size,
|
.allocationSize = aligned_size,
|
||||||
.memoryTypeIndex = memory_type_index.value(),
|
.memoryTypeIndex = memory_type_index.value(),
|
||||||
@ -1067,8 +1068,7 @@ bool RendererVulkan::TryRenderScreenshotWithHostMemory() {
|
|||||||
const vk::UniqueDeviceMemory imported_memory =
|
const vk::UniqueDeviceMemory imported_memory =
|
||||||
device.allocateMemoryUnique(allocation_chain.get());
|
device.allocateMemoryUnique(allocation_chain.get());
|
||||||
|
|
||||||
const vk::StructureChain<vk::BufferCreateInfo, vk::ExternalMemoryBufferCreateInfo> buffer_info =
|
const vk::StructureChain buffer_info = {
|
||||||
{
|
|
||||||
vk::BufferCreateInfo{
|
vk::BufferCreateInfo{
|
||||||
.size = aligned_size,
|
.size = aligned_size,
|
||||||
.usage = vk::BufferUsageFlagBits::eTransferDst,
|
.usage = vk::BufferUsageFlagBits::eTransferDst,
|
||||||
|
@ -4,20 +4,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <mutex>
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
#include "core/hw/gpu.h"
|
#include "core/hw/gpu.h"
|
||||||
#include "video_core/renderer_base.h"
|
#include "video_core/renderer_base.h"
|
||||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
#include "video_core/renderer_vulkan/vk_present_window.h"
|
#include "video_core/renderer_vulkan/vk_present_window.h"
|
||||||
#include "video_core/renderer_vulkan/vk_rasterizer.h"
|
#include "video_core/renderer_vulkan/vk_rasterizer.h"
|
||||||
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_resource_pool.h"
|
||||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||||
#include "video_core/renderer_vulkan/vk_swapchain.h"
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class System;
|
class System;
|
||||||
@ -61,7 +56,8 @@ static_assert(sizeof(PresentUniformData) == 112,
|
|||||||
"PresentUniformData does not structure in shader!");
|
"PresentUniformData does not structure in shader!");
|
||||||
|
|
||||||
class RendererVulkan : public VideoCore::RendererBase {
|
class RendererVulkan : public VideoCore::RendererBase {
|
||||||
static constexpr std::size_t PRESENT_PIPELINES = 3;
|
static constexpr std::size_t NUM_PIPELINES = 3;
|
||||||
|
static constexpr std::size_t NUM_SCREENS = 3;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RendererVulkan(Core::System& system, Frontend::EmuWindow& window,
|
explicit RendererVulkan(Core::System& system, Frontend::EmuWindow& window,
|
||||||
@ -83,7 +79,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void ReloadPipeline();
|
void ReloadPipeline();
|
||||||
void CompileShaders();
|
void CompileShaders();
|
||||||
void BuildLayouts();
|
void BuildLayoutsAndDescriptors();
|
||||||
void BuildPipelines();
|
void BuildPipelines();
|
||||||
void ConfigureFramebufferTexture(TextureInfo& texture,
|
void ConfigureFramebufferTexture(TextureInfo& texture,
|
||||||
const GPU::Regs::FramebufferConfig& framebuffer);
|
const GPU::Regs::FramebufferConfig& framebuffer);
|
||||||
@ -121,16 +117,18 @@ private:
|
|||||||
RasterizerVulkan rasterizer;
|
RasterizerVulkan rasterizer;
|
||||||
std::unique_ptr<PresentWindow> second_window;
|
std::unique_ptr<PresentWindow> second_window;
|
||||||
|
|
||||||
vk::UniquePipelineLayout present_pipeline_layout;
|
vk::PipelineLayout pipeline_layout;
|
||||||
DescriptorSetProvider present_set_provider;
|
vk::DescriptorSetLayout descriptor_set_layout;
|
||||||
std::array<vk::Pipeline, PRESENT_PIPELINES> present_pipelines;
|
vk::DescriptorUpdateTemplate update_template;
|
||||||
std::array<vk::ShaderModule, PRESENT_PIPELINES> present_shaders;
|
std::vector<vk::DescriptorSet> present_sets;
|
||||||
std::array<vk::Sampler, 2> present_samplers;
|
std::array<vk::Pipeline, NUM_PIPELINES> pipelines;
|
||||||
vk::ShaderModule present_vertex_shader;
|
std::array<vk::ShaderModule, NUM_PIPELINES> frag_shaders;
|
||||||
|
std::array<vk::Sampler, 2> samplers;
|
||||||
|
vk::ShaderModule vert_shader;
|
||||||
u32 current_pipeline = 0;
|
u32 current_pipeline = 0;
|
||||||
|
|
||||||
std::array<ScreenInfo, 3> screen_infos{};
|
std::array<ScreenInfo, NUM_SCREENS> screen_infos{};
|
||||||
std::array<DescriptorData, 3> present_textures{};
|
std::array<vk::DescriptorImageInfo, NUM_SCREENS> image_infos{};
|
||||||
PresentUniformData draw_info{};
|
PresentUniformData draw_info{};
|
||||||
vk::ClearColorValue clear_color{};
|
vk::ClearColorValue clear_color{};
|
||||||
};
|
};
|
||||||
|
@ -177,10 +177,9 @@ constexpr vk::PipelineShaderStageCreateInfo MakeStages(vk::ShaderModule compute_
|
|||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
BlitHelper::BlitHelper(const Instance& instance_, Scheduler& scheduler_, DescriptorPool& pool,
|
BlitHelper::BlitHelper(const Instance& instance_, Scheduler& scheduler_)
|
||||||
RenderpassCache& renderpass_cache_)
|
: instance{instance_}, scheduler{scheduler_}, device{instance.GetDevice()},
|
||||||
: instance{instance_}, scheduler{scheduler_}, renderpass_cache{renderpass_cache_},
|
compute_provider{instance, pool, COMPUTE_BINDINGS},
|
||||||
device{instance.GetDevice()}, compute_provider{instance, pool, COMPUTE_BINDINGS},
|
|
||||||
compute_buffer_provider{instance, pool, COMPUTE_BUFFER_BINDINGS},
|
compute_buffer_provider{instance, pool, COMPUTE_BUFFER_BINDINGS},
|
||||||
two_textures_provider{instance, pool, TWO_TEXTURES_BINDINGS},
|
two_textures_provider{instance, pool, TWO_TEXTURES_BINDINGS},
|
||||||
compute_pipeline_layout{
|
compute_pipeline_layout{
|
||||||
@ -314,7 +313,6 @@ bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest,
|
|||||||
|
|
||||||
const auto descriptor_set = compute_provider.Acquire(textures);
|
const auto descriptor_set = compute_provider.Acquire(textures);
|
||||||
|
|
||||||
renderpass_cache.EndRendering();
|
|
||||||
scheduler.Record([this, descriptor_set, copy, src_image = source.Image(),
|
scheduler.Record([this, descriptor_set, copy, src_image = source.Image(),
|
||||||
dst_image = dest.Image()](vk::CommandBuffer cmdbuf) {
|
dst_image = dest.Image()](vk::CommandBuffer cmdbuf) {
|
||||||
const std::array pre_barriers = {
|
const std::array pre_barriers = {
|
||||||
@ -418,18 +416,18 @@ bool BlitHelper::ConvertDS24S8ToRGBA8(Surface& source, Surface& dest,
|
|||||||
|
|
||||||
bool BlitHelper::DepthToBuffer(Surface& source, vk::Buffer buffer,
|
bool BlitHelper::DepthToBuffer(Surface& source, vk::Buffer buffer,
|
||||||
const VideoCore::BufferTextureCopy& copy) {
|
const VideoCore::BufferTextureCopy& copy) {
|
||||||
std::array<DescriptorData, 3> textures{};
|
std::array<vk::DescriptorImageInfo, 3> image_infos;
|
||||||
textures[0].image_info = vk::DescriptorImageInfo{
|
image_infos[0] = vk::DescriptorImageInfo{
|
||||||
.sampler = nearest_sampler,
|
.sampler = nearest_sampler,
|
||||||
.imageView = source.DepthView(),
|
.imageView = source.DepthView(),
|
||||||
.imageLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal,
|
.imageLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal,
|
||||||
};
|
};
|
||||||
textures[1].image_info = vk::DescriptorImageInfo{
|
image_infos[1] = vk::DescriptorImageInfo{
|
||||||
.sampler = nearest_sampler,
|
.sampler = nearest_sampler,
|
||||||
.imageView = source.StencilView(),
|
.imageView = source.StencilView(),
|
||||||
.imageLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal,
|
.imageLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal,
|
||||||
};
|
};
|
||||||
textures[2].buffer_info = vk::DescriptorBufferInfo{
|
image_infos[2] = vk::DescriptorBufferInfo{
|
||||||
.buffer = buffer,
|
.buffer = buffer,
|
||||||
.offset = copy.buffer_offset,
|
.offset = copy.buffer_offset,
|
||||||
.range = copy.buffer_size,
|
.range = copy.buffer_size,
|
||||||
@ -437,7 +435,6 @@ bool BlitHelper::DepthToBuffer(Surface& source, vk::Buffer buffer,
|
|||||||
|
|
||||||
const auto descriptor_set = compute_buffer_provider.Acquire(textures);
|
const auto descriptor_set = compute_buffer_provider.Acquire(textures);
|
||||||
|
|
||||||
renderpass_cache.EndRendering();
|
|
||||||
scheduler.Record([this, descriptor_set, copy, src_image = source.Image(),
|
scheduler.Record([this, descriptor_set, copy, src_image = source.Image(),
|
||||||
extent = source.RealExtent(false)](vk::CommandBuffer cmdbuf) {
|
extent = source.RealExtent(false)](vk::CommandBuffer cmdbuf) {
|
||||||
const vk::ImageMemoryBarrier pre_barrier = {
|
const vk::ImageMemoryBarrier pre_barrier = {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
#include "video_core/renderer_vulkan/vk_common.h"
|
||||||
|
|
||||||
namespace VideoCore {
|
namespace VideoCore {
|
||||||
struct TextureBlit;
|
struct TextureBlit;
|
||||||
@ -23,8 +23,7 @@ class BlitHelper {
|
|||||||
friend class TextureRuntime;
|
friend class TextureRuntime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BlitHelper(const Instance& instance, Scheduler& scheduler, DescriptorPool& pool,
|
explicit BlitHelper(const Instance& instance, Scheduler& scheduler);
|
||||||
RenderpassCache& renderpass_cache);
|
|
||||||
~BlitHelper();
|
~BlitHelper();
|
||||||
|
|
||||||
bool BlitDepthStencil(Surface& source, Surface& dest, const VideoCore::TextureBlit& blit);
|
bool BlitDepthStencil(Surface& source, Surface& dest, const VideoCore::TextureBlit& blit);
|
||||||
@ -35,23 +34,16 @@ public:
|
|||||||
const VideoCore::BufferTextureCopy& copy);
|
const VideoCore::BufferTextureCopy& copy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Creates compute pipelines used for blit
|
|
||||||
vk::Pipeline MakeComputePipeline(vk::ShaderModule shader, vk::PipelineLayout layout);
|
vk::Pipeline MakeComputePipeline(vk::ShaderModule shader, vk::PipelineLayout layout);
|
||||||
|
|
||||||
/// Creates graphics pipelines used for blit
|
|
||||||
vk::Pipeline MakeDepthStencilBlitPipeline();
|
vk::Pipeline MakeDepthStencilBlitPipeline();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Instance& instance;
|
const Instance& instance;
|
||||||
Scheduler& scheduler;
|
Scheduler& scheduler;
|
||||||
RenderpassCache& renderpass_cache;
|
|
||||||
|
|
||||||
vk::Device device;
|
vk::Device device;
|
||||||
vk::RenderPass r32_renderpass;
|
vk::RenderPass r32_renderpass;
|
||||||
|
|
||||||
DescriptorSetProvider compute_provider;
|
|
||||||
DescriptorSetProvider compute_buffer_provider;
|
|
||||||
DescriptorSetProvider two_textures_provider;
|
|
||||||
vk::PipelineLayout compute_pipeline_layout;
|
vk::PipelineLayout compute_pipeline_layout;
|
||||||
vk::PipelineLayout compute_buffer_pipeline_layout;
|
vk::PipelineLayout compute_buffer_pipeline_layout;
|
||||||
vk::PipelineLayout two_textures_pipeline_layout;
|
vk::PipelineLayout two_textures_pipeline_layout;
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
|
||||||
#define VULKAN_HPP_NO_CONSTRUCTORS
|
#define VULKAN_HPP_NO_CONSTRUCTORS
|
||||||
#define VULKAN_HPP_NO_UNION_CONSTRUCTORS
|
|
||||||
#define VULKAN_HPP_NO_STRUCT_SETTERS
|
#define VULKAN_HPP_NO_STRUCT_SETTERS
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
|
@ -1,141 +0,0 @@
|
|||||||
// Copyright 2023 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include "common/microprofile.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
MICROPROFILE_DEFINE(Vulkan_DescriptorSetAcquire, "Vulkan", "Descriptor Set Acquire",
|
|
||||||
MP_RGB(64, 128, 256));
|
|
||||||
|
|
||||||
constexpr u32 MAX_BATCH_SIZE = 8;
|
|
||||||
|
|
||||||
DescriptorPool::DescriptorPool(const Instance& instance_) : instance{instance_} {
|
|
||||||
auto& pool = pools.emplace_back();
|
|
||||||
pool = CreatePool();
|
|
||||||
}
|
|
||||||
|
|
||||||
DescriptorPool::~DescriptorPool() = default;
|
|
||||||
|
|
||||||
std::vector<vk::DescriptorSet> DescriptorPool::Allocate(vk::DescriptorSetLayout layout,
|
|
||||||
u32 num_sets) {
|
|
||||||
std::array<vk::DescriptorSetLayout, MAX_BATCH_SIZE> layouts;
|
|
||||||
layouts.fill(layout);
|
|
||||||
|
|
||||||
u32 current_pool = 0;
|
|
||||||
vk::DescriptorSetAllocateInfo alloc_info = {
|
|
||||||
.descriptorPool = *pools[current_pool],
|
|
||||||
.descriptorSetCount = num_sets,
|
|
||||||
.pSetLayouts = layouts.data(),
|
|
||||||
};
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
return instance.GetDevice().allocateDescriptorSets(alloc_info);
|
|
||||||
} catch (const vk::OutOfPoolMemoryError&) {
|
|
||||||
current_pool++;
|
|
||||||
if (current_pool == pools.size()) {
|
|
||||||
LOG_INFO(Render_Vulkan, "Run out of pools, creating new one!");
|
|
||||||
auto& pool = pools.emplace_back();
|
|
||||||
pool = CreatePool();
|
|
||||||
}
|
|
||||||
alloc_info.descriptorPool = *pools[current_pool];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::DescriptorSet DescriptorPool::Allocate(vk::DescriptorSetLayout layout) {
|
|
||||||
const auto sets = Allocate(layout, 1);
|
|
||||||
return sets[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::UniqueDescriptorPool DescriptorPool::CreatePool() {
|
|
||||||
// Choose a sane pool size good for most games
|
|
||||||
static constexpr std::array<vk::DescriptorPoolSize, 6> pool_sizes = {{
|
|
||||||
{vk::DescriptorType::eUniformBufferDynamic, 64},
|
|
||||||
{vk::DescriptorType::eUniformTexelBuffer, 64},
|
|
||||||
{vk::DescriptorType::eCombinedImageSampler, 4096},
|
|
||||||
{vk::DescriptorType::eSampledImage, 256},
|
|
||||||
{vk::DescriptorType::eStorageImage, 256},
|
|
||||||
{vk::DescriptorType::eStorageBuffer, 32},
|
|
||||||
}};
|
|
||||||
|
|
||||||
const vk::DescriptorPoolCreateInfo descriptor_pool_info = {
|
|
||||||
.maxSets = 4098,
|
|
||||||
.poolSizeCount = static_cast<u32>(pool_sizes.size()),
|
|
||||||
.pPoolSizes = pool_sizes.data(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return instance.GetDevice().createDescriptorPoolUnique(descriptor_pool_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
DescriptorSetProvider::DescriptorSetProvider(
|
|
||||||
const Instance& instance, DescriptorPool& pool_,
|
|
||||||
std::span<const vk::DescriptorSetLayoutBinding> bindings)
|
|
||||||
: pool{pool_}, device{instance.GetDevice()} {
|
|
||||||
std::array<vk::DescriptorUpdateTemplateEntry, MAX_DESCRIPTORS> update_entries;
|
|
||||||
|
|
||||||
for (u32 i = 0; i < bindings.size(); i++) {
|
|
||||||
update_entries[i] = vk::DescriptorUpdateTemplateEntry{
|
|
||||||
.dstBinding = bindings[i].binding,
|
|
||||||
.dstArrayElement = 0,
|
|
||||||
.descriptorCount = bindings[i].descriptorCount,
|
|
||||||
.descriptorType = bindings[i].descriptorType,
|
|
||||||
.offset = i * sizeof(DescriptorData),
|
|
||||||
.stride = sizeof(DescriptorData),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const vk::DescriptorSetLayoutCreateInfo layout_info = {
|
|
||||||
.bindingCount = static_cast<u32>(bindings.size()),
|
|
||||||
.pBindings = bindings.data(),
|
|
||||||
};
|
|
||||||
layout = device.createDescriptorSetLayoutUnique(layout_info);
|
|
||||||
|
|
||||||
const vk::DescriptorUpdateTemplateCreateInfo template_info = {
|
|
||||||
.descriptorUpdateEntryCount = static_cast<u32>(bindings.size()),
|
|
||||||
.pDescriptorUpdateEntries = update_entries.data(),
|
|
||||||
.templateType = vk::DescriptorUpdateTemplateType::eDescriptorSet,
|
|
||||||
.descriptorSetLayout = *layout,
|
|
||||||
};
|
|
||||||
update_template = device.createDescriptorUpdateTemplateUnique(template_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
DescriptorSetProvider::~DescriptorSetProvider() = default;
|
|
||||||
|
|
||||||
vk::DescriptorSet DescriptorSetProvider::Acquire(std::span<const DescriptorData> data) {
|
|
||||||
MICROPROFILE_SCOPE(Vulkan_DescriptorSetAcquire);
|
|
||||||
DescriptorSetData key{};
|
|
||||||
std::memcpy(key.data(), data.data(), data.size_bytes());
|
|
||||||
const auto [it, new_set] = descriptor_set_map.try_emplace(key);
|
|
||||||
if (!new_set) {
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
if (free_sets.empty()) {
|
|
||||||
free_sets = pool.Allocate(*layout, MAX_BATCH_SIZE);
|
|
||||||
}
|
|
||||||
it.value() = free_sets.back();
|
|
||||||
free_sets.pop_back();
|
|
||||||
device.updateDescriptorSetWithTemplate(it->second, *update_template, data[0]);
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptorSetProvider::FreeWithImage(vk::ImageView image_view) {
|
|
||||||
for (auto it = descriptor_set_map.begin(); it != descriptor_set_map.end();) {
|
|
||||||
const auto& [data, set] = *it;
|
|
||||||
const bool has_image = std::any_of(data.begin(), data.end(), [image_view](auto& info) {
|
|
||||||
return info.image_info.imageView == image_view;
|
|
||||||
});
|
|
||||||
if (has_image) {
|
|
||||||
free_sets.push_back(set);
|
|
||||||
it = descriptor_set_map.erase(it);
|
|
||||||
} else {
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
@ -1,92 +0,0 @@
|
|||||||
// Copyright 2023 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <span>
|
|
||||||
#include <vector>
|
|
||||||
#include <tsl/robin_map.h>
|
|
||||||
|
|
||||||
#include "common/hash.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_common.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
class Instance;
|
|
||||||
|
|
||||||
constexpr u32 MAX_DESCRIPTORS = 7;
|
|
||||||
|
|
||||||
union DescriptorData {
|
|
||||||
vk::DescriptorImageInfo image_info;
|
|
||||||
vk::DescriptorBufferInfo buffer_info;
|
|
||||||
vk::BufferView buffer_view;
|
|
||||||
|
|
||||||
bool operator==(const DescriptorData& other) const noexcept {
|
|
||||||
return std::memcmp(this, &other, sizeof(DescriptorData)) == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
using DescriptorSetData = std::array<DescriptorData, MAX_DESCRIPTORS>;
|
|
||||||
|
|
||||||
struct DataHasher {
|
|
||||||
u64 operator()(const DescriptorSetData& data) const noexcept {
|
|
||||||
return Common::ComputeHash64(data.data(), sizeof(data));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface for allocating descriptor sets that manages a collection of descriptor pools.
|
|
||||||
*/
|
|
||||||
class DescriptorPool {
|
|
||||||
public:
|
|
||||||
explicit DescriptorPool(const Instance& instance);
|
|
||||||
~DescriptorPool();
|
|
||||||
|
|
||||||
std::vector<vk::DescriptorSet> Allocate(vk::DescriptorSetLayout layout, u32 num_sets);
|
|
||||||
|
|
||||||
vk::DescriptorSet Allocate(vk::DescriptorSetLayout layout);
|
|
||||||
|
|
||||||
private:
|
|
||||||
vk::UniqueDescriptorPool CreatePool();
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Instance& instance;
|
|
||||||
std::vector<vk::UniqueDescriptorPool> pools;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates and caches descriptor sets of a specific layout.
|
|
||||||
*/
|
|
||||||
class DescriptorSetProvider {
|
|
||||||
public:
|
|
||||||
explicit DescriptorSetProvider(const Instance& instance, DescriptorPool& pool,
|
|
||||||
std::span<const vk::DescriptorSetLayoutBinding> bindings);
|
|
||||||
~DescriptorSetProvider();
|
|
||||||
|
|
||||||
vk::DescriptorSet Acquire(std::span<const DescriptorData> data);
|
|
||||||
|
|
||||||
void FreeWithImage(vk::ImageView image_view);
|
|
||||||
|
|
||||||
[[nodiscard]] vk::DescriptorSetLayout Layout() const noexcept {
|
|
||||||
return *layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] vk::DescriptorSetLayout& Layout() noexcept {
|
|
||||||
return layout.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] vk::DescriptorUpdateTemplate UpdateTemplate() const noexcept {
|
|
||||||
return *update_template;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DescriptorPool& pool;
|
|
||||||
vk::Device device;
|
|
||||||
vk::UniqueDescriptorSetLayout layout;
|
|
||||||
vk::UniqueDescriptorUpdateTemplate update_template;
|
|
||||||
std::vector<vk::DescriptorSet> free_sets;
|
|
||||||
tsl::robin_map<DescriptorSetData, vk::DescriptorSet, DataHasher> descriptor_set_map;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
75
src/video_core/renderer_vulkan/vk_descriptor_update.cpp
Normal file
75
src/video_core/renderer_vulkan/vk_descriptor_update.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// Copyright 2023 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "video_core/renderer_vulkan/vk_descriptor_update.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
constexpr size_t NUM_MAX_DESCRIPTORS = 5;
|
||||||
|
|
||||||
|
DescriptorSetSpec::DescriptorSetSpec(const Instance& instance,
|
||||||
|
std::span<const vk::DescriptorSetLayoutBinding> bindings) {
|
||||||
|
const vk::Device device = instance.GetDevice();
|
||||||
|
std::array<vk::DescriptorUpdateTemplateEntry, NUM_MAX_DESCRIPTORS> update_entries;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < bindings.size(); i++) {
|
||||||
|
update_entries[i] = vk::DescriptorUpdateTemplateEntry{
|
||||||
|
.dstBinding = bindings[i].binding,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = bindings[i].descriptorCount,
|
||||||
|
.descriptorType = bindings[i].descriptorType,
|
||||||
|
.offset = i * sizeof(DescriptorUpdateEntry),
|
||||||
|
.stride = sizeof(DescriptorUpdateEntry),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const vk::DescriptorSetLayoutCreateInfo layout_info = {
|
||||||
|
.bindingCount = static_cast<u32>(bindings.size()),
|
||||||
|
.pBindings = bindings.data(),
|
||||||
|
};
|
||||||
|
descriptor_set_layout = device.createDescriptorSetLayoutUnique(layout_info);
|
||||||
|
|
||||||
|
const vk::DescriptorUpdateTemplateCreateInfo template_info = {
|
||||||
|
.descriptorUpdateEntryCount = static_cast<u32>(bindings.size()),
|
||||||
|
.pDescriptorUpdateEntries = update_entries.data(),
|
||||||
|
.templateType = vk::DescriptorUpdateTemplateType::eDescriptorSet,
|
||||||
|
.descriptorSetLayout = descriptor_set_layout.get(),
|
||||||
|
};
|
||||||
|
update_template = device.createDescriptorUpdateTemplateUnique(template_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
DescriptorSetSpec::~DescriptorSetSpec() = default;
|
||||||
|
|
||||||
|
DescriptorUpdateQueue::DescriptorUpdateQueue(Scheduler& scheduler_, size_t num_frames_)
|
||||||
|
: scheduler{scheduler_}, num_frames{num_frames_} {
|
||||||
|
frame_payload_size = PAYLOAD_SIZE / num_frames;
|
||||||
|
payload_start = payload.data();
|
||||||
|
payload_cursor = payload.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
DescriptorUpdateQueue::~DescriptorUpdateQueue() = default;
|
||||||
|
|
||||||
|
void DescriptorUpdateQueue::TickFrame() {
|
||||||
|
if (++frame_index >= num_frames) {
|
||||||
|
frame_index = 0;
|
||||||
|
}
|
||||||
|
payload_start = payload.data() + frame_index * frame_payload_size;
|
||||||
|
payload_cursor = payload_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptorUpdateQueue::Acquire() {
|
||||||
|
// This is the maximum number of entries a single draw call might use.
|
||||||
|
static constexpr size_t MAX_ENTRIES = 0x14;
|
||||||
|
|
||||||
|
if (std::distance(payload_start, payload_cursor) + MAX_ENTRIES >= frame_payload_size) {
|
||||||
|
LOG_WARNING(Render_Vulkan, "Payload overflow, waiting for worker thread");
|
||||||
|
scheduler.WaitWorker();
|
||||||
|
payload_cursor = payload_start;
|
||||||
|
}
|
||||||
|
upload_start = payload_cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
96
src/video_core/renderer_vulkan/vk_descriptor_update.h
Normal file
96
src/video_core/renderer_vulkan/vk_descriptor_update.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
// Copyright 2023 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/literals.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_common.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
class Instance;
|
||||||
|
class Scheduler;
|
||||||
|
|
||||||
|
union DescriptorUpdateEntry {
|
||||||
|
vk::DescriptorImageInfo image;
|
||||||
|
vk::DescriptorBufferInfo buffer;
|
||||||
|
vk::BufferView texel_buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DescriptorSetSpec {
|
||||||
|
public:
|
||||||
|
explicit DescriptorSetSpec(const Instance& instance,
|
||||||
|
std::span<const vk::DescriptorSetLayoutBinding> bindings);
|
||||||
|
~DescriptorSetSpec();
|
||||||
|
|
||||||
|
vk::DescriptorSetLayout Layout() const noexcept {
|
||||||
|
return descriptor_set_layout.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::DescriptorUpdateTemplate Template() const noexcept {
|
||||||
|
return update_template.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
vk::UniqueDescriptorSetLayout descriptor_set_layout;
|
||||||
|
vk::UniqueDescriptorUpdateTemplate update_template;
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace Common::Literals;
|
||||||
|
|
||||||
|
class DescriptorUpdateQueue final {
|
||||||
|
static constexpr size_t PAYLOAD_SIZE = 1_MiB;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DescriptorUpdateQueue(Scheduler& scheduler, size_t num_frames);
|
||||||
|
~DescriptorUpdateQueue();
|
||||||
|
|
||||||
|
void TickFrame();
|
||||||
|
|
||||||
|
void Acquire();
|
||||||
|
|
||||||
|
const DescriptorUpdateEntry* UpdateData() const noexcept {
|
||||||
|
return upload_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddImage(vk::ImageView image_view) {
|
||||||
|
(payload_cursor++)->image = vk::DescriptorImageInfo{
|
||||||
|
.sampler = VK_NULL_HANDLE,
|
||||||
|
.imageView = image_view,
|
||||||
|
.imageLayout = vk::ImageLayout::eGeneral,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSampledImage(vk::ImageView image_view, vk::Sampler sampler) {
|
||||||
|
(payload_cursor++)->image = vk::DescriptorImageInfo{
|
||||||
|
.sampler = sampler,
|
||||||
|
.imageView = image_view,
|
||||||
|
.imageLayout = vk::ImageLayout::eGeneral,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddBuffer(vk::Buffer buffer, vk::DeviceSize offset, vk::DeviceSize size) {
|
||||||
|
(payload_cursor++)->buffer = vk::DescriptorBufferInfo{
|
||||||
|
.buffer = buffer,
|
||||||
|
.offset = offset,
|
||||||
|
.range = size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddTexelBuffer(vk::BufferView texel_buffer) {
|
||||||
|
*(payload_cursor++)->texel_buffer = texel_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scheduler& scheduler;
|
||||||
|
size_t num_frames{};
|
||||||
|
size_t frame_payload_size{};
|
||||||
|
size_t frame_index{};
|
||||||
|
DescriptorUpdateEntry* payload_cursor{};
|
||||||
|
DescriptorUpdateEntry* payload_start{};
|
||||||
|
const DescriptorUpdateEntry* upload_start{};
|
||||||
|
std::array<DescriptorUpdateEntry, PAYLOAD_SIZE> payload;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
@ -272,10 +272,10 @@ bool GraphicsPipeline::Build(bool fail_on_compile_required) {
|
|||||||
pipeline_info.flags |= vk::PipelineCreateFlagBits::eFailOnPipelineCompileRequiredEXT;
|
pipeline_info.flags |= vk::PipelineCreateFlagBits::eFailOnPipelineCompileRequiredEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info);
|
auto [result, handle] = device.createGraphicsPipelineUnique(pipeline_cache, pipeline_info);
|
||||||
if (result.result == vk::Result::eSuccess) {
|
if (result == vk::Result::eSuccess) {
|
||||||
pipeline = std::move(result.value);
|
pipeline = std::move(handle);
|
||||||
} else if (result.result == vk::Result::eErrorPipelineCompileRequiredEXT) {
|
} else if (result == vk::Result::eErrorPipelineCompileRequiredEXT) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
UNREACHABLE_MSG("Graphics pipeline creation failed!");
|
UNREACHABLE_MSG("Graphics pipeline creation failed!");
|
||||||
|
@ -42,22 +42,18 @@ namespace Vulkan {
|
|||||||
class Instance;
|
class Instance;
|
||||||
class RenderpassCache;
|
class RenderpassCache;
|
||||||
|
|
||||||
constexpr u32 MAX_SHADER_STAGES = 3;
|
constexpr size_t MAX_SHADER_STAGES = 3;
|
||||||
constexpr u32 MAX_VERTEX_ATTRIBUTES = 16;
|
constexpr size_t MAX_VERTEX_ATTRIBUTES = 16;
|
||||||
constexpr u32 MAX_VERTEX_BINDINGS = 13;
|
constexpr size_t MAX_VERTEX_BINDINGS = 13;
|
||||||
|
|
||||||
/**
|
|
||||||
* The pipeline state is tightly packed with bitfields to reduce
|
|
||||||
* the overhead of hashing as much as possible
|
|
||||||
*/
|
|
||||||
union RasterizationState {
|
union RasterizationState {
|
||||||
u8 value = 0;
|
u32 raw;
|
||||||
BitField<0, 2, Pica::PipelineRegs::TriangleTopology> topology;
|
BitField<0, 2, Pica::PipelineRegs::TriangleTopology> topology;
|
||||||
BitField<4, 2, Pica::RasterizerRegs::CullMode> cull_mode;
|
BitField<4, 2, Pica::RasterizerRegs::CullMode> cull_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
union DepthStencilState {
|
union DepthStencilState {
|
||||||
u32 value = 0;
|
u32 raw;
|
||||||
BitField<0, 1, u32> depth_test_enable;
|
BitField<0, 1, u32> depth_test_enable;
|
||||||
BitField<1, 1, u32> depth_write_enable;
|
BitField<1, 1, u32> depth_write_enable;
|
||||||
BitField<2, 1, u32> stencil_test_enable;
|
BitField<2, 1, u32> stencil_test_enable;
|
||||||
@ -73,7 +69,7 @@ struct BlendingState {
|
|||||||
u16 color_write_mask;
|
u16 color_write_mask;
|
||||||
Pica::FramebufferRegs::LogicOp logic_op;
|
Pica::FramebufferRegs::LogicOp logic_op;
|
||||||
union {
|
union {
|
||||||
u32 value = 0;
|
u32 raw;
|
||||||
BitField<0, 4, Pica::FramebufferRegs::BlendFactor> src_color_blend_factor;
|
BitField<0, 4, Pica::FramebufferRegs::BlendFactor> src_color_blend_factor;
|
||||||
BitField<4, 4, Pica::FramebufferRegs::BlendFactor> dst_color_blend_factor;
|
BitField<4, 4, Pica::FramebufferRegs::BlendFactor> dst_color_blend_factor;
|
||||||
BitField<8, 3, Pica::FramebufferRegs::BlendEquation> color_blend_eq;
|
BitField<8, 3, Pica::FramebufferRegs::BlendEquation> color_blend_eq;
|
||||||
@ -84,10 +80,11 @@ struct BlendingState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct DynamicState {
|
struct DynamicState {
|
||||||
u32 blend_color = 0;
|
u32 blend_color;
|
||||||
u8 stencil_reference;
|
u8 stencil_reference;
|
||||||
u8 stencil_compare_mask;
|
u8 stencil_compare_mask;
|
||||||
u8 stencil_write_mask;
|
u8 stencil_write_mask;
|
||||||
|
INSERT_PADDING_BYTES(1);
|
||||||
|
|
||||||
Common::Rectangle<u32> scissor;
|
Common::Rectangle<u32> scissor;
|
||||||
Common::Rectangle<s32> viewport;
|
Common::Rectangle<s32> viewport;
|
||||||
@ -129,12 +126,19 @@ struct AttachmentInfo {
|
|||||||
* Information about a graphics/compute pipeline
|
* Information about a graphics/compute pipeline
|
||||||
*/
|
*/
|
||||||
struct PipelineInfo {
|
struct PipelineInfo {
|
||||||
BlendingState blending;
|
BlendingState blending{};
|
||||||
AttachmentInfo attachments;
|
AttachmentInfo attachments{};
|
||||||
RasterizationState rasterization;
|
RasterizationState rasterization{};
|
||||||
DepthStencilState depth_stencil;
|
DepthStencilState depth_stencil{};
|
||||||
DynamicState dynamic;
|
DynamicState dynamic{};
|
||||||
VertexLayout vertex_layout;
|
VertexLayout vertex_layout{};
|
||||||
|
|
||||||
|
enum Type : u32 {
|
||||||
|
Normal,
|
||||||
|
ShadowPlane,
|
||||||
|
ShadowCube,
|
||||||
|
};
|
||||||
|
Type type{Type::Normal};
|
||||||
|
|
||||||
[[nodiscard]] u64 Hash(const Instance& instance) const;
|
[[nodiscard]] u64 Hash(const Instance& instance) const;
|
||||||
|
|
||||||
@ -148,6 +152,7 @@ struct PipelineInfo {
|
|||||||
return depth_write || stencil_write;
|
return depth_write || stencil_write;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
static_assert(std::has_unique_object_representations_v<PipelineInfo>);
|
||||||
|
|
||||||
struct Shader : public Common::AsyncHandle {
|
struct Shader : public Common::AsyncHandle {
|
||||||
explicit Shader(const Instance& instance);
|
explicit Shader(const Instance& instance);
|
||||||
@ -176,7 +181,7 @@ public:
|
|||||||
bool Build(bool fail_on_compile_required = false);
|
bool Build(bool fail_on_compile_required = false);
|
||||||
|
|
||||||
[[nodiscard]] vk::Pipeline Handle() const noexcept {
|
[[nodiscard]] vk::Pipeline Handle() const noexcept {
|
||||||
return *pipeline;
|
return pipeline.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/microprofile.h"
|
#include "common/microprofile.h"
|
||||||
|
#include "common/scope_exit.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "video_core/renderer_vulkan/pica_to_vk.h"
|
#include "video_core/renderer_vulkan/pica_to_vk.h"
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
@ -26,6 +27,12 @@ MICROPROFILE_DEFINE(Vulkan_Bind, "Vulkan", "Pipeline Bind", MP_RGB(192, 32, 32))
|
|||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
|
enum DescriptorSet {
|
||||||
|
Buffer,
|
||||||
|
Texture,
|
||||||
|
Utility,
|
||||||
|
};
|
||||||
|
|
||||||
u32 AttribBytes(Pica::PipelineRegs::VertexAttributeFormat format, u32 size) {
|
u32 AttribBytes(Pica::PipelineRegs::VertexAttributeFormat format, u32 size) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case Pica::PipelineRegs::VertexAttributeFormat::FLOAT:
|
case Pica::PipelineRegs::VertexAttributeFormat::FLOAT:
|
||||||
@ -61,35 +68,33 @@ constexpr std::array<vk::DescriptorSetLayoutBinding, 6> BUFFER_BINDINGS = {{
|
|||||||
{5, vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eFragment},
|
{5, vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eFragment},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
constexpr std::array<vk::DescriptorSetLayoutBinding, 4> TEXTURE_BINDINGS = {{
|
template <vk::DescriptorType tex0_type, u32 num_faces>
|
||||||
{0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
constexpr std::array<vk::DescriptorSetLayoutBinding, 3> TEXTURE_BINDINGS = {{
|
||||||
|
{0, tex0_type, num_faces, vk::ShaderStageFlagBits::eFragment},
|
||||||
{1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
{1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
||||||
{2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
{2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
||||||
{3, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// TODO: Use descriptor array for shadow cube
|
constexpr std::array<vk::DescriptorSetLayoutBinding, 1> UTILITY_BINDINGS = {{
|
||||||
constexpr std::array<vk::DescriptorSetLayoutBinding, 7> SHADOW_BINDINGS = {{
|
|
||||||
{0, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
{0, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
||||||
{1, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
{2, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
{3, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
{4, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
{5, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
{6, vk::DescriptorType::eStorageImage, 1, vk::ShaderStageFlagBits::eFragment},
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_,
|
PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_,
|
||||||
RenderpassCache& renderpass_cache_, DescriptorPool& pool_)
|
RenderpassCache& renderpass_cache_, DescriptorPool& persistent_pool)
|
||||||
: instance{instance_}, scheduler{scheduler_}, renderpass_cache{renderpass_cache_}, pool{pool_},
|
: instance{instance_}, scheduler{scheduler_},
|
||||||
|
renderpass_cache{renderpass_cache_}, pool{instance, scheduler.GetMasterSemaphore()},
|
||||||
num_worker_threads{std::max(std::thread::hardware_concurrency(), 2U)},
|
num_worker_threads{std::max(std::thread::hardware_concurrency(), 2U)},
|
||||||
workers{num_worker_threads, "Pipeline workers"},
|
workers{num_worker_threads, "Pipeline workers"}, buffer_set_spec{instance, BUFFER_BINDINGS},
|
||||||
descriptor_set_providers{DescriptorSetProvider{instance, pool, BUFFER_BINDINGS},
|
utility_set_spec{instance, UTILITY_BINDINGS},
|
||||||
DescriptorSetProvider{instance, pool, TEXTURE_BINDINGS},
|
texture_set_specs{
|
||||||
DescriptorSetProvider{instance, pool, SHADOW_BINDINGS}},
|
DescriptorSetSpec{instance,
|
||||||
|
TEXTURE_BINDINGS<vk::DescriptorType::eCombinedImageSampler, 1>},
|
||||||
|
DescriptorSetSpec{instance, TEXTURE_BINDINGS<vk::DescriptorType::eStorageImage, 1>},
|
||||||
|
DescriptorSetSpec{instance, TEXTURE_BINDINGS<vk::DescriptorType::eStorageImage, 6>}},
|
||||||
trivial_vertex_shader{
|
trivial_vertex_shader{
|
||||||
instance, vk::ShaderStageFlagBits::eVertex,
|
instance, vk::ShaderStageFlagBits::eVertex,
|
||||||
GLSL::GenerateTrivialVertexShader(instance.IsShaderClipDistanceSupported(), true)} {
|
GLSL::GenerateTrivialVertexShader(instance.IsShaderClipDistanceSupported(), true)} {
|
||||||
|
// Create profile for driver assisted shader features.
|
||||||
profile = Pica::Shader::Profile{
|
profile = Pica::Shader::Profile{
|
||||||
.has_separable_shaders = true,
|
.has_separable_shaders = true,
|
||||||
.has_clip_planes = instance.IsShaderClipDistanceSupported(),
|
.has_clip_planes = instance.IsShaderClipDistanceSupported(),
|
||||||
@ -102,14 +107,10 @@ PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_,
|
|||||||
.has_logic_op = !instance.NeedsLogicOpEmulation(),
|
.has_logic_op = !instance.NeedsLogicOpEmulation(),
|
||||||
.is_vulkan = true,
|
.is_vulkan = true,
|
||||||
};
|
};
|
||||||
BuildLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::BuildLayout() {
|
|
||||||
std::array<vk::DescriptorSetLayout, NUM_RASTERIZER_SETS> descriptor_set_layouts;
|
std::array<vk::DescriptorSetLayout, NUM_RASTERIZER_SETS> descriptor_set_layouts;
|
||||||
std::transform(descriptor_set_providers.begin(), descriptor_set_providers.end(),
|
descriptor_set_layouts[DescriptorSet::Buffer] = buffer_set_spec.Layout();
|
||||||
descriptor_set_layouts.begin(),
|
descriptor_set_layouts[DescriptorSet::Utility] = utility_set_spec.Layout();
|
||||||
[](const auto& provider) { return provider.Layout(); });
|
|
||||||
|
|
||||||
const vk::PipelineLayoutCreateInfo layout_info = {
|
const vk::PipelineLayoutCreateInfo layout_info = {
|
||||||
.setLayoutCount = NUM_RASTERIZER_SETS,
|
.setLayoutCount = NUM_RASTERIZER_SETS,
|
||||||
@ -117,7 +118,15 @@ void PipelineCache::BuildLayout() {
|
|||||||
.pushConstantRangeCount = 0,
|
.pushConstantRangeCount = 0,
|
||||||
.pPushConstantRanges = nullptr,
|
.pPushConstantRanges = nullptr,
|
||||||
};
|
};
|
||||||
pipeline_layout = instance.GetDevice().createPipelineLayoutUnique(layout_info);
|
|
||||||
|
// Create rasterizer pipeline layouts.
|
||||||
|
for (size_t i = 0; i < NUM_PIPELINE_CONFIGS; i++) {
|
||||||
|
descriptor_set_layouts[DescriptorSet::Texture] = texture_set_specs[i].Layout();
|
||||||
|
pipeline_layouts[i] = instance.GetDevice().createPipelineLayoutUnique(layout_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate buffer descriptor set from the persistent pool
|
||||||
|
bound_descriptor_sets[DescriptorSet::Buffer] = persistent_pool.Commit(buffer_set_spec.Layout());
|
||||||
}
|
}
|
||||||
|
|
||||||
PipelineCache::~PipelineCache() {
|
PipelineCache::~PipelineCache() {
|
||||||
@ -129,57 +138,64 @@ void PipelineCache::LoadDiskCache() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string cache_file_path = fmt::format("{}{:x}{:x}.bin", GetPipelineCacheDir(),
|
const auto cache_dir = GetPipelineCacheDir();
|
||||||
instance.GetVendorID(), instance.GetDeviceID());
|
const u32 vendor_id = instance.GetVendorID();
|
||||||
vk::PipelineCacheCreateInfo cache_info = {
|
const u32 device_id = instance.GetDeviceID();
|
||||||
.initialDataSize = 0,
|
const auto cache_file_path = fmt::format("{}{:x}{:x}.bin", cache_dir, vendor_id, device_id);
|
||||||
.pInitialData = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
vk::PipelineCacheCreateInfo cache_info{};
|
||||||
std::vector<u8> cache_data;
|
std::vector<u8> cache_data;
|
||||||
FileUtil::IOFile cache_file{cache_file_path, "r"};
|
|
||||||
if (cache_file.IsOpen()) {
|
SCOPE_EXIT({
|
||||||
LOG_INFO(Render_Vulkan, "Loading pipeline cache");
|
const vk::Device device = instance.GetDevice();
|
||||||
|
pipeline_cache = device.createPipelineCacheUnique(cache_info);
|
||||||
|
});
|
||||||
|
|
||||||
|
FileUtil::IOFile cache_file{cache_file_path, "rb"};
|
||||||
|
if (!cache_file.IsOpen()) {
|
||||||
|
LOG_INFO(Render_Vulkan, "No pipeline cache found for device");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const u64 cache_file_size = cache_file.GetSize();
|
const u64 cache_file_size = cache_file.GetSize();
|
||||||
cache_data.resize(cache_file_size);
|
cache_data.resize(cache_file_size);
|
||||||
if (cache_file.ReadBytes(cache_data.data(), cache_file_size)) {
|
if (cache_file.ReadBytes(cache_data.data(), cache_file_size) != cache_file_size) {
|
||||||
|
LOG_ERROR(Render_Vulkan, "Error during pipeline cache read, removing");
|
||||||
|
FileUtil::Delete(cache_file_path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsCacheValid(cache_data)) {
|
if (!IsCacheValid(cache_data)) {
|
||||||
LOG_WARNING(Render_Vulkan, "Pipeline cache provided invalid, ignoring");
|
LOG_WARNING(Render_Vulkan, "Pipeline cache provided invalid, ignoring");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
LOG_INFO(Render_Vulkan, "Loading pipeline cache with size {} KB", cache_file_size / 1024);
|
||||||
cache_info.initialDataSize = cache_file_size;
|
cache_info.initialDataSize = cache_file_size;
|
||||||
cache_info.pInitialData = cache_data.data();
|
cache_info.pInitialData = cache_data.data();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
cache_file.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::Device device = instance.GetDevice();
|
|
||||||
pipeline_cache = device.createPipelineCacheUnique(cache_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::SaveDiskCache() {
|
void PipelineCache::SaveDiskCache() {
|
||||||
if (!Settings::values.use_disk_shader_cache || !EnsureDirectories() || !pipeline_cache) {
|
if (!Settings::values.use_disk_shader_cache || !EnsureDirectories() || !pipeline_cache) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string cache_file_path = fmt::format("{}{:x}{:x}.bin", GetPipelineCacheDir(),
|
const auto cache_dir = GetPipelineCacheDir();
|
||||||
instance.GetVendorID(), instance.GetDeviceID());
|
const u32 vendor_id = instance.GetVendorID();
|
||||||
|
const u32 device_id = instance.GetDeviceID();
|
||||||
|
const auto cache_file_path = fmt::format("{}{:x}{:x}.bin", cache_dir, vendor_id, device_id);
|
||||||
|
|
||||||
FileUtil::IOFile cache_file{cache_file_path, "wb"};
|
FileUtil::IOFile cache_file{cache_file_path, "wb"};
|
||||||
if (!cache_file.IsOpen()) {
|
if (!cache_file.IsOpen()) {
|
||||||
LOG_ERROR(Render_Vulkan, "Unable to open pipeline cache for writing");
|
LOG_ERROR(Render_Vulkan, "Unable to open pipeline cache for writing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
auto cache_data = device.getPipelineCacheData(*pipeline_cache);
|
const auto cache_data = device.getPipelineCacheData(*pipeline_cache);
|
||||||
if (!cache_file.WriteBytes(cache_data.data(), cache_data.size())) {
|
if (cache_file.WriteBytes(cache_data.data(), cache_data.size()) != cache_data.size()) {
|
||||||
LOG_ERROR(Render_Vulkan, "Error during pipeline cache write");
|
LOG_ERROR(Render_Vulkan, "Error during pipeline cache write, removing");
|
||||||
return;
|
FileUtil::Delete(cache_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_file.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PipelineCache::BindPipeline(const PipelineInfo& info, bool wait_built) {
|
bool PipelineCache::BindPipeline(const PipelineInfo& info, bool wait_built) {
|
||||||
@ -195,12 +211,14 @@ bool PipelineCache::BindPipeline(const PipelineInfo& info, bool wait_built) {
|
|||||||
|
|
||||||
auto [it, new_pipeline] = graphics_pipelines.try_emplace(pipeline_hash);
|
auto [it, new_pipeline] = graphics_pipelines.try_emplace(pipeline_hash);
|
||||||
if (new_pipeline) {
|
if (new_pipeline) {
|
||||||
it.value() =
|
const auto pipeline_layout = pipeline_layouts[info.type].get();
|
||||||
std::make_unique<GraphicsPipeline>(instance, renderpass_cache, info, *pipeline_cache,
|
auto pipeline = std::make_unique<GraphicsPipeline>(instance, renderpass_cache, info,
|
||||||
*pipeline_layout, current_shaders, &workers);
|
pipeline_cache.get(), pipeline_layout,
|
||||||
|
current_shaders, &workers);
|
||||||
|
it.value() = std::move(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsPipeline* const pipeline{it->second.get()};
|
GraphicsPipeline* const pipeline = it->second.get();
|
||||||
if (!pipeline->IsDone() && !pipeline->TryBuild(wait_built)) {
|
if (!pipeline->IsDone() && !pipeline->TryBuild(wait_built)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -403,7 +421,7 @@ bool PipelineCache::UseProgrammableVertexShader(const Pica::Regs& regs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto [iter, new_program] = programmable_vertex_cache.try_emplace(program, instance);
|
auto [iter, new_program] = programmable_vertex_cache.try_emplace(program, instance);
|
||||||
auto& shader = iter->second;
|
auto& shader = iter.value();
|
||||||
|
|
||||||
if (new_program) {
|
if (new_program) {
|
||||||
shader.program = std::move(program);
|
shader.program = std::move(program);
|
||||||
@ -414,7 +432,7 @@ bool PipelineCache::UseProgrammableVertexShader(const Pica::Regs& regs,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second = &shader;
|
it.value() = &shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader* const shader{it->second};
|
Shader* const shader{it->second};
|
||||||
@ -442,7 +460,7 @@ bool PipelineCache::UseFixedGeometryShader(const Pica::Regs& regs) {
|
|||||||
|
|
||||||
const PicaFixedGSConfig gs_config{regs, instance.IsShaderClipDistanceSupported()};
|
const PicaFixedGSConfig gs_config{regs, instance.IsShaderClipDistanceSupported()};
|
||||||
auto [it, new_shader] = fixed_geometry_shaders.try_emplace(gs_config, instance);
|
auto [it, new_shader] = fixed_geometry_shaders.try_emplace(gs_config, instance);
|
||||||
auto& shader = it->second;
|
auto& shader = it.value();
|
||||||
|
|
||||||
if (new_shader) {
|
if (new_shader) {
|
||||||
workers.QueueWork([gs_config, device = instance.GetDevice(), &shader]() {
|
workers.QueueWork([gs_config, device = instance.GetDevice(), &shader]() {
|
||||||
@ -467,7 +485,7 @@ void PipelineCache::UseFragmentShader(const Pica::Regs& regs,
|
|||||||
const Pica::Shader::UserConfig& user) {
|
const Pica::Shader::UserConfig& user) {
|
||||||
const FSConfig fs_config{regs, user, profile};
|
const FSConfig fs_config{regs, user, profile};
|
||||||
const auto [it, new_shader] = fragment_shaders.try_emplace(fs_config, instance);
|
const auto [it, new_shader] = fragment_shaders.try_emplace(fs_config, instance);
|
||||||
auto& shader = it->second;
|
auto& shader = it.value();
|
||||||
|
|
||||||
if (new_shader) {
|
if (new_shader) {
|
||||||
const bool use_spirv = Settings::values.spirv_shader_gen.GetValue();
|
const bool use_spirv = Settings::values.spirv_shader_gen.GetValue();
|
||||||
@ -489,52 +507,6 @@ void PipelineCache::UseFragmentShader(const Pica::Regs& regs,
|
|||||||
shader_hashes[ProgramType::FS] = fs_config.Hash();
|
shader_hashes[ProgramType::FS] = fs_config.Hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineCache::BindTexture(u32 binding, vk::ImageView image_view, vk::Sampler sampler) {
|
|
||||||
auto& info = update_data[1][binding].image_info;
|
|
||||||
if (info.imageView == image_view && info.sampler == sampler) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
set_dirty[1] = true;
|
|
||||||
info = vk::DescriptorImageInfo{
|
|
||||||
.sampler = sampler,
|
|
||||||
.imageView = image_view,
|
|
||||||
.imageLayout = vk::ImageLayout::eGeneral,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::BindStorageImage(u32 binding, vk::ImageView image_view) {
|
|
||||||
auto& info = update_data[2][binding].image_info;
|
|
||||||
if (info.imageView == image_view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
set_dirty[2] = true;
|
|
||||||
info = vk::DescriptorImageInfo{
|
|
||||||
.imageView = image_view,
|
|
||||||
.imageLayout = vk::ImageLayout::eGeneral,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::BindBuffer(u32 binding, vk::Buffer buffer, u32 offset, u32 size) {
|
|
||||||
auto& info = update_data[0][binding].buffer_info;
|
|
||||||
if (info.buffer == buffer && info.offset == offset && info.range == size) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
set_dirty[0] = true;
|
|
||||||
info = vk::DescriptorBufferInfo{
|
|
||||||
.buffer = buffer,
|
|
||||||
.offset = offset,
|
|
||||||
.range = size,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::BindTexelBuffer(u32 binding, vk::BufferView buffer_view) {
|
|
||||||
auto& view = update_data[0][binding].buffer_view;
|
|
||||||
if (view != buffer_view) {
|
|
||||||
set_dirty[0] = true;
|
|
||||||
view = buffer_view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipelineCache::SetBufferOffset(u32 binding, size_t offset) {
|
void PipelineCache::SetBufferOffset(u32 binding, size_t offset) {
|
||||||
if (offsets[binding] != static_cast<u32>(offset)) {
|
if (offsets[binding] != static_cast<u32>(offset)) {
|
||||||
offsets[binding] = static_cast<u32>(offset);
|
offsets[binding] = static_cast<u32>(offset);
|
||||||
|
@ -6,9 +6,11 @@
|
|||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <tsl/robin_map.h>
|
#include <tsl/robin_map.h>
|
||||||
|
#include "common/thread_worker.h"
|
||||||
|
|
||||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
#include "video_core/renderer_vulkan/vk_descriptor_update.h"
|
||||||
#include "video_core/renderer_vulkan/vk_graphics_pipeline.h"
|
#include "video_core/renderer_vulkan/vk_graphics_pipeline.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_resource_pool.h"
|
||||||
#include "video_core/shader/generator/pica_fs_config.h"
|
#include "video_core/shader/generator/pica_fs_config.h"
|
||||||
#include "video_core/shader/generator/profile.h"
|
#include "video_core/shader/generator/profile.h"
|
||||||
#include "video_core/shader/generator/shader_gen.h"
|
#include "video_core/shader/generator/shader_gen.h"
|
||||||
@ -28,22 +30,25 @@ class Scheduler;
|
|||||||
class RenderpassCache;
|
class RenderpassCache;
|
||||||
class DescriptorPool;
|
class DescriptorPool;
|
||||||
|
|
||||||
constexpr u32 NUM_RASTERIZER_SETS = 3;
|
enum class PipelineConfig {
|
||||||
constexpr u32 NUM_DYNAMIC_OFFSETS = 3;
|
Normal,
|
||||||
|
ShadowPlane,
|
||||||
|
ShadowCube,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a collection of rasterizer pipelines used during rendering.
|
* Stores a collection of rasterizer pipelines used during rendering.
|
||||||
*/
|
*/
|
||||||
class PipelineCache {
|
class PipelineCache {
|
||||||
|
static constexpr size_t NUM_RASTERIZER_SETS = 3;
|
||||||
|
static constexpr size_t NUM_PIPELINE_CONFIGS = 3;
|
||||||
|
static constexpr size_t NUM_DYNAMIC_OFFSETS = 3;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PipelineCache(const Instance& instance, Scheduler& scheduler,
|
explicit PipelineCache(const Instance& instance, Scheduler& scheduler,
|
||||||
RenderpassCache& renderpass_cache, DescriptorPool& pool);
|
RenderpassCache& renderpass_cache, DescriptorPool& pool);
|
||||||
~PipelineCache();
|
~PipelineCache();
|
||||||
|
|
||||||
[[nodiscard]] DescriptorSetProvider& TextureProvider() noexcept {
|
|
||||||
return descriptor_set_providers[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads the pipeline cache stored to disk
|
/// Loads the pipeline cache stored to disk
|
||||||
void LoadDiskCache();
|
void LoadDiskCache();
|
||||||
|
|
||||||
@ -69,25 +74,10 @@ public:
|
|||||||
/// Binds a fragment shader generated from PICA state
|
/// Binds a fragment shader generated from PICA state
|
||||||
void UseFragmentShader(const Pica::Regs& regs, const Pica::Shader::UserConfig& user);
|
void UseFragmentShader(const Pica::Regs& regs, const Pica::Shader::UserConfig& user);
|
||||||
|
|
||||||
/// Binds a texture to the specified binding
|
|
||||||
void BindTexture(u32 binding, vk::ImageView image_view, vk::Sampler sampler);
|
|
||||||
|
|
||||||
/// Binds a storage image to the specified binding
|
|
||||||
void BindStorageImage(u32 binding, vk::ImageView image_view);
|
|
||||||
|
|
||||||
/// Binds a buffer to the specified binding
|
|
||||||
void BindBuffer(u32 binding, vk::Buffer buffer, u32 offset, u32 size);
|
|
||||||
|
|
||||||
/// Binds a buffer to the specified binding
|
|
||||||
void BindTexelBuffer(u32 binding, vk::BufferView buffer_view);
|
|
||||||
|
|
||||||
/// Sets the dynamic offset for the uniform buffer at binding
|
/// Sets the dynamic offset for the uniform buffer at binding
|
||||||
void SetBufferOffset(u32 binding, size_t offset);
|
void BindBufferRange(u32 binding, size_t offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Builds the rasterizer pipeline layout
|
|
||||||
void BuildLayout();
|
|
||||||
|
|
||||||
/// Returns true when the disk data can be used by the current driver
|
/// Returns true when the disk data can be used by the current driver
|
||||||
bool IsCacheValid(std::span<const u8> cache_data) const;
|
bool IsCacheValid(std::span<const u8> cache_data) const;
|
||||||
|
|
||||||
@ -101,11 +91,10 @@ private:
|
|||||||
const Instance& instance;
|
const Instance& instance;
|
||||||
Scheduler& scheduler;
|
Scheduler& scheduler;
|
||||||
RenderpassCache& renderpass_cache;
|
RenderpassCache& renderpass_cache;
|
||||||
DescriptorPool& pool;
|
DescriptorPool pool;
|
||||||
|
|
||||||
Pica::Shader::Profile profile{};
|
Pica::Shader::Profile profile{};
|
||||||
vk::UniquePipelineCache pipeline_cache;
|
vk::UniquePipelineCache pipeline_cache;
|
||||||
vk::UniquePipelineLayout pipeline_layout;
|
|
||||||
std::size_t num_worker_threads;
|
std::size_t num_worker_threads;
|
||||||
Common::ThreadWorker workers;
|
Common::ThreadWorker workers;
|
||||||
PipelineInfo current_info{};
|
PipelineInfo current_info{};
|
||||||
@ -113,18 +102,21 @@ private:
|
|||||||
tsl::robin_map<u64, std::unique_ptr<GraphicsPipeline>, Common::IdentityHash<u64>>
|
tsl::robin_map<u64, std::unique_ptr<GraphicsPipeline>, Common::IdentityHash<u64>>
|
||||||
graphics_pipelines;
|
graphics_pipelines;
|
||||||
|
|
||||||
std::array<DescriptorSetProvider, NUM_RASTERIZER_SETS> descriptor_set_providers;
|
DescriptorSetSpec buffer_set_spec;
|
||||||
std::array<DescriptorSetData, NUM_RASTERIZER_SETS> update_data{};
|
DescriptorSetSpec utility_set_spec;
|
||||||
std::array<vk::DescriptorSet, NUM_RASTERIZER_SETS> bound_descriptor_sets{};
|
std::array<DescriptorSetSpec, NUM_PIPELINE_CONFIGS> texture_set_specs;
|
||||||
|
std::array<vk::UniquePipelineLayout, NUM_PIPELINE_CONFIGS> pipeline_layouts;
|
||||||
|
|
||||||
|
std::array<vk::DescriptorSet, NUM_RASTERIZER_SETS> bound_descriptor_sets;
|
||||||
std::array<u32, NUM_DYNAMIC_OFFSETS> offsets{};
|
std::array<u32, NUM_DYNAMIC_OFFSETS> offsets{};
|
||||||
std::bitset<NUM_RASTERIZER_SETS> set_dirty{};
|
std::bitset<NUM_RASTERIZER_SETS> set_dirty{};
|
||||||
|
|
||||||
std::array<u64, MAX_SHADER_STAGES> shader_hashes;
|
std::array<u64, MAX_SHADER_STAGES> shader_hashes;
|
||||||
std::array<Shader*, MAX_SHADER_STAGES> current_shaders;
|
std::array<Shader*, MAX_SHADER_STAGES> current_shaders;
|
||||||
std::unordered_map<Pica::Shader::Generator::PicaVSConfig, Shader*> programmable_vertex_map;
|
tsl::robin_map<Pica::Shader::Generator::PicaVSConfig, Shader*> programmable_vertex_map;
|
||||||
std::unordered_map<std::string, Shader> programmable_vertex_cache;
|
tsl::robin_map<std::string, Shader> programmable_vertex_cache;
|
||||||
std::unordered_map<Pica::Shader::Generator::PicaFixedGSConfig, Shader> fixed_geometry_shaders;
|
tsl::robin_map<Pica::Shader::Generator::PicaFixedGSConfig, Shader> fixed_geometry_shaders;
|
||||||
std::unordered_map<Pica::Shader::FSConfig, Shader> fragment_shaders;
|
tsl::robin_map<Pica::Shader::FSConfig, Shader> fragment_shaders;
|
||||||
Shader trivial_vertex_shader;
|
Shader trivial_vertex_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,8 +106,7 @@ PresentWindow::PresentWindow(Frontend::EmuWindow& emu_window_, const Instance& i
|
|||||||
vsync_enabled{Settings::values.use_vsync_new.GetValue()},
|
vsync_enabled{Settings::values.use_vsync_new.GetValue()},
|
||||||
blit_supported{
|
blit_supported{
|
||||||
CanBlitToSwapchain(instance.GetPhysicalDevice(), swapchain.GetSurfaceFormat().format)},
|
CanBlitToSwapchain(instance.GetPhysicalDevice(), swapchain.GetSurfaceFormat().format)},
|
||||||
use_present_thread{Settings::values.async_presentation.GetValue()},
|
use_present_thread{Settings::values.async_presentation.GetValue()} {
|
||||||
last_render_surface{emu_window.GetWindowInfo().render_surface} {
|
|
||||||
|
|
||||||
const u32 num_images = swapchain.GetImageCount();
|
const u32 num_images = swapchain.GetImageCount();
|
||||||
const vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
@ -130,6 +129,7 @@ PresentWindow::PresentWindow(Frontend::EmuWindow& emu_window_, const Instance& i
|
|||||||
for (u32 i = 0; i < num_images; i++) {
|
for (u32 i = 0; i < num_images; i++) {
|
||||||
Frame& frame = swap_chain[i];
|
Frame& frame = swap_chain[i];
|
||||||
frame.cmdbuf = command_buffers[i];
|
frame.cmdbuf = command_buffers[i];
|
||||||
|
frame.index = i;
|
||||||
frame.render_ready = device.createSemaphore({});
|
frame.render_ready = device.createSemaphore({});
|
||||||
frame.present_done = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled});
|
frame.present_done = device.createFence({.flags = vk::FenceCreateFlagBits::eSignaled});
|
||||||
free_queue.push(&frame);
|
free_queue.push(&frame);
|
||||||
@ -155,7 +155,7 @@ PresentWindow::~PresentWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PresentWindow::RecreateFrame(Frame* frame, u32 width, u32 height) {
|
void PresentWindow::RecreateFrame(Frame* frame, u32 width, u32 height) {
|
||||||
vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
if (frame->framebuffer) {
|
if (frame->framebuffer) {
|
||||||
device.destroyFramebuffer(frame->framebuffer);
|
device.destroyFramebuffer(frame->framebuffer);
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ Frame* PresentWindow::GetRenderFrame() {
|
|||||||
Frame* frame = free_queue.front();
|
Frame* frame = free_queue.front();
|
||||||
free_queue.pop();
|
free_queue.pop();
|
||||||
|
|
||||||
vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
vk::Result result{};
|
vk::Result result{};
|
||||||
|
|
||||||
const auto wait = [&]() {
|
const auto wait = [&]() {
|
||||||
@ -452,7 +452,7 @@ void PresentWindow::CopyToSwapchain(Frame* frame) {
|
|||||||
const vk::Semaphore image_acquired = swapchain.GetImageAcquiredSemaphore();
|
const vk::Semaphore image_acquired = swapchain.GetImageAcquiredSemaphore();
|
||||||
const std::array wait_semaphores = {image_acquired, frame->render_ready};
|
const std::array wait_semaphores = {image_acquired, frame->render_ready};
|
||||||
|
|
||||||
vk::SubmitInfo submit_info = {
|
const vk::SubmitInfo submit_info = {
|
||||||
.waitSemaphoreCount = static_cast<u32>(wait_semaphores.size()),
|
.waitSemaphoreCount = static_cast<u32>(wait_semaphores.size()),
|
||||||
.pWaitSemaphores = wait_semaphores.data(),
|
.pWaitSemaphores = wait_semaphores.data(),
|
||||||
.pWaitDstStageMask = wait_stage_masks.data(),
|
.pWaitDstStageMask = wait_stage_masks.data(),
|
||||||
@ -467,8 +467,7 @@ void PresentWindow::CopyToSwapchain(Frame* frame) {
|
|||||||
try {
|
try {
|
||||||
graphics_queue.submit(submit_info, frame->present_done);
|
graphics_queue.submit(submit_info, frame->present_done);
|
||||||
} catch (vk::DeviceLostError& err) {
|
} catch (vk::DeviceLostError& err) {
|
||||||
LOG_CRITICAL(Render_Vulkan, "Device lost during present submit: {}", err.what());
|
UNREACHABLE_MSG("Device lost during present submit: {}", err.what());
|
||||||
UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchain.Present();
|
swapchain.Present();
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "common/polyfill_thread.h"
|
#include "common/polyfill_thread.h"
|
||||||
#include "video_core/renderer_vulkan/vk_swapchain.h"
|
#include "video_core/renderer_vulkan/vk_swapchain.h"
|
||||||
@ -25,6 +24,7 @@ class RenderpassCache;
|
|||||||
struct Frame {
|
struct Frame {
|
||||||
u32 width;
|
u32 width;
|
||||||
u32 height;
|
u32 height;
|
||||||
|
u32 index;
|
||||||
VmaAllocation allocation;
|
VmaAllocation allocation;
|
||||||
vk::Framebuffer framebuffer;
|
vk::Framebuffer framebuffer;
|
||||||
vk::Image image;
|
vk::Image image;
|
||||||
@ -55,12 +55,12 @@ public:
|
|||||||
/// This is called to notify the rendering backend of a surface change
|
/// This is called to notify the rendering backend of a surface change
|
||||||
void NotifySurfaceChanged();
|
void NotifySurfaceChanged();
|
||||||
|
|
||||||
[[nodiscard]] vk::RenderPass Renderpass() const noexcept {
|
vk::RenderPass Renderpass() const noexcept {
|
||||||
return present_renderpass;
|
return present_renderpass;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ImageCount() const noexcept {
|
u32 ImageCount() const noexcept {
|
||||||
return swapchain.GetImageCount();
|
return swap_chain.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -94,7 +94,6 @@ private:
|
|||||||
bool vsync_enabled{};
|
bool vsync_enabled{};
|
||||||
bool blit_supported;
|
bool blit_supported;
|
||||||
bool use_present_thread{true};
|
bool use_present_thread{true};
|
||||||
void* last_render_surface{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
@ -89,6 +89,7 @@ RasterizerVulkan::RasterizerVulkan(Memory::MemorySystem& memory,
|
|||||||
MakeSoftwareVertexLayout();
|
MakeSoftwareVertexLayout();
|
||||||
pipeline_info.vertex_layout = software_layout;
|
pipeline_info.vertex_layout = software_layout;
|
||||||
|
|
||||||
|
// Create texture buffer views for the lighting LUTs.
|
||||||
const vk::Device device = instance.GetDevice();
|
const vk::Device device = instance.GetDevice();
|
||||||
texture_lf_view = device.createBufferViewUnique({
|
texture_lf_view = device.createBufferViewUnique({
|
||||||
.buffer = texture_lf_buffer.Handle(),
|
.buffer = texture_lf_buffer.Handle(),
|
||||||
@ -109,26 +110,14 @@ RasterizerVulkan::RasterizerVulkan(Memory::MemorySystem& memory,
|
|||||||
.range = VK_WHOLE_SIZE,
|
.range = VK_WHOLE_SIZE,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Since we don't have access to VK_EXT_descriptor_indexing we need to intiallize
|
// Update persistent buffer descriptor set with our rasterizer buffers.
|
||||||
// all descriptor sets even the ones we don't use.
|
update_queue.Acquire();
|
||||||
pipeline_cache.BindBuffer(0, uniform_buffer.Handle(), 0, sizeof(VSPicaUniformData));
|
update_queue.AddBuffer(uniform_buffer.Handle(), 0, sizeof(VSPicaUniformData));
|
||||||
pipeline_cache.BindBuffer(1, uniform_buffer.Handle(), 0, sizeof(VSUniformData));
|
update_queue.AddBuffer(uniform_buffer.Handle(), 0, sizeof(VSPicaUniformData));
|
||||||
pipeline_cache.BindBuffer(2, uniform_buffer.Handle(), 0, sizeof(FSUniformData));
|
update_queue.AddBuffer(uniform_buffer.Handle(), 0, sizeof(VSUniformData));
|
||||||
pipeline_cache.BindTexelBuffer(3, *texture_lf_view);
|
update_queue.AddTexelBuffer(texture_lf_view.get());
|
||||||
pipeline_cache.BindTexelBuffer(4, *texture_rg_view);
|
update_queue.AddTexelBuffer(texture_rg_view.get());
|
||||||
pipeline_cache.BindTexelBuffer(5, *texture_rgba_view);
|
update_queue.AddTexelBuffer(texture_rgba_view.get());
|
||||||
|
|
||||||
Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
|
|
||||||
Surface& null_cube_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_CUBE_ID);
|
|
||||||
Sampler& null_sampler = res_cache.GetSampler(VideoCore::NULL_SAMPLER_ID);
|
|
||||||
for (u32 i = 0; i < 3; i++) {
|
|
||||||
pipeline_cache.BindTexture(i, null_surface.ImageView(), null_sampler.Handle());
|
|
||||||
}
|
|
||||||
pipeline_cache.BindTexture(3, null_cube_surface.ImageView(), null_sampler.Handle());
|
|
||||||
|
|
||||||
for (u32 i = 0; i < 7; i++) {
|
|
||||||
pipeline_cache.BindStorageImage(i, null_surface.StorageView());
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncEntireState();
|
SyncEntireState();
|
||||||
}
|
}
|
||||||
@ -478,16 +467,10 @@ bool RasterizerVulkan::Draw(bool accelerate, bool is_indexed) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update attachment formats
|
||||||
pipeline_info.attachments.color = framebuffer->Format(SurfaceType::Color);
|
pipeline_info.attachments.color = framebuffer->Format(SurfaceType::Color);
|
||||||
pipeline_info.attachments.depth = framebuffer->Format(SurfaceType::Depth);
|
pipeline_info.attachments.depth = framebuffer->Format(SurfaceType::Depth);
|
||||||
|
|
||||||
if (shadow_rendering) {
|
|
||||||
pipeline_cache.BindStorageImage(6, framebuffer->ImageView(SurfaceType::Color));
|
|
||||||
} else {
|
|
||||||
Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
|
|
||||||
pipeline_cache.BindStorageImage(6, null_surface.StorageView());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update scissor uniforms
|
// Update scissor uniforms
|
||||||
const auto [scissor_x1, scissor_y2, scissor_x2, scissor_y1] = fb_helper.Scissor();
|
const auto [scissor_x1, scissor_y2, scissor_x2, scissor_y1] = fb_helper.Scissor();
|
||||||
if (fs_uniform_block_data.data.scissor_x1 != scissor_x1 ||
|
if (fs_uniform_block_data.data.scissor_x1 != scissor_x1 ||
|
||||||
@ -505,6 +488,11 @@ bool RasterizerVulkan::Draw(bool accelerate, bool is_indexed) {
|
|||||||
// Sync and bind the texture surfaces
|
// Sync and bind the texture surfaces
|
||||||
SyncTextureUnits(framebuffer);
|
SyncTextureUnits(framebuffer);
|
||||||
|
|
||||||
|
// Attach the framebuffer as storage image during shadow rendering.
|
||||||
|
if (shadow_rendering) {
|
||||||
|
update_queue.AddImage(framebuffer->ImageView(SurfaceType::Color));
|
||||||
|
}
|
||||||
|
|
||||||
// Sync and bind the shader
|
// Sync and bind the shader
|
||||||
if (shader_dirty) {
|
if (shader_dirty) {
|
||||||
pipeline_cache.UseFragmentShader(regs, user_config);
|
pipeline_cache.UseFragmentShader(regs, user_config);
|
||||||
@ -557,7 +545,17 @@ bool RasterizerVulkan::Draw(bool accelerate, bool is_indexed) {
|
|||||||
void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
||||||
using TextureType = Pica::TexturingRegs::TextureConfig::TextureType;
|
using TextureType = Pica::TexturingRegs::TextureConfig::TextureType;
|
||||||
|
|
||||||
|
// Check if the PICA texture configuration changed.
|
||||||
const auto pica_textures = regs.texturing.GetTextures();
|
const auto pica_textures = regs.texturing.GetTextures();
|
||||||
|
if (pica_textures == textures && textures[0].config.type != TextureType::TextureCube) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reserve space in the queue for incoming texture data.
|
||||||
|
// We will write the image data in the same order as defined
|
||||||
|
// in the rasterizer descriptor texture sets.
|
||||||
|
update_queue.Acquire();
|
||||||
|
|
||||||
for (u32 texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
|
for (u32 texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
|
||||||
const auto& texture = pica_textures[texture_index];
|
const auto& texture = pica_textures[texture_index];
|
||||||
|
|
||||||
@ -565,8 +563,7 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
|||||||
if (!texture.enabled) {
|
if (!texture.enabled) {
|
||||||
const Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
|
const Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
|
||||||
const Sampler& null_sampler = res_cache.GetSampler(VideoCore::NULL_SAMPLER_ID);
|
const Sampler& null_sampler = res_cache.GetSampler(VideoCore::NULL_SAMPLER_ID);
|
||||||
pipeline_cache.BindTexture(texture_index, null_surface.ImageView(),
|
update_queue.AddSampledImage(null_surface.ImageView(), null_sampler.Handle());
|
||||||
null_sampler.Handle());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +573,7 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
|||||||
case TextureType::Shadow2D: {
|
case TextureType::Shadow2D: {
|
||||||
Surface& surface = res_cache.GetTextureSurface(texture);
|
Surface& surface = res_cache.GetTextureSurface(texture);
|
||||||
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
|
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
|
||||||
pipeline_cache.BindStorageImage(0, surface.StorageView());
|
update_queue.AddImage(surface.StorageView());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case TextureType::ShadowCube: {
|
case TextureType::ShadowCube: {
|
||||||
@ -588,7 +585,6 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
UnbindSpecial();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -596,10 +592,12 @@ void RasterizerVulkan::SyncTextureUnits(const Framebuffer* framebuffer) {
|
|||||||
// Bind the texture provided by the rasterizer cache
|
// Bind the texture provided by the rasterizer cache
|
||||||
Surface& surface = res_cache.GetTextureSurface(texture);
|
Surface& surface = res_cache.GetTextureSurface(texture);
|
||||||
Sampler& sampler = res_cache.GetSampler(texture.config);
|
Sampler& sampler = res_cache.GetSampler(texture.config);
|
||||||
if (!IsFeedbackLoop(texture_index, framebuffer, surface, sampler)) {
|
if (!IsFeedbackLoop(framebuffer, surface, sampler)) {
|
||||||
pipeline_cache.BindTexture(texture_index, surface.ImageView(), sampler.Handle());
|
update_queue.AddSampledImage(surface.ImageView(), sampler.Handle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textures = pica_textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture) {
|
void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture) {
|
||||||
@ -611,13 +609,11 @@ void RasterizerVulkan::BindShadowCube(const Pica::TexturingRegs::FullTextureConf
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (CubeFace face : faces) {
|
for (CubeFace face : faces) {
|
||||||
const u32 binding = static_cast<u32>(face);
|
|
||||||
info.physical_address = regs.texturing.GetCubePhysicalAddress(face);
|
info.physical_address = regs.texturing.GetCubePhysicalAddress(face);
|
||||||
|
const auto surface_id = res_cache.GetTextureSurface(info);
|
||||||
const VideoCore::SurfaceId surface_id = res_cache.GetTextureSurface(info);
|
|
||||||
Surface& surface = res_cache.GetSurface(surface_id);
|
Surface& surface = res_cache.GetSurface(surface_id);
|
||||||
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
|
surface.flags |= VideoCore::SurfaceFlagBits::ShadowMap;
|
||||||
pipeline_cache.BindStorageImage(binding, surface.StorageView());
|
update_queue.AddImage(surface.StorageView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,13 +631,13 @@ void RasterizerVulkan::BindTextureCube(const Pica::TexturingRegs::FullTextureCon
|
|||||||
.format = texture.format,
|
.format = texture.format,
|
||||||
};
|
};
|
||||||
|
|
||||||
Surface& surface = res_cache.GetTextureCube(config);
|
const Surface& surface = res_cache.GetTextureCube(config);
|
||||||
Sampler& sampler = res_cache.GetSampler(texture.config);
|
const Sampler& sampler = res_cache.GetSampler(texture.config);
|
||||||
pipeline_cache.BindTexture(3, surface.ImageView(), sampler.Handle());
|
update_queue.AddSampledImage(surface.ImageView(), sampler.Handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasterizerVulkan::IsFeedbackLoop(u32 texture_index, const Framebuffer* framebuffer,
|
bool RasterizerVulkan::IsFeedbackLoop(const Framebuffer* framebuffer, Surface& surface,
|
||||||
Surface& surface, Sampler& sampler) {
|
Sampler& sampler) {
|
||||||
const vk::ImageView color_view = framebuffer->ImageView(SurfaceType::Color);
|
const vk::ImageView color_view = framebuffer->ImageView(SurfaceType::Color);
|
||||||
const bool is_feedback_loop = color_view == surface.ImageView();
|
const bool is_feedback_loop = color_view == surface.ImageView();
|
||||||
if (!is_feedback_loop) {
|
if (!is_feedback_loop) {
|
||||||
@ -649,20 +645,10 @@ bool RasterizerVulkan::IsFeedbackLoop(u32 texture_index, const Framebuffer* fram
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make a temporary copy of the framebuffer to sample from
|
// Make a temporary copy of the framebuffer to sample from
|
||||||
pipeline_cache.BindTexture(texture_index, surface.CopyImageView(), sampler.Handle());
|
update_queue.AddSampledImage(surface.CopyImageView(), sampler.Handle());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerVulkan::UnbindSpecial() {
|
|
||||||
Surface& null_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_ID);
|
|
||||||
const Surface& null_cube_surface = res_cache.GetSurface(VideoCore::NULL_SURFACE_CUBE_ID);
|
|
||||||
const Sampler& null_sampler = res_cache.GetSampler(VideoCore::NULL_SAMPLER_ID);
|
|
||||||
pipeline_cache.BindTexture(3, null_cube_surface.ImageView(), null_sampler.Handle());
|
|
||||||
for (u32 i = 0; i < 6; i++) {
|
|
||||||
pipeline_cache.BindStorageImage(i, null_surface.StorageView());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RasterizerVulkan::NotifyFixedFunctionPicaRegisterChanged(u32 id) {
|
void RasterizerVulkan::NotifyFixedFunctionPicaRegisterChanged(u32 id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
// Culling
|
// Culling
|
||||||
@ -1103,24 +1089,24 @@ void RasterizerVulkan::UploadUniforms(bool accelerate_draw) {
|
|||||||
auto [uniforms, offset, invalidate] =
|
auto [uniforms, offset, invalidate] =
|
||||||
uniform_buffer.Map(uniform_size, uniform_buffer_alignment);
|
uniform_buffer.Map(uniform_size, uniform_buffer_alignment);
|
||||||
|
|
||||||
u32 used_bytes = 0;
|
size_t used_bytes = 0;
|
||||||
|
|
||||||
if (sync_vs || invalidate) {
|
if (sync_vs || invalidate) {
|
||||||
std::memcpy(uniforms + used_bytes, &vs_uniform_block_data.data,
|
std::memcpy(uniforms + used_bytes, &vs_uniform_block_data.data,
|
||||||
sizeof(vs_uniform_block_data.data));
|
sizeof(vs_uniform_block_data.data));
|
||||||
|
|
||||||
pipeline_cache.SetBufferOffset(1, offset + used_bytes);
|
pipeline_cache.BindBufferRange(1, offset + used_bytes);
|
||||||
vs_uniform_block_data.dirty = false;
|
vs_uniform_block_data.dirty = false;
|
||||||
used_bytes += static_cast<u32>(uniform_size_aligned_vs);
|
used_bytes += uniform_size_aligned_vs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sync_fs || invalidate) {
|
if (sync_fs || invalidate) {
|
||||||
std::memcpy(uniforms + used_bytes, &fs_uniform_block_data.data,
|
std::memcpy(uniforms + used_bytes, &fs_uniform_block_data.data,
|
||||||
sizeof(fs_uniform_block_data.data));
|
sizeof(fs_uniform_block_data.data));
|
||||||
|
|
||||||
pipeline_cache.SetBufferOffset(2, offset + used_bytes);
|
pipeline_cache.BindBufferRange(2, offset + used_bytes);
|
||||||
fs_uniform_block_data.dirty = false;
|
fs_uniform_block_data.dirty = false;
|
||||||
used_bytes += static_cast<u32>(uniform_size_aligned_fs);
|
used_bytes += uniform_size_aligned_fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sync_vs_pica) {
|
if (sync_vs_pica) {
|
||||||
@ -1128,8 +1114,8 @@ void RasterizerVulkan::UploadUniforms(bool accelerate_draw) {
|
|||||||
vs_uniforms.uniforms.SetFromRegs(regs.vs, Pica::g_state.vs);
|
vs_uniforms.uniforms.SetFromRegs(regs.vs, Pica::g_state.vs);
|
||||||
std::memcpy(uniforms + used_bytes, &vs_uniforms, sizeof(vs_uniforms));
|
std::memcpy(uniforms + used_bytes, &vs_uniforms, sizeof(vs_uniforms));
|
||||||
|
|
||||||
pipeline_cache.SetBufferOffset(0, offset + used_bytes);
|
pipeline_cache.BindBufferRange(0, offset + used_bytes);
|
||||||
used_bytes += static_cast<u32>(uniform_size_aligned_vs_pica);
|
used_bytes += uniform_size_aligned_vs_pica;
|
||||||
}
|
}
|
||||||
|
|
||||||
uniform_buffer.Commit(used_bytes);
|
uniform_buffer.Commit(used_bytes);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "core/hw/gpu.h"
|
#include "core/hw/gpu.h"
|
||||||
#include "video_core/rasterizer_accelerated.h"
|
#include "video_core/rasterizer_accelerated.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_descriptor_update.h"
|
||||||
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
||||||
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
||||||
#include "video_core/renderer_vulkan/vk_stream_buffer.h"
|
#include "video_core/renderer_vulkan/vk_stream_buffer.h"
|
||||||
@ -104,11 +105,7 @@ private:
|
|||||||
void BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture);
|
void BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture);
|
||||||
|
|
||||||
/// Makes a temporary copy of the framebuffer if a feedback loop is detected
|
/// Makes a temporary copy of the framebuffer if a feedback loop is detected
|
||||||
bool IsFeedbackLoop(u32 texture_index, const Framebuffer* framebuffer, Surface& surface,
|
bool IsFeedbackLoop(const Framebuffer* framebuffer, Surface& surface, Sampler& sampler);
|
||||||
Sampler& sampler);
|
|
||||||
|
|
||||||
/// Unbinds all special texture unit 0 texture configurations
|
|
||||||
void UnbindSpecial();
|
|
||||||
|
|
||||||
/// Upload the uniform blocks to the uniform buffer object
|
/// Upload the uniform blocks to the uniform buffer object
|
||||||
void UploadUniforms(bool accelerate_draw);
|
void UploadUniforms(bool accelerate_draw);
|
||||||
@ -144,6 +141,7 @@ private:
|
|||||||
PipelineCache pipeline_cache;
|
PipelineCache pipeline_cache;
|
||||||
TextureRuntime runtime;
|
TextureRuntime runtime;
|
||||||
RasterizerCache res_cache;
|
RasterizerCache res_cache;
|
||||||
|
DescriptorUpdateQueue update_queue;
|
||||||
|
|
||||||
VertexLayout software_layout;
|
VertexLayout software_layout;
|
||||||
std::array<u32, 16> binding_offsets{};
|
std::array<u32, 16> binding_offsets{};
|
||||||
@ -159,6 +157,7 @@ private:
|
|||||||
vk::UniqueBufferView texture_lf_view;
|
vk::UniqueBufferView texture_lf_view;
|
||||||
vk::UniqueBufferView texture_rg_view;
|
vk::UniqueBufferView texture_rg_view;
|
||||||
vk::UniqueBufferView texture_rgba_view;
|
vk::UniqueBufferView texture_rgba_view;
|
||||||
|
Pica::TexturingRegs::Textures textures{};
|
||||||
u64 uniform_buffer_alignment;
|
u64 uniform_buffer_alignment;
|
||||||
u64 uniform_size_aligned_vs_pica;
|
u64 uniform_size_aligned_vs_pica;
|
||||||
u64 uniform_size_aligned_vs;
|
u64 uniform_size_aligned_vs;
|
||||||
|
@ -1,113 +1,147 @@
|
|||||||
// Copyright 2020 yuzu Emulator Project
|
// Copyright 2023 Citra Emulator Project
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <optional>
|
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
#include "video_core/renderer_vulkan/vk_master_semaphore.h"
|
#include "video_core/renderer_vulkan/vk_master_semaphore.h"
|
||||||
#include "video_core/renderer_vulkan/vk_resource_pool.h"
|
#include "video_core/renderer_vulkan/vk_resource_pool.h"
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
ResourcePool::ResourcePool(MasterSemaphore* master_semaphore_, size_t grow_step_)
|
ResourcePool::ResourcePool(MasterSemaphore* master_semaphore_)
|
||||||
: master_semaphore{master_semaphore_}, grow_step{grow_step_} {}
|
: master_semaphore{master_semaphore_} {}
|
||||||
|
|
||||||
std::size_t ResourcePool::CommitResource() {
|
ResourcePool::~ResourcePool() = default;
|
||||||
|
|
||||||
|
s64 ResourcePool::CommitResource() {
|
||||||
// Refresh semaphore to query updated results
|
// Refresh semaphore to query updated results
|
||||||
master_semaphore->Refresh();
|
master_semaphore->Refresh();
|
||||||
const u64 gpu_tick = master_semaphore->KnownGpuTick();
|
const u64 gpu_tick = master_semaphore->KnownGpuTick();
|
||||||
const auto search = [this, gpu_tick](std::size_t begin,
|
|
||||||
std::size_t end) -> std::optional<std::size_t> {
|
|
||||||
for (std::size_t iterator = begin; iterator < end; ++iterator) {
|
|
||||||
if (gpu_tick >= ticks[iterator]) {
|
|
||||||
ticks[iterator] = master_semaphore->CurrentTick();
|
|
||||||
return iterator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to find a free resource from the hinted position to the end.
|
// Update the last used tick of the previous resource.
|
||||||
std::optional<std::size_t> found = search(hint_iterator, ticks.size());
|
if (last_index != -1) {
|
||||||
if (!found) {
|
ticks[last_index] = master_semaphore->CurrentTick();
|
||||||
// Search from beginning to the hinted position.
|
}
|
||||||
found = search(0, hint_iterator);
|
|
||||||
if (!found) {
|
|
||||||
// Both searches failed, the pool is full; handle it.
|
|
||||||
const std::size_t free_resource = ManageOverflow();
|
|
||||||
|
|
||||||
ticks[free_resource] = master_semaphore->CurrentTick();
|
// Try to find a free resource.
|
||||||
found = free_resource;
|
size_t found = ticks.size();
|
||||||
|
for (size_t index = 0; index < ticks.size(); index++) {
|
||||||
|
if (gpu_tick >= ticks[index]) {
|
||||||
|
found = index;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free iterator is hinted to the resource after the one that's been commited.
|
// The pool is full; handle it.
|
||||||
hint_iterator = (*found + 1) % ticks.size();
|
if (found == ticks.size()) {
|
||||||
return *found;
|
ticks.resize(found + 1);
|
||||||
|
Allocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t ResourcePool::ManageOverflow() {
|
// Return found resource.
|
||||||
const std::size_t old_capacity = ticks.size();
|
last_index = found;
|
||||||
Grow();
|
return found;
|
||||||
|
|
||||||
// The last entry is guaranted to be free, since it's the first element of the freshly
|
|
||||||
// allocated resources.
|
|
||||||
return old_capacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePool::Grow() {
|
|
||||||
const size_t old_capacity = ticks.size();
|
|
||||||
ticks.resize(old_capacity + grow_step);
|
|
||||||
Allocate(old_capacity, old_capacity + grow_step);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr size_t COMMAND_BUFFER_POOL_SIZE = 4;
|
|
||||||
|
|
||||||
struct CommandPool::Pool {
|
|
||||||
vk::CommandPool handle;
|
|
||||||
std::array<vk::CommandBuffer, COMMAND_BUFFER_POOL_SIZE> cmdbufs;
|
|
||||||
};
|
|
||||||
|
|
||||||
CommandPool::CommandPool(const Instance& instance, MasterSemaphore* master_semaphore)
|
CommandPool::CommandPool(const Instance& instance, MasterSemaphore* master_semaphore)
|
||||||
: ResourcePool{master_semaphore, COMMAND_BUFFER_POOL_SIZE}, instance{instance} {}
|
: ResourcePool{master_semaphore}, device{instance.GetDevice()} {
|
||||||
|
|
||||||
CommandPool::~CommandPool() {
|
|
||||||
vk::Device device = instance.GetDevice();
|
|
||||||
for (Pool& pool : pools) {
|
|
||||||
device.destroyCommandPool(pool.handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommandPool::Allocate(std::size_t begin, std::size_t end) {
|
|
||||||
// Command buffers are going to be commited, recorded, executed every single usage cycle.
|
|
||||||
// They are also going to be reseted when commited.
|
|
||||||
Pool& pool = pools.emplace_back();
|
|
||||||
|
|
||||||
const vk::CommandPoolCreateInfo pool_create_info = {
|
const vk::CommandPoolCreateInfo pool_create_info = {
|
||||||
.flags = vk::CommandPoolCreateFlagBits::eTransient |
|
.flags = vk::CommandPoolCreateFlagBits::eTransient |
|
||||||
vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||||
.queueFamilyIndex = instance.GetGraphicsQueueFamilyIndex(),
|
.queueFamilyIndex = instance.GetGraphicsQueueFamilyIndex(),
|
||||||
};
|
};
|
||||||
|
cmdpool = device.createCommandPoolUnique(pool_create_info);
|
||||||
|
}
|
||||||
|
|
||||||
vk::Device device = instance.GetDevice();
|
CommandPool::~CommandPool() = default;
|
||||||
pool.handle = device.createCommandPool(pool_create_info);
|
|
||||||
|
void CommandPool::Allocate() {
|
||||||
|
// Command buffers are going to be commited, recorded, executed every single usage cycle.
|
||||||
|
// They are also going to be reseted when commited.
|
||||||
|
auto& cmdbuf = cmdbuffers.emplace_back();
|
||||||
|
|
||||||
const vk::CommandBufferAllocateInfo buffer_alloc_info = {
|
const vk::CommandBufferAllocateInfo buffer_alloc_info = {
|
||||||
.commandPool = pool.handle,
|
.commandPool = cmdpool.get(),
|
||||||
.level = vk::CommandBufferLevel::ePrimary,
|
.level = vk::CommandBufferLevel::ePrimary,
|
||||||
.commandBufferCount = COMMAND_BUFFER_POOL_SIZE,
|
.commandBufferCount = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto buffers = device.allocateCommandBuffers(buffer_alloc_info);
|
const auto buffers = device.allocateCommandBuffers(buffer_alloc_info);
|
||||||
std::copy(buffers.begin(), buffers.end(), pool.cmdbufs.begin());
|
cmdbuf = buffers[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::CommandBuffer CommandPool::Commit() {
|
vk::CommandBuffer CommandPool::Commit() {
|
||||||
const std::size_t index = CommitResource();
|
const size_t index = CommitResource();
|
||||||
const auto pool_index = index / COMMAND_BUFFER_POOL_SIZE;
|
return cmdbuffers[index];
|
||||||
const auto sub_index = index % COMMAND_BUFFER_POOL_SIZE;
|
}
|
||||||
return pools[pool_index].cmdbufs[sub_index];
|
|
||||||
|
constexpr size_t MAX_BATCH_SIZE = 8;
|
||||||
|
|
||||||
|
DescriptorPool::DescriptorPool(const Instance& instance, MasterSemaphore* master_semaphore)
|
||||||
|
: ResourcePool{master_semaphore}, device{instance.GetDevice()} {
|
||||||
|
// Ensure we have at least one pool available.
|
||||||
|
CommitResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
DescriptorPool::~DescriptorPool() = default;
|
||||||
|
|
||||||
|
void DescriptorPool::Allocate() {
|
||||||
|
// Descriptor pools are going to be commited and used for descriptor allocation.
|
||||||
|
// When out of memory, a new pool is allocated or an old is reused
|
||||||
|
auto& pool = pools.emplace_back();
|
||||||
|
|
||||||
|
static constexpr std::array<vk::DescriptorPoolSize, 6> pool_sizes = {{
|
||||||
|
{vk::DescriptorType::eUniformBufferDynamic, 64},
|
||||||
|
{vk::DescriptorType::eUniformTexelBuffer, 64},
|
||||||
|
{vk::DescriptorType::eCombinedImageSampler, 4096},
|
||||||
|
{vk::DescriptorType::eSampledImage, 256},
|
||||||
|
{vk::DescriptorType::eStorageImage, 256},
|
||||||
|
{vk::DescriptorType::eStorageBuffer, 32},
|
||||||
|
}};
|
||||||
|
|
||||||
|
const vk::DescriptorPoolCreateInfo descriptor_pool_info = {
|
||||||
|
.maxSets = 4098,
|
||||||
|
.poolSizeCount = static_cast<u32>(pool_sizes.size()),
|
||||||
|
.pPoolSizes = pool_sizes.data(),
|
||||||
|
};
|
||||||
|
|
||||||
|
pool = device.createDescriptorPoolUnique(descriptor_pool_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<vk::DescriptorSet> DescriptorPool::Commit(vk::DescriptorSetLayout layout,
|
||||||
|
u32 num_sets) {
|
||||||
|
ASSERT_MSG(num_sets <= MAX_BATCH_SIZE, "Cannot allocate more than {} descriptor sets",
|
||||||
|
MAX_BATCH_SIZE);
|
||||||
|
|
||||||
|
// Fill array with the layout handle
|
||||||
|
std::array<vk::DescriptorSetLayout, MAX_BATCH_SIZE> layouts;
|
||||||
|
layouts.fill(layout);
|
||||||
|
|
||||||
|
vk::DescriptorSetAllocateInfo alloc_info = {
|
||||||
|
.descriptorPool = pools[last_index].get(),
|
||||||
|
.descriptorSetCount = num_sets,
|
||||||
|
.pSetLayouts = layouts.data(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Attempt to allocate the descriptor sets.
|
||||||
|
try {
|
||||||
|
return device.allocateDescriptorSets(alloc_info);
|
||||||
|
} catch (const vk::OutOfPoolMemoryError&) {
|
||||||
|
// If out of memory switch to a new pool.
|
||||||
|
const size_t index = CommitResource();
|
||||||
|
const auto new_pool = pools[index].get();
|
||||||
|
device.resetDescriptorPool(new_pool);
|
||||||
|
alloc_info.descriptorPool = new_pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This time the allocation should succeed.
|
||||||
|
return device.allocateDescriptorSets(alloc_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::DescriptorSet DescriptorPool::Commit(vk::DescriptorSetLayout layout) {
|
||||||
|
const auto sets = Commit(layout, 1);
|
||||||
|
return sets[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2020 yuzu Emulator Project
|
// Copyright 2023 Citra Emulator Project
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
@ -13,40 +13,19 @@ namespace Vulkan {
|
|||||||
class Instance;
|
class Instance;
|
||||||
class MasterSemaphore;
|
class MasterSemaphore;
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles a pool of resources protected by fences. Manages resource overflow allocating more
|
|
||||||
* resources.
|
|
||||||
*/
|
|
||||||
class ResourcePool {
|
class ResourcePool {
|
||||||
public:
|
public:
|
||||||
explicit ResourcePool() = default;
|
explicit ResourcePool(MasterSemaphore* master_semaphore);
|
||||||
explicit ResourcePool(MasterSemaphore* master_semaphore, std::size_t grow_step);
|
virtual ~ResourcePool();
|
||||||
virtual ~ResourcePool() = default;
|
|
||||||
|
|
||||||
ResourcePool& operator=(ResourcePool&&) noexcept = default;
|
|
||||||
ResourcePool(ResourcePool&&) noexcept = default;
|
|
||||||
|
|
||||||
ResourcePool& operator=(const ResourcePool&) = default;
|
|
||||||
ResourcePool(const ResourcePool&) = default;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::size_t CommitResource();
|
s64 CommitResource();
|
||||||
|
virtual void Allocate() = 0;
|
||||||
/// Called when a chunk of resources have to be allocated.
|
|
||||||
virtual void Allocate(std::size_t begin, std::size_t end) = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Manages pool overflow allocating new resources.
|
|
||||||
std::size_t ManageOverflow();
|
|
||||||
|
|
||||||
/// Allocates a new page of resources.
|
|
||||||
void Grow();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MasterSemaphore* master_semaphore{nullptr};
|
MasterSemaphore* master_semaphore{nullptr};
|
||||||
std::size_t grow_step = 0; ///< Number of new resources created after an overflow
|
s64 last_index = -1; ///< Hint to where the last commited resource was found
|
||||||
std::size_t hint_iterator = 0; ///< Hint to where the next free resources is likely to be found
|
std::vector<u64> ticks; ///< Ticks each resource was last used
|
||||||
std::vector<u64> ticks; ///< Ticks for each resource
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CommandPool final : public ResourcePool {
|
class CommandPool final : public ResourcePool {
|
||||||
@ -54,14 +33,31 @@ public:
|
|||||||
explicit CommandPool(const Instance& instance, MasterSemaphore* master_semaphore);
|
explicit CommandPool(const Instance& instance, MasterSemaphore* master_semaphore);
|
||||||
~CommandPool() override;
|
~CommandPool() override;
|
||||||
|
|
||||||
void Allocate(std::size_t begin, std::size_t end) override;
|
void Allocate() override;
|
||||||
|
|
||||||
vk::CommandBuffer Commit();
|
vk::CommandBuffer Commit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Pool;
|
vk::Device device;
|
||||||
const Instance& instance;
|
vk::UniqueCommandPool cmdpool;
|
||||||
std::vector<Pool> pools;
|
std::vector<vk::CommandBuffer> cmdbuffers;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DescriptorPool : public ResourcePool {
|
||||||
|
public:
|
||||||
|
explicit DescriptorPool(const Instance& instance, MasterSemaphore* master_semaphore);
|
||||||
|
~DescriptorPool();
|
||||||
|
|
||||||
|
std::vector<vk::DescriptorSet> Commit(vk::DescriptorSetLayout layout, u32 num_sets);
|
||||||
|
|
||||||
|
vk::DescriptorSet Commit(vk::DescriptorSetLayout layout);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Allocate() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
vk::Device device;
|
||||||
|
std::vector<vk::UniqueDescriptorPool> pools;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
@ -56,6 +56,10 @@ public:
|
|||||||
return image_count;
|
return image_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetImageIndex() const {
|
||||||
|
return image_index;
|
||||||
|
}
|
||||||
|
|
||||||
vk::Extent2D GetExtent() const {
|
vk::Extent2D GetExtent() const {
|
||||||
return extent;
|
return extent;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "video_core/rasterizer_cache/texture_codec.h"
|
#include "video_core/rasterizer_cache/texture_codec.h"
|
||||||
#include "video_core/rasterizer_cache/utils.h"
|
#include "video_core/rasterizer_cache/utils.h"
|
||||||
#include "video_core/renderer_vulkan/pica_to_vk.h"
|
#include "video_core/renderer_vulkan/pica_to_vk.h"
|
||||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_instance.h"
|
#include "video_core/renderer_vulkan/vk_instance.h"
|
||||||
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
||||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||||
@ -253,9 +252,9 @@ constexpr u64 DOWNLOAD_BUFFER_SIZE = 16_MiB;
|
|||||||
|
|
||||||
TextureRuntime::TextureRuntime(const Instance& instance, Scheduler& scheduler,
|
TextureRuntime::TextureRuntime(const Instance& instance, Scheduler& scheduler,
|
||||||
RenderpassCache& renderpass_cache, DescriptorPool& pool,
|
RenderpassCache& renderpass_cache, DescriptorPool& pool,
|
||||||
DescriptorSetProvider& texture_provider_, u32 num_swapchain_images_)
|
u32 num_swapchain_images_)
|
||||||
: instance{instance}, scheduler{scheduler}, renderpass_cache{renderpass_cache},
|
: instance{instance}, scheduler{scheduler}, renderpass_cache{renderpass_cache},
|
||||||
texture_provider{texture_provider_}, blit_helper{instance, scheduler, pool, renderpass_cache},
|
blit_helper{instance, scheduler, pool, renderpass_cache},
|
||||||
upload_buffer{instance, scheduler, vk::BufferUsageFlagBits::eTransferSrc, UPLOAD_BUFFER_SIZE,
|
upload_buffer{instance, scheduler, vk::BufferUsageFlagBits::eTransferSrc, UPLOAD_BUFFER_SIZE,
|
||||||
BufferType::Upload},
|
BufferType::Upload},
|
||||||
download_buffer{instance, scheduler,
|
download_buffer{instance, scheduler,
|
||||||
@ -697,13 +696,6 @@ bool TextureRuntime::NeedsConversion(VideoCore::PixelFormat format) const {
|
|||||||
traits.aspect != (vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil);
|
traits.aspect != (vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureRuntime::FreeDescriptorSetsWithImage(vk::ImageView image_view) {
|
|
||||||
texture_provider.FreeWithImage(image_view);
|
|
||||||
blit_helper.compute_provider.FreeWithImage(image_view);
|
|
||||||
blit_helper.compute_buffer_provider.FreeWithImage(image_view);
|
|
||||||
blit_helper.two_textures_provider.FreeWithImage(image_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface::Surface(TextureRuntime& runtime_, const VideoCore::SurfaceParams& params)
|
Surface::Surface(TextureRuntime& runtime_, const VideoCore::SurfaceParams& params)
|
||||||
: SurfaceBase{params}, runtime{&runtime_}, instance{&runtime_.GetInstance()},
|
: SurfaceBase{params}, runtime{&runtime_}, instance{&runtime_.GetInstance()},
|
||||||
scheduler{&runtime_.GetScheduler()}, traits{instance->GetTraits(pixel_format)} {
|
scheduler{&runtime_.GetScheduler()}, traits{instance->GetTraits(pixel_format)} {
|
||||||
@ -803,9 +795,6 @@ Surface::~Surface() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const auto& [alloc, image, image_view] : handles) {
|
for (const auto& [alloc, image, image_view] : handles) {
|
||||||
if (image_view) {
|
|
||||||
runtime->FreeDescriptorSetsWithImage(*image_view);
|
|
||||||
}
|
|
||||||
if (image) {
|
if (image) {
|
||||||
vmaDestroyImage(instance->GetAllocator(), image, alloc);
|
vmaDestroyImage(instance->GetAllocator(), image, alloc);
|
||||||
}
|
}
|
||||||
@ -1558,13 +1547,13 @@ Sampler::Sampler(TextureRuntime& runtime, const VideoCore::SamplerParams& params
|
|||||||
|
|
||||||
Sampler::~Sampler() = default;
|
Sampler::~Sampler() = default;
|
||||||
|
|
||||||
DebugScope::DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string_view label)
|
DebugScope::DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string&& label)
|
||||||
: scheduler{runtime.GetScheduler()}, has_debug_tool{
|
: scheduler{runtime.GetScheduler()}, has_debug_tool{
|
||||||
runtime.GetInstance().HasDebuggingToolAttached()} {
|
runtime.GetInstance().HasDebuggingToolAttached()} {
|
||||||
if (!has_debug_tool) {
|
if (!has_debug_tool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scheduler.Record([color, label = std::string(label)](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([color, label = std::move(label)](vk::CommandBuffer cmdbuf) {
|
||||||
const vk::DebugUtilsLabelEXT debug_label = {
|
const vk::DebugUtilsLabelEXT debug_label = {
|
||||||
.pLabelName = label.data(),
|
.pLabelName = label.data(),
|
||||||
.color = std::array{color[0], color[1], color[2], color[3]},
|
.color = std::array{color[0], color[1], color[2], color[3]},
|
||||||
|
@ -42,8 +42,8 @@ class TextureRuntime {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TextureRuntime(const Instance& instance, Scheduler& scheduler,
|
explicit TextureRuntime(const Instance& instance, Scheduler& scheduler,
|
||||||
RenderpassCache& renderpass_cache, DescriptorPool& pool,
|
RenderpassCache& renderpass_cache,
|
||||||
DescriptorSetProvider& texture_provider, u32 num_swapchain_images);
|
u32 num_swapchain_images);
|
||||||
~TextureRuntime();
|
~TextureRuntime();
|
||||||
|
|
||||||
const Instance& GetInstance() const {
|
const Instance& GetInstance() const {
|
||||||
@ -85,9 +85,6 @@ public:
|
|||||||
/// Returns true if the provided pixel format needs convertion
|
/// Returns true if the provided pixel format needs convertion
|
||||||
bool NeedsConversion(VideoCore::PixelFormat format) const;
|
bool NeedsConversion(VideoCore::PixelFormat format) const;
|
||||||
|
|
||||||
/// Removes any descriptor sets that contain the provided image view.
|
|
||||||
void FreeDescriptorSetsWithImage(vk::ImageView image_view);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Clears a partial texture rect using a clear rectangle
|
/// Clears a partial texture rect using a clear rectangle
|
||||||
void ClearTextureWithRenderpass(Surface& surface, const VideoCore::TextureClear& clear);
|
void ClearTextureWithRenderpass(Surface& surface, const VideoCore::TextureClear& clear);
|
||||||
@ -96,7 +93,6 @@ private:
|
|||||||
const Instance& instance;
|
const Instance& instance;
|
||||||
Scheduler& scheduler;
|
Scheduler& scheduler;
|
||||||
RenderpassCache& renderpass_cache;
|
RenderpassCache& renderpass_cache;
|
||||||
DescriptorSetProvider& texture_provider;
|
|
||||||
BlitHelper blit_helper;
|
BlitHelper blit_helper;
|
||||||
StreamBuffer upload_buffer;
|
StreamBuffer upload_buffer;
|
||||||
StreamBuffer download_buffer;
|
StreamBuffer download_buffer;
|
||||||
@ -277,7 +273,7 @@ public:
|
|||||||
explicit DebugScope(TextureRuntime& runtime, Common::Vec4f color,
|
explicit DebugScope(TextureRuntime& runtime, Common::Vec4f color,
|
||||||
fmt::format_string<T...> format, T... args)
|
fmt::format_string<T...> format, T... args)
|
||||||
: DebugScope{runtime, color, fmt::format(format, std::forward<T>(args)...)} {}
|
: DebugScope{runtime, color, fmt::format(format, std::forward<T>(args)...)} {}
|
||||||
explicit DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string_view label);
|
explicit DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string&& label);
|
||||||
~DebugScope();
|
~DebugScope();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -10,6 +10,7 @@ using ProcTexClamp = TexturingRegs::ProcTexClamp;
|
|||||||
using ProcTexShift = TexturingRegs::ProcTexShift;
|
using ProcTexShift = TexturingRegs::ProcTexShift;
|
||||||
using ProcTexCombiner = TexturingRegs::ProcTexCombiner;
|
using ProcTexCombiner = TexturingRegs::ProcTexCombiner;
|
||||||
using ProcTexFilter = TexturingRegs::ProcTexFilter;
|
using ProcTexFilter = TexturingRegs::ProcTexFilter;
|
||||||
|
using TextureType = Pica::TexturingRegs::TextureConfig::TextureType;
|
||||||
|
|
||||||
constexpr static size_t RESERVE_SIZE = 8 * 1024 * 1024;
|
constexpr static size_t RESERVE_SIZE = 8 * 1024 * 1024;
|
||||||
|
|
||||||
@ -1265,7 +1266,7 @@ void FragmentModule::DefineExtensions() {
|
|||||||
out += "#extension GL_ARM_shader_framebuffer_fetch : enable\n";
|
out += "#extension GL_ARM_shader_framebuffer_fetch : enable\n";
|
||||||
out += "#define destFactor gl_LastFragColorARM\n";
|
out += "#define destFactor gl_LastFragColorARM\n";
|
||||||
} else {
|
} else {
|
||||||
out += "#define destFactor texelFetch(color_buffer, ivec2(gl_FragCoord.xy), 0)\n";
|
out += "#define destFactor texelFetch(tex_color, ivec2(gl_FragCoord.xy), 0)\n";
|
||||||
use_blend_fallback = true;
|
use_blend_fallback = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1301,27 +1302,32 @@ void FragmentModule::DefineInterface() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FragmentModule::DefineBindings() {
|
void FragmentModule::DefineBindings() {
|
||||||
|
// Uniform and texture buffers
|
||||||
out += FSUniformBlockDef;
|
out += FSUniformBlockDef;
|
||||||
out += "layout(binding = 3) uniform samplerBuffer texture_buffer_lut_lf;\n";
|
out += "layout(binding = 3) uniform samplerBuffer texture_buffer_lut_lf;\n";
|
||||||
out += "layout(binding = 4) uniform samplerBuffer texture_buffer_lut_rg;\n";
|
out += "layout(binding = 4) uniform samplerBuffer texture_buffer_lut_rg;\n";
|
||||||
out += "layout(binding = 5) uniform samplerBuffer texture_buffer_lut_rgba;\n\n";
|
out += "layout(binding = 5) uniform samplerBuffer texture_buffer_lut_rgba;\n\n";
|
||||||
|
|
||||||
const std::string_view texunit_set = profile.is_vulkan ? "set = 1, " : "";
|
// Texture samplers
|
||||||
|
const auto texunit_set = profile.is_vulkan ? "set = 1, " : "";
|
||||||
|
const auto texture_type = config.texture.texture0_type.Value();
|
||||||
for (u32 i = 0; i < 3; i++) {
|
for (u32 i = 0; i < 3; i++) {
|
||||||
out += fmt::format("layout({0}binding = {1}) uniform sampler2D tex{1};\n", texunit_set, i);
|
const auto sampler =
|
||||||
|
i == 0 && texture_type == TextureType::TextureCube ? "samplerCube" : "sampler2D";
|
||||||
|
out +=
|
||||||
|
fmt::format("layout({0}binding = {1}) uniform {2} tex{1};\n", texunit_set, i, sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
out += fmt::format("layout({}binding = 3) uniform samplerCube tex_cube;\n\n", texunit_set);
|
|
||||||
|
|
||||||
if (config.user.use_custom_normal && !profile.is_vulkan) {
|
if (config.user.use_custom_normal && !profile.is_vulkan) {
|
||||||
out += "layout(binding = 7) uniform sampler2D tex_normal;\n";
|
out += "layout(binding = 6) uniform sampler2D tex_normal;\n";
|
||||||
}
|
}
|
||||||
if (use_blend_fallback && !profile.is_vulkan) {
|
if (use_blend_fallback && !profile.is_vulkan) {
|
||||||
out += "layout(location = 10) uniform sampler2D color_buffer;\n";
|
out += "layout(location = 7) uniform sampler2D tex_color;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Storage images
|
||||||
static constexpr std::array postfixes = {"px", "nx", "py", "ny", "pz", "nz"};
|
static constexpr std::array postfixes = {"px", "nx", "py", "ny", "pz", "nz"};
|
||||||
const std::string_view shadow_set = profile.is_vulkan ? "set = 2, " : "";
|
const auto shadow_set = profile.is_vulkan ? "set = 2, " : "";
|
||||||
for (u32 i = 0; i < postfixes.size(); i++) {
|
for (u32 i = 0; i < postfixes.size(); i++) {
|
||||||
out += fmt::format(
|
out += fmt::format(
|
||||||
"layout({}binding = {}, r32ui) uniform readonly uimage2D shadow_texture_{};\n",
|
"layout({}binding = {}, r32ui) uniform readonly uimage2D shadow_texture_{};\n",
|
||||||
@ -1591,7 +1597,7 @@ void FragmentModule::DefineTexUnitSampler(u32 texture_unit) {
|
|||||||
out += "return textureProj(tex0, vec3(texcoord0, texcoord0_w));";
|
out += "return textureProj(tex0, vec3(texcoord0, texcoord0_w));";
|
||||||
break;
|
break;
|
||||||
case TexturingRegs::TextureConfig::TextureCube:
|
case TexturingRegs::TextureConfig::TextureCube:
|
||||||
out += "return texture(tex_cube, vec3(texcoord0, texcoord0_w));";
|
out += "return texture(tex0, vec3(texcoord0, texcoord0_w));";
|
||||||
break;
|
break;
|
||||||
case TexturingRegs::TextureConfig::Shadow2D:
|
case TexturingRegs::TextureConfig::Shadow2D:
|
||||||
out += "return shadowTexture(texcoord0, texcoord0_w);";
|
out += "return shadowTexture(texcoord0, texcoord0_w);";
|
||||||
|
@ -12,6 +12,7 @@ using Pica::LightingRegs;
|
|||||||
using Pica::RasterizerRegs;
|
using Pica::RasterizerRegs;
|
||||||
using Pica::TexturingRegs;
|
using Pica::TexturingRegs;
|
||||||
using TevStageConfig = TexturingRegs::TevStageConfig;
|
using TevStageConfig = TexturingRegs::TevStageConfig;
|
||||||
|
using TextureType = TexturingRegs::TextureConfig::TextureType;
|
||||||
|
|
||||||
constexpr u32 SPIRV_VERSION_1_3 = 0x00010300;
|
constexpr u32 SPIRV_VERSION_1_3 = 0x00010300;
|
||||||
|
|
||||||
@ -977,7 +978,7 @@ void FragmentModule::DefineTexSampler(u32 texture_unit) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto sample_3d = [&](Id tex_id, bool projection) {
|
const auto sample_3d = [&](Id tex_id, bool projection) {
|
||||||
const Id image_type = tex_id.value == tex_cube_id.value ? image_cube_id : image2d_id;
|
const Id image_type = !projection ? image_cube_id : image2d_id;
|
||||||
const Id sampled_image{OpLoad(TypeSampledImage(image_type), tex_id)};
|
const Id sampled_image{OpLoad(TypeSampledImage(image_type), tex_id)};
|
||||||
const Id texcoord0_w{OpLoad(f32_id, texcoord0_w_id)};
|
const Id texcoord0_w{OpLoad(f32_id, texcoord0_w_id)};
|
||||||
const Id coord{OpCompositeConstruct(vec_ids.Get(3), OpCompositeExtract(f32_id, texcoord, 0),
|
const Id coord{OpCompositeConstruct(vec_ids.Get(3), OpCompositeExtract(f32_id, texcoord, 0),
|
||||||
@ -1001,7 +1002,7 @@ void FragmentModule::DefineTexSampler(u32 texture_unit) {
|
|||||||
ret_val = sample_3d(tex0_id, true);
|
ret_val = sample_3d(tex0_id, true);
|
||||||
break;
|
break;
|
||||||
case Pica::TexturingRegs::TextureConfig::TextureCube:
|
case Pica::TexturingRegs::TextureConfig::TextureCube:
|
||||||
ret_val = sample_3d(tex_cube_id, false);
|
ret_val = sample_3d(tex0_id, false);
|
||||||
break;
|
break;
|
||||||
case Pica::TexturingRegs::TextureConfig::Shadow2D:
|
case Pica::TexturingRegs::TextureConfig::Shadow2D:
|
||||||
ret_val = SampleShadow();
|
ret_val = SampleShadow();
|
||||||
@ -1564,20 +1565,24 @@ void FragmentModule::DefineInterface() {
|
|||||||
view_id = DefineInput(vec_ids.Get(3), 7);
|
view_id = DefineInput(vec_ids.Get(3), 7);
|
||||||
color_id = DefineOutput(vec_ids.Get(4), 0);
|
color_id = DefineOutput(vec_ids.Get(4), 0);
|
||||||
|
|
||||||
// Define the texture unit samplers/uniforms
|
// Define the texture unit samplers types
|
||||||
image_buffer_id = TypeImage(f32_id, spv::Dim::Buffer, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
image_buffer_id = TypeImage(f32_id, spv::Dim::Buffer, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
||||||
image2d_id = TypeImage(f32_id, spv::Dim::Dim2D, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
image2d_id = TypeImage(f32_id, spv::Dim::Dim2D, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
||||||
image_cube_id = TypeImage(f32_id, spv::Dim::Cube, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
image_cube_id = TypeImage(f32_id, spv::Dim::Cube, 0, 0, 0, 1, spv::ImageFormat::Unknown);
|
||||||
image_r32_id = TypeImage(u32_id, spv::Dim::Dim2D, 0, 0, 0, 2, spv::ImageFormat::R32ui);
|
image_r32_id = TypeImage(u32_id, spv::Dim::Dim2D, 0, 0, 0, 2, spv::ImageFormat::R32ui);
|
||||||
sampler_id = TypeSampler();
|
sampler_id = TypeSampler();
|
||||||
|
|
||||||
|
// Define lighting texture buffers
|
||||||
texture_buffer_lut_lf_id = DefineUniformConst(image_buffer_id, 0, 3);
|
texture_buffer_lut_lf_id = DefineUniformConst(image_buffer_id, 0, 3);
|
||||||
texture_buffer_lut_rg_id = DefineUniformConst(image_buffer_id, 0, 4);
|
texture_buffer_lut_rg_id = DefineUniformConst(image_buffer_id, 0, 4);
|
||||||
texture_buffer_lut_rgba_id = DefineUniformConst(image_buffer_id, 0, 5);
|
texture_buffer_lut_rgba_id = DefineUniformConst(image_buffer_id, 0, 5);
|
||||||
tex0_id = DefineUniformConst(TypeSampledImage(image2d_id), 1, 0);
|
|
||||||
|
// Define texture unit samplers
|
||||||
|
const auto texture_type = config.texture.texture0_type.Value();
|
||||||
|
const auto tex0_type = texture_type == TextureType::TextureCube ? image_cube_id : image2d_id;
|
||||||
|
tex0_id = DefineUniformConst(TypeSampledImage(tex0_type), 1, 0);
|
||||||
tex1_id = DefineUniformConst(TypeSampledImage(image2d_id), 1, 1);
|
tex1_id = DefineUniformConst(TypeSampledImage(image2d_id), 1, 1);
|
||||||
tex2_id = DefineUniformConst(TypeSampledImage(image2d_id), 1, 2);
|
tex2_id = DefineUniformConst(TypeSampledImage(image2d_id), 1, 2);
|
||||||
tex_cube_id = DefineUniformConst(TypeSampledImage(image_cube_id), 1, 3);
|
|
||||||
|
|
||||||
// Define shadow textures
|
// Define shadow textures
|
||||||
shadow_texture_px_id = DefineUniformConst(image_r32_id, 2, 0, true);
|
shadow_texture_px_id = DefineUniformConst(image_r32_id, 2, 0, true);
|
||||||
|
@ -252,7 +252,6 @@ private:
|
|||||||
Id tex0_id{};
|
Id tex0_id{};
|
||||||
Id tex1_id{};
|
Id tex1_id{};
|
||||||
Id tex2_id{};
|
Id tex2_id{};
|
||||||
Id tex_cube_id{};
|
|
||||||
Id texture_buffer_lut_lf_id{};
|
Id texture_buffer_lut_lf_id{};
|
||||||
Id texture_buffer_lut_rg_id{};
|
Id texture_buffer_lut_rg_id{};
|
||||||
Id texture_buffer_lut_rgba_id{};
|
Id texture_buffer_lut_rgba_id{};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user