dolphin/Source/Core/VideoCommon/VertexLoader_Normal.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

151 lines
6.9 KiB
C
Raw Permalink Normal View History

// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Common/CommonTypes.h"
2022-09-14 21:58:09 +00:00
#include "Common/EnumMap.h"
#include "Common/Inline.h"
2022-09-14 21:58:09 +00:00
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/VertexLoader.h"
class VertexLoader_Normal
{
public:
2022-09-14 21:58:09 +00:00
static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format,
NormalComponentCount elements, bool index3)
{
return s_table_size[type][index3][elements][format];
}
static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format,
2021-04-25 23:04:13 +00:00
NormalComponentCount elements, bool index3);
2022-09-14 21:58:09 +00:00
private:
template <typename T, auto last_member>
using EnumMap = typename Common::EnumMap<T, last_member>;
using SizeTable = EnumMap<
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
std::array<EnumMap<EnumMap<u32, ComponentFormat::InvalidFloat7>, NormalComponentCount::NTB>,
2>,
2022-09-14 21:58:09 +00:00
VertexComponentFormat::Index16>;
static constexpr SizeTable s_table_size = []() consteval
{
SizeTable table{};
using VCF = VertexComponentFormat;
using NCC = NormalComponentCount;
using FMT = ComponentFormat;
table[VCF::Direct][false][NCC::N][FMT::UByte] = 3;
table[VCF::Direct][false][NCC::N][FMT::Byte] = 3;
table[VCF::Direct][false][NCC::N][FMT::UShort] = 6;
table[VCF::Direct][false][NCC::N][FMT::Short] = 6;
table[VCF::Direct][false][NCC::N][FMT::Float] = 12;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Direct][false][NCC::N][FMT::InvalidFloat5] = 12;
table[VCF::Direct][false][NCC::N][FMT::InvalidFloat6] = 12;
table[VCF::Direct][false][NCC::N][FMT::InvalidFloat7] = 12;
2022-09-14 21:58:09 +00:00
table[VCF::Direct][false][NCC::NTB][FMT::UByte] = 9;
table[VCF::Direct][false][NCC::NTB][FMT::Byte] = 9;
table[VCF::Direct][false][NCC::NTB][FMT::UShort] = 18;
table[VCF::Direct][false][NCC::NTB][FMT::Short] = 18;
table[VCF::Direct][false][NCC::NTB][FMT::Float] = 36;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat5] = 36;
table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat6] = 36;
table[VCF::Direct][false][NCC::NTB][FMT::InvalidFloat7] = 36;
2022-09-14 21:58:09 +00:00
// Same as above, since there are no indices
table[VCF::Direct][true][NCC::N][FMT::UByte] = 3;
table[VCF::Direct][true][NCC::N][FMT::Byte] = 3;
table[VCF::Direct][true][NCC::N][FMT::UShort] = 6;
table[VCF::Direct][true][NCC::N][FMT::Short] = 6;
table[VCF::Direct][true][NCC::N][FMT::Float] = 12;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Direct][true][NCC::N][FMT::InvalidFloat5] = 12;
table[VCF::Direct][true][NCC::N][FMT::InvalidFloat6] = 12;
table[VCF::Direct][true][NCC::N][FMT::InvalidFloat7] = 12;
2022-09-14 21:58:09 +00:00
table[VCF::Direct][true][NCC::NTB][FMT::UByte] = 9;
table[VCF::Direct][true][NCC::NTB][FMT::Byte] = 9;
table[VCF::Direct][true][NCC::NTB][FMT::UShort] = 18;
table[VCF::Direct][true][NCC::NTB][FMT::Short] = 18;
table[VCF::Direct][true][NCC::NTB][FMT::Float] = 36;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat5] = 36;
table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat6] = 36;
table[VCF::Direct][true][NCC::NTB][FMT::InvalidFloat7] = 36;
2022-09-14 21:58:09 +00:00
table[VCF::Index8][false][NCC::N][FMT::UByte] = 1;
table[VCF::Index8][false][NCC::N][FMT::Byte] = 1;
table[VCF::Index8][false][NCC::N][FMT::UShort] = 1;
table[VCF::Index8][false][NCC::N][FMT::Short] = 1;
table[VCF::Index8][false][NCC::N][FMT::Float] = 1;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index8][false][NCC::N][FMT::InvalidFloat5] = 1;
table[VCF::Index8][false][NCC::N][FMT::InvalidFloat6] = 1;
table[VCF::Index8][false][NCC::N][FMT::InvalidFloat7] = 1;
2022-09-14 21:58:09 +00:00
table[VCF::Index8][false][NCC::NTB][FMT::UByte] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::Byte] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::UShort] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::Short] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::Float] = 1;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat5] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat6] = 1;
table[VCF::Index8][false][NCC::NTB][FMT::InvalidFloat7] = 1;
2022-09-14 21:58:09 +00:00
// Same for NormalComponentCount::N; differs for NTB
table[VCF::Index8][true][NCC::N][FMT::UByte] = 1;
table[VCF::Index8][true][NCC::N][FMT::Byte] = 1;
table[VCF::Index8][true][NCC::N][FMT::UShort] = 1;
table[VCF::Index8][true][NCC::N][FMT::Short] = 1;
table[VCF::Index8][true][NCC::N][FMT::Float] = 1;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index8][true][NCC::N][FMT::InvalidFloat5] = 1;
table[VCF::Index8][true][NCC::N][FMT::InvalidFloat6] = 1;
table[VCF::Index8][true][NCC::N][FMT::InvalidFloat7] = 1;
2022-09-14 21:58:09 +00:00
table[VCF::Index8][true][NCC::NTB][FMT::UByte] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::Byte] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::UShort] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::Short] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::Float] = 3;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat5] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat6] = 3;
table[VCF::Index8][true][NCC::NTB][FMT::InvalidFloat7] = 3;
2022-09-14 21:58:09 +00:00
table[VCF::Index16][false][NCC::N][FMT::UByte] = 2;
table[VCF::Index16][false][NCC::N][FMT::Byte] = 2;
table[VCF::Index16][false][NCC::N][FMT::UShort] = 2;
table[VCF::Index16][false][NCC::N][FMT::Short] = 2;
table[VCF::Index16][false][NCC::N][FMT::Float] = 2;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index16][false][NCC::N][FMT::InvalidFloat5] = 2;
table[VCF::Index16][false][NCC::N][FMT::InvalidFloat6] = 2;
table[VCF::Index16][false][NCC::N][FMT::InvalidFloat7] = 2;
2022-09-14 21:58:09 +00:00
table[VCF::Index16][false][NCC::NTB][FMT::UByte] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::Byte] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::UShort] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::Short] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::Float] = 2;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat5] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat6] = 2;
table[VCF::Index16][false][NCC::NTB][FMT::InvalidFloat7] = 2;
2022-09-14 21:58:09 +00:00
// Same for NormalComponentCount::N; differs for NTB
table[VCF::Index16][true][NCC::N][FMT::UByte] = 2;
table[VCF::Index16][true][NCC::N][FMT::Byte] = 2;
table[VCF::Index16][true][NCC::N][FMT::UShort] = 2;
table[VCF::Index16][true][NCC::N][FMT::Short] = 2;
table[VCF::Index16][true][NCC::N][FMT::Float] = 2;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index16][true][NCC::N][FMT::InvalidFloat5] = 2;
table[VCF::Index16][true][NCC::N][FMT::InvalidFloat6] = 2;
table[VCF::Index16][true][NCC::N][FMT::InvalidFloat7] = 2;
2022-09-14 21:58:09 +00:00
table[VCF::Index16][true][NCC::NTB][FMT::UByte] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::Byte] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::UShort] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::Short] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::Float] = 6;
Fix out of bounds accesses for invalid vertex component formats On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
2024-04-02 04:37:11 +00:00
table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat5] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat6] = 6;
table[VCF::Index16][true][NCC::NTB][FMT::InvalidFloat7] = 6;
2022-09-14 21:58:09 +00:00
return table;
}
();
};