VERY experimental Nintendo Switch 2 emulator
C++
video_core: Implement opengl/vulkan draw_texture
Feng Chen3b5e1a24bccd
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txtindex aa271a3770..f9001104c6 100644--- a/src/video_core/CMakeLists.txt+++ b/src/video_core/CMakeLists.txt@@ -99,6 +99,8 @@ add_library(video_core STATICrenderer_null/null_rasterizer.hrenderer_null/renderer_null.cpprenderer_null/renderer_null.h+ renderer_opengl/blit_image.cpp+ renderer_opengl/blit_image.hrenderer_opengl/gl_buffer_cache.cpprenderer_opengl/gl_buffer_cache.hrenderer_opengl/gl_compute_pipeline.cppdiff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txtindex e6dc24f220..1a7961cb9c 100644--- a/src/video_core/host_shaders/CMakeLists.txt+++ b/src/video_core/host_shaders/CMakeLists.txt@@ -11,6 +11,7 @@ set(GLSL_INCLUDESset(SHADER_FILESastc_decoder.comp+ blit_color_float.fragblock_linear_unswizzle_2d.compblock_linear_unswizzle_3d.compconvert_abgr8_to_d24s8.frag@@ -36,7 +37,6 @@ set(SHADER_FILESsmaa_blending_weight_calculation.fragsmaa_neighborhood_blending.vertsmaa_neighborhood_blending.frag- vulkan_blit_color_float.fragvulkan_blit_depth_stencil.fragvulkan_fidelityfx_fsr_easu_fp16.compvulkan_fidelityfx_fsr_easu_fp32.compdiff --git a/src/video_core/host_shaders/full_screen_triangle.vert b/src/video_core/host_shaders/full_screen_triangle.vertindex 2c976b19f6..8ac936efdf 100644--- a/src/video_core/host_shaders/full_screen_triangle.vert+++ b/src/video_core/host_shaders/full_screen_triangle.vert@@ -4,13 +4,20 @@#version 450#ifdef VULKAN+#define VERTEX_ID gl_VertexIndex#define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants {#define END_PUSH_CONSTANTS };#define UNIFORM(n)+#define FLIPY 1#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv+#define VERTEX_ID gl_VertexID#define BEGIN_PUSH_CONSTANTS#define END_PUSH_CONSTANTS+#define FLIPY -1#define UNIFORM(n) layout (location = n) uniform+out gl_PerVertex {+ vec4 gl_Position;+};#endifBEGIN_PUSH_CONSTANTS@@ -21,8 +28,8 @@ END_PUSH_CONSTANTSlayout(location = 0) out vec2 texcoord;void main() {- float x = float((gl_VertexIndex & 1) << 2);- float y = float((gl_VertexIndex & 2) << 1);- gl_Position = vec4(x - 1.0, y - 1.0, 0.0, 1.0);+ float x = float((VERTEX_ID & 1) << 2);+ float y = float((VERTEX_ID & 2) << 1);+ gl_Position = vec4(x - 1.0, FLIPY * (y - 1.0), 0.0, 1.0);texcoord = fma(vec2(x, y) / 2.0, tex_scale, tex_offset);-}+}\ No newline at end of filediff --git a/src/video_core/host_shaders/vulkan_blit_color_float.frag b/src/video_core/host_shaders/vulkan_blit_color_float.fragdeleted file mode 100644index c0c8322969..0000000000--- a/src/video_core/host_shaders/vulkan_blit_color_float.frag+++ /dev/null@@ -1,13 +0,0 @@-// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project-// SPDX-License-Identifier: GPL-2.0-or-later--#version 450--layout(binding = 0) uniform sampler2D tex;--layout(location = 0) in vec2 texcoord;-layout(location = 0) out vec4 color;--void main() {- color = textureLod(tex, texcoord, 0);-}diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.hindex f44c7df506..f980b12c61 100644--- a/src/video_core/rasterizer_interface.h+++ b/src/video_core/rasterizer_interface.h@@ -46,6 +46,9 @@ public:/// Dispatches an indirect draw invocationvirtual void DrawIndirect() {}+ /// Dispatches an draw texture invocation+ virtual void DrawTexture() = 0;+/// Clear the current framebuffervirtual void Clear(u32 layer_count) = 0;diff --git a/src/video_core/renderer_null/null_rasterizer.cpp b/src/video_core/renderer_null/null_rasterizer.cppindex 2c11345d7b..2b5c7defa6 100644--- a/src/video_core/renderer_null/null_rasterizer.cpp+++ b/src/video_core/renderer_null/null_rasterizer.cpp@@ -21,6 +21,7 @@ RasterizerNull::RasterizerNull(Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpRasterizerNull::~RasterizerNull() = default;void RasterizerNull::Draw(bool is_indexed, u32 instance_count) {}+void RasterizerNull::DrawTexture() {}void RasterizerNull::Clear(u32 layer_count) {}void RasterizerNull::DispatchCompute() {}void RasterizerNull::ResetCounter(VideoCore::QueryType type) {}diff --git a/src/video_core/renderer_null/null_rasterizer.h b/src/video_core/renderer_null/null_rasterizer.hindex 2112aa70e1..51f896e43c 100644--- a/src/video_core/renderer_null/null_rasterizer.h+++ b/src/video_core/renderer_null/null_rasterizer.h@@ -31,6 +31,7 @@ public:~RasterizerNull() override;void Draw(bool is_indexed, u32 instance_count) override;+ void DrawTexture() override;void Clear(u32 layer_count) override;void DispatchCompute() override;void ResetCounter(VideoCore::QueryType type) override;diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cppindex cee5c32470..22ed16ebfb 100644--- a/src/video_core/renderer_opengl/gl_device.cpp+++ b/src/video_core/renderer_opengl/gl_device.cpp@@ -166,6 +166,7 @@ Device::Device(Core::Frontend::EmuWindow& emu_window) {has_shader_int64 = HasExtension(extensions, "GL_ARB_gpu_shader_int64");has_amd_shader_half_float = GLAD_GL_AMD_gpu_shader_half_float;has_sparse_texture_2 = GLAD_GL_ARB_sparse_texture2;+ has_draw_texture = GLAD_GL_NV_draw_texture;warp_size_potentially_larger_than_guest = !is_nvidia && !is_intel;need_fastmath_off = is_nvidia;can_report_memory = GLAD_GL_NVX_gpu_memory_info;diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.hindex 2a72d84be0..3ff8cad83b 100644--- a/src/video_core/renderer_opengl/gl_device.h+++ b/src/video_core/renderer_opengl/gl_device.h@@ -4,6 +4,8 @@#pragma once#include <cstddef>+#include <string>+#include "common/common_types.h"#include "core/frontend/emu_window.h"#include "shader_recompiler/stage.h"@@ -146,6 +148,10 @@ public:return has_sparse_texture_2;}+ bool HasDrawTexture() const {+ return has_draw_texture;+ }+bool IsWarpSizePotentiallyLargerThanGuest() const {return warp_size_potentially_larger_than_guest;}@@ -216,6 +222,7 @@ private:bool has_shader_int64{};bool has_amd_shader_half_float{};bool has_sparse_texture_2{};+ bool has_draw_texture{};bool warp_size_potentially_larger_than_guest{};bool need_fastmath_off{};bool has_cbuf_ftou_bug{};diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cppindex 7d48af8e17..651608a069 100644--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp@@ -64,7 +64,8 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegrashader_cache(*this, emu_window_, device, texture_cache, buffer_cache, program_manager,state_tracker, gpu.ShaderNotify()),query_cache(*this), accelerate_dma(buffer_cache),- fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache) {}+ fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache),+ blit_image(program_manager_) {}RasterizerOpenGL::~RasterizerOpenGL() = default;@@ -318,6 +319,47 @@ void RasterizerOpenGL::DrawIndirect() {buffer_cache.SetDrawIndirect(nullptr);}+void RasterizerOpenGL::DrawTexture() {+ MICROPROFILE_SCOPE(OpenGL_Drawing);++ SCOPE_EXIT({ gpu.TickWork(); });+ query_cache.UpdateCounters();++ texture_cache.SynchronizeGraphicsDescriptors();+ texture_cache.UpdateRenderTargets(false);++ SyncState();++ const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState();+ const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);+ const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);++ if (device.HasDrawTexture()) {+ state_tracker.BindFramebuffer(texture_cache.GetFramebuffer()->Handle());++ glDrawTextureNV(texture.DefaultHandle(), sampler->Handle(), draw_texture_state.dst_x0,+ draw_texture_state.dst_y0, draw_texture_state.dst_x1,+ draw_texture_state.dst_y1, 0,+ draw_texture_state.src_x0 / static_cast<float>(texture.size.width),+ draw_texture_state.src_y0 / static_cast<float>(texture.size.height),+ draw_texture_state.src_x1 / static_cast<float>(texture.size.width),+ draw_texture_state.src_y1 / static_cast<float>(texture.size.height));+ } else {+ Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0),+ .y = static_cast<s32>(draw_texture_state.dst_y0)},+ Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1),+ .y = static_cast<s32>(draw_texture_state.dst_y1)}};+ Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0),+ .y = static_cast<s32>(draw_texture_state.src_y0)},+ Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1),+ .y = static_cast<s32>(draw_texture_state.src_y1)}};+ blit_image.BlitColor(texture_cache.GetFramebuffer()->Handle(), texture.DefaultHandle(),+ sampler->Handle(), dst_region, src_region, texture.size);+ }++ ++num_queued_commands;+}+void RasterizerOpenGL::DispatchCompute() {ComputePipeline* const pipeline{shader_cache.CurrentComputePipeline()};if (!pipeline) {diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.hindex be4f76c18d..0c45832ae1 100644--- a/src/video_core/renderer_opengl/gl_rasterizer.h+++ b/src/video_core/renderer_opengl/gl_rasterizer.h@@ -16,6 +16,7 @@#include "video_core/engines/maxwell_dma.h"#include "video_core/rasterizer_accelerated.h"#include "video_core/rasterizer_interface.h"+#include "video_core/renderer_opengl/blit_image.h"#include "video_core/renderer_opengl/gl_buffer_cache.h"#include "video_core/renderer_opengl/gl_device.h"#include "video_core/renderer_opengl/gl_fence_manager.h"@@ -70,6 +71,7 @@ public:void Draw(bool is_indexed, u32 instance_count) override;void DrawIndirect() override;+ void DrawTexture() override;void Clear(u32 layer_count) override;void DispatchCompute() override;void ResetCounter(VideoCore::QueryType type) override;@@ -224,6 +226,8 @@ private:AccelerateDMA accelerate_dma;FenceManagerOpenGL fence_manager;+ BlitImageHelper blit_image;+boost::container::static_vector<u32, MAX_IMAGE_VIEWS> image_view_indices;std::array<ImageViewId, MAX_IMAGE_VIEWS> image_view_ids;boost::container::static_vector<GLuint, MAX_TEXTURES> sampler_handles;diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cppindex d9c29d8b79..98841ae65e 100644--- a/src/video_core/renderer_opengl/gl_shader_manager.cpp+++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp@@ -1,2 +1,123 @@// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project// SPDX-License-Identifier: GPL-2.0-or-later++#include <glad/glad.h>++#include "video_core/renderer_opengl/gl_shader_manager.h"++namespace OpenGL {++static constexpr std::array ASSEMBLY_PROGRAM_ENUMS{+ GL_VERTEX_PROGRAM_NV, GL_TESS_CONTROL_PROGRAM_NV, GL_TESS_EVALUATION_PROGRAM_NV,+ GL_GEOMETRY_PROGRAM_NV, GL_FRAGMENT_PROGRAM_NV,+};++ProgramManager::ProgramManager(const Device& device) {+ glCreateProgramPipelines(1, &pipeline.handle);+ if (device.UseAssemblyShaders()) {+ glEnable(GL_COMPUTE_PROGRAM_NV);+ }+}++void ProgramManager::BindComputeProgram(GLuint program) {+ glUseProgram(program);+ is_compute_bound = true;+}++void ProgramManager::BindComputeAssemblyProgram(GLuint program) {+ if (current_assembly_compute_program != program) {+ current_assembly_compute_program = program;+ glBindProgramARB(GL_COMPUTE_PROGRAM_NV, program);+ }+ UnbindPipeline();+}++void ProgramManager::BindSourcePrograms(std::span<const OGLProgram, NUM_STAGES> programs) {+ static constexpr std::array<GLenum, 5> stage_enums{+ GL_VERTEX_SHADER_BIT, GL_TESS_CONTROL_SHADER_BIT, GL_TESS_EVALUATION_SHADER_BIT,+ GL_GEOMETRY_SHADER_BIT, GL_FRAGMENT_SHADER_BIT,+ };+ for (size_t stage = 0; stage < NUM_STAGES; ++stage) {+ if (current_programs[stage] != programs[stage].handle) {+ current_programs[stage] = programs[stage].handle;+ glUseProgramStages(pipeline.handle, stage_enums[stage], programs[stage].handle);+ }+ }+ BindPipeline();+}++void ProgramManager::BindPresentPrograms(GLuint vertex, GLuint fragment) {+ if (current_programs[0] != vertex) {+ current_programs[0] = vertex;+ glUseProgramStages(pipeline.handle, GL_VERTEX_SHADER_BIT, vertex);+ }+ if (current_programs[4] != fragment) {+ current_programs[4] = fragment;+ glUseProgramStages(pipeline.handle, GL_FRAGMENT_SHADER_BIT, fragment);+ }+ glUseProgramStages(+ pipeline.handle,+ GL_TESS_CONTROL_SHADER_BIT | GL_TESS_EVALUATION_SHADER_BIT | GL_GEOMETRY_SHADER_BIT, 0);+ current_programs[1] = 0;+ current_programs[2] = 0;+ current_programs[3] = 0;++ if (current_stage_mask != 0) {+ current_stage_mask = 0;+ for (const GLenum program_type : ASSEMBLY_PROGRAM_ENUMS) {+ glDisable(program_type);+ }+ }+ BindPipeline();+}++void ProgramManager::BindAssemblyPrograms(std::span<const OGLAssemblyProgram, NUM_STAGES> programs,+ u32 stage_mask) {+ const u32 changed_mask = current_stage_mask ^ stage_mask;+ current_stage_mask = stage_mask;++ if (changed_mask != 0) {+ for (size_t stage = 0; stage < NUM_STAGES; ++stage) {+ if (((changed_mask >> stage) & 1) != 0) {+ if (((stage_mask >> stage) & 1) != 0) {+ glEnable(ASSEMBLY_PROGRAM_ENUMS[stage]);+ } else {+ glDisable(ASSEMBLY_PROGRAM_ENUMS[stage]);+ }+ }+ }+ }+ for (size_t stage = 0; stage < NUM_STAGES; ++stage) {+ if (current_programs[stage] != programs[stage].handle) {+ current_programs[stage] = programs[stage].handle;+ glBindProgramARB(ASSEMBLY_PROGRAM_ENUMS[stage], programs[stage].handle);+ }+ }+ UnbindPipeline();+}++void ProgramManager::RestoreGuestCompute() {}++void ProgramManager::BindPipeline() {+ if (!is_pipeline_bound) {+ is_pipeline_bound = true;+ glBindProgramPipeline(pipeline.handle);+ }+ UnbindCompute();+}++void ProgramManager::UnbindPipeline() {+ if (is_pipeline_bound) {+ is_pipeline_bound = false;+ glBindProgramPipeline(0);+ }+ UnbindCompute();+}++void ProgramManager::UnbindCompute() {+ if (is_compute_bound) {+ is_compute_bound = false;+ glUseProgram(0);+ }+}+} // namespace OpenGLdiff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.hindex a84f5aeb3d..07ffab77f1 100644--- a/src/video_core/renderer_opengl/gl_shader_manager.h+++ b/src/video_core/renderer_opengl/gl_shader_manager.h@@ -6,8 +6,6 @@#include <array>#include <span>-#include <glad/glad.h>-#include "video_core/renderer_opengl/gl_device.h"#include "video_core/renderer_opengl/gl_resource_manager.h"@@ -16,121 +14,28 @@ namespace OpenGL {class ProgramManager {static constexpr size_t NUM_STAGES = 5;- static constexpr std::array ASSEMBLY_PROGRAM_ENUMS{- GL_VERTEX_PROGRAM_NV, GL_TESS_CONTROL_PROGRAM_NV, GL_TESS_EVALUATION_PROGRAM_NV,- GL_GEOMETRY_PROGRAM_NV, GL_FRAGMENT_PROGRAM_NV,- };-public:- explicit ProgramManager(const Device& device) {- glCreateProgramPipelines(1, &pipeline.handle);- if (device.UseAssemblyShaders()) {- glEnable(GL_COMPUTE_PROGRAM_NV);- }- }-- void BindComputeProgram(GLuint program) {- glUseProgram(program);- is_compute_bound = true;- }-- void BindComputeAssemblyProgram(GLuint program) {- if (current_assembly_compute_program != program) {- current_assembly_compute_program = program;- glBindProgramARB(GL_COMPUTE_PROGRAM_NV, program);- }- UnbindPipeline();- }-- void BindSourcePrograms(std::span<const OGLProgram, NUM_STAGES> programs) {- static constexpr std::array<GLenum, 5> stage_enums{- GL_VERTEX_SHADER_BIT, GL_TESS_CONTROL_SHADER_BIT, GL_TESS_EVALUATION_SHADER_BIT,- GL_GEOMETRY_SHADER_BIT, GL_FRAGMENT_SHADER_BIT,- };- for (size_t stage = 0; stage < NUM_STAGES; ++stage) {- if (current_programs[stage] != programs[stage].handle) {- current_programs[stage] = programs[stage].handle;- glUseProgramStages(pipeline.handle, stage_enums[stage], programs[stage].handle);- }- }- BindPipeline();- }-- void BindPresentPrograms(GLuint vertex, GLuint fragment) {- if (current_programs[0] != vertex) {- current_programs[0] = vertex;- glUseProgramStages(pipeline.handle, GL_VERTEX_SHADER_BIT, vertex);- }- if (current_programs[4] != fragment) {- current_programs[4] = fragment;- glUseProgramStages(pipeline.handle, GL_FRAGMENT_SHADER_BIT, fragment);- }- glUseProgramStages(- pipeline.handle,- GL_TESS_CONTROL_SHADER_BIT | GL_TESS_EVALUATION_SHADER_BIT | GL_GEOMETRY_SHADER_BIT, 0);- current_programs[1] = 0;- current_programs[2] = 0;- current_programs[3] = 0;-- if (current_stage_mask != 0) {- current_stage_mask = 0;- for (const GLenum program_type : ASSEMBLY_PROGRAM_ENUMS) {- glDisable(program_type);- }- }- BindPipeline();- }+ explicit ProgramManager(const Device& device);++ void BindComputeProgram(GLuint program);++ void BindComputeAssemblyProgram(GLuint program);++ void BindSourcePrograms(std::span<const OGLProgram, NUM_STAGES> programs);++ void BindPresentPrograms(GLuint vertex, GLuint fragment);void BindAssemblyPrograms(std::span<const OGLAssemblyProgram, NUM_STAGES> programs,- u32 stage_mask) {- const u32 changed_mask = current_stage_mask ^ stage_mask;- current_stage_mask = stage_mask;-- if (changed_mask != 0) {- for (size_t stage = 0; stage < NUM_STAGES; ++stage) {- if (((changed_mask >> stage) & 1) != 0) {- if (((stage_mask >> stage) & 1) != 0) {- glEnable(ASSEMBLY_PROGRAM_ENUMS[stage]);- } else {- glDisable(ASSEMBLY_PROGRAM_ENUMS[stage]);- }- }- }- }- for (size_t stage = 0; stage < NUM_STAGES; ++stage) {- if (current_programs[stage] != programs[stage].handle) {- current_programs[stage] = programs[stage].handle;- glBindProgramARB(ASSEMBLY_PROGRAM_ENUMS[stage], programs[stage].handle);- }- }- UnbindPipeline();- }-- void RestoreGuestCompute() {}+ u32 stage_mask);++ void RestoreGuestCompute();private:- void BindPipeline() {- if (!is_pipeline_bound) {- is_pipeline_bound = true;- glBindProgramPipeline(pipeline.handle);- }- UnbindCompute();- }-- void UnbindPipeline() {- if (is_pipeline_bound) {- is_pipeline_bound = false;- glBindProgramPipeline(0);- }- UnbindCompute();- }-- void UnbindCompute() {- if (is_compute_bound) {- is_compute_bound = false;- glUseProgram(0);- }- }+ void BindPipeline();++ void UnbindPipeline();++ void UnbindCompute();OGLPipeline pipeline;bool is_pipeline_bound{};diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cppindex 3f2b139e0c..d728e5c6c9 100644--- a/src/video_core/renderer_vulkan/blit_image.cpp+++ b/src/video_core/renderer_vulkan/blit_image.cpp@@ -4,13 +4,13 @@#include <algorithm>#include "common/settings.h"+#include "video_core/host_shaders/blit_color_float_frag_spv.h"#include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h"#include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"#include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"-#include "video_core/host_shaders/vulkan_blit_color_float_frag_spv.h"#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"#include "video_core/renderer_vulkan/blit_image.h"#include "video_core/renderer_vulkan/maxwell_to_vk.h"@@ -303,7 +303,7 @@ void UpdateTwoTexturesDescriptorSet(const Device& device, VkDescriptorSet descri}void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout, const Region2D& dst_region,- const Region2D& src_region) {+ const Region2D& src_region, const Extent3D& src_size = {1, 1, 1}) {const VkOffset2D offset{.x = std::min(dst_region.start.x, dst_region.end.x),.y = std::min(dst_region.start.y, dst_region.end.y),@@ -325,12 +325,15 @@ void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout, const Regi.offset = offset,.extent = extent,};- const float scale_x = static_cast<float>(src_region.end.x - src_region.start.x);- const float scale_y = static_cast<float>(src_region.end.y - src_region.start.y);+ const float scale_x = static_cast<float>(src_region.end.x - src_region.start.x) /+ static_cast<float>(src_size.width);+ const float scale_y = static_cast<float>(src_region.end.y - src_region.start.y) /+ static_cast<float>(src_size.height);const PushConstants push_constants{.tex_scale = {scale_x, scale_y},- .tex_offset = {static_cast<float>(src_region.start.x),- static_cast<float>(src_region.start.y)},+ .tex_offset = {static_cast<float>(src_region.start.x) / static_cast<float>(src_size.width),+ static_cast<float>(src_region.start.y) /+ static_cast<float>(src_size.height)},};cmdbuf.SetViewport(0, viewport);cmdbuf.SetScissor(0, scissor);@@ -365,7 +368,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,two_textures_pipeline_layout(device.GetLogical().CreatePipelineLayout(PipelineLayoutCreateInfo(two_textures_set_layout.address()))),full_screen_vert(BuildShader(device, FULL_SCREEN_TRIANGLE_VERT_SPV)),- blit_color_to_color_frag(BuildShader(device, VULKAN_BLIT_COLOR_FLOAT_FRAG_SPV)),+ blit_color_to_color_frag(BuildShader(device, BLIT_COLOR_FLOAT_FRAG_SPV)),blit_depth_stencil_frag(BuildShader(device, VULKAN_BLIT_DEPTH_STENCIL_FRAG_SPV)),convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),@@ -404,6 +407,30 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageViewscheduler.InvalidateState();}+void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,+ VkSampler src_sampler, const Region2D& dst_region,+ const Region2D& src_region, const Extent3D& src_size) {+ const BlitImagePipelineKey key{+ .renderpass = dst_framebuffer->RenderPass(),+ .operation = Tegra::Engines::Fermi2D::Operation::SrcCopy,+ };+ const VkPipelineLayout layout = *one_texture_pipeline_layout;+ const VkPipeline pipeline = FindOrEmplaceColorPipeline(key);+ scheduler.RequestRenderpass(dst_framebuffer);+ scheduler.Record([this, dst_region, src_region, src_size, pipeline, layout, src_sampler,+ src_image_view](vk::CommandBuffer cmdbuf) {+ // TODO: Barriers+ const VkDescriptorSet descriptor_set = one_texture_descriptor_allocator.Commit();+ UpdateOneTextureDescriptorSet(device, descriptor_set, src_sampler, src_image_view);+ cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);+ cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set,+ nullptr);+ BindBlitState(cmdbuf, layout, dst_region, src_region, src_size);+ cmdbuf.Draw(3, 1, 0, 0);+ });+ scheduler.InvalidateState();+}+void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,VkImageView src_depth_view, VkImageView src_stencil_view,const Region2D& dst_region, const Region2D& src_region,diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.hindex 5df679fb43..e2db33f563 100644--- a/src/video_core/renderer_vulkan/blit_image.h+++ b/src/video_core/renderer_vulkan/blit_image.h@@ -10,6 +10,8 @@namespace Vulkan {+using VideoCommon::Extent3D;+using VideoCommon::Offset2D;using VideoCommon::Region2D;class Device;@@ -36,6 +38,10 @@ public:Tegra::Engines::Fermi2D::Filter filter,Tegra::Engines::Fermi2D::Operation operation);+ void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,+ VkSampler src_sampler, const Region2D& dst_region, const Region2D& src_region,+ const Extent3D& src_size);+void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,VkImageView src_stencil_view, const Region2D& dst_region,const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cppindex 242bf9602a..153096fa40 100644--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp@@ -265,6 +265,34 @@ void RasterizerVulkan::DrawIndirect() {buffer_cache.SetDrawIndirect(nullptr);}+void RasterizerVulkan::DrawTexture() {+ MICROPROFILE_SCOPE(Vulkan_Drawing);++ SCOPE_EXIT({ gpu.TickWork(); });+ FlushWork();++ query_cache.UpdateCounters();++ texture_cache.SynchronizeGraphicsDescriptors();+ texture_cache.UpdateRenderTargets(false);++ UpdateDynamicStates();++ const auto& draw_texture_state = maxwell3d->draw_manager->GetDrawTextureState();+ const auto& sampler = texture_cache.GetGraphicsSampler(draw_texture_state.src_sampler);+ const auto& texture = texture_cache.GetImageView(draw_texture_state.src_texture);+ Region2D dst_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x0),+ .y = static_cast<s32>(draw_texture_state.dst_y0)},+ Offset2D{.x = static_cast<s32>(draw_texture_state.dst_x1),+ .y = static_cast<s32>(draw_texture_state.dst_y1)}};+ Region2D src_region = {Offset2D{.x = static_cast<s32>(draw_texture_state.src_x0),+ .y = static_cast<s32>(draw_texture_state.src_y0)},+ Offset2D{.x = static_cast<s32>(draw_texture_state.src_x1),+ .y = static_cast<s32>(draw_texture_state.src_y1)}};+ blit_image.BlitColor(texture_cache.GetFramebuffer(), texture.RenderTarget(), sampler->Handle(),+ dst_region, src_region, texture.size);+}+void RasterizerVulkan::Clear(u32 layer_count) {MICROPROFILE_SCOPE(Vulkan_Clearing);diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.hindex c661e5b197..deb44dcaa5 100644--- a/src/video_core/renderer_vulkan/vk_rasterizer.h+++ b/src/video_core/renderer_vulkan/vk_rasterizer.h@@ -66,6 +66,7 @@ public:void Draw(bool is_indexed, u32 instance_count) override;void DrawIndirect() override;+ void DrawTexture() override;void Clear(u32 layer_count) override;void DispatchCompute() override;void ResetCounter(VideoCore::QueryType type) override;diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.hindex 87152c8e99..1b01990a44 100644--- a/src/video_core/texture_cache/texture_cache.h+++ b/src/video_core/texture_cache/texture_cache.h@@ -148,6 +148,13 @@ typename P::ImageView& TextureCache<P>::GetImageView(ImageViewId id) noexcept {return slot_image_views[id];}+template <class P>+typename P::ImageView& TextureCache<P>::GetImageView(u32 index) noexcept {+ const auto image_view_id = VisitImageView(channel_state->graphics_image_table,+ channel_state->graphics_image_view_ids, index);+ return slot_image_views[image_view_id];+}+template <class P>void TextureCache<P>::MarkModification(ImageId id) noexcept {MarkModification(slot_images[id]);diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.hindex 4eea1f609e..485eaabaa8 100644--- a/src/video_core/texture_cache/texture_cache_base.h+++ b/src/video_core/texture_cache/texture_cache_base.h@@ -129,6 +129,9 @@ public:/// Return a reference to the given image view id[[nodiscard]] ImageView& GetImageView(ImageViewId id) noexcept;+ /// Get the imageview from the graphics descriptor table in the specified index+ [[nodiscard]] ImageView& GetImageView(u32 index) noexcept;+/// Mark an image as modified from the GPUvoid MarkModification(ImageId id) noexcept;