aboutsummaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/CMakeLists.txt11
-rw-r--r--src/video_core/regs_texturing.h27
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp20
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp87
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp10
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.h3
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp53
-rw-r--r--src/video_core/video_core.h15
8 files changed, 137 insertions, 89 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index e00b88f71..0961a3251 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -79,13 +79,14 @@ endif()
create_directory_groups(${SRCS} ${HEADERS})
add_library(video_core STATIC ${SRCS} ${HEADERS})
-target_link_libraries(video_core glad)
+target_link_libraries(video_core PUBLIC common core)
+target_link_libraries(video_core PRIVATE glad nihstro-headers)
+
if (ARCHITECTURE_x86_64)
- target_link_libraries(video_core xbyak)
+ target_link_libraries(video_core PRIVATE xbyak)
endif()
if (PNG_FOUND)
- target_link_libraries(video_core ${PNG_LIBRARIES})
- include_directories(${PNG_INCLUDE_DIRS})
- add_definitions(${PNG_DEFINITIONS})
+ target_link_libraries(video_core PRIVATE PNG::PNG)
+ target_compile_definitions(video_core PRIVATE HAVE_PNG)
endif()
diff --git a/src/video_core/regs_texturing.h b/src/video_core/regs_texturing.h
index e4038b41b..3f5355fa9 100644
--- a/src/video_core/regs_texturing.h
+++ b/src/video_core/regs_texturing.h
@@ -133,7 +133,32 @@ struct TexturingRegs {
BitField<16, 1, u32> clear_texture_cache; // TODO: unimplemented
} main_config;
TextureConfig texture0;
- INSERT_PADDING_WORDS(0x8);
+
+ enum class CubeFace {
+ PositiveX = 0,
+ NegativeX = 1,
+ PositiveY = 2,
+ NegativeY = 3,
+ PositiveZ = 4,
+ NegativeZ = 5,
+ };
+
+ BitField<0, 22, u32> cube_address[5];
+
+ PAddr GetCubePhysicalAddress(CubeFace face) const {
+ PAddr address = texture0.address;
+ if (face != CubeFace::PositiveX) {
+ // Bits [22:27] from the main texture address is shared with all cubemap additional
+ // addresses.
+ auto& face_addr = cube_address[static_cast<size_t>(face) - 1];
+ address &= ~face_addr.mask;
+ address |= face_addr;
+ }
+ // A multiplier of 8 is also needed in the same way as the main address.
+ return address * 8;
+ }
+
+ INSERT_PADDING_WORDS(0x3);
BitField<0, 4, TextureFormat> texture0_format;
BitField<0, 1, u32> fragment_lighting_enable;
INSERT_PADDING_WORDS(0x1);
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 456443e86..8b717e43d 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -561,20 +561,16 @@ RasterizerCacheOpenGL::GetFramebufferSurfaces(
color_params.is_tiled = depth_params.is_tiled = true;
// Set the internal resolution, assume the same scaling factor for top and bottom screens
- const Layout::FramebufferLayout& layout = VideoCore::g_emu_window->GetFramebufferLayout();
- if (Settings::values.resolution_factor == 0.0f) {
+ float resolution_scale_factor = Settings::values.resolution_factor;
+ if (resolution_scale_factor == 0.0f) {
// Auto - scale resolution to the window size
- color_params.res_scale_width = depth_params.res_scale_width =
- (float)layout.top_screen.GetWidth() / VideoCore::kScreenTopWidth;
- color_params.res_scale_height = depth_params.res_scale_height =
- (float)layout.top_screen.GetHeight() / VideoCore::kScreenTopHeight;
- } else {
- // Otherwise, scale the resolution by the specified factor
- color_params.res_scale_width = Settings::values.resolution_factor;
- depth_params.res_scale_width = Settings::values.resolution_factor;
- color_params.res_scale_height = Settings::values.resolution_factor;
- depth_params.res_scale_height = Settings::values.resolution_factor;
+ resolution_scale_factor = VideoCore::g_emu_window->GetFramebufferLayout().GetScalingRatio();
}
+ // Scale the resolution by the specified factor
+ color_params.res_scale_width = resolution_scale_factor;
+ depth_params.res_scale_width = resolution_scale_factor;
+ color_params.res_scale_height = resolution_scale_factor;
+ depth_params.res_scale_height = resolution_scale_factor;
color_params.addr = config.GetColorBufferPhysicalAddress();
color_params.pixel_format = CachedSurface::PixelFormatFromColorFormat(config.color_format);
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 3eeb47d33..db53710aa 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -152,12 +152,40 @@ static bool IsPassThroughTevStage(const TevStageConfig& stage) {
stage.GetColorMultiplier() == 1 && stage.GetAlphaMultiplier() == 1);
}
-static std::string TexCoord(const PicaShaderConfig& config, int texture_unit) {
- if (texture_unit == 2 && config.state.texture2_use_coord1) {
- return "texcoord[1]";
+static std::string SampleTexture(const PicaShaderConfig& config, unsigned texture_unit) {
+ const auto& state = config.state;
+ switch (texture_unit) {
+ case 0:
+ // Only unit 0 respects the texturing type
+ switch (state.texture0_type) {
+ case TexturingRegs::TextureConfig::Texture2D:
+ return "texture(tex[0], texcoord[0])";
+ case TexturingRegs::TextureConfig::Projection2D:
+ return "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))";
+ default:
+ LOG_CRITICAL(HW_GPU, "Unhandled texture type %x",
+ static_cast<int>(state.texture0_type));
+ UNIMPLEMENTED();
+ return "texture(tex[0], texcoord[0])";
+ }
+ case 1:
+ return "texture(tex[1], texcoord[1])";
+ case 2:
+ if (state.texture2_use_coord1)
+ return "texture(tex[2], texcoord[1])";
+ else
+ return "texture(tex[2], texcoord[2])";
+ case 3:
+ if (state.proctex.enable) {
+ return "ProcTex()";
+ } else {
+ LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it");
+ return "vec4(0.0)";
+ }
+ default:
+ UNREACHABLE();
+ return "";
}
-
- return "texcoord[" + std::to_string(texture_unit) + "]";
}
/// Writes the specified TEV stage source component(s)
@@ -176,35 +204,16 @@ static void AppendSource(std::string& out, const PicaShaderConfig& config,
out += "secondary_fragment_color";
break;
case Source::Texture0:
- // Only unit 0 respects the texturing type (according to 3DBrew)
- switch (state.texture0_type) {
- case TexturingRegs::TextureConfig::Texture2D:
- out += "texture(tex[0], texcoord[0])";
- break;
- case TexturingRegs::TextureConfig::Projection2D:
- out += "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))";
- break;
- default:
- out += "texture(tex[0], texcoord[0])";
- LOG_CRITICAL(HW_GPU, "Unhandled texture type %x",
- static_cast<int>(state.texture0_type));
- UNIMPLEMENTED();
- break;
- }
+ out += SampleTexture(config, 0);
break;
case Source::Texture1:
- out += "texture(tex[1], texcoord[1])";
+ out += SampleTexture(config, 1);
break;
case Source::Texture2:
- out += "texture(tex[2], " + TexCoord(config, 2) + ")";
+ out += SampleTexture(config, 2);
break;
case Source::Texture3:
- if (config.state.proctex.enable) {
- out += "ProcTex()";
- } else {
- LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it");
- out += "vec4(0.0)";
- }
+ out += SampleTexture(config, 3);
break;
case Source::PreviousBuffer:
out += "combiner_buffer";
@@ -515,18 +524,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) {
// Bump mapping is enabled using a normal map, read perturbation vector from the selected
// texture
- if (lighting.bump_selector == 3) {
- if (config.state.proctex.enable) {
- out += "vec3 surface_normal = 2.0 * ProcTex().rgb - 1.0;\n";
- } else {
- LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it");
- out += "vec3 surface_normal = vec3(-1.0);\n";
- }
- } else {
- std::string bump_selector = std::to_string(lighting.bump_selector);
- out += "vec3 surface_normal = 2.0 * texture(tex[" + bump_selector + "], " +
- TexCoord(config, lighting.bump_selector) + ").rgb - 1.0;\n";
- }
+ out += "vec3 surface_normal = 2.0 * (" + SampleTexture(config, lighting.bump_selector) +
+ ").rgb - 1.0;\n";
// Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher
// precision result
@@ -545,8 +544,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
}
// Rotate the surface-local normal by the interpolated normal quaternion to convert it to
- // eyespace
- out += "vec3 normal = normalize(quaternion_rotate(normquat, surface_normal));\n";
+ // eyespace.
+ out += "vec3 normal = quaternion_rotate(normalize(normquat), surface_normal);\n";
// Gets the index into the specified lookup table for specular lighting
auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input,
@@ -1030,7 +1029,9 @@ uniform sampler1D proctex_diff_lut;
// Rotate the vector v by the quaternion q
vec3 quaternion_rotate(vec4 q, vec3 v) {
return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
-})";
+}
+
+)";
if (config.state.proctex.enable)
AppendProcTexSampler(out, config);
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index e19375466..d90c776f9 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -94,14 +94,8 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons
return matrix;
}
-/// RendererOpenGL constructor
-RendererOpenGL::RendererOpenGL() {
- resolution_width = std::max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth);
- resolution_height = VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight;
-}
-
-/// RendererOpenGL destructor
-RendererOpenGL::~RendererOpenGL() {}
+RendererOpenGL::RendererOpenGL() = default;
+RendererOpenGL::~RendererOpenGL() = default;
/// Swap buffers (render frame)
void RendererOpenGL::SwapBuffers() {
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h
index 87c556cff..0b4f69e8f 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.h
+++ b/src/video_core/renderer_opengl/renderer_opengl.h
@@ -68,9 +68,6 @@ private:
EmuWindow* render_window; ///< Handle to render window
- int resolution_width; ///< Current resolution width
- int resolution_height; ///< Current resolution height
-
OpenGLState state;
// OpenGL object IDs
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index e9edf0360..8b7b1defb 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <array>
#include <cmath>
+#include <tuple>
#include "common/assert.h"
#include "common/bit_field.h"
#include "common/color.h"
@@ -70,6 +71,49 @@ static int SignedArea(const Math::Vec2<Fix12P4>& vtx1, const Math::Vec2<Fix12P4>
return Math::Cross(vec1, vec2).z;
};
+/// Convert a 3D vector for cube map coordinates to 2D texture coordinates along with the face name
+static std::tuple<float24, float24, PAddr> ConvertCubeCoord(float24 u, float24 v, float24 w,
+ const TexturingRegs& regs) {
+ const float abs_u = std::abs(u.ToFloat32());
+ const float abs_v = std::abs(v.ToFloat32());
+ const float abs_w = std::abs(w.ToFloat32());
+ float24 x, y, z;
+ PAddr addr;
+ if (abs_u > abs_v && abs_u > abs_w) {
+ if (u > float24::FromFloat32(0)) {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveX);
+ y = -v;
+ } else {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeX);
+ y = v;
+ }
+ x = -w;
+ z = u;
+ } else if (abs_v > abs_w) {
+ if (v > float24::FromFloat32(0)) {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveY);
+ x = u;
+ } else {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeY);
+ x = -u;
+ }
+ y = w;
+ z = v;
+ } else {
+ if (w > float24::FromFloat32(0)) {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveZ);
+ y = -v;
+ } else {
+ addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeZ);
+ y = v;
+ }
+ x = u;
+ z = w;
+ }
+ const float24 half = float24::FromFloat32(0.5f);
+ return std::make_tuple(x / z * half + half, y / z * half + half, addr);
+}
+
MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240));
/**
@@ -284,10 +328,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
// Only unit 0 respects the texturing type (according to 3DBrew)
// TODO: Refactor so cubemaps and shadowmaps can be handled
+ PAddr texture_address = texture.config.GetPhysicalAddress();
if (i == 0) {
switch (texture.config.type) {
case TexturingRegs::TextureConfig::Texture2D:
break;
+ case TexturingRegs::TextureConfig::TextureCube: {
+ auto w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w);
+ std::tie(u, v, texture_address) = ConvertCubeCoord(u, v, w, regs.texturing);
+ break;
+ }
case TexturingRegs::TextureConfig::Projection2D: {
auto tc0_w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w);
u /= tc0_w;
@@ -322,8 +372,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
t = texture.config.height - 1 -
GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height);
- u8* texture_data =
- Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
+ const u8* texture_data = Memory::GetPhysicalPointer(texture_address);
auto info =
Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h
index 4aba19ca0..94e0867f0 100644
--- a/src/video_core/video_core.h
+++ b/src/video_core/video_core.h
@@ -15,21 +15,6 @@ class RendererBase;
namespace VideoCore {
-// 3DS Video Constants
-// -------------------
-
-// NOTE: The LCDs actually rotate the image 90 degrees when displaying. Because of that the
-// framebuffers in video memory are stored in column-major order and rendered sideways, causing
-// the widths and heights of the framebuffers read by the LCD to be switched compared to the
-// heights and widths of the screens listed here.
-static const int kScreenTopWidth = 400; ///< 3DS top screen width
-static const int kScreenTopHeight = 240; ///< 3DS top screen height
-static const int kScreenBottomWidth = 320; ///< 3DS bottom screen width
-static const int kScreenBottomHeight = 240; ///< 3DS bottom screen height
-
-// Video core renderer
-// ---------------------
-
extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin
extern EmuWindow* g_emu_window; ///< Emu window