2015-05-19 06:21:33 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-26 13:23:25 +02:00
|
|
|
#include <algorithm>
|
2015-06-21 14:40:28 +02:00
|
|
|
#include <memory>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
2015-08-30 08:37:42 +02:00
|
|
|
#include <glad/glad.h>
|
2017-12-13 19:18:09 +01:00
|
|
|
#include "common/alignment.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2015-06-27 18:56:17 +02:00
|
|
|
#include "common/math_util.h"
|
2016-12-15 07:52:09 +01:00
|
|
|
#include "common/microprofile.h"
|
2018-05-11 15:41:26 +02:00
|
|
|
#include "common/scope_exit.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "common/vector_math.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "core/hw/gpu.h"
|
2016-03-03 04:16:38 +01:00
|
|
|
#include "video_core/pica_state.h"
|
2017-01-29 00:12:09 +01:00
|
|
|
#include "video_core/regs_framebuffer.h"
|
|
|
|
#include "video_core/regs_rasterizer.h"
|
|
|
|
#include "video_core/regs_texturing.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
2015-10-06 04:33:47 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
2015-05-19 06:21:33 +02:00
|
|
|
#include "video_core/renderer_opengl/pica_to_gl.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "video_core/renderer_opengl/renderer_opengl.h"
|
2018-11-21 18:01:19 +01:00
|
|
|
#include "video_core/video_core.h"
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-11-17 08:29:10 +01:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
using PixelFormat = SurfaceParams::PixelFormat;
|
|
|
|
using SurfaceType = SurfaceParams::SurfaceType;
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
MICROPROFILE_DEFINE(OpenGL_VAO, "OpenGL", "Vertex Array Setup", MP_RGB(255, 128, 0));
|
|
|
|
MICROPROFILE_DEFINE(OpenGL_VS, "OpenGL", "Vertex Shader Setup", MP_RGB(192, 128, 128));
|
|
|
|
MICROPROFILE_DEFINE(OpenGL_GS, "OpenGL", "Geometry Shader Setup", MP_RGB(128, 192, 128));
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
|
|
|
|
MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
|
|
|
|
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
|
|
|
|
|
2018-07-31 12:51:42 +02:00
|
|
|
static bool IsVendorAmd() {
|
|
|
|
std::string gpu_vendor{reinterpret_cast<char const*>(glGetString(GL_VENDOR))};
|
|
|
|
return gpu_vendor == "ATI Technologies Inc." || gpu_vendor == "Advanced Micro Devices, Inc.";
|
|
|
|
}
|
|
|
|
|
2018-08-24 15:18:46 +02:00
|
|
|
RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window)
|
2018-07-31 12:51:42 +02:00
|
|
|
: is_amd(IsVendorAmd()), shader_dirty(true),
|
|
|
|
vertex_buffer(GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE, is_amd),
|
|
|
|
uniform_buffer(GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, false),
|
|
|
|
index_buffer(GL_ELEMENT_ARRAY_BUFFER, INDEX_BUFFER_SIZE, false),
|
2018-08-24 15:18:46 +02:00
|
|
|
texture_buffer(GL_TEXTURE_BUFFER, TEXTURE_BUFFER_SIZE, false), emu_window{window} {
|
2018-04-11 14:47:02 +02:00
|
|
|
|
|
|
|
allow_shadow = GLAD_GL_ARB_shader_image_load_store && GLAD_GL_ARB_shader_image_size &&
|
|
|
|
GLAD_GL_ARB_framebuffer_no_attachments;
|
|
|
|
if (!allow_shadow) {
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_WARNING(Render_OpenGL,
|
|
|
|
"Shadow might not be able to render because of unsupported OpenGL extensions.");
|
2018-04-11 14:47:02 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:56:53 +02:00
|
|
|
if (!GLAD_GL_ARB_texture_barrier) {
|
|
|
|
LOG_WARNING(Render_OpenGL,
|
|
|
|
"ARB_texture_barrier not supported. Some games might produce artifacts.");
|
|
|
|
}
|
|
|
|
|
2017-08-17 09:46:59 +02:00
|
|
|
// Clipping plane 0 is always enabled for PICA fixed clip plane z <= 0
|
|
|
|
state.clip_distance[0] = true;
|
|
|
|
|
2015-08-30 15:05:56 +02:00
|
|
|
// Create sampler objects
|
2018-09-06 22:03:28 +02:00
|
|
|
for (std::size_t i = 0; i < texture_samplers.size(); ++i) {
|
2015-08-30 15:05:56 +02:00
|
|
|
texture_samplers[i].Create();
|
|
|
|
state.texture_units[i].sampler = texture_samplers[i].sampler.handle;
|
|
|
|
}
|
|
|
|
|
2018-03-09 15:46:34 +01:00
|
|
|
// Create cubemap texture and sampler objects
|
|
|
|
texture_cube_sampler.Create();
|
|
|
|
state.texture_cube_unit.sampler = texture_cube_sampler.sampler.handle;
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
// Generate VAO
|
|
|
|
sw_vao.Create();
|
|
|
|
hw_vao.Create();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-11-10 17:58:53 +01:00
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
|
2018-05-19 14:47:25 +02:00
|
|
|
uniform_block_data.lighting_lut_dirty.fill(true);
|
|
|
|
uniform_block_data.lighting_lut_dirty_any = true;
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2016-05-21 01:04:57 +02:00
|
|
|
uniform_block_data.fog_lut_dirty = true;
|
|
|
|
|
2017-05-05 14:25:04 +02:00
|
|
|
uniform_block_data.proctex_noise_lut_dirty = true;
|
|
|
|
uniform_block_data.proctex_color_map_dirty = true;
|
|
|
|
uniform_block_data.proctex_alpha_map_dirty = true;
|
|
|
|
uniform_block_data.proctex_lut_dirty = true;
|
|
|
|
uniform_block_data.proctex_diff_lut_dirty = true;
|
|
|
|
|
2018-05-02 09:34:36 +02:00
|
|
|
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniform_buffer_alignment);
|
2018-05-11 15:41:26 +02:00
|
|
|
uniform_size_aligned_vs =
|
2018-09-06 22:03:28 +02:00
|
|
|
Common::AlignUp<std::size_t>(sizeof(VSUniformData), uniform_buffer_alignment);
|
2018-05-11 15:41:26 +02:00
|
|
|
uniform_size_aligned_gs =
|
2018-09-06 22:03:28 +02:00
|
|
|
Common::AlignUp<std::size_t>(sizeof(GSUniformData), uniform_buffer_alignment);
|
2018-05-02 09:34:36 +02:00
|
|
|
uniform_size_aligned_fs =
|
2018-09-06 22:03:28 +02:00
|
|
|
Common::AlignUp<std::size_t>(sizeof(UniformData), uniform_buffer_alignment);
|
2018-05-02 09:34:36 +02:00
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
// Set vertex attributes for software shader path
|
|
|
|
state.draw.vertex_array = sw_vao.handle;
|
|
|
|
state.draw.vertex_buffer = vertex_buffer.GetHandle();
|
|
|
|
state.Apply();
|
|
|
|
|
2018-11-17 08:29:10 +01:00
|
|
|
glVertexAttribPointer(ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, position));
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_POSITION);
|
2015-07-26 03:13:11 +02:00
|
|
|
|
2018-11-17 08:29:10 +01:00
|
|
|
glVertexAttribPointer(ATTRIBUTE_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
2016-09-18 02:38:01 +02:00
|
|
|
(GLvoid*)offsetof(HardwareVertex, color));
|
2018-11-17 08:29:10 +01:00
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_COLOR);
|
|
|
|
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, tex_coord0));
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, tex_coord1));
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, tex_coord2));
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0);
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD1);
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD2);
|
|
|
|
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_TEXCOORD0_W, 1, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, tex_coord0_w));
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0_W);
|
|
|
|
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_NORMQUAT, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
|
|
|
(GLvoid*)offsetof(HardwareVertex, normquat));
|
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_NORMQUAT);
|
|
|
|
|
|
|
|
glVertexAttribPointer(ATTRIBUTE_VIEW, 3, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
|
2016-09-18 02:38:01 +02:00
|
|
|
(GLvoid*)offsetof(HardwareVertex, view));
|
2018-11-17 08:29:10 +01:00
|
|
|
glEnableVertexAttribArray(ATTRIBUTE_VIEW);
|
2015-11-12 23:33:21 +01:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
// Create render framebuffer
|
2015-05-19 06:21:33 +02:00
|
|
|
framebuffer.Create();
|
|
|
|
|
2018-05-19 12:54:50 +02:00
|
|
|
// Allocate and bind texture buffer lut textures
|
|
|
|
texture_buffer_lut_rg.Create();
|
|
|
|
texture_buffer_lut_rgba.Create();
|
|
|
|
state.texture_buffer_lut_rg.texture_buffer = texture_buffer_lut_rg.handle;
|
|
|
|
state.texture_buffer_lut_rgba.texture_buffer = texture_buffer_lut_rgba.handle;
|
|
|
|
state.Apply();
|
|
|
|
glActiveTexture(TextureUnits::TextureBufferLUT_RG.Enum());
|
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, texture_buffer.GetHandle());
|
|
|
|
glActiveTexture(TextureUnits::TextureBufferLUT_RGBA.Enum());
|
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, texture_buffer.GetHandle());
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
// Bind index buffer for hardware shader path
|
|
|
|
state.draw.vertex_array = hw_vao.handle;
|
|
|
|
state.Apply();
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer.GetHandle());
|
|
|
|
|
2018-04-09 23:31:11 +02:00
|
|
|
shader_program_manager =
|
2018-07-31 12:51:42 +02:00
|
|
|
std::make_unique<ShaderProgramManager>(GLAD_GL_ARB_separate_shader_objects, is_amd);
|
2018-04-09 23:31:11 +02:00
|
|
|
|
2017-11-09 04:50:42 +01:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2018-04-04 16:23:55 +02:00
|
|
|
SyncEntireState();
|
|
|
|
}
|
|
|
|
|
|
|
|
RasterizerOpenGL::~RasterizerOpenGL() {}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncEntireState() {
|
2016-04-17 00:57:57 +02:00
|
|
|
// Sync fixed function OpenGL state
|
2017-08-22 08:49:53 +02:00
|
|
|
SyncClipEnabled();
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncCullMode();
|
|
|
|
SyncBlendEnabled();
|
|
|
|
SyncBlendFuncs();
|
|
|
|
SyncBlendColor();
|
2015-05-26 00:39:03 +02:00
|
|
|
SyncLogicOp();
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncStencilTest();
|
|
|
|
SyncDepthTest();
|
2016-03-31 15:36:00 +02:00
|
|
|
SyncColorWriteMask();
|
|
|
|
SyncStencilWriteMask();
|
|
|
|
SyncDepthWriteMask();
|
2018-04-03 08:00:06 +02:00
|
|
|
|
|
|
|
// Sync uniforms
|
|
|
|
SyncClipCoef();
|
|
|
|
SyncDepthScale();
|
|
|
|
SyncDepthOffset();
|
|
|
|
SyncAlphaTest();
|
|
|
|
SyncCombinerColor();
|
|
|
|
auto& tev_stages = Pica::g_state.regs.texturing.GetTevStages();
|
|
|
|
for (std::size_t index = 0; index < tev_stages.size(); ++index)
|
|
|
|
SyncTevConstColor(index, tev_stages[index]);
|
|
|
|
|
|
|
|
SyncGlobalAmbient();
|
|
|
|
for (unsigned light_index = 0; light_index < 8; light_index++) {
|
|
|
|
SyncLightSpecular0(light_index);
|
|
|
|
SyncLightSpecular1(light_index);
|
|
|
|
SyncLightDiffuse(light_index);
|
|
|
|
SyncLightAmbient(light_index);
|
|
|
|
SyncLightPosition(light_index);
|
|
|
|
SyncLightDistanceAttenuationBias(light_index);
|
|
|
|
SyncLightDistanceAttenuationScale(light_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncFogColor();
|
|
|
|
SyncProcTexNoise();
|
2018-07-04 16:16:38 +02:00
|
|
|
SyncProcTexBias();
|
2018-04-11 14:47:02 +02:00
|
|
|
SyncShadowBias();
|
2019-02-03 02:39:51 +01:00
|
|
|
SyncShadowTextureBias();
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2016-01-29 05:29:33 +01:00
|
|
|
/**
|
2017-06-10 10:55:17 +02:00
|
|
|
* This is a helper function to resolve an issue when interpolating opposite quaternions. See below
|
|
|
|
* for a detailed description of this issue (yuriks):
|
2016-01-29 05:29:33 +01:00
|
|
|
*
|
|
|
|
* For any rotation, there are two quaternions Q, and -Q, that represent the same rotation. If you
|
|
|
|
* interpolate two quaternions that are opposite, instead of going from one rotation to another
|
|
|
|
* using the shortest path, you'll go around the longest path. You can test if two quaternions are
|
2017-06-10 10:55:17 +02:00
|
|
|
* opposite by checking if Dot(Q1, Q2) < 0. In that case, you can flip either of them, therefore
|
|
|
|
* making Dot(Q1, -Q2) positive.
|
2016-01-29 05:29:33 +01:00
|
|
|
*
|
2017-06-10 10:55:17 +02:00
|
|
|
* This solution corrects this issue per-vertex before passing the quaternions to OpenGL. This is
|
|
|
|
* correct for most cases but can still rotate around the long way sometimes. An implementation
|
|
|
|
* which did `lerp(lerp(Q1, Q2), Q3)` (with proper weighting), applying the dot product check
|
|
|
|
* between each step would work for those cases at the cost of being more complex to implement.
|
|
|
|
*
|
|
|
|
* Fortunately however, the 3DS hardware happens to also use this exact same logic to work around
|
|
|
|
* these issues, making this basic implementation actually more accurate to the hardware.
|
2016-01-29 05:29:33 +01:00
|
|
|
*/
|
2019-02-27 04:38:34 +01:00
|
|
|
static bool AreQuaternionsOpposite(Common::Vec4<Pica::float24> qa, Common::Vec4<Pica::float24> qb) {
|
|
|
|
Common::Vec4f a{qa.x.ToFloat32(), qa.y.ToFloat32(), qa.z.ToFloat32(), qa.w.ToFloat32()};
|
|
|
|
Common::Vec4f b{qb.x.ToFloat32(), qb.y.ToFloat32(), qb.z.ToFloat32(), qb.w.ToFloat32()};
|
2016-01-29 05:29:33 +01:00
|
|
|
|
2019-02-27 04:38:34 +01:00
|
|
|
return (Common::Dot(a, b) < 0.f);
|
2016-01-29 05:29:33 +01:00
|
|
|
}
|
|
|
|
|
2015-07-22 01:04:05 +02:00
|
|
|
void RasterizerOpenGL::AddTriangle(const Pica::Shader::OutputVertex& v0,
|
|
|
|
const Pica::Shader::OutputVertex& v1,
|
|
|
|
const Pica::Shader::OutputVertex& v2) {
|
2016-01-29 05:29:33 +01:00
|
|
|
vertex_batch.emplace_back(v0, false);
|
|
|
|
vertex_batch.emplace_back(v1, AreQuaternionsOpposite(v0.quat, v1.quat));
|
|
|
|
vertex_batch.emplace_back(v2, AreQuaternionsOpposite(v0.quat, v2.quat));
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
static constexpr std::array<GLenum, 4> vs_attrib_types{
|
|
|
|
GL_BYTE, // VertexAttributeFormat::BYTE
|
|
|
|
GL_UNSIGNED_BYTE, // VertexAttributeFormat::UBYTE
|
|
|
|
GL_SHORT, // VertexAttributeFormat::SHORT
|
|
|
|
GL_FLOAT // VertexAttributeFormat::FLOAT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexArrayInfo {
|
|
|
|
u32 vs_input_index_min;
|
|
|
|
u32 vs_input_index_max;
|
|
|
|
u32 vs_input_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
RasterizerOpenGL::VertexArrayInfo RasterizerOpenGL::AnalyzeVertexArray(bool is_indexed) {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
const auto& vertex_attributes = regs.pipeline.vertex_attributes;
|
|
|
|
|
|
|
|
u32 vertex_min;
|
|
|
|
u32 vertex_max;
|
|
|
|
if (is_indexed) {
|
|
|
|
const auto& index_info = regs.pipeline.index_array;
|
|
|
|
PAddr address = vertex_attributes.GetPhysicalBaseAddress() + index_info.offset;
|
2018-11-21 18:01:19 +01:00
|
|
|
const u8* index_address_8 = VideoCore::g_memory->GetPhysicalPointer(address);
|
2018-05-11 15:41:26 +02:00
|
|
|
const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
|
|
|
|
bool index_u16 = index_info.format != 0;
|
|
|
|
|
|
|
|
vertex_min = 0xFFFF;
|
|
|
|
vertex_max = 0;
|
|
|
|
std::size_t size = regs.pipeline.num_vertices * (index_u16 ? 2 : 1);
|
|
|
|
res_cache.FlushRegion(address, size, nullptr);
|
|
|
|
for (u32 index = 0; index < regs.pipeline.num_vertices; ++index) {
|
|
|
|
u32 vertex = index_u16 ? index_address_16[index] : index_address_8[index];
|
|
|
|
vertex_min = std::min(vertex_min, vertex);
|
|
|
|
vertex_max = std::max(vertex_max, vertex);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vertex_min = regs.pipeline.vertex_offset;
|
|
|
|
vertex_max = regs.pipeline.vertex_offset + regs.pipeline.num_vertices - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 vertex_num = vertex_max - vertex_min + 1;
|
|
|
|
u32 vs_input_size = 0;
|
|
|
|
for (auto& loader : vertex_attributes.attribute_loaders) {
|
|
|
|
if (loader.component_count != 0) {
|
|
|
|
vs_input_size += loader.byte_count * vertex_num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {vertex_min, vertex_max, vs_input_size};
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset,
|
|
|
|
GLuint vs_input_index_min, GLuint vs_input_index_max) {
|
|
|
|
MICROPROFILE_SCOPE(OpenGL_VAO);
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
const auto& vertex_attributes = regs.pipeline.vertex_attributes;
|
|
|
|
PAddr base_address = vertex_attributes.GetPhysicalBaseAddress();
|
|
|
|
|
|
|
|
state.draw.vertex_array = hw_vao.handle;
|
|
|
|
state.draw.vertex_buffer = vertex_buffer.GetHandle();
|
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
std::array<bool, 16> enable_attributes{};
|
|
|
|
|
|
|
|
for (const auto& loader : vertex_attributes.attribute_loaders) {
|
|
|
|
if (loader.component_count == 0 || loader.byte_count == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 offset = 0;
|
|
|
|
for (u32 comp = 0; comp < loader.component_count && comp < 12; ++comp) {
|
|
|
|
u32 attribute_index = loader.GetComponent(comp);
|
|
|
|
if (attribute_index < 12) {
|
|
|
|
if (vertex_attributes.GetNumElements(attribute_index) != 0) {
|
|
|
|
offset = Common::AlignUp(
|
|
|
|
offset, vertex_attributes.GetElementSizeInBytes(attribute_index));
|
|
|
|
|
|
|
|
u32 input_reg = regs.vs.GetRegisterForAttribute(attribute_index);
|
|
|
|
GLint size = vertex_attributes.GetNumElements(attribute_index);
|
|
|
|
GLenum type = vs_attrib_types[static_cast<u32>(
|
|
|
|
vertex_attributes.GetFormat(attribute_index))];
|
|
|
|
GLsizei stride = loader.byte_count;
|
|
|
|
glVertexAttribPointer(input_reg, size, type, GL_FALSE, stride,
|
|
|
|
reinterpret_cast<GLvoid*>(buffer_offset + offset));
|
|
|
|
enable_attributes[input_reg] = true;
|
|
|
|
|
|
|
|
offset += vertex_attributes.GetStride(attribute_index);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Attribute ids 12, 13, 14 and 15 signify 4, 8, 12 and 16-byte paddings,
|
|
|
|
// respectively
|
|
|
|
offset = Common::AlignUp(offset, 4);
|
|
|
|
offset += (attribute_index - 11) * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PAddr data_addr =
|
|
|
|
base_address + loader.data_offset + (vs_input_index_min * loader.byte_count);
|
|
|
|
|
|
|
|
u32 vertex_num = vs_input_index_max - vs_input_index_min + 1;
|
|
|
|
u32 data_size = loader.byte_count * vertex_num;
|
|
|
|
|
|
|
|
res_cache.FlushRegion(data_addr, data_size, nullptr);
|
2018-11-21 18:01:19 +01:00
|
|
|
std::memcpy(array_ptr, VideoCore::g_memory->GetPhysicalPointer(data_addr), data_size);
|
2018-05-11 15:41:26 +02:00
|
|
|
|
|
|
|
array_ptr += data_size;
|
|
|
|
buffer_offset += data_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < enable_attributes.size(); ++i) {
|
|
|
|
if (enable_attributes[i] != hw_vao_enabled_attributes[i]) {
|
|
|
|
if (enable_attributes[i]) {
|
|
|
|
glEnableVertexAttribArray(i);
|
|
|
|
} else {
|
|
|
|
glDisableVertexAttribArray(i);
|
|
|
|
}
|
|
|
|
hw_vao_enabled_attributes[i] = enable_attributes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vertex_attributes.IsDefaultAttribute(i)) {
|
|
|
|
u32 reg = regs.vs.GetRegisterForAttribute(i);
|
|
|
|
if (!enable_attributes[reg]) {
|
|
|
|
const auto& attr = Pica::g_state.input_default_attributes.attr[i];
|
|
|
|
glVertexAttrib4f(reg, attr.x.ToFloat32(), attr.y.ToFloat32(), attr.z.ToFloat32(),
|
|
|
|
attr.w.ToFloat32());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RasterizerOpenGL::SetupVertexShader() {
|
|
|
|
MICROPROFILE_SCOPE(OpenGL_VS);
|
2018-11-17 08:29:10 +01:00
|
|
|
PicaVSConfig vs_config(Pica::g_state.regs, Pica::g_state.vs);
|
2018-05-11 15:41:26 +02:00
|
|
|
return shader_program_manager->UseProgrammableVertexShader(vs_config, Pica::g_state.vs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RasterizerOpenGL::SetupGeometryShader() {
|
|
|
|
MICROPROFILE_SCOPE(OpenGL_GS);
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
if (regs.pipeline.use_gs == Pica::PipelineRegs::UseGS::No) {
|
2018-11-17 08:29:10 +01:00
|
|
|
PicaFixedGSConfig gs_config(regs);
|
2018-05-11 15:41:26 +02:00
|
|
|
shader_program_manager->UseFixedGeometryShader(gs_config);
|
|
|
|
return true;
|
|
|
|
} else {
|
2018-11-17 08:29:10 +01:00
|
|
|
PicaGSConfig gs_config(regs, Pica::g_state.gs);
|
2018-05-11 15:41:26 +02:00
|
|
|
return shader_program_manager->UseProgrammableGeometryShader(gs_config, Pica::g_state.gs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RasterizerOpenGL::AccelerateDrawBatch(bool is_indexed) {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
if (regs.pipeline.use_gs != Pica::PipelineRegs::UseGS::No) {
|
|
|
|
if (regs.pipeline.gs_config.mode != Pica::PipelineRegs::GSMode::Point) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (regs.pipeline.triangle_topology != Pica::PipelineRegs::TriangleTopology::Shader) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetupVertexShader())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!SetupGeometryShader())
|
|
|
|
return false;
|
|
|
|
|
2018-05-18 12:55:19 +02:00
|
|
|
return Draw(true, is_indexed);
|
2018-05-11 15:41:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum GetCurrentPrimitiveMode(bool use_gs) {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
if (use_gs) {
|
|
|
|
switch ((regs.gs.max_input_attribute_index + 1) /
|
|
|
|
(regs.pipeline.vs_outmap_total_minus_1_a + 1)) {
|
|
|
|
case 1:
|
|
|
|
return GL_POINTS;
|
|
|
|
case 2:
|
|
|
|
return GL_LINES;
|
|
|
|
case 4:
|
|
|
|
return GL_LINES_ADJACENCY;
|
|
|
|
case 3:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
case 6:
|
|
|
|
return GL_TRIANGLES_ADJACENCY;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (regs.pipeline.triangle_topology) {
|
|
|
|
case Pica::PipelineRegs::TriangleTopology::Shader:
|
|
|
|
case Pica::PipelineRegs::TriangleTopology::List:
|
|
|
|
return GL_TRIANGLES;
|
|
|
|
case Pica::PipelineRegs::TriangleTopology::Fan:
|
|
|
|
return GL_TRIANGLE_FAN;
|
|
|
|
case Pica::PipelineRegs::TriangleTopology::Strip:
|
|
|
|
return GL_TRIANGLE_STRIP;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:55:19 +02:00
|
|
|
bool RasterizerOpenGL::AccelerateDrawBatchInternal(bool is_indexed, bool use_gs) {
|
2018-05-11 15:41:26 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
GLenum primitive_mode = GetCurrentPrimitiveMode(use_gs);
|
|
|
|
|
|
|
|
auto [vs_input_index_min, vs_input_index_max, vs_input_size] = AnalyzeVertexArray(is_indexed);
|
|
|
|
|
2018-05-18 12:55:19 +02:00
|
|
|
if (vs_input_size > VERTEX_BUFFER_SIZE) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Render_OpenGL, "Too large vertex input size {}", vs_input_size);
|
2018-05-18 12:55:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
state.draw.vertex_buffer = vertex_buffer.GetHandle();
|
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
u8* buffer_ptr;
|
|
|
|
GLintptr buffer_offset;
|
|
|
|
std::tie(buffer_ptr, buffer_offset, std::ignore) = vertex_buffer.Map(vs_input_size, 4);
|
|
|
|
SetupVertexArray(buffer_ptr, buffer_offset, vs_input_index_min, vs_input_index_max);
|
|
|
|
vertex_buffer.Unmap(vs_input_size);
|
|
|
|
|
|
|
|
shader_program_manager->ApplyTo(state);
|
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
if (is_indexed) {
|
|
|
|
bool index_u16 = regs.pipeline.index_array.format != 0;
|
|
|
|
std::size_t index_buffer_size = regs.pipeline.num_vertices * (index_u16 ? 2 : 1);
|
2018-05-18 12:55:19 +02:00
|
|
|
|
|
|
|
if (index_buffer_size > INDEX_BUFFER_SIZE) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Render_OpenGL, "Too large index input size {}", index_buffer_size);
|
2018-05-18 12:55:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-21 18:01:19 +01:00
|
|
|
const u8* index_data = VideoCore::g_memory->GetPhysicalPointer(
|
|
|
|
regs.pipeline.vertex_attributes.GetPhysicalBaseAddress() +
|
|
|
|
regs.pipeline.index_array.offset);
|
2018-05-11 15:41:26 +02:00
|
|
|
std::tie(buffer_ptr, buffer_offset, std::ignore) = index_buffer.Map(index_buffer_size, 4);
|
|
|
|
std::memcpy(buffer_ptr, index_data, index_buffer_size);
|
|
|
|
index_buffer.Unmap(index_buffer_size);
|
|
|
|
|
|
|
|
glDrawRangeElementsBaseVertex(
|
|
|
|
primitive_mode, vs_input_index_min, vs_input_index_max, regs.pipeline.num_vertices,
|
|
|
|
index_u16 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE,
|
|
|
|
reinterpret_cast<const void*>(buffer_offset), -static_cast<GLint>(vs_input_index_min));
|
|
|
|
} else {
|
|
|
|
glDrawArrays(primitive_mode, 0, regs.pipeline.num_vertices);
|
|
|
|
}
|
2018-05-18 12:55:19 +02:00
|
|
|
return true;
|
2018-05-11 15:41:26 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void RasterizerOpenGL::DrawTriangles() {
|
2016-03-06 03:09:55 +01:00
|
|
|
if (vertex_batch.empty())
|
|
|
|
return;
|
2018-05-11 15:41:26 +02:00
|
|
|
Draw(false, false);
|
|
|
|
}
|
2016-03-06 03:09:55 +01:00
|
|
|
|
2018-05-18 12:55:19 +02:00
|
|
|
bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) {
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_Drawing);
|
2016-04-17 00:57:57 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
bool shadow_rendering = regs.framebuffer.output_merger.fragment_operation_mode ==
|
|
|
|
Pica::FramebufferRegs::FragmentOperationMode::Shadow;
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
const bool has_stencil =
|
|
|
|
regs.framebuffer.framebuffer.depth_format == Pica::FramebufferRegs::DepthFormat::D24S8;
|
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
const bool write_color_fb = shadow_rendering || state.color_mask.red_enabled == GL_TRUE ||
|
|
|
|
state.color_mask.green_enabled == GL_TRUE ||
|
|
|
|
state.color_mask.blue_enabled == GL_TRUE ||
|
|
|
|
state.color_mask.alpha_enabled == GL_TRUE;
|
2017-12-12 18:21:55 +01:00
|
|
|
|
|
|
|
const bool write_depth_fb =
|
|
|
|
(state.depth.test_enabled && state.depth.write_mask == GL_TRUE) ||
|
|
|
|
(has_stencil && state.stencil.test_enabled && state.stencil.write_mask != 0);
|
|
|
|
|
|
|
|
const bool using_color_fb =
|
|
|
|
regs.framebuffer.framebuffer.GetColorBufferPhysicalAddress() != 0 && write_color_fb;
|
|
|
|
const bool using_depth_fb =
|
2018-04-11 14:47:02 +02:00
|
|
|
!shadow_rendering && regs.framebuffer.framebuffer.GetDepthBufferPhysicalAddress() != 0 &&
|
2017-12-12 18:21:55 +01:00
|
|
|
(write_depth_fb || regs.framebuffer.output_merger.depth_test_enable != 0 ||
|
|
|
|
(has_stencil && state.stencil.test_enabled));
|
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<s32> viewport_rect_unscaled{
|
2017-12-12 18:21:55 +01:00
|
|
|
// These registers hold half-width and half-height, so must be multiplied by 2
|
|
|
|
regs.rasterizer.viewport_corner.x, // left
|
|
|
|
regs.rasterizer.viewport_corner.y + // top
|
|
|
|
static_cast<s32>(Pica::float24::FromRaw(regs.rasterizer.viewport_size_y).ToFloat32() *
|
|
|
|
2),
|
|
|
|
regs.rasterizer.viewport_corner.x + // right
|
|
|
|
static_cast<s32>(Pica::float24::FromRaw(regs.rasterizer.viewport_size_x).ToFloat32() *
|
|
|
|
2),
|
|
|
|
regs.rasterizer.viewport_corner.y // bottom
|
|
|
|
};
|
|
|
|
|
|
|
|
Surface color_surface;
|
|
|
|
Surface depth_surface;
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> surfaces_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
std::tie(color_surface, depth_surface, surfaces_rect) =
|
|
|
|
res_cache.GetFramebufferSurfaces(using_color_fb, using_depth_fb, viewport_rect_unscaled);
|
|
|
|
|
|
|
|
const u16 res_scale = color_surface != nullptr
|
|
|
|
? color_surface->res_scale
|
|
|
|
: (depth_surface == nullptr ? 1u : depth_surface->res_scale);
|
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> draw_rect{
|
2018-07-24 19:08:17 +02:00
|
|
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
2018-07-26 13:23:25 +02:00
|
|
|
viewport_rect_unscaled.left * res_scale,
|
|
|
|
surfaces_rect.left, surfaces_rect.right)), // Left
|
2018-07-24 19:08:17 +02:00
|
|
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
2018-07-26 13:23:25 +02:00
|
|
|
viewport_rect_unscaled.top * res_scale,
|
|
|
|
surfaces_rect.bottom, surfaces_rect.top)), // Top
|
2018-07-24 19:08:17 +02:00
|
|
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.left) +
|
2018-07-26 13:23:25 +02:00
|
|
|
viewport_rect_unscaled.right * res_scale,
|
|
|
|
surfaces_rect.left, surfaces_rect.right)), // Right
|
2018-07-24 19:08:17 +02:00
|
|
|
static_cast<u32>(std::clamp<s32>(static_cast<s32>(surfaces_rect.bottom) +
|
2018-07-26 13:23:25 +02:00
|
|
|
viewport_rect_unscaled.bottom * res_scale,
|
|
|
|
surfaces_rect.bottom, surfaces_rect.top))}; // Bottom
|
2017-12-12 18:21:55 +01:00
|
|
|
|
|
|
|
// Bind the framebuffer surfaces
|
2016-04-17 00:57:57 +02:00
|
|
|
state.draw.draw_framebuffer = framebuffer.handle;
|
|
|
|
state.Apply();
|
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
if (shadow_rendering) {
|
|
|
|
if (!allow_shadow || color_surface == nullptr) {
|
|
|
|
return true;
|
2017-09-16 05:30:35 +02:00
|
|
|
}
|
2018-04-11 14:47:02 +02:00
|
|
|
glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH,
|
|
|
|
color_surface->width * color_surface->res_scale);
|
|
|
|
glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT,
|
|
|
|
color_surface->height * color_surface->res_scale);
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
|
2017-09-16 05:30:35 +02:00
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
|
|
|
|
0);
|
2018-04-11 14:47:02 +02:00
|
|
|
state.image_shadow_buffer = color_surface->texture.handle;
|
|
|
|
} else {
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
|
|
|
color_surface != nullptr ? color_surface->texture.handle : 0, 0);
|
|
|
|
if (depth_surface != nullptr) {
|
|
|
|
if (has_stencil) {
|
|
|
|
// attach both depth and stencil
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
GL_TEXTURE_2D, depth_surface->texture.handle, 0);
|
|
|
|
} else {
|
|
|
|
// attach depth
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
|
|
|
depth_surface->texture.handle, 0);
|
|
|
|
// clear stencil attachment
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// clear both depth and stencil attachment
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
|
|
|
|
0, 0);
|
|
|
|
}
|
2017-09-16 05:30:35 +02:00
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
// Sync the viewport
|
2017-12-12 18:21:55 +01:00
|
|
|
state.viewport.x =
|
2017-12-29 17:07:01 +01:00
|
|
|
static_cast<GLint>(surfaces_rect.left) + viewport_rect_unscaled.left * res_scale;
|
2017-12-12 18:21:55 +01:00
|
|
|
state.viewport.y =
|
2017-12-29 17:07:01 +01:00
|
|
|
static_cast<GLint>(surfaces_rect.bottom) + viewport_rect_unscaled.bottom * res_scale;
|
2017-12-12 18:21:55 +01:00
|
|
|
state.viewport.width = static_cast<GLsizei>(viewport_rect_unscaled.GetWidth() * res_scale);
|
|
|
|
state.viewport.height = static_cast<GLsizei>(viewport_rect_unscaled.GetHeight() * res_scale);
|
|
|
|
|
|
|
|
if (uniform_block_data.data.framebuffer_scale != res_scale) {
|
|
|
|
uniform_block_data.data.framebuffer_scale = res_scale;
|
2016-06-28 07:16:04 +02:00
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
|
2016-09-16 09:25:28 +02:00
|
|
|
// Scissor checks are window-, not viewport-relative, which means that if the cached texture
|
|
|
|
// sub-rect changes, the scissor bounds also need to be updated.
|
2017-12-12 18:21:55 +01:00
|
|
|
GLint scissor_x1 =
|
|
|
|
static_cast<GLint>(surfaces_rect.left + regs.rasterizer.scissor_test.x1 * res_scale);
|
|
|
|
GLint scissor_y1 =
|
|
|
|
static_cast<GLint>(surfaces_rect.bottom + regs.rasterizer.scissor_test.y1 * res_scale);
|
2016-09-16 09:25:28 +02:00
|
|
|
// x2, y2 have +1 added to cover the entire pixel area, otherwise you might get cracks when
|
|
|
|
// scaling or doing multisampling.
|
2017-12-12 18:21:55 +01:00
|
|
|
GLint scissor_x2 =
|
|
|
|
static_cast<GLint>(surfaces_rect.left + (regs.rasterizer.scissor_test.x2 + 1) * res_scale);
|
|
|
|
GLint scissor_y2 = static_cast<GLint>(surfaces_rect.bottom +
|
|
|
|
(regs.rasterizer.scissor_test.y2 + 1) * res_scale);
|
2016-09-16 09:25:28 +02:00
|
|
|
|
|
|
|
if (uniform_block_data.data.scissor_x1 != scissor_x1 ||
|
|
|
|
uniform_block_data.data.scissor_x2 != scissor_x2 ||
|
|
|
|
uniform_block_data.data.scissor_y1 != scissor_y1 ||
|
|
|
|
uniform_block_data.data.scissor_y2 != scissor_y2) {
|
|
|
|
|
|
|
|
uniform_block_data.data.scissor_x1 = scissor_x1;
|
|
|
|
uniform_block_data.data.scissor_x2 = scissor_x2;
|
|
|
|
uniform_block_data.data.scissor_y1 = scissor_y1;
|
|
|
|
uniform_block_data.data.scissor_y2 = scissor_y2;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:56:53 +02:00
|
|
|
bool need_texture_barrier = false;
|
|
|
|
auto CheckBarrier = [&need_texture_barrier, &color_surface](GLuint handle) {
|
|
|
|
if (color_surface && color_surface->texture.handle == handle) {
|
|
|
|
need_texture_barrier = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
// Sync and bind the texture surfaces
|
2017-01-28 05:51:59 +01:00
|
|
|
const auto pica_textures = regs.texturing.GetTextures();
|
2016-04-17 00:57:57 +02:00
|
|
|
for (unsigned texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
|
|
|
|
const auto& texture = pica_textures[texture_index];
|
|
|
|
|
|
|
|
if (texture.enabled) {
|
2018-03-09 15:46:34 +01:00
|
|
|
if (texture_index == 0) {
|
|
|
|
using TextureType = Pica::TexturingRegs::TextureConfig::TextureType;
|
|
|
|
switch (texture.config.type.Value()) {
|
2018-04-11 14:47:02 +02:00
|
|
|
case TextureType::Shadow2D: {
|
|
|
|
if (!allow_shadow)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Surface surface = res_cache.GetTextureSurface(texture);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_px = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_px = 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case TextureType::ShadowCube: {
|
|
|
|
if (!allow_shadow)
|
|
|
|
continue;
|
|
|
|
Pica::Texture::TextureInfo info = Pica::Texture::TextureInfo::FromPicaRegister(
|
|
|
|
texture.config, texture.format);
|
|
|
|
Surface surface;
|
|
|
|
|
|
|
|
using CubeFace = Pica::TexturingRegs::CubeFace;
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveX);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_px = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_px = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeX);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_nx = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_nx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveY);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_py = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_py = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeY);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_ny = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_ny = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveZ);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_pz = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_pz = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.physical_address =
|
|
|
|
regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeZ);
|
|
|
|
surface = res_cache.GetTextureSurface(info);
|
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.image_shadow_texture_nz = surface->texture.handle);
|
2018-04-11 14:47:02 +02:00
|
|
|
} else {
|
|
|
|
state.image_shadow_texture_nz = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-09 15:46:34 +01:00
|
|
|
case TextureType::TextureCube:
|
|
|
|
using CubeFace = Pica::TexturingRegs::CubeFace;
|
2018-04-29 11:51:02 +02:00
|
|
|
TextureCubeConfig config;
|
|
|
|
config.px = regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveX);
|
|
|
|
config.nx = regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeX);
|
|
|
|
config.py = regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveY);
|
|
|
|
config.ny = regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeY);
|
|
|
|
config.pz = regs.texturing.GetCubePhysicalAddress(CubeFace::PositiveZ);
|
|
|
|
config.nz = regs.texturing.GetCubePhysicalAddress(CubeFace::NegativeZ);
|
|
|
|
config.width = texture.config.width;
|
|
|
|
config.format = texture.format;
|
|
|
|
state.texture_cube_unit.texture_cube =
|
|
|
|
res_cache.GetTextureCube(config).texture.handle;
|
|
|
|
|
2018-03-09 15:46:34 +01:00
|
|
|
texture_cube_sampler.SyncWithConfig(texture.config);
|
|
|
|
state.texture_units[texture_index].texture_2d = 0;
|
|
|
|
continue; // Texture unit 0 setup finished. Continue to next unit
|
|
|
|
}
|
2018-05-28 20:58:44 +02:00
|
|
|
state.texture_cube_unit.texture_cube = 0;
|
2018-03-09 15:46:34 +01:00
|
|
|
}
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
texture_samplers[texture_index].SyncWithConfig(texture.config);
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface surface = res_cache.GetTextureSurface(texture);
|
2016-04-17 00:57:57 +02:00
|
|
|
if (surface != nullptr) {
|
2018-07-09 21:56:53 +02:00
|
|
|
CheckBarrier(state.texture_units[texture_index].texture_2d =
|
|
|
|
surface->texture.handle);
|
2016-04-17 00:57:57 +02:00
|
|
|
} else {
|
|
|
|
// Can occur when texture addr is null or its memory is unmapped/invalid
|
|
|
|
state.texture_units[texture_index].texture_2d = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state.texture_units[texture_index].texture_2d = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
// Sync and bind the shader
|
|
|
|
if (shader_dirty) {
|
2015-10-06 04:33:47 +02:00
|
|
|
SetShader();
|
2016-04-17 00:57:57 +02:00
|
|
|
shader_dirty = false;
|
2015-07-26 03:13:11 +02:00
|
|
|
}
|
|
|
|
|
2018-05-19 11:12:51 +02:00
|
|
|
// Sync the LUTs within the texture buffer
|
|
|
|
SyncAndUploadLUTs();
|
2017-05-05 14:25:04 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
// Sync the uniform data
|
2018-05-11 15:41:26 +02:00
|
|
|
const bool use_gs = regs.pipeline.use_gs == Pica::PipelineRegs::UseGS::Yes;
|
|
|
|
UploadUniforms(accelerate, use_gs);
|
2015-11-10 17:58:53 +01:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
// Viewport can have negative offsets or larger
|
|
|
|
// dimensions than our framebuffer sub-rect.
|
|
|
|
// Enable scissor test to prevent drawing
|
|
|
|
// outside of the framebuffer region
|
|
|
|
state.scissor.enabled = true;
|
|
|
|
state.scissor.x = draw_rect.left;
|
|
|
|
state.scissor.y = draw_rect.bottom;
|
|
|
|
state.scissor.width = draw_rect.GetWidth();
|
|
|
|
state.scissor.height = draw_rect.GetHeight();
|
2016-04-17 00:57:57 +02:00
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
// Draw the vertex batch
|
2018-05-18 12:55:19 +02:00
|
|
|
bool succeeded = true;
|
2018-05-11 15:41:26 +02:00
|
|
|
if (accelerate) {
|
2018-05-18 12:55:19 +02:00
|
|
|
succeeded = AccelerateDrawBatchInternal(is_indexed, use_gs);
|
2018-05-11 15:41:26 +02:00
|
|
|
} else {
|
|
|
|
state.draw.vertex_array = sw_vao.handle;
|
|
|
|
state.draw.vertex_buffer = vertex_buffer.GetHandle();
|
|
|
|
shader_program_manager->UseTrivialVertexShader();
|
|
|
|
shader_program_manager->UseTrivialGeometryShader();
|
|
|
|
shader_program_manager->ApplyTo(state);
|
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
std::size_t max_vertices = 3 * (VERTEX_BUFFER_SIZE / (3 * sizeof(HardwareVertex)));
|
|
|
|
for (std::size_t base_vertex = 0; base_vertex < vertex_batch.size();
|
|
|
|
base_vertex += max_vertices) {
|
|
|
|
std::size_t vertices = std::min(max_vertices, vertex_batch.size() - base_vertex);
|
|
|
|
std::size_t vertex_size = vertices * sizeof(HardwareVertex);
|
|
|
|
u8* vbo;
|
|
|
|
GLintptr offset;
|
|
|
|
std::tie(vbo, offset, std::ignore) =
|
|
|
|
vertex_buffer.Map(vertex_size, sizeof(HardwareVertex));
|
|
|
|
std::memcpy(vbo, vertex_batch.data() + base_vertex, vertex_size);
|
|
|
|
vertex_buffer.Unmap(vertex_size);
|
|
|
|
glDrawArrays(GL_TRIANGLES, offset / sizeof(HardwareVertex), (GLsizei)vertices);
|
|
|
|
}
|
2018-03-14 23:36:54 +01:00
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
vertex_batch.clear();
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-06-01 00:27:46 +02:00
|
|
|
// Reset textures in rasterizer state context because the rasterizer cache might delete them
|
|
|
|
for (unsigned texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
|
|
|
|
state.texture_units[texture_index].texture_2d = 0;
|
|
|
|
}
|
|
|
|
state.texture_cube_unit.texture_cube = 0;
|
2018-04-11 14:47:02 +02:00
|
|
|
if (allow_shadow) {
|
|
|
|
state.image_shadow_texture_px = 0;
|
|
|
|
state.image_shadow_texture_nx = 0;
|
|
|
|
state.image_shadow_texture_py = 0;
|
|
|
|
state.image_shadow_texture_ny = 0;
|
|
|
|
state.image_shadow_texture_pz = 0;
|
|
|
|
state.image_shadow_texture_nz = 0;
|
|
|
|
state.image_shadow_buffer = 0;
|
|
|
|
}
|
2018-06-01 00:27:46 +02:00
|
|
|
state.Apply();
|
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
if (shadow_rendering) {
|
|
|
|
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT |
|
|
|
|
GL_TEXTURE_UPDATE_BARRIER_BIT | GL_FRAMEBUFFER_BARRIER_BIT);
|
|
|
|
}
|
|
|
|
|
2018-07-09 21:56:53 +02:00
|
|
|
if (need_texture_barrier && GLAD_GL_ARB_texture_barrier) {
|
|
|
|
glTextureBarrier();
|
|
|
|
}
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
// Mark framebuffer surfaces as dirty
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> draw_rect_unscaled{draw_rect.left / res_scale, draw_rect.top / res_scale,
|
|
|
|
draw_rect.right / res_scale,
|
|
|
|
draw_rect.bottom / res_scale};
|
2017-12-12 18:21:55 +01:00
|
|
|
|
|
|
|
if (color_surface != nullptr && write_color_fb) {
|
|
|
|
auto interval = color_surface->GetSubRectInterval(draw_rect_unscaled);
|
|
|
|
res_cache.InvalidateRegion(boost::icl::first(interval), boost::icl::length(interval),
|
|
|
|
color_surface);
|
|
|
|
}
|
|
|
|
if (depth_surface != nullptr && write_depth_fb) {
|
|
|
|
auto interval = depth_surface->GetSubRectInterval(draw_rect_unscaled);
|
|
|
|
res_cache.InvalidateRegion(boost::icl::first(interval), boost::icl::length(interval),
|
|
|
|
depth_surface);
|
|
|
|
}
|
2018-05-18 12:55:19 +02:00
|
|
|
|
|
|
|
return succeeded;
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
2015-05-14 05:29:27 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
switch (id) {
|
2015-05-19 06:21:33 +02:00
|
|
|
// Culling
|
2017-01-28 05:16:36 +01:00
|
|
|
case PICA_REG_INDEX(rasterizer.cull_mode):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncCullMode();
|
|
|
|
break;
|
|
|
|
|
2017-08-22 08:49:53 +02:00
|
|
|
// Clipping plane
|
|
|
|
case PICA_REG_INDEX(rasterizer.clip_enable):
|
|
|
|
SyncClipEnabled();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(rasterizer.clip_coef[0], 0x48):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(rasterizer.clip_coef[1], 0x49):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(rasterizer.clip_coef[2], 0x4a):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(rasterizer.clip_coef[3], 0x4b):
|
|
|
|
SyncClipCoef();
|
|
|
|
break;
|
|
|
|
|
2016-01-04 00:46:54 +01:00
|
|
|
// Depth modifiers
|
2017-01-28 05:16:36 +01:00
|
|
|
case PICA_REG_INDEX(rasterizer.viewport_depth_range):
|
2016-05-14 10:16:45 +02:00
|
|
|
SyncDepthScale();
|
|
|
|
break;
|
2017-01-28 05:16:36 +01:00
|
|
|
case PICA_REG_INDEX(rasterizer.viewport_depth_near_plane):
|
2016-05-14 10:16:45 +02:00
|
|
|
SyncDepthOffset();
|
2016-01-04 00:46:54 +01:00
|
|
|
break;
|
|
|
|
|
2016-03-30 19:27:04 +02:00
|
|
|
// Depth buffering
|
2017-01-28 05:16:36 +01:00
|
|
|
case PICA_REG_INDEX(rasterizer.depthmap_enable):
|
2016-03-30 19:27:04 +02:00
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
// Blending
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.alphablend_enable):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncBlendEnabled();
|
|
|
|
break;
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.alpha_blending):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncBlendFuncs();
|
|
|
|
break;
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.blend_const):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncBlendColor();
|
|
|
|
break;
|
|
|
|
|
2019-02-03 02:39:51 +01:00
|
|
|
// Shadow texture
|
|
|
|
case PICA_REG_INDEX(texturing.shadow):
|
|
|
|
SyncShadowTextureBias();
|
|
|
|
break;
|
|
|
|
|
2016-05-21 01:04:57 +02:00
|
|
|
// Fog state
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.fog_color):
|
2016-05-21 01:04:57 +02:00
|
|
|
SyncFogColor();
|
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[0], 0xe8):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[1], 0xe9):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[2], 0xea):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[3], 0xeb):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[4], 0xec):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[5], 0xed):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[6], 0xee):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.fog_lut_data[7], 0xef):
|
2016-05-21 01:04:57 +02:00
|
|
|
uniform_block_data.fog_lut_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2017-05-05 14:25:04 +02:00
|
|
|
// ProcTex state
|
|
|
|
case PICA_REG_INDEX(texturing.proctex):
|
|
|
|
case PICA_REG_INDEX(texturing.proctex_lut):
|
|
|
|
case PICA_REG_INDEX(texturing.proctex_lut_offset):
|
2018-07-04 16:16:38 +02:00
|
|
|
SyncProcTexBias();
|
2017-05-05 14:25:04 +02:00
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PICA_REG_INDEX(texturing.proctex_noise_u):
|
|
|
|
case PICA_REG_INDEX(texturing.proctex_noise_v):
|
|
|
|
case PICA_REG_INDEX(texturing.proctex_noise_frequency):
|
|
|
|
SyncProcTexNoise();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[0], 0xb0):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[1], 0xb1):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[2], 0xb2):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[3], 0xb3):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[4], 0xb4):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[5], 0xb5):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[6], 0xb6):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(texturing.proctex_lut_data[7], 0xb7):
|
|
|
|
using Pica::TexturingRegs;
|
|
|
|
switch (regs.texturing.proctex_lut_config.ref_table.Value()) {
|
|
|
|
case TexturingRegs::ProcTexLutTable::Noise:
|
|
|
|
uniform_block_data.proctex_noise_lut_dirty = true;
|
|
|
|
break;
|
|
|
|
case TexturingRegs::ProcTexLutTable::ColorMap:
|
|
|
|
uniform_block_data.proctex_color_map_dirty = true;
|
|
|
|
break;
|
|
|
|
case TexturingRegs::ProcTexLutTable::AlphaMap:
|
|
|
|
uniform_block_data.proctex_alpha_map_dirty = true;
|
|
|
|
break;
|
|
|
|
case TexturingRegs::ProcTexLutTable::Color:
|
|
|
|
uniform_block_data.proctex_lut_dirty = true;
|
|
|
|
break;
|
|
|
|
case TexturingRegs::ProcTexLutTable::ColorDiff:
|
|
|
|
uniform_block_data.proctex_diff_lut_dirty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
// Alpha test
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.alpha_test):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncAlphaTest();
|
2016-04-17 00:57:57 +02:00
|
|
|
shader_dirty = true;
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
|
|
|
|
2016-03-31 15:36:00 +02:00
|
|
|
// Sync GL stencil test + stencil write mask
|
|
|
|
// (Pica stencil test function register also contains a stencil write mask)
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.stencil_test.raw_func):
|
2016-03-31 15:36:00 +02:00
|
|
|
SyncStencilTest();
|
|
|
|
SyncStencilWriteMask();
|
|
|
|
break;
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.stencil_test.raw_op):
|
|
|
|
case PICA_REG_INDEX(framebuffer.framebuffer.depth_format):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncStencilTest();
|
|
|
|
break;
|
|
|
|
|
2016-03-31 15:36:00 +02:00
|
|
|
// Sync GL depth test + depth and color write mask
|
|
|
|
// (Pica depth test function register also contains a depth and color write mask)
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.depth_test_enable):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncDepthTest();
|
2016-03-31 15:36:00 +02:00
|
|
|
SyncDepthWriteMask();
|
|
|
|
SyncColorWriteMask();
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
|
|
|
|
2016-04-01 15:50:30 +02:00
|
|
|
// Sync GL depth and stencil write mask
|
|
|
|
// (This is a dedicated combined depth / stencil write-enable register)
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.framebuffer.allow_depth_stencil_write):
|
2016-04-01 15:50:30 +02:00
|
|
|
SyncDepthWriteMask();
|
|
|
|
SyncStencilWriteMask();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Sync GL color write mask
|
|
|
|
// (This is a dedicated color write-enable register)
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.framebuffer.allow_color_write):
|
2016-04-01 15:50:30 +02:00
|
|
|
SyncColorWriteMask();
|
|
|
|
break;
|
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
case PICA_REG_INDEX(framebuffer.shadow):
|
|
|
|
SyncShadowBias();
|
|
|
|
break;
|
|
|
|
|
2015-12-02 19:23:51 +01:00
|
|
|
// Scissor test
|
2017-01-28 05:16:36 +01:00
|
|
|
case PICA_REG_INDEX(rasterizer.scissor_test.mode):
|
2015-12-02 19:23:51 +01:00
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2015-05-26 00:39:03 +02:00
|
|
|
// Logic op
|
2017-01-28 06:47:34 +01:00
|
|
|
case PICA_REG_INDEX(framebuffer.output_merger.logic_op):
|
2015-05-26 00:39:03 +02:00
|
|
|
SyncLogicOp();
|
|
|
|
break;
|
|
|
|
|
2017-05-05 14:29:35 +02:00
|
|
|
case PICA_REG_INDEX(texturing.main_config):
|
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2016-04-19 00:53:42 +02:00
|
|
|
// Texture 0 type
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.texture0.type):
|
2016-04-19 00:53:42 +02:00
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2015-07-26 03:13:11 +02:00
|
|
|
// TEV stages
|
2016-05-21 01:04:57 +02:00
|
|
|
// (This also syncs fog_mode and fog_flip which are part of tev_combiner_buffer_input)
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage0.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage0.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage0.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage0.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage1.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage1.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage1.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage1.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage2.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage2.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage2.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage2.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage3.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage3.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage3.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage3.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage4.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage4.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage4.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage4.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage5.color_source1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage5.color_modifier1):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage5.color_op):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_stage5.color_scale):
|
|
|
|
case PICA_REG_INDEX(texturing.tev_combiner_buffer_input):
|
2016-04-17 00:57:57 +02:00
|
|
|
shader_dirty = true;
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage0.const_r):
|
|
|
|
SyncTevConstColor(0, regs.texturing.tev_stage0);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage1.const_r):
|
|
|
|
SyncTevConstColor(1, regs.texturing.tev_stage1);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage2.const_r):
|
|
|
|
SyncTevConstColor(2, regs.texturing.tev_stage2);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage3.const_r):
|
|
|
|
SyncTevConstColor(3, regs.texturing.tev_stage3);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage4.const_r):
|
|
|
|
SyncTevConstColor(4, regs.texturing.tev_stage4);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_stage5.const_r):
|
|
|
|
SyncTevConstColor(5, regs.texturing.tev_stage5);
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
2015-05-25 20:34:09 +02:00
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
// TEV combiner buffer color
|
2017-01-28 05:51:59 +01:00
|
|
|
case PICA_REG_INDEX(texturing.tev_combiner_buffer_color):
|
2015-05-19 06:21:33 +02:00
|
|
|
SyncCombinerColor();
|
|
|
|
break;
|
2015-11-12 23:33:21 +01:00
|
|
|
|
2016-05-23 19:09:28 +02:00
|
|
|
// Fragment lighting switches
|
|
|
|
case PICA_REG_INDEX(lighting.disable):
|
2016-12-19 00:39:56 +01:00
|
|
|
case PICA_REG_INDEX(lighting.max_light_index):
|
2016-05-23 19:09:28 +02:00
|
|
|
case PICA_REG_INDEX(lighting.config0):
|
|
|
|
case PICA_REG_INDEX(lighting.config1):
|
|
|
|
case PICA_REG_INDEX(lighting.abs_lut_input):
|
|
|
|
case PICA_REG_INDEX(lighting.lut_input):
|
|
|
|
case PICA_REG_INDEX(lighting.lut_scale):
|
|
|
|
case PICA_REG_INDEX(lighting.light_enable):
|
|
|
|
break;
|
|
|
|
|
2015-11-15 05:23:08 +01:00
|
|
|
// Fragment lighting specular 0 color
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].specular_0, 0x140 + 0 * 0x10):
|
|
|
|
SyncLightSpecular0(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].specular_0, 0x140 + 1 * 0x10):
|
|
|
|
SyncLightSpecular0(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].specular_0, 0x140 + 2 * 0x10):
|
|
|
|
SyncLightSpecular0(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].specular_0, 0x140 + 3 * 0x10):
|
|
|
|
SyncLightSpecular0(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].specular_0, 0x140 + 4 * 0x10):
|
|
|
|
SyncLightSpecular0(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].specular_0, 0x140 + 5 * 0x10):
|
|
|
|
SyncLightSpecular0(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].specular_0, 0x140 + 6 * 0x10):
|
|
|
|
SyncLightSpecular0(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].specular_0, 0x140 + 7 * 0x10):
|
|
|
|
SyncLightSpecular0(7);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Fragment lighting specular 1 color
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].specular_1, 0x141 + 0 * 0x10):
|
|
|
|
SyncLightSpecular1(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].specular_1, 0x141 + 1 * 0x10):
|
|
|
|
SyncLightSpecular1(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].specular_1, 0x141 + 2 * 0x10):
|
|
|
|
SyncLightSpecular1(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].specular_1, 0x141 + 3 * 0x10):
|
|
|
|
SyncLightSpecular1(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].specular_1, 0x141 + 4 * 0x10):
|
|
|
|
SyncLightSpecular1(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].specular_1, 0x141 + 5 * 0x10):
|
|
|
|
SyncLightSpecular1(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].specular_1, 0x141 + 6 * 0x10):
|
|
|
|
SyncLightSpecular1(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].specular_1, 0x141 + 7 * 0x10):
|
|
|
|
SyncLightSpecular1(7);
|
|
|
|
break;
|
|
|
|
|
2015-11-12 23:33:21 +01:00
|
|
|
// Fragment lighting diffuse color
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].diffuse, 0x142 + 0 * 0x10):
|
|
|
|
SyncLightDiffuse(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].diffuse, 0x142 + 1 * 0x10):
|
|
|
|
SyncLightDiffuse(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].diffuse, 0x142 + 2 * 0x10):
|
|
|
|
SyncLightDiffuse(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].diffuse, 0x142 + 3 * 0x10):
|
|
|
|
SyncLightDiffuse(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].diffuse, 0x142 + 4 * 0x10):
|
|
|
|
SyncLightDiffuse(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].diffuse, 0x142 + 5 * 0x10):
|
|
|
|
SyncLightDiffuse(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].diffuse, 0x142 + 6 * 0x10):
|
|
|
|
SyncLightDiffuse(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].diffuse, 0x142 + 7 * 0x10):
|
|
|
|
SyncLightDiffuse(7);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Fragment lighting ambient color
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].ambient, 0x143 + 0 * 0x10):
|
|
|
|
SyncLightAmbient(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].ambient, 0x143 + 1 * 0x10):
|
|
|
|
SyncLightAmbient(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].ambient, 0x143 + 2 * 0x10):
|
|
|
|
SyncLightAmbient(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].ambient, 0x143 + 3 * 0x10):
|
|
|
|
SyncLightAmbient(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].ambient, 0x143 + 4 * 0x10):
|
|
|
|
SyncLightAmbient(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].ambient, 0x143 + 5 * 0x10):
|
|
|
|
SyncLightAmbient(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].ambient, 0x143 + 6 * 0x10):
|
|
|
|
SyncLightAmbient(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].ambient, 0x143 + 7 * 0x10):
|
|
|
|
SyncLightAmbient(7);
|
|
|
|
break;
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
// Fragment lighting position
|
2015-11-12 23:33:21 +01:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].x, 0x144 + 0 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].z, 0x145 + 0 * 0x10):
|
|
|
|
SyncLightPosition(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].x, 0x144 + 1 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].z, 0x145 + 1 * 0x10):
|
|
|
|
SyncLightPosition(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].x, 0x144 + 2 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].z, 0x145 + 2 * 0x10):
|
|
|
|
SyncLightPosition(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].x, 0x144 + 3 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].z, 0x145 + 3 * 0x10):
|
|
|
|
SyncLightPosition(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].x, 0x144 + 4 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].z, 0x145 + 4 * 0x10):
|
|
|
|
SyncLightPosition(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].x, 0x144 + 5 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].z, 0x145 + 5 * 0x10):
|
|
|
|
SyncLightPosition(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].x, 0x144 + 6 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].z, 0x145 + 6 * 0x10):
|
|
|
|
SyncLightPosition(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].x, 0x144 + 7 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].z, 0x145 + 7 * 0x10):
|
|
|
|
SyncLightPosition(7);
|
|
|
|
break;
|
|
|
|
|
2017-05-25 19:15:12 +02:00
|
|
|
// Fragment spot lighting direction
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].spot_x, 0x146 + 0 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].spot_z, 0x147 + 0 * 0x10):
|
|
|
|
SyncLightSpotDirection(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].spot_x, 0x146 + 1 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].spot_z, 0x147 + 1 * 0x10):
|
|
|
|
SyncLightSpotDirection(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].spot_x, 0x146 + 2 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].spot_z, 0x147 + 2 * 0x10):
|
|
|
|
SyncLightSpotDirection(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].spot_x, 0x146 + 3 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].spot_z, 0x147 + 3 * 0x10):
|
|
|
|
SyncLightSpotDirection(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].spot_x, 0x146 + 4 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].spot_z, 0x147 + 4 * 0x10):
|
|
|
|
SyncLightSpotDirection(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].spot_x, 0x146 + 5 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].spot_z, 0x147 + 5 * 0x10):
|
|
|
|
SyncLightSpotDirection(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].spot_x, 0x146 + 6 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].spot_z, 0x147 + 6 * 0x10):
|
|
|
|
SyncLightSpotDirection(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].spot_x, 0x146 + 7 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].spot_z, 0x147 + 7 * 0x10):
|
|
|
|
SyncLightSpotDirection(7);
|
|
|
|
break;
|
|
|
|
|
2016-05-23 19:09:28 +02:00
|
|
|
// Fragment lighting light source config
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].config, 0x149 + 0 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].config, 0x149 + 1 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].config, 0x149 + 2 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].config, 0x149 + 3 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].config, 0x149 + 4 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].config, 0x149 + 5 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].config, 0x149 + 6 * 0x10):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].config, 0x149 + 7 * 0x10):
|
|
|
|
shader_dirty = true;
|
|
|
|
break;
|
|
|
|
|
2016-05-23 22:53:53 +02:00
|
|
|
// Fragment lighting distance attenuation bias
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_bias, 0x014A + 0 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_bias, 0x014A + 1 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_bias, 0x014A + 2 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_bias, 0x014A + 3 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_bias, 0x014A + 4 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_bias, 0x014A + 5 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_bias, 0x014A + 6 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_bias, 0x014A + 7 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationBias(7);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Fragment lighting distance attenuation scale
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_scale, 0x014B + 0 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(0);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_scale, 0x014B + 1 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(1);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_scale, 0x014B + 2 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(2);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_scale, 0x014B + 3 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(3);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_scale, 0x014B + 4 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(4);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_scale, 0x014B + 5 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(5);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_scale, 0x014B + 6 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(6);
|
|
|
|
break;
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_scale, 0x014B + 7 * 0x10):
|
|
|
|
SyncLightDistanceAttenuationScale(7);
|
|
|
|
break;
|
|
|
|
|
2015-11-12 23:33:21 +01:00
|
|
|
// Fragment lighting global ambient color (emission + ambient * ambient)
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.global_ambient, 0x1c0):
|
|
|
|
SyncGlobalAmbient();
|
|
|
|
break;
|
|
|
|
|
2015-11-14 04:52:20 +01:00
|
|
|
// Fragment lighting lookup tables
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[0], 0x1c8):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[1], 0x1c9):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[2], 0x1ca):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[3], 0x1cb):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[4], 0x1cc):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[5], 0x1cd):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[6], 0x1ce):
|
2016-09-18 02:38:01 +02:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[7], 0x1cf): {
|
2015-11-14 04:52:20 +01:00
|
|
|
auto& lut_config = regs.lighting.lut_config;
|
2018-05-19 14:47:25 +02:00
|
|
|
uniform_block_data.lighting_lut_dirty[lut_config.type] = true;
|
|
|
|
uniform_block_data.lighting_lut_dirty_any = true;
|
2015-11-14 04:52:20 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
void RasterizerOpenGL::FlushAll() {
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
2016-04-17 00:57:57 +02:00
|
|
|
res_cache.FlushAll();
|
|
|
|
}
|
|
|
|
|
2015-12-07 02:56:45 +01:00
|
|
|
void RasterizerOpenGL::FlushRegion(PAddr addr, u32 size) {
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
2017-12-12 18:21:55 +01:00
|
|
|
res_cache.FlushRegion(addr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::InvalidateRegion(PAddr addr, u32 size) {
|
|
|
|
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
|
|
|
res_cache.InvalidateRegion(addr, size, nullptr);
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
2015-05-14 05:29:27 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
void RasterizerOpenGL::FlushAndInvalidateRegion(PAddr addr, u32 size) {
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
2017-12-12 18:21:55 +01:00
|
|
|
res_cache.FlushRegion(addr, size);
|
|
|
|
res_cache.InvalidateRegion(addr, size, nullptr);
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2016-04-17 00:57:57 +02:00
|
|
|
bool RasterizerOpenGL::AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) {
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_Blits);
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
SurfaceParams src_params;
|
2016-04-17 00:57:57 +02:00
|
|
|
src_params.addr = config.GetPhysicalInputAddress();
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.width = config.output_width;
|
|
|
|
src_params.stride = config.input_width;
|
2016-04-17 00:57:57 +02:00
|
|
|
src_params.height = config.output_height;
|
|
|
|
src_params.is_tiled = !config.input_linear;
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.pixel_format = SurfaceParams::PixelFormatFromGPUPixelFormat(config.input_format);
|
|
|
|
src_params.UpdateParams();
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
SurfaceParams dst_params;
|
2016-04-17 00:57:57 +02:00
|
|
|
dst_params.addr = config.GetPhysicalOutputAddress();
|
2017-12-12 18:21:55 +01:00
|
|
|
dst_params.width = config.scaling != config.NoScale ? config.output_width.Value() / 2
|
|
|
|
: config.output_width.Value();
|
|
|
|
dst_params.height = config.scaling == config.ScaleXY ? config.output_height.Value() / 2
|
|
|
|
: config.output_height.Value();
|
2016-04-17 00:57:57 +02:00
|
|
|
dst_params.is_tiled = config.input_linear != config.dont_swizzle;
|
2017-12-12 18:21:55 +01:00
|
|
|
dst_params.pixel_format = SurfaceParams::PixelFormatFromGPUPixelFormat(config.output_format);
|
|
|
|
dst_params.UpdateParams();
|
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> src_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface src_surface;
|
|
|
|
std::tie(src_surface, src_rect) =
|
|
|
|
res_cache.GetSurfaceSubRect(src_params, ScaleMatch::Ignore, true);
|
|
|
|
if (src_surface == nullptr)
|
2016-04-17 00:57:57 +02:00
|
|
|
return false;
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
dst_params.res_scale = src_surface->res_scale;
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> dst_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface dst_surface;
|
|
|
|
std::tie(dst_surface, dst_rect) =
|
|
|
|
res_cache.GetSurfaceSubRect(dst_params, ScaleMatch::Upscale, false);
|
|
|
|
if (dst_surface == nullptr)
|
2016-04-17 00:57:57 +02:00
|
|
|
return false;
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
if (src_surface->is_tiled != dst_surface->is_tiled)
|
|
|
|
std::swap(src_rect.top, src_rect.bottom);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
if (config.flip_vertically)
|
|
|
|
std::swap(src_rect.top, src_rect.bottom);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
if (!res_cache.BlitSurfaces(src_surface, src_rect, dst_surface, dst_rect))
|
2016-04-17 00:57:57 +02:00
|
|
|
return false;
|
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
res_cache.InvalidateRegion(dst_params.addr, dst_params.size, dst_surface);
|
2016-04-17 00:57:57 +02:00
|
|
|
return true;
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 12:09:53 +02:00
|
|
|
bool RasterizerOpenGL::AccelerateTextureCopy(const GPU::Regs::DisplayTransferConfig& config) {
|
2017-12-13 19:18:09 +01:00
|
|
|
u32 copy_size = Common::AlignDown(config.texture_copy.size, 16);
|
2018-01-15 10:05:56 +01:00
|
|
|
if (copy_size == 0) {
|
2017-12-13 19:18:09 +01:00
|
|
|
return false;
|
2018-01-15 10:05:56 +01:00
|
|
|
}
|
2017-12-13 19:18:09 +01:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
u32 input_gap = config.texture_copy.input_gap * 16;
|
2017-12-13 19:18:09 +01:00
|
|
|
u32 input_width = config.texture_copy.input_width * 16;
|
2018-01-15 10:05:56 +01:00
|
|
|
if (input_width == 0 && input_gap != 0) {
|
|
|
|
return false;
|
2017-12-13 19:18:09 +01:00
|
|
|
}
|
2018-01-15 10:05:56 +01:00
|
|
|
if (input_gap == 0 || input_width >= copy_size) {
|
2017-12-13 19:18:09 +01:00
|
|
|
input_width = copy_size;
|
2017-12-12 18:21:55 +01:00
|
|
|
input_gap = 0;
|
2016-04-17 00:57:57 +02:00
|
|
|
}
|
2018-01-15 10:05:56 +01:00
|
|
|
if (copy_size % input_width != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2018-01-15 10:05:56 +01:00
|
|
|
u32 output_gap = config.texture_copy.output_gap * 16;
|
|
|
|
u32 output_width = config.texture_copy.output_width * 16;
|
|
|
|
if (output_width == 0 && output_gap != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (output_gap == 0 || output_width >= copy_size) {
|
2017-12-13 19:18:09 +01:00
|
|
|
output_width = copy_size;
|
2017-12-12 18:21:55 +01:00
|
|
|
output_gap = 0;
|
|
|
|
}
|
2018-01-15 10:05:56 +01:00
|
|
|
if (copy_size % output_width != 0) {
|
2017-12-12 18:21:55 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-14 05:29:27 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
SurfaceParams src_params;
|
|
|
|
src_params.addr = config.GetPhysicalInputAddress();
|
|
|
|
src_params.stride = input_width + input_gap; // stride in bytes
|
|
|
|
src_params.width = input_width; // width in bytes
|
2017-12-13 19:18:09 +01:00
|
|
|
src_params.height = copy_size / input_width;
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.size = ((src_params.height - 1) * src_params.stride) + src_params.width;
|
|
|
|
src_params.end = src_params.addr + src_params.size;
|
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> src_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface src_surface;
|
|
|
|
std::tie(src_surface, src_rect) = res_cache.GetTexCopySurface(src_params);
|
2018-01-15 10:05:56 +01:00
|
|
|
if (src_surface == nullptr) {
|
2017-12-12 18:21:55 +01:00
|
|
|
return false;
|
2018-01-15 10:05:56 +01:00
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-01-15 10:05:56 +01:00
|
|
|
if (output_gap != 0 &&
|
2018-03-09 18:54:43 +01:00
|
|
|
(output_width != src_surface->BytesInPixels(src_rect.GetWidth() / src_surface->res_scale) *
|
|
|
|
(src_surface->is_tiled ? 8 : 1) ||
|
2018-01-15 10:05:56 +01:00
|
|
|
output_gap % src_surface->BytesInPixels(src_surface->is_tiled ? 64 : 1) != 0)) {
|
2017-12-12 18:21:55 +01:00
|
|
|
return false;
|
2018-01-15 10:05:56 +01:00
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
SurfaceParams dst_params = *src_surface;
|
|
|
|
dst_params.addr = config.GetPhysicalOutputAddress();
|
|
|
|
dst_params.width = src_rect.GetWidth() / src_surface->res_scale;
|
2018-03-09 18:54:43 +01:00
|
|
|
dst_params.stride = dst_params.width + src_surface->PixelsInBytes(
|
|
|
|
src_surface->is_tiled ? output_gap / 8 : output_gap);
|
2017-12-12 18:21:55 +01:00
|
|
|
dst_params.height = src_rect.GetHeight() / src_surface->res_scale;
|
|
|
|
dst_params.res_scale = src_surface->res_scale;
|
|
|
|
dst_params.UpdateParams();
|
|
|
|
|
2018-02-06 04:31:50 +01:00
|
|
|
// Since we are going to invalidate the gap if there is one, we will have to load it first
|
|
|
|
const bool load_gap = output_gap != 0;
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> dst_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface dst_surface;
|
|
|
|
std::tie(dst_surface, dst_rect) =
|
|
|
|
res_cache.GetSurfaceSubRect(dst_params, ScaleMatch::Upscale, load_gap);
|
2018-03-29 03:13:54 +02:00
|
|
|
if (dst_surface == nullptr) {
|
2017-12-12 18:21:55 +01:00
|
|
|
return false;
|
2018-01-15 10:05:56 +01:00
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2018-03-05 06:06:09 +01:00
|
|
|
if (dst_surface->type == SurfaceType::Texture) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-15 10:05:56 +01:00
|
|
|
if (!res_cache.BlitSurfaces(src_surface, src_rect, dst_surface, dst_rect)) {
|
2017-12-12 18:21:55 +01:00
|
|
|
return false;
|
2018-01-15 10:05:56 +01:00
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
res_cache.InvalidateRegion(dst_params.addr, dst_params.size, dst_surface);
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
bool RasterizerOpenGL::AccelerateFill(const GPU::Regs::MemoryFillConfig& config) {
|
|
|
|
Surface dst_surface = res_cache.GetFillSurface(config);
|
|
|
|
if (dst_surface == nullptr)
|
|
|
|
return false;
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
res_cache.InvalidateRegion(dst_surface->addr, dst_surface->size, dst_surface);
|
2016-04-17 00:57:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
bool RasterizerOpenGL::AccelerateDisplay(const GPU::Regs::FramebufferConfig& config,
|
|
|
|
PAddr framebuffer_addr, u32 pixel_stride,
|
|
|
|
ScreenInfo& screen_info) {
|
2016-04-17 00:57:57 +02:00
|
|
|
if (framebuffer_addr == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-15 07:52:09 +01:00
|
|
|
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2017-12-12 18:21:55 +01:00
|
|
|
SurfaceParams src_params;
|
2016-04-17 00:57:57 +02:00
|
|
|
src_params.addr = framebuffer_addr;
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.width = std::min(config.width.Value(), pixel_stride);
|
2016-04-17 00:57:57 +02:00
|
|
|
src_params.height = config.height;
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.stride = pixel_stride;
|
2016-04-17 00:57:57 +02:00
|
|
|
src_params.is_tiled = false;
|
2017-12-12 18:21:55 +01:00
|
|
|
src_params.pixel_format = SurfaceParams::PixelFormatFromGPUPixelFormat(config.color_format);
|
|
|
|
src_params.UpdateParams();
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
Common::Rectangle<u32> src_rect;
|
2017-12-12 18:21:55 +01:00
|
|
|
Surface src_surface;
|
|
|
|
std::tie(src_surface, src_rect) =
|
|
|
|
res_cache.GetSurfaceSubRect(src_params, ScaleMatch::Ignore, true);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
if (src_surface == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 scaled_width = src_surface->GetScaledWidth();
|
|
|
|
u32 scaled_height = src_surface->GetScaledHeight();
|
|
|
|
|
2019-02-27 04:47:49 +01:00
|
|
|
screen_info.display_texcoords = Common::Rectangle<float>(
|
2017-12-12 18:21:55 +01:00
|
|
|
(float)src_rect.bottom / (float)scaled_height, (float)src_rect.left / (float)scaled_width,
|
|
|
|
(float)src_rect.top / (float)scaled_height, (float)src_rect.right / (float)scaled_width);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
|
|
|
screen_info.display_texture = src_surface->texture.handle;
|
|
|
|
|
|
|
|
return true;
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2015-08-30 15:05:56 +02:00
|
|
|
void RasterizerOpenGL::SamplerInfo::Create() {
|
|
|
|
sampler.Create();
|
|
|
|
mag_filter = min_filter = TextureConfig::Linear;
|
|
|
|
wrap_s = wrap_t = TextureConfig::Repeat;
|
|
|
|
border_color = 0;
|
|
|
|
|
2017-12-24 00:09:25 +01:00
|
|
|
// default is GL_LINEAR_MIPMAP_LINEAR
|
|
|
|
glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2015-08-30 15:05:56 +02:00
|
|
|
// Other attributes have correct defaults
|
|
|
|
}
|
|
|
|
|
2017-01-28 05:51:59 +01:00
|
|
|
void RasterizerOpenGL::SamplerInfo::SyncWithConfig(
|
|
|
|
const Pica::TexturingRegs::TextureConfig& config) {
|
|
|
|
|
2015-08-30 15:05:56 +02:00
|
|
|
GLuint s = sampler.handle;
|
|
|
|
|
|
|
|
if (mag_filter != config.mag_filter) {
|
|
|
|
mag_filter = config.mag_filter;
|
|
|
|
glSamplerParameteri(s, GL_TEXTURE_MAG_FILTER, PicaToGL::TextureFilterMode(mag_filter));
|
|
|
|
}
|
|
|
|
if (min_filter != config.min_filter) {
|
|
|
|
min_filter = config.min_filter;
|
|
|
|
glSamplerParameteri(s, GL_TEXTURE_MIN_FILTER, PicaToGL::TextureFilterMode(min_filter));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrap_s != config.wrap_s) {
|
|
|
|
wrap_s = config.wrap_s;
|
|
|
|
glSamplerParameteri(s, GL_TEXTURE_WRAP_S, PicaToGL::WrapMode(wrap_s));
|
|
|
|
}
|
|
|
|
if (wrap_t != config.wrap_t) {
|
|
|
|
wrap_t = config.wrap_t;
|
|
|
|
glSamplerParameteri(s, GL_TEXTURE_WRAP_T, PicaToGL::WrapMode(wrap_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrap_s == TextureConfig::ClampToBorder || wrap_t == TextureConfig::ClampToBorder) {
|
|
|
|
if (border_color != config.border_color.raw) {
|
2016-04-30 21:20:23 +02:00
|
|
|
border_color = config.border_color.raw;
|
2015-08-30 15:05:56 +02:00
|
|
|
auto gl_color = PicaToGL::ColorRGBA8(border_color);
|
|
|
|
glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, gl_color.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
void RasterizerOpenGL::SetShader() {
|
2018-11-17 08:29:10 +01:00
|
|
|
auto config = PicaFSConfig::BuildFromRegs(Pica::g_state.regs);
|
2018-04-09 23:31:11 +02:00
|
|
|
shader_program_manager->UseFragmentShader(config);
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2017-08-22 08:49:53 +02:00
|
|
|
void RasterizerOpenGL::SyncClipEnabled() {
|
|
|
|
state.clip_distance[1] = Pica::g_state.regs.rasterizer.clip_enable != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncClipCoef() {
|
|
|
|
const auto raw_clip_coef = Pica::g_state.regs.rasterizer.GetClipCoef();
|
|
|
|
const GLvec4 new_clip_coef = {raw_clip_coef.x.ToFloat32(), raw_clip_coef.y.ToFloat32(),
|
|
|
|
raw_clip_coef.z.ToFloat32(), raw_clip_coef.w.ToFloat32()};
|
|
|
|
if (new_clip_coef != uniform_block_data.data.clip_coef) {
|
|
|
|
uniform_block_data.data.clip_coef = new_clip_coef;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void RasterizerOpenGL::SyncCullMode() {
|
2015-05-14 05:29:27 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
|
|
|
|
2017-01-28 05:16:36 +01:00
|
|
|
switch (regs.rasterizer.cull_mode) {
|
|
|
|
case Pica::RasterizerRegs::CullMode::KeepAll:
|
2015-05-19 06:21:33 +02:00
|
|
|
state.cull.enabled = false;
|
|
|
|
break;
|
|
|
|
|
2017-01-28 05:16:36 +01:00
|
|
|
case Pica::RasterizerRegs::CullMode::KeepClockWise:
|
2015-05-19 06:21:33 +02:00
|
|
|
state.cull.enabled = true;
|
2015-12-05 07:23:39 +01:00
|
|
|
state.cull.front_face = GL_CW;
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
|
|
|
|
2017-01-28 05:16:36 +01:00
|
|
|
case Pica::RasterizerRegs::CullMode::KeepCounterClockWise:
|
2015-05-19 06:21:33 +02:00
|
|
|
state.cull.enabled = true;
|
2015-12-05 07:23:39 +01:00
|
|
|
state.cull.front_face = GL_CCW;
|
2015-05-19 06:21:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown cull mode {}",
|
2018-06-29 15:56:12 +02:00
|
|
|
static_cast<u32>(regs.rasterizer.cull_mode.Value()));
|
2015-05-19 06:21:33 +02:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 10:16:45 +02:00
|
|
|
void RasterizerOpenGL::SyncDepthScale() {
|
2017-01-28 05:16:36 +01:00
|
|
|
float depth_scale =
|
|
|
|
Pica::float24::FromRaw(Pica::g_state.regs.rasterizer.viewport_depth_range).ToFloat32();
|
2016-05-14 10:16:45 +02:00
|
|
|
if (depth_scale != uniform_block_data.data.depth_scale) {
|
|
|
|
uniform_block_data.data.depth_scale = depth_scale;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
2016-01-04 00:46:54 +01:00
|
|
|
|
2016-05-14 10:16:45 +02:00
|
|
|
void RasterizerOpenGL::SyncDepthOffset() {
|
2016-09-18 02:38:01 +02:00
|
|
|
float depth_offset =
|
2017-01-28 05:16:36 +01:00
|
|
|
Pica::float24::FromRaw(Pica::g_state.regs.rasterizer.viewport_depth_near_plane).ToFloat32();
|
2016-05-14 10:16:45 +02:00
|
|
|
if (depth_offset != uniform_block_data.data.depth_offset) {
|
|
|
|
uniform_block_data.data.depth_offset = depth_offset;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
2016-01-04 00:46:54 +01:00
|
|
|
}
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void RasterizerOpenGL::SyncBlendEnabled() {
|
2017-01-28 06:47:34 +01:00
|
|
|
state.blend.enabled = (Pica::g_state.regs.framebuffer.output_merger.alphablend_enable == 1);
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncBlendFuncs() {
|
2015-05-14 05:29:27 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
2016-09-18 02:38:01 +02:00
|
|
|
state.blend.rgb_equation =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::BlendEquation(regs.framebuffer.output_merger.alpha_blending.blend_equation_rgb);
|
2016-09-18 02:38:01 +02:00
|
|
|
state.blend.a_equation =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::BlendEquation(regs.framebuffer.output_merger.alpha_blending.blend_equation_a);
|
2016-09-18 02:38:01 +02:00
|
|
|
state.blend.src_rgb_func =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_source_rgb);
|
2016-09-18 02:38:01 +02:00
|
|
|
state.blend.dst_rgb_func =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_dest_rgb);
|
|
|
|
state.blend.src_a_func =
|
|
|
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_source_a);
|
|
|
|
state.blend.dst_a_func =
|
|
|
|
PicaToGL::BlendFunc(regs.framebuffer.output_merger.alpha_blending.factor_dest_a);
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncBlendColor() {
|
2017-01-28 06:47:34 +01:00
|
|
|
auto blend_color =
|
|
|
|
PicaToGL::ColorRGBA8(Pica::g_state.regs.framebuffer.output_merger.blend_const.raw);
|
2015-05-19 06:21:33 +02:00
|
|
|
state.blend.color.red = blend_color[0];
|
|
|
|
state.blend.color.green = blend_color[1];
|
|
|
|
state.blend.color.blue = blend_color[2];
|
|
|
|
state.blend.color.alpha = blend_color[3];
|
|
|
|
}
|
|
|
|
|
2016-05-21 01:04:57 +02:00
|
|
|
void RasterizerOpenGL::SyncFogColor() {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
2016-09-19 03:01:46 +02:00
|
|
|
uniform_block_data.data.fog_color = {
|
2018-03-09 18:54:43 +01:00
|
|
|
regs.texturing.fog_color.r.Value() / 255.0f,
|
|
|
|
regs.texturing.fog_color.g.Value() / 255.0f,
|
2017-01-28 05:51:59 +01:00
|
|
|
regs.texturing.fog_color.b.Value() / 255.0f,
|
2016-09-19 03:01:46 +02:00
|
|
|
};
|
2016-05-21 01:04:57 +02:00
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
|
2017-05-05 14:25:04 +02:00
|
|
|
void RasterizerOpenGL::SyncProcTexNoise() {
|
|
|
|
const auto& regs = Pica::g_state.regs.texturing;
|
|
|
|
uniform_block_data.data.proctex_noise_f = {
|
|
|
|
Pica::float16::FromRaw(regs.proctex_noise_frequency.u).ToFloat32(),
|
|
|
|
Pica::float16::FromRaw(regs.proctex_noise_frequency.v).ToFloat32(),
|
|
|
|
};
|
|
|
|
uniform_block_data.data.proctex_noise_a = {
|
2018-03-09 18:54:43 +01:00
|
|
|
regs.proctex_noise_u.amplitude / 4095.0f,
|
|
|
|
regs.proctex_noise_v.amplitude / 4095.0f,
|
2017-05-05 14:25:04 +02:00
|
|
|
};
|
|
|
|
uniform_block_data.data.proctex_noise_p = {
|
|
|
|
Pica::float16::FromRaw(regs.proctex_noise_u.phase).ToFloat32(),
|
|
|
|
Pica::float16::FromRaw(regs.proctex_noise_v.phase).ToFloat32(),
|
|
|
|
};
|
|
|
|
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
|
2018-07-04 16:16:38 +02:00
|
|
|
void RasterizerOpenGL::SyncProcTexBias() {
|
|
|
|
const auto& regs = Pica::g_state.regs.texturing;
|
|
|
|
uniform_block_data.data.proctex_bias =
|
|
|
|
Pica::float16::FromRaw(regs.proctex.bias_low | (regs.proctex_lut.bias_high << 8))
|
|
|
|
.ToFloat32();
|
|
|
|
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void RasterizerOpenGL::SyncAlphaTest() {
|
2015-05-14 05:29:27 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
2017-01-28 06:47:34 +01:00
|
|
|
if (regs.framebuffer.output_merger.alpha_test.ref != uniform_block_data.data.alphatest_ref) {
|
|
|
|
uniform_block_data.data.alphatest_ref = regs.framebuffer.output_merger.alpha_test.ref;
|
2015-11-10 17:58:53 +01:00
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2015-05-26 00:39:03 +02:00
|
|
|
void RasterizerOpenGL::SyncLogicOp() {
|
2017-01-28 06:47:34 +01:00
|
|
|
state.logic_op = PicaToGL::LogicOp(Pica::g_state.regs.framebuffer.output_merger.logic_op);
|
2015-05-26 00:39:03 +02:00
|
|
|
}
|
|
|
|
|
2016-03-31 15:36:00 +02:00
|
|
|
void RasterizerOpenGL::SyncColorWriteMask() {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
2016-04-01 15:50:30 +02:00
|
|
|
|
|
|
|
auto IsColorWriteEnabled = [&](u32 value) {
|
2017-01-28 06:47:34 +01:00
|
|
|
return (regs.framebuffer.framebuffer.allow_color_write != 0 && value != 0) ? GL_TRUE
|
|
|
|
: GL_FALSE;
|
2016-04-01 15:50:30 +02:00
|
|
|
};
|
|
|
|
|
2017-01-28 06:47:34 +01:00
|
|
|
state.color_mask.red_enabled = IsColorWriteEnabled(regs.framebuffer.output_merger.red_enable);
|
|
|
|
state.color_mask.green_enabled =
|
|
|
|
IsColorWriteEnabled(regs.framebuffer.output_merger.green_enable);
|
|
|
|
state.color_mask.blue_enabled = IsColorWriteEnabled(regs.framebuffer.output_merger.blue_enable);
|
|
|
|
state.color_mask.alpha_enabled =
|
|
|
|
IsColorWriteEnabled(regs.framebuffer.output_merger.alpha_enable);
|
2016-03-31 15:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncStencilWriteMask() {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
2017-01-28 06:47:34 +01:00
|
|
|
state.stencil.write_mask =
|
|
|
|
(regs.framebuffer.framebuffer.allow_depth_stencil_write != 0)
|
|
|
|
? static_cast<GLuint>(regs.framebuffer.output_merger.stencil_test.write_mask)
|
|
|
|
: 0;
|
2016-03-31 15:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncDepthWriteMask() {
|
|
|
|
const auto& regs = Pica::g_state.regs;
|
2017-01-28 06:47:34 +01:00
|
|
|
state.depth.write_mask = (regs.framebuffer.framebuffer.allow_depth_stencil_write != 0 &&
|
|
|
|
regs.framebuffer.output_merger.depth_write_enable)
|
|
|
|
? GL_TRUE
|
|
|
|
: GL_FALSE;
|
2016-03-31 15:36:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void RasterizerOpenGL::SyncStencilTest() {
|
2015-08-20 17:11:09 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
2017-01-28 06:47:34 +01:00
|
|
|
state.stencil.test_enabled =
|
|
|
|
regs.framebuffer.output_merger.stencil_test.enable &&
|
|
|
|
regs.framebuffer.framebuffer.depth_format == Pica::FramebufferRegs::DepthFormat::D24S8;
|
|
|
|
state.stencil.test_func =
|
|
|
|
PicaToGL::CompareFunc(regs.framebuffer.output_merger.stencil_test.func);
|
|
|
|
state.stencil.test_ref = regs.framebuffer.output_merger.stencil_test.reference_value;
|
|
|
|
state.stencil.test_mask = regs.framebuffer.output_merger.stencil_test.input_mask;
|
2016-09-18 02:38:01 +02:00
|
|
|
state.stencil.action_stencil_fail =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_stencil_fail);
|
2016-09-18 02:38:01 +02:00
|
|
|
state.stencil.action_depth_fail =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_depth_fail);
|
2016-09-18 02:38:01 +02:00
|
|
|
state.stencil.action_depth_pass =
|
2017-01-28 06:47:34 +01:00
|
|
|
PicaToGL::StencilOp(regs.framebuffer.output_merger.stencil_test.action_depth_pass);
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncDepthTest() {
|
2015-05-14 05:29:27 +02:00
|
|
|
const auto& regs = Pica::g_state.regs;
|
2017-01-28 06:47:34 +01:00
|
|
|
state.depth.test_enabled = regs.framebuffer.output_merger.depth_test_enable == 1 ||
|
|
|
|
regs.framebuffer.output_merger.depth_write_enable == 1;
|
|
|
|
state.depth.test_func =
|
|
|
|
regs.framebuffer.output_merger.depth_test_enable == 1
|
|
|
|
? PicaToGL::CompareFunc(regs.framebuffer.output_merger.depth_test_func)
|
|
|
|
: GL_ALWAYS;
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncCombinerColor() {
|
2017-01-28 05:51:59 +01:00
|
|
|
auto combiner_color =
|
|
|
|
PicaToGL::ColorRGBA8(Pica::g_state.regs.texturing.tev_combiner_buffer_color.raw);
|
2015-11-10 17:58:53 +01:00
|
|
|
if (combiner_color != uniform_block_data.data.tev_combiner_buffer_color) {
|
|
|
|
uniform_block_data.data.tev_combiner_buffer_color = combiner_color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
void RasterizerOpenGL::SyncTevConstColor(int stage_index,
|
2017-01-28 05:51:59 +01:00
|
|
|
const Pica::TexturingRegs::TevStageConfig& tev_stage) {
|
2015-10-10 01:32:38 +02:00
|
|
|
auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color);
|
2015-11-10 17:58:53 +01:00
|
|
|
if (const_color != uniform_block_data.data.const_color[stage_index]) {
|
|
|
|
uniform_block_data.data.const_color[stage_index] = const_color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
2015-05-19 06:21:33 +02:00
|
|
|
}
|
|
|
|
|
2015-11-12 23:33:21 +01:00
|
|
|
void RasterizerOpenGL::SyncGlobalAmbient() {
|
|
|
|
auto color = PicaToGL::LightColor(Pica::g_state.regs.lighting.global_ambient);
|
|
|
|
if (color != uniform_block_data.data.lighting_global_ambient) {
|
|
|
|
uniform_block_data.data.lighting_global_ambient = color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 05:23:08 +01:00
|
|
|
void RasterizerOpenGL::SyncLightSpecular0(int light_index) {
|
|
|
|
auto color = PicaToGL::LightColor(Pica::g_state.regs.lighting.light[light_index].specular_0);
|
|
|
|
if (color != uniform_block_data.data.light_src[light_index].specular_0) {
|
|
|
|
uniform_block_data.data.light_src[light_index].specular_0 = color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncLightSpecular1(int light_index) {
|
|
|
|
auto color = PicaToGL::LightColor(Pica::g_state.regs.lighting.light[light_index].specular_1);
|
|
|
|
if (color != uniform_block_data.data.light_src[light_index].specular_1) {
|
|
|
|
uniform_block_data.data.light_src[light_index].specular_1 = color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 23:33:21 +01:00
|
|
|
void RasterizerOpenGL::SyncLightDiffuse(int light_index) {
|
|
|
|
auto color = PicaToGL::LightColor(Pica::g_state.regs.lighting.light[light_index].diffuse);
|
|
|
|
if (color != uniform_block_data.data.light_src[light_index].diffuse) {
|
|
|
|
uniform_block_data.data.light_src[light_index].diffuse = color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncLightAmbient(int light_index) {
|
|
|
|
auto color = PicaToGL::LightColor(Pica::g_state.regs.lighting.light[light_index].ambient);
|
|
|
|
if (color != uniform_block_data.data.light_src[light_index].ambient) {
|
|
|
|
uniform_block_data.data.light_src[light_index].ambient = color;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncLightPosition(int light_index) {
|
2016-02-04 06:03:20 +01:00
|
|
|
GLvec3 position = {
|
2015-12-17 05:23:50 +01:00
|
|
|
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].x).ToFloat32(),
|
|
|
|
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].y).ToFloat32(),
|
2016-09-18 02:38:01 +02:00
|
|
|
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].z).ToFloat32()};
|
2015-11-12 23:33:21 +01:00
|
|
|
|
|
|
|
if (position != uniform_block_data.data.light_src[light_index].position) {
|
|
|
|
uniform_block_data.data.light_src[light_index].position = position;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 22:53:53 +02:00
|
|
|
|
2017-05-25 19:15:12 +02:00
|
|
|
void RasterizerOpenGL::SyncLightSpotDirection(int light_index) {
|
|
|
|
const auto& light = Pica::g_state.regs.lighting.light[light_index];
|
|
|
|
GLvec3 spot_direction = {light.spot_x / 2047.0f, light.spot_y / 2047.0f,
|
|
|
|
light.spot_z / 2047.0f};
|
|
|
|
|
|
|
|
if (spot_direction != uniform_block_data.data.light_src[light_index].spot_direction) {
|
|
|
|
uniform_block_data.data.light_src[light_index].spot_direction = spot_direction;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:53:53 +02:00
|
|
|
void RasterizerOpenGL::SyncLightDistanceAttenuationBias(int light_index) {
|
2016-09-18 02:38:01 +02:00
|
|
|
GLfloat dist_atten_bias =
|
|
|
|
Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_bias)
|
|
|
|
.ToFloat32();
|
2016-05-23 22:53:53 +02:00
|
|
|
|
|
|
|
if (dist_atten_bias != uniform_block_data.data.light_src[light_index].dist_atten_bias) {
|
|
|
|
uniform_block_data.data.light_src[light_index].dist_atten_bias = dist_atten_bias;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterizerOpenGL::SyncLightDistanceAttenuationScale(int light_index) {
|
2016-09-18 02:38:01 +02:00
|
|
|
GLfloat dist_atten_scale =
|
|
|
|
Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_scale)
|
|
|
|
.ToFloat32();
|
2016-05-23 22:53:53 +02:00
|
|
|
|
|
|
|
if (dist_atten_scale != uniform_block_data.data.light_src[light_index].dist_atten_scale) {
|
|
|
|
uniform_block_data.data.light_src[light_index].dist_atten_scale = dist_atten_scale;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
2018-05-02 09:34:36 +02:00
|
|
|
|
2018-04-11 14:47:02 +02:00
|
|
|
void RasterizerOpenGL::SyncShadowBias() {
|
|
|
|
const auto& shadow = Pica::g_state.regs.framebuffer.shadow;
|
|
|
|
GLfloat constant = Pica::float16::FromRaw(shadow.constant).ToFloat32();
|
|
|
|
GLfloat linear = Pica::float16::FromRaw(shadow.linear).ToFloat32();
|
|
|
|
|
|
|
|
if (constant != uniform_block_data.data.shadow_bias_constant ||
|
|
|
|
linear != uniform_block_data.data.shadow_bias_linear) {
|
|
|
|
uniform_block_data.data.shadow_bias_constant = constant;
|
|
|
|
uniform_block_data.data.shadow_bias_linear = linear;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 02:39:51 +01:00
|
|
|
void RasterizerOpenGL::SyncShadowTextureBias() {
|
|
|
|
GLint bias = Pica::g_state.regs.texturing.shadow.bias << 1;
|
|
|
|
if (bias != uniform_block_data.data.shadow_texture_bias) {
|
|
|
|
uniform_block_data.data.shadow_texture_bias = bias;
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-19 11:12:51 +02:00
|
|
|
void RasterizerOpenGL::SyncAndUploadLUTs() {
|
2018-09-06 22:03:28 +02:00
|
|
|
constexpr std::size_t max_size = sizeof(GLvec2) * 256 * Pica::LightingRegs::NumLightingSampler +
|
|
|
|
sizeof(GLvec2) * 128 + // fog
|
|
|
|
sizeof(GLvec2) * 128 * 3 + // proctex: noise + color + alpha
|
|
|
|
sizeof(GLvec4) * 256 + // proctex
|
|
|
|
sizeof(GLvec4) * 256; // proctex diff
|
2018-05-19 12:54:50 +02:00
|
|
|
|
2018-05-19 15:09:57 +02:00
|
|
|
if (!uniform_block_data.lighting_lut_dirty_any && !uniform_block_data.fog_lut_dirty &&
|
|
|
|
!uniform_block_data.proctex_noise_lut_dirty &&
|
|
|
|
!uniform_block_data.proctex_color_map_dirty &&
|
|
|
|
!uniform_block_data.proctex_alpha_map_dirty && !uniform_block_data.proctex_lut_dirty &&
|
|
|
|
!uniform_block_data.proctex_diff_lut_dirty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8* buffer;
|
|
|
|
GLintptr offset;
|
|
|
|
bool invalidate;
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t bytes_used = 0;
|
2018-05-19 15:09:57 +02:00
|
|
|
glBindBuffer(GL_TEXTURE_BUFFER, texture_buffer.GetHandle());
|
|
|
|
std::tie(buffer, offset, invalidate) = texture_buffer.Map(max_size, sizeof(GLvec4));
|
|
|
|
|
2018-05-19 11:12:51 +02:00
|
|
|
// Sync the lighting luts
|
2018-05-19 15:09:57 +02:00
|
|
|
if (uniform_block_data.lighting_lut_dirty_any || invalidate) {
|
2018-05-19 14:47:25 +02:00
|
|
|
for (unsigned index = 0; index < uniform_block_data.lighting_lut_dirty.size(); index++) {
|
2018-05-19 15:09:57 +02:00
|
|
|
if (uniform_block_data.lighting_lut_dirty[index] || invalidate) {
|
2018-05-19 14:47:25 +02:00
|
|
|
std::array<GLvec2, 256> new_data;
|
|
|
|
const auto& source_lut = Pica::g_state.lighting.luts[index];
|
|
|
|
std::transform(source_lut.begin(), source_lut.end(), new_data.begin(),
|
|
|
|
[](const auto& entry) {
|
|
|
|
return GLvec2{entry.ToFloat(), entry.DiffToFloat()};
|
|
|
|
});
|
|
|
|
|
2018-05-19 15:09:57 +02:00
|
|
|
if (new_data != lighting_lut_data[index] || invalidate) {
|
2018-05-19 14:47:25 +02:00
|
|
|
lighting_lut_data[index] = new_data;
|
2018-05-19 15:09:57 +02:00
|
|
|
std::memcpy(buffer + bytes_used, new_data.data(),
|
|
|
|
new_data.size() * sizeof(GLvec2));
|
|
|
|
uniform_block_data.data.lighting_lut_offset[index / 4][index % 4] =
|
|
|
|
(offset + bytes_used) / sizeof(GLvec2);
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
bytes_used += new_data.size() * sizeof(GLvec2);
|
2018-05-19 14:47:25 +02:00
|
|
|
}
|
|
|
|
uniform_block_data.lighting_lut_dirty[index] = false;
|
2018-05-19 12:00:14 +02:00
|
|
|
}
|
2018-05-19 11:12:51 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-19 14:47:25 +02:00
|
|
|
uniform_block_data.lighting_lut_dirty_any = false;
|
2018-05-19 11:12:51 +02:00
|
|
|
|
|
|
|
// Sync the fog lut
|
2018-05-19 15:16:49 +02:00
|
|
|
if (uniform_block_data.fog_lut_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
std::array<GLvec2, 128> new_data;
|
|
|
|
|
|
|
|
std::transform(Pica::g_state.fog.lut.begin(), Pica::g_state.fog.lut.end(), new_data.begin(),
|
|
|
|
[](const auto& entry) {
|
|
|
|
return GLvec2{entry.ToFloat(), entry.DiffToFloat()};
|
|
|
|
});
|
|
|
|
|
2018-05-19 15:16:49 +02:00
|
|
|
if (new_data != fog_lut_data || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
fog_lut_data = new_data;
|
2018-05-19 15:16:49 +02:00
|
|
|
std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2));
|
|
|
|
uniform_block_data.data.fog_lut_offset = (offset + bytes_used) / sizeof(GLvec2);
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
bytes_used += new_data.size() * sizeof(GLvec2);
|
2018-05-19 12:00:14 +02:00
|
|
|
}
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.fog_lut_dirty = false;
|
|
|
|
}
|
|
|
|
|
2018-05-19 12:00:14 +02:00
|
|
|
// helper function for SyncProcTexNoiseLUT/ColorMap/AlphaMap
|
2018-05-19 15:28:55 +02:00
|
|
|
auto SyncProcTexValueLUT = [this, buffer, offset, invalidate, &bytes_used](
|
|
|
|
const std::array<Pica::State::ProcTex::ValueEntry, 128>& lut,
|
|
|
|
std::array<GLvec2, 128>& lut_data, GLint& lut_offset) {
|
2018-05-19 12:00:14 +02:00
|
|
|
std::array<GLvec2, 128> new_data;
|
|
|
|
std::transform(lut.begin(), lut.end(), new_data.begin(), [](const auto& entry) {
|
|
|
|
return GLvec2{entry.ToFloat(), entry.DiffToFloat()};
|
|
|
|
});
|
|
|
|
|
2018-05-19 15:28:55 +02:00
|
|
|
if (new_data != lut_data || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
lut_data = new_data;
|
2018-05-19 15:28:55 +02:00
|
|
|
std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec2));
|
|
|
|
lut_offset = (offset + bytes_used) / sizeof(GLvec2);
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
bytes_used += new_data.size() * sizeof(GLvec2);
|
2018-05-19 12:00:14 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-19 11:12:51 +02:00
|
|
|
// Sync the proctex noise lut
|
2018-05-19 15:28:55 +02:00
|
|
|
if (uniform_block_data.proctex_noise_lut_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
SyncProcTexValueLUT(Pica::g_state.proctex.noise_table, proctex_noise_lut_data,
|
2018-05-19 15:28:55 +02:00
|
|
|
uniform_block_data.data.proctex_noise_lut_offset);
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.proctex_noise_lut_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync the proctex color map
|
2018-05-19 15:28:55 +02:00
|
|
|
if (uniform_block_data.proctex_color_map_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
SyncProcTexValueLUT(Pica::g_state.proctex.color_map_table, proctex_color_map_data,
|
2018-05-19 15:28:55 +02:00
|
|
|
uniform_block_data.data.proctex_color_map_offset);
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.proctex_color_map_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync the proctex alpha map
|
2018-05-19 15:28:55 +02:00
|
|
|
if (uniform_block_data.proctex_alpha_map_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
SyncProcTexValueLUT(Pica::g_state.proctex.alpha_map_table, proctex_alpha_map_data,
|
2018-05-19 15:28:55 +02:00
|
|
|
uniform_block_data.data.proctex_alpha_map_offset);
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.proctex_alpha_map_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync the proctex lut
|
2018-05-19 15:38:48 +02:00
|
|
|
if (uniform_block_data.proctex_lut_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
std::array<GLvec4, 256> new_data;
|
|
|
|
|
|
|
|
std::transform(Pica::g_state.proctex.color_table.begin(),
|
|
|
|
Pica::g_state.proctex.color_table.end(), new_data.begin(),
|
|
|
|
[](const auto& entry) {
|
|
|
|
auto rgba = entry.ToVector() / 255.0f;
|
|
|
|
return GLvec4{rgba.r(), rgba.g(), rgba.b(), rgba.a()};
|
|
|
|
});
|
|
|
|
|
2018-05-19 15:38:48 +02:00
|
|
|
if (new_data != proctex_lut_data || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
proctex_lut_data = new_data;
|
2018-05-19 15:38:48 +02:00
|
|
|
std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4));
|
|
|
|
uniform_block_data.data.proctex_lut_offset = (offset + bytes_used) / sizeof(GLvec4);
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
bytes_used += new_data.size() * sizeof(GLvec4);
|
2018-05-19 12:00:14 +02:00
|
|
|
}
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.proctex_lut_dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync the proctex difference lut
|
2018-05-19 15:38:48 +02:00
|
|
|
if (uniform_block_data.proctex_diff_lut_dirty || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
std::array<GLvec4, 256> new_data;
|
|
|
|
|
|
|
|
std::transform(Pica::g_state.proctex.color_diff_table.begin(),
|
|
|
|
Pica::g_state.proctex.color_diff_table.end(), new_data.begin(),
|
|
|
|
[](const auto& entry) {
|
|
|
|
auto rgba = entry.ToVector() / 255.0f;
|
|
|
|
return GLvec4{rgba.r(), rgba.g(), rgba.b(), rgba.a()};
|
|
|
|
});
|
|
|
|
|
2018-05-19 15:38:48 +02:00
|
|
|
if (new_data != proctex_diff_lut_data || invalidate) {
|
2018-05-19 12:00:14 +02:00
|
|
|
proctex_diff_lut_data = new_data;
|
2018-05-19 15:38:48 +02:00
|
|
|
std::memcpy(buffer + bytes_used, new_data.data(), new_data.size() * sizeof(GLvec4));
|
|
|
|
uniform_block_data.data.proctex_diff_lut_offset =
|
|
|
|
(offset + bytes_used) / sizeof(GLvec4);
|
|
|
|
uniform_block_data.dirty = true;
|
|
|
|
bytes_used += new_data.size() * sizeof(GLvec4);
|
2018-05-19 12:00:14 +02:00
|
|
|
}
|
2018-05-19 11:12:51 +02:00
|
|
|
uniform_block_data.proctex_diff_lut_dirty = false;
|
|
|
|
}
|
2018-05-19 15:09:57 +02:00
|
|
|
|
|
|
|
texture_buffer.Unmap(bytes_used);
|
2018-05-19 11:12:51 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
void RasterizerOpenGL::UploadUniforms(bool accelerate_draw, bool use_gs) {
|
|
|
|
// glBindBufferRange below also changes the generic buffer binding point, so we sync the state
|
|
|
|
// first
|
|
|
|
state.draw.uniform_buffer = uniform_buffer.GetHandle();
|
|
|
|
state.Apply();
|
|
|
|
|
|
|
|
bool sync_vs = accelerate_draw;
|
|
|
|
bool sync_gs = accelerate_draw && use_gs;
|
|
|
|
bool sync_fs = uniform_block_data.dirty;
|
|
|
|
|
|
|
|
if (!sync_vs && !sync_gs && !sync_fs)
|
2018-05-02 09:34:36 +02:00
|
|
|
return;
|
|
|
|
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t uniform_size =
|
2018-05-11 15:41:26 +02:00
|
|
|
uniform_size_aligned_vs + uniform_size_aligned_gs + uniform_size_aligned_fs;
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t used_bytes = 0;
|
2018-05-02 09:34:36 +02:00
|
|
|
u8* uniforms;
|
|
|
|
GLintptr offset;
|
2018-05-11 15:41:26 +02:00
|
|
|
bool invalidate;
|
|
|
|
std::tie(uniforms, offset, invalidate) =
|
2018-05-02 09:34:36 +02:00
|
|
|
uniform_buffer.Map(uniform_size, uniform_buffer_alignment);
|
2018-05-11 15:41:26 +02:00
|
|
|
|
|
|
|
if (sync_vs) {
|
|
|
|
VSUniformData vs_uniforms;
|
|
|
|
vs_uniforms.uniforms.SetFromRegs(Pica::g_state.regs.vs, Pica::g_state.vs);
|
|
|
|
std::memcpy(uniforms + used_bytes, &vs_uniforms, sizeof(vs_uniforms));
|
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(UniformBindings::VS),
|
|
|
|
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(VSUniformData));
|
|
|
|
used_bytes += uniform_size_aligned_vs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sync_gs) {
|
|
|
|
GSUniformData gs_uniforms;
|
|
|
|
gs_uniforms.uniforms.SetFromRegs(Pica::g_state.regs.gs, Pica::g_state.gs);
|
|
|
|
std::memcpy(uniforms + used_bytes, &gs_uniforms, sizeof(gs_uniforms));
|
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(UniformBindings::GS),
|
|
|
|
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(GSUniformData));
|
|
|
|
used_bytes += uniform_size_aligned_gs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sync_fs || invalidate) {
|
|
|
|
std::memcpy(uniforms + used_bytes, &uniform_block_data.data, sizeof(UniformData));
|
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(UniformBindings::Common),
|
|
|
|
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(UniformData));
|
|
|
|
uniform_block_data.dirty = false;
|
|
|
|
used_bytes += uniform_size_aligned_fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
uniform_buffer.Unmap(used_bytes);
|
2018-05-02 09:34:36 +02:00
|
|
|
}
|
2018-11-17 08:29:10 +01:00
|
|
|
|
|
|
|
} // namespace OpenGL
|