mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-06 01:59:58 +00:00
video_core: Implement opengl/vulkan draw_texture
This commit is contained in:
parent
1e8cee2ddf
commit
013b689153
19 changed files with 284 additions and 131 deletions
|
@ -99,6 +99,8 @@ add_library(video_core STATIC
|
|||
renderer_null/null_rasterizer.h
|
||||
renderer_null/renderer_null.cpp
|
||||
renderer_null/renderer_null.h
|
||||
renderer_opengl/blit_image.cpp
|
||||
renderer_opengl/blit_image.h
|
||||
renderer_opengl/gl_buffer_cache.cpp
|
||||
renderer_opengl/gl_buffer_cache.h
|
||||
renderer_opengl/gl_compute_pipeline.cpp
|
||||
|
|
|
@ -11,6 +11,7 @@ set(GLSL_INCLUDES
|
|||
|
||||
set(SHADER_FILES
|
||||
astc_decoder.comp
|
||||
blit_color_float.frag
|
||||
block_linear_unswizzle_2d.comp
|
||||
block_linear_unswizzle_3d.comp
|
||||
convert_abgr8_to_d24s8.frag
|
||||
|
@ -36,7 +37,6 @@ set(SHADER_FILES
|
|||
smaa_blending_weight_calculation.frag
|
||||
smaa_neighborhood_blending.vert
|
||||
smaa_neighborhood_blending.frag
|
||||
vulkan_blit_color_float.frag
|
||||
vulkan_blit_depth_stencil.frag
|
||||
vulkan_fidelityfx_fsr_easu_fp16.comp
|
||||
vulkan_fidelityfx_fsr_easu_fp32.comp
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
#endif
|
||||
|
||||
BEGIN_PUSH_CONSTANTS
|
||||
|
@ -21,8 +28,8 @@ END_PUSH_CONSTANTS
|
|||
layout(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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -46,6 +46,9 @@ public:
|
|||
/// Dispatches an indirect draw invocation
|
||||
virtual void DrawIndirect() {}
|
||||
|
||||
/// Dispatches an draw texture invocation
|
||||
virtual void DrawTexture() = 0;
|
||||
|
||||
/// Clear the current framebuffer
|
||||
virtual void Clear(u32 layer_count) = 0;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ RasterizerNull::RasterizerNull(Core::Memory::Memory& cpu_memory_, Tegra::GPU& gp
|
|||
RasterizerNull::~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) {}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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{};
|
||||
|
|
|
@ -64,7 +64,8 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra
|
|||
shader_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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 OpenGL
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
explicit ProgramManager(const Device& device);
|
||||
|
||||
void BindComputeProgram(GLuint program) {
|
||||
glUseProgram(program);
|
||||
is_compute_bound = true;
|
||||
}
|
||||
void BindComputeProgram(GLuint program);
|
||||
|
||||
void BindComputeAssemblyProgram(GLuint program) {
|
||||
if (current_assembly_compute_program != program) {
|
||||
current_assembly_compute_program = program;
|
||||
glBindProgramARB(GL_COMPUTE_PROGRAM_NV, program);
|
||||
}
|
||||
UnbindPipeline();
|
||||
}
|
||||
void BindComputeAssemblyProgram(GLuint program);
|
||||
|
||||
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 BindSourcePrograms(std::span<const OGLProgram, NUM_STAGES> programs);
|
||||
|
||||
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();
|
||||
}
|
||||
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;
|
||||
u32 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() {}
|
||||
void RestoreGuestCompute();
|
||||
|
||||
private:
|
||||
void BindPipeline() {
|
||||
if (!is_pipeline_bound) {
|
||||
is_pipeline_bound = true;
|
||||
glBindProgramPipeline(pipeline.handle);
|
||||
}
|
||||
UnbindCompute();
|
||||
}
|
||||
void BindPipeline();
|
||||
|
||||
void UnbindPipeline() {
|
||||
if (is_pipeline_bound) {
|
||||
is_pipeline_bound = false;
|
||||
glBindProgramPipeline(0);
|
||||
}
|
||||
UnbindCompute();
|
||||
}
|
||||
void UnbindPipeline();
|
||||
|
||||
void UnbindCompute() {
|
||||
if (is_compute_bound) {
|
||||
is_compute_bound = false;
|
||||
glUseProgram(0);
|
||||
}
|
||||
}
|
||||
void UnbindCompute();
|
||||
|
||||
OGLPipeline pipeline;
|
||||
bool is_pipeline_bound{};
|
||||
|
|
|
@ -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, VkImageView
|
|||
scheduler.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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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 GPU
|
||||
void MarkModification(ImageId id) noexcept;
|
||||
|
||||
|
|
Loading…
Reference in a new issue