Refactor software renderer (#6621)

This commit is contained in:
GPUCode 2023-06-24 01:59:18 +03:00 committed by GitHub
parent 7198243319
commit 9b82de6b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 1815 additions and 1796 deletions

View file

@ -10,6 +10,8 @@
namespace VideoCore {
using Pica::f24;
static Common::Vec4f ColorRGBA8(const u32 color) {
const auto rgba =
Common::Vec4u{color >> 0 & 0xFF, color >> 8 & 0xFF, color >> 16 & 0xFF, color >> 24 & 0xFF};
@ -73,7 +75,7 @@ RasterizerAccelerated::RasterizerAccelerated(Memory::MemorySystem& memory_)
* 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.
*/
static bool AreQuaternionsOpposite(Common::Vec4<Pica::float24> qa, Common::Vec4<Pica::float24> qb) {
static bool AreQuaternionsOpposite(Common::Vec4<f24> qa, Common::Vec4<f24> 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()};
@ -612,7 +614,7 @@ void RasterizerAccelerated::NotifyPicaRegisterChanged(u32 id) {
}
void RasterizerAccelerated::SyncDepthScale() {
float depth_scale = Pica::float24::FromRaw(regs.rasterizer.viewport_depth_range).ToFloat32();
const f32 depth_scale = f24::FromRaw(regs.rasterizer.viewport_depth_range).ToFloat32();
if (depth_scale != uniform_block_data.data.depth_scale) {
uniform_block_data.data.depth_scale = depth_scale;
@ -621,8 +623,7 @@ void RasterizerAccelerated::SyncDepthScale() {
}
void RasterizerAccelerated::SyncDepthOffset() {
float depth_offset =
Pica::float24::FromRaw(regs.rasterizer.viewport_depth_near_plane).ToFloat32();
const f32 depth_offset = f24::FromRaw(regs.rasterizer.viewport_depth_near_plane).ToFloat32();
if (depth_offset != uniform_block_data.data.depth_offset) {
uniform_block_data.data.depth_offset = depth_offset;
@ -646,16 +647,16 @@ void RasterizerAccelerated::SyncFogColor() {
void RasterizerAccelerated::SyncProcTexNoise() {
const Common::Vec2f proctex_noise_f = {
Pica::float16::FromRaw(regs.texturing.proctex_noise_frequency.u).ToFloat32(),
Pica::float16::FromRaw(regs.texturing.proctex_noise_frequency.v).ToFloat32(),
Pica::f16::FromRaw(regs.texturing.proctex_noise_frequency.u).ToFloat32(),
Pica::f16::FromRaw(regs.texturing.proctex_noise_frequency.v).ToFloat32(),
};
const Common::Vec2f proctex_noise_a = {
regs.texturing.proctex_noise_u.amplitude / 4095.0f,
regs.texturing.proctex_noise_v.amplitude / 4095.0f,
};
const Common::Vec2f proctex_noise_p = {
Pica::float16::FromRaw(regs.texturing.proctex_noise_u.phase).ToFloat32(),
Pica::float16::FromRaw(regs.texturing.proctex_noise_v.phase).ToFloat32(),
Pica::f16::FromRaw(regs.texturing.proctex_noise_u.phase).ToFloat32(),
Pica::f16::FromRaw(regs.texturing.proctex_noise_v.phase).ToFloat32(),
};
if (proctex_noise_f != uniform_block_data.data.proctex_noise_f ||
@ -669,8 +670,8 @@ void RasterizerAccelerated::SyncProcTexNoise() {
}
void RasterizerAccelerated::SyncProcTexBias() {
const auto proctex_bias = Pica::float16::FromRaw(regs.texturing.proctex.bias_low |
(regs.texturing.proctex_lut.bias_high << 8))
const auto proctex_bias = Pica::f16::FromRaw(regs.texturing.proctex.bias_low |
(regs.texturing.proctex_lut.bias_high << 8))
.ToFloat32();
if (proctex_bias != uniform_block_data.data.proctex_bias) {
uniform_block_data.data.proctex_bias = proctex_bias;
@ -687,7 +688,7 @@ void RasterizerAccelerated::SyncAlphaTest() {
}
void RasterizerAccelerated::SyncCombinerColor() {
auto combiner_color = ColorRGBA8(regs.texturing.tev_combiner_buffer_color.raw);
const auto combiner_color = ColorRGBA8(regs.texturing.tev_combiner_buffer_color.raw);
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;
@ -695,7 +696,7 @@ void RasterizerAccelerated::SyncCombinerColor() {
}
void RasterizerAccelerated::SyncTevConstColor(
std::size_t stage_index, const Pica::TexturingRegs::TevStageConfig& tev_stage) {
const size_t stage_index, const Pica::TexturingRegs::TevStageConfig& tev_stage) {
const auto const_color = ColorRGBA8(tev_stage.const_color);
if (const_color == uniform_block_data.data.const_color[stage_index]) {
@ -707,7 +708,7 @@ void RasterizerAccelerated::SyncTevConstColor(
}
void RasterizerAccelerated::SyncGlobalAmbient() {
auto color = LightColor(regs.lighting.global_ambient);
const auto color = LightColor(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;
@ -715,7 +716,7 @@ void RasterizerAccelerated::SyncGlobalAmbient() {
}
void RasterizerAccelerated::SyncLightSpecular0(int light_index) {
auto color = LightColor(regs.lighting.light[light_index].specular_0);
const auto color = LightColor(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;
@ -723,7 +724,7 @@ void RasterizerAccelerated::SyncLightSpecular0(int light_index) {
}
void RasterizerAccelerated::SyncLightSpecular1(int light_index) {
auto color = LightColor(regs.lighting.light[light_index].specular_1);
const auto color = LightColor(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;
@ -731,7 +732,7 @@ void RasterizerAccelerated::SyncLightSpecular1(int light_index) {
}
void RasterizerAccelerated::SyncLightDiffuse(int light_index) {
auto color = LightColor(regs.lighting.light[light_index].diffuse);
const auto color = LightColor(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;
@ -739,7 +740,7 @@ void RasterizerAccelerated::SyncLightDiffuse(int light_index) {
}
void RasterizerAccelerated::SyncLightAmbient(int light_index) {
auto color = LightColor(regs.lighting.light[light_index].ambient);
const auto color = LightColor(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;
@ -748,9 +749,9 @@ void RasterizerAccelerated::SyncLightAmbient(int light_index) {
void RasterizerAccelerated::SyncLightPosition(int light_index) {
const Common::Vec3f position = {
Pica::float16::FromRaw(regs.lighting.light[light_index].x).ToFloat32(),
Pica::float16::FromRaw(regs.lighting.light[light_index].y).ToFloat32(),
Pica::float16::FromRaw(regs.lighting.light[light_index].z).ToFloat32(),
Pica::f16::FromRaw(regs.lighting.light[light_index].x).ToFloat32(),
Pica::f16::FromRaw(regs.lighting.light[light_index].y).ToFloat32(),
Pica::f16::FromRaw(regs.lighting.light[light_index].z).ToFloat32(),
};
if (position != uniform_block_data.data.light_src[light_index].position) {
@ -771,8 +772,8 @@ void RasterizerAccelerated::SyncLightSpotDirection(int light_index) {
}
void RasterizerAccelerated::SyncLightDistanceAttenuationBias(int light_index) {
float dist_atten_bias =
Pica::float20::FromRaw(regs.lighting.light[light_index].dist_atten_bias).ToFloat32();
const f32 dist_atten_bias =
Pica::f20::FromRaw(regs.lighting.light[light_index].dist_atten_bias).ToFloat32();
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;
@ -781,8 +782,8 @@ void RasterizerAccelerated::SyncLightDistanceAttenuationBias(int light_index) {
}
void RasterizerAccelerated::SyncLightDistanceAttenuationScale(int light_index) {
float dist_atten_scale =
Pica::float20::FromRaw(regs.lighting.light[light_index].dist_atten_scale).ToFloat32();
const f32 dist_atten_scale =
Pica::f20::FromRaw(regs.lighting.light[light_index].dist_atten_scale).ToFloat32();
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;
@ -792,8 +793,8 @@ void RasterizerAccelerated::SyncLightDistanceAttenuationScale(int light_index) {
void RasterizerAccelerated::SyncShadowBias() {
const auto& shadow = regs.framebuffer.shadow;
float constant = Pica::float16::FromRaw(shadow.constant).ToFloat32();
float linear = Pica::float16::FromRaw(shadow.linear).ToFloat32();
const f32 constant = Pica::f16::FromRaw(shadow.constant).ToFloat32();
const f32 linear = Pica::f16::FromRaw(shadow.linear).ToFloat32();
if (constant != uniform_block_data.data.shadow_bias_constant ||
linear != uniform_block_data.data.shadow_bias_linear) {
@ -804,7 +805,7 @@ void RasterizerAccelerated::SyncShadowBias() {
}
void RasterizerAccelerated::SyncShadowTextureBias() {
int bias = regs.texturing.shadow.bias << 1;
const s32 bias = 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;
@ -813,7 +814,7 @@ void RasterizerAccelerated::SyncShadowTextureBias() {
void RasterizerAccelerated::SyncTextureLodBias(int tex_index) {
const auto pica_textures = regs.texturing.GetTextures();
const float bias = pica_textures[tex_index].config.lod.bias / 256.0f;
const f32 bias = pica_textures[tex_index].config.lod.bias / 256.0f;
if (bias != uniform_block_data.data.tex_lod_bias[tex_index]) {
uniform_block_data.data.tex_lod_bias[tex_index] = bias;
uniform_block_data.dirty = true;