mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 01:02:48 +01:00
video_core: Implement maxwell3d draw texture method
This commit is contained in:
parent
b78328f19a
commit
1e8cee2ddf
7 changed files with 177 additions and 1 deletions
|
@ -51,6 +51,10 @@ void DrawManager::ProcessMethodCall(u32 method, u32 argument) {
|
||||||
LOG_WARNING(HW_GPU, "(STUBBED) called");
|
LOG_WARNING(HW_GPU, "(STUBBED) called");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MAXWELL3D_REG_INDEX(draw_texture.src_y0): {
|
||||||
|
DrawTexture();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +183,33 @@ void DrawManager::DrawIndexSmall(u32 argument) {
|
||||||
ProcessDraw(true, 1);
|
ProcessDraw(true, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawManager::DrawTexture() {
|
||||||
|
const auto& regs{maxwell3d->regs};
|
||||||
|
draw_texture_state.dst_x0 = static_cast<float>(regs.draw_texture.dst_x0) / 4096.f;
|
||||||
|
draw_texture_state.dst_y0 = static_cast<float>(regs.draw_texture.dst_y0) / 4096.f;
|
||||||
|
const auto dst_width = static_cast<float>(regs.draw_texture.dst_width) / 4096.f;
|
||||||
|
const auto dst_height = static_cast<float>(regs.draw_texture.dst_height) / 4096.f;
|
||||||
|
const bool lower_left{regs.window_origin.mode !=
|
||||||
|
Maxwell3D::Regs::WindowOrigin::Mode::UpperLeft};
|
||||||
|
if (lower_left) {
|
||||||
|
draw_texture_state.dst_y0 -= dst_height;
|
||||||
|
}
|
||||||
|
draw_texture_state.dst_x1 = draw_texture_state.dst_x0 + dst_width;
|
||||||
|
draw_texture_state.dst_y1 = draw_texture_state.dst_y0 + dst_height;
|
||||||
|
draw_texture_state.src_x0 = static_cast<float>(regs.draw_texture.src_x0) / 4096.f;
|
||||||
|
draw_texture_state.src_y0 = static_cast<float>(regs.draw_texture.src_y0) / 4096.f;
|
||||||
|
draw_texture_state.src_x1 =
|
||||||
|
(static_cast<float>(regs.draw_texture.dx_du) / 4294967295.f) * dst_width +
|
||||||
|
draw_texture_state.src_x0;
|
||||||
|
draw_texture_state.src_y1 =
|
||||||
|
(static_cast<float>(regs.draw_texture.dy_dv) / 4294967295.f) * dst_height +
|
||||||
|
draw_texture_state.src_y0;
|
||||||
|
draw_texture_state.src_sampler = regs.draw_texture.src_sampler;
|
||||||
|
draw_texture_state.src_texture = regs.draw_texture.src_texture;
|
||||||
|
|
||||||
|
maxwell3d->rasterizer->DrawTexture();
|
||||||
|
}
|
||||||
|
|
||||||
void DrawManager::UpdateTopology() {
|
void DrawManager::UpdateTopology() {
|
||||||
const auto& regs{maxwell3d->regs};
|
const auto& regs{maxwell3d->regs};
|
||||||
switch (regs.primitive_topology_control) {
|
switch (regs.primitive_topology_control) {
|
||||||
|
|
|
@ -32,6 +32,19 @@ public:
|
||||||
std::vector<u8> inline_index_draw_indexes;
|
std::vector<u8> inline_index_draw_indexes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DrawTextureState {
|
||||||
|
f32 dst_x0;
|
||||||
|
f32 dst_y0;
|
||||||
|
f32 dst_x1;
|
||||||
|
f32 dst_y1;
|
||||||
|
f32 src_x0;
|
||||||
|
f32 src_y0;
|
||||||
|
f32 src_x1;
|
||||||
|
f32 src_y1;
|
||||||
|
u32 src_sampler;
|
||||||
|
u32 src_texture;
|
||||||
|
};
|
||||||
|
|
||||||
struct IndirectParams {
|
struct IndirectParams {
|
||||||
bool is_indexed;
|
bool is_indexed;
|
||||||
bool include_count;
|
bool include_count;
|
||||||
|
@ -64,6 +77,10 @@ public:
|
||||||
return draw_state;
|
return draw_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DrawTextureState& GetDrawTextureState() const {
|
||||||
|
return draw_texture_state;
|
||||||
|
}
|
||||||
|
|
||||||
IndirectParams& GetIndirectParams() {
|
IndirectParams& GetIndirectParams() {
|
||||||
return indirect_state;
|
return indirect_state;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +98,8 @@ private:
|
||||||
|
|
||||||
void DrawIndexSmall(u32 argument);
|
void DrawIndexSmall(u32 argument);
|
||||||
|
|
||||||
|
void DrawTexture();
|
||||||
|
|
||||||
void UpdateTopology();
|
void UpdateTopology();
|
||||||
|
|
||||||
void ProcessDraw(bool draw_indexed, u32 instance_count);
|
void ProcessDraw(bool draw_indexed, u32 instance_count);
|
||||||
|
@ -89,6 +108,7 @@ private:
|
||||||
|
|
||||||
Maxwell3D* maxwell3d{};
|
Maxwell3D* maxwell3d{};
|
||||||
State draw_state{};
|
State draw_state{};
|
||||||
|
DrawTextureState draw_texture_state{};
|
||||||
IndirectParams indirect_state{};
|
IndirectParams indirect_state{};
|
||||||
};
|
};
|
||||||
} // namespace Tegra::Engines
|
} // namespace Tegra::Engines
|
||||||
|
|
|
@ -149,6 +149,7 @@ bool Maxwell3D::IsMethodExecutable(u32 method) {
|
||||||
case MAXWELL3D_REG_INDEX(inline_index_4x8.index0):
|
case MAXWELL3D_REG_INDEX(inline_index_4x8.index0):
|
||||||
case MAXWELL3D_REG_INDEX(vertex_array_instance_first):
|
case MAXWELL3D_REG_INDEX(vertex_array_instance_first):
|
||||||
case MAXWELL3D_REG_INDEX(vertex_array_instance_subsequent):
|
case MAXWELL3D_REG_INDEX(vertex_array_instance_subsequent):
|
||||||
|
case MAXWELL3D_REG_INDEX(draw_texture.src_y0):
|
||||||
case MAXWELL3D_REG_INDEX(wait_for_idle):
|
case MAXWELL3D_REG_INDEX(wait_for_idle):
|
||||||
case MAXWELL3D_REG_INDEX(shadow_ram_control):
|
case MAXWELL3D_REG_INDEX(shadow_ram_control):
|
||||||
case MAXWELL3D_REG_INDEX(load_mme.instruction_ptr):
|
case MAXWELL3D_REG_INDEX(load_mme.instruction_ptr):
|
||||||
|
|
|
@ -1599,6 +1599,20 @@ public:
|
||||||
};
|
};
|
||||||
static_assert(sizeof(TIRModulationCoeff) == 0x4);
|
static_assert(sizeof(TIRModulationCoeff) == 0x4);
|
||||||
|
|
||||||
|
struct DrawTexture {
|
||||||
|
s32 dst_x0;
|
||||||
|
s32 dst_y0;
|
||||||
|
s32 dst_width;
|
||||||
|
s32 dst_height;
|
||||||
|
s64 dx_du;
|
||||||
|
s64 dy_dv;
|
||||||
|
u32 src_sampler;
|
||||||
|
u32 src_texture;
|
||||||
|
s32 src_x0;
|
||||||
|
s32 src_y0;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(DrawTexture) == 0x30);
|
||||||
|
|
||||||
struct ReduceColorThreshold {
|
struct ReduceColorThreshold {
|
||||||
union {
|
union {
|
||||||
BitField<0, 8, u32> all_hit_once;
|
BitField<0, 8, u32> all_hit_once;
|
||||||
|
@ -2751,7 +2765,7 @@ public:
|
||||||
u32 reserved_sw_method2; ///< 0x102C
|
u32 reserved_sw_method2; ///< 0x102C
|
||||||
std::array<TIRModulationCoeff, 5> tir_modulation_coeff; ///< 0x1030
|
std::array<TIRModulationCoeff, 5> tir_modulation_coeff; ///< 0x1030
|
||||||
std::array<u32, 15> spare_nop; ///< 0x1044
|
std::array<u32, 15> spare_nop; ///< 0x1044
|
||||||
INSERT_PADDING_BYTES_NOINIT(0x30);
|
DrawTexture draw_texture; ///< 0x1080
|
||||||
std::array<u32, 7> reserved_sw_method3_to_7; ///< 0x10B0
|
std::array<u32, 7> reserved_sw_method3_to_7; ///< 0x10B0
|
||||||
ReduceColorThreshold reduce_color_thresholds_unorm8; ///< 0x10CC
|
ReduceColorThreshold reduce_color_thresholds_unorm8; ///< 0x10CC
|
||||||
std::array<u32, 4> reserved_sw_method10_to_13; ///< 0x10D0
|
std::array<u32, 4> reserved_sw_method10_to_13; ///< 0x10D0
|
||||||
|
|
13
src/video_core/host_shaders/blit_color_float.frag
Normal file
13
src/video_core/host_shaders/blit_color_float.frag
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// 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);
|
||||||
|
}
|
59
src/video_core/renderer_opengl/blit_image.cpp
Normal file
59
src/video_core/renderer_opengl/blit_image.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "video_core/host_shaders/blit_color_float_frag.h"
|
||||||
|
#include "video_core/host_shaders/full_screen_triangle_vert.h"
|
||||||
|
#include "video_core/renderer_opengl/blit_image.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
BlitImageHelper::BlitImageHelper(ProgramManager& program_manager_)
|
||||||
|
: program_manager(program_manager_),
|
||||||
|
full_screen_vert(CreateProgram(HostShaders::FULL_SCREEN_TRIANGLE_VERT, GL_VERTEX_SHADER)),
|
||||||
|
blit_color_to_color_frag(
|
||||||
|
CreateProgram(HostShaders::BLIT_COLOR_FLOAT_FRAG, GL_FRAGMENT_SHADER)) {}
|
||||||
|
|
||||||
|
BlitImageHelper::~BlitImageHelper() = default;
|
||||||
|
|
||||||
|
void BlitImageHelper::BlitColor(GLuint dst_framebuffer, GLuint src_image_view, GLuint src_sampler,
|
||||||
|
const Region2D& dst_region, const Region2D& src_region,
|
||||||
|
const Extent3D& src_size) {
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glDisable(GL_COLOR_LOGIC_OP);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_STENCIL_TEST);
|
||||||
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
glDisable(GL_RASTERIZER_DISCARD);
|
||||||
|
glDisable(GL_ALPHA_TEST);
|
||||||
|
glDisablei(GL_BLEND, 0);
|
||||||
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glFrontFace(GL_CW);
|
||||||
|
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
glDepthRangeIndexed(0, 0.0, 0.0);
|
||||||
|
|
||||||
|
program_manager.BindPresentPrograms(full_screen_vert.handle, blit_color_to_color_frag.handle);
|
||||||
|
glProgramUniform2f(full_screen_vert.handle, 0,
|
||||||
|
static_cast<float>(src_region.end.x - src_region.start.x) /
|
||||||
|
static_cast<float>(src_size.width),
|
||||||
|
static_cast<float>(src_region.end.y - src_region.start.y) /
|
||||||
|
static_cast<float>(src_size.height));
|
||||||
|
glProgramUniform2f(full_screen_vert.handle, 1,
|
||||||
|
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));
|
||||||
|
glViewport(std::min(dst_region.start.x, dst_region.end.x),
|
||||||
|
std::min(dst_region.start.y, dst_region.end.y),
|
||||||
|
std::abs(dst_region.end.x - dst_region.start.x),
|
||||||
|
std::abs(dst_region.end.y - dst_region.start.y));
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst_framebuffer);
|
||||||
|
glBindSampler(0, src_sampler);
|
||||||
|
glBindTextureUnit(0, src_image_view);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
}
|
||||||
|
} // namespace OpenGL
|
38
src/video_core/renderer_opengl/blit_image.h
Normal file
38
src/video_core/renderer_opengl/blit_image.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include "video_core/engines/fermi_2d.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||||
|
#include "video_core/texture_cache/types.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
using VideoCommon::Extent3D;
|
||||||
|
using VideoCommon::Offset2D;
|
||||||
|
using VideoCommon::Region2D;
|
||||||
|
|
||||||
|
class ProgramManager;
|
||||||
|
class Framebuffer;
|
||||||
|
class ImageView;
|
||||||
|
|
||||||
|
class BlitImageHelper {
|
||||||
|
public:
|
||||||
|
explicit BlitImageHelper(ProgramManager& program_manager);
|
||||||
|
~BlitImageHelper();
|
||||||
|
|
||||||
|
void BlitColor(GLuint dst_framebuffer, GLuint src_image_view, GLuint src_sampler,
|
||||||
|
const Region2D& dst_region, const Region2D& src_region,
|
||||||
|
const Extent3D& src_size);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ProgramManager& program_manager;
|
||||||
|
|
||||||
|
OGLProgram full_screen_vert;
|
||||||
|
OGLProgram blit_color_to_color_frag;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace OpenGL
|
Loading…
Reference in a new issue