From c27efb3f1fefa49db7962532865fbbe483f248f1 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 28 Feb 2021 13:53:32 -0800 Subject: Create constants for CP registers and masks --- Source/Core/VideoCommon/VertexLoaderManager.cpp | 77 ++++++++++++++----------- 1 file changed, 43 insertions(+), 34 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index bcbf64d3d4..93322de512 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -15,9 +15,11 @@ #include "Common/Assert.h" #include "Common/CommonTypes.h" +#include "Common/Logging/Log.h" #include "Core/HW/Memmap.h" #include "VideoCommon/BPMemory.h" +#include "VideoCommon/CPMemory.h" #include "VideoCommon/CommandProcessor.h" #include "VideoCommon/DataReader.h" #include "VideoCommon/IndexGenerator.h" @@ -302,79 +304,86 @@ void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess) { bool update_global_state = !is_preprocess; CPState* state = is_preprocess ? &g_preprocess_cp_state : &g_main_cp_state; - switch (sub_cmd & 0xF0) + switch (sub_cmd & CP_COMMAND_MASK) { - case 0x30: + case MATINDEX_A: if (update_global_state) VertexShaderManager::SetTexMatrixChangedA(value); break; - case 0x40: + case MATINDEX_B: if (update_global_state) VertexShaderManager::SetTexMatrixChangedB(value); break; - case 0x50: + case VCD_LO: state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits state->vtx_desc.Hex |= value; - state->attr_dirty = BitSet32::AllTrue(8); + state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); state->bases_dirty = true; break; - case 0x60: + case VCD_HI: state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits state->vtx_desc.Hex |= (u64)value << 17; - state->attr_dirty = BitSet32::AllTrue(8); + state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); state->bases_dirty = true; break; - case 0x70: - ASSERT((sub_cmd & 0x0F) < 8); - state->vtx_attr[sub_cmd & 7].g0.Hex = value; - state->attr_dirty[sub_cmd & 7] = true; + case CP_VAT_REG_A: + if ((sub_cmd - CP_VAT_REG_A) >= CP_NUM_VAT_REG) + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_A: Invalid VAT {}", sub_cmd - CP_VAT_REG_A); + state->vtx_attr[sub_cmd & CP_VAT_MASK].g0.Hex = value; + state->attr_dirty[sub_cmd & CP_VAT_MASK] = true; break; - case 0x80: - ASSERT((sub_cmd & 0x0F) < 8); - state->vtx_attr[sub_cmd & 7].g1.Hex = value; - state->attr_dirty[sub_cmd & 7] = true; + case CP_VAT_REG_B: + if ((sub_cmd - CP_VAT_REG_B) >= CP_NUM_VAT_REG) + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_B: Invalid VAT {}", sub_cmd - CP_VAT_REG_B); + state->vtx_attr[sub_cmd & CP_VAT_MASK].g1.Hex = value; + state->attr_dirty[sub_cmd & CP_VAT_MASK] = true; break; - case 0x90: - ASSERT((sub_cmd & 0x0F) < 8); - state->vtx_attr[sub_cmd & 7].g2.Hex = value; - state->attr_dirty[sub_cmd & 7] = true; + case CP_VAT_REG_C: + if ((sub_cmd - CP_VAT_REG_C) >= CP_NUM_VAT_REG) + WARN_LOG_FMT(VIDEO, "CP_VAT_REG_C: Invalid VAT {}", sub_cmd - CP_VAT_REG_C); + state->vtx_attr[sub_cmd & CP_VAT_MASK].g2.Hex = value; + state->attr_dirty[sub_cmd & CP_VAT_MASK] = true; break; // Pointers to vertex arrays in GC RAM - case 0xA0: - state->array_bases[sub_cmd & 0xF] = value & CommandProcessor::GetPhysicalAddressMask(); + case ARRAY_BASE: + state->array_bases[sub_cmd & CP_ARRAY_MASK] = + value & CommandProcessor::GetPhysicalAddressMask(); state->bases_dirty = true; break; - case 0xB0: - state->array_strides[sub_cmd & 0xF] = value & 0xFF; + case ARRAY_STRIDE: + state->array_strides[sub_cmd & CP_ARRAY_MASK] = value & 0xFF; break; + + default: + WARN_LOG_FMT(VIDEO, "Unknown CP register {:02x} set to {:08x}", sub_cmd, value); } } void FillCPMemoryArray(u32* memory) { - memory[0x30] = g_main_cp_state.matrix_index_a.Hex; - memory[0x40] = g_main_cp_state.matrix_index_b.Hex; - memory[0x50] = (u32)g_main_cp_state.vtx_desc.Hex; - memory[0x60] = (u32)(g_main_cp_state.vtx_desc.Hex >> 17); + memory[MATINDEX_A] = g_main_cp_state.matrix_index_a.Hex; + memory[MATINDEX_B] = g_main_cp_state.matrix_index_b.Hex; + memory[VCD_LO] = (u32)g_main_cp_state.vtx_desc.Hex; + memory[VCD_HI] = (u32)(g_main_cp_state.vtx_desc.Hex >> 17); - for (int i = 0; i < 8; ++i) + for (int i = 0; i < CP_NUM_VAT_REG; ++i) { - memory[0x70 + i] = g_main_cp_state.vtx_attr[i].g0.Hex; - memory[0x80 + i] = g_main_cp_state.vtx_attr[i].g1.Hex; - memory[0x90 + i] = g_main_cp_state.vtx_attr[i].g2.Hex; + memory[CP_VAT_REG_A + i] = g_main_cp_state.vtx_attr[i].g0.Hex; + memory[CP_VAT_REG_B + i] = g_main_cp_state.vtx_attr[i].g1.Hex; + memory[CP_VAT_REG_C + i] = g_main_cp_state.vtx_attr[i].g2.Hex; } - for (int i = 0; i < 16; ++i) + for (int i = 0; i < CP_NUM_ARRAYS; ++i) { - memory[0xA0 + i] = g_main_cp_state.array_bases[i]; - memory[0xB0 + i] = g_main_cp_state.array_strides[i]; + memory[ARRAY_BASE + i] = g_main_cp_state.array_bases[i]; + memory[ARRAY_STRIDE + i] = g_main_cp_state.array_strides[i]; } } -- cgit v1.2.3 From f749fcfa9f42cda679ff7f4288c8418d2b56b08d Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 8 Feb 2021 15:22:10 -0800 Subject: Convert CPMemory to BitField and enum class Additionally, VCacheEnhance has been added to UVAT_group1. According to YAGCD, this field is always 1. TVtxDesc also now has separate low and high fields whose hex values correspond with the proper registers, instead of having one 33-bit value. This change was made in a way that should be backwards-compatible. --- Source/Core/VideoCommon/VertexLoaderManager.cpp | 33 +++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 93322de512..4dcc211178 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -77,11 +77,26 @@ void UpdateVertexArrayPointers() // But the vertex arrays with invalid addresses aren't actually enabled. // Note: Only array bases 0 through 11 are used by the Vertex loaders. // 12 through 15 are used for loading data into xfmem. - for (int i = 0; i < 12; i++) + // We also only update the array base if the vertex description states we are going to use it. + if (IsIndexed(g_main_cp_state.vtx_desc.low.Position)) + cached_arraybases[ARRAY_POSITION] = + Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_POSITION]); + + if (IsIndexed(g_main_cp_state.vtx_desc.low.Normal)) + cached_arraybases[ARRAY_NORMAL] = Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_NORMAL]); + + for (size_t i = 0; i < g_main_cp_state.vtx_desc.low.Color.Size(); i++) + { + if (IsIndexed(g_main_cp_state.vtx_desc.low.Color[i])) + cached_arraybases[ARRAY_COLOR + i] = + Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_COLOR + i]); + } + + for (size_t i = 0; i < g_main_cp_state.vtx_desc.high.TexCoord.Size(); i++) { - // Only update the array base if the vertex description states we are going to use it. - if (g_main_cp_state.vtx_desc.GetVertexArrayStatus(i) & MASK_INDEXED) - cached_arraybases[i] = Memory::GetPointer(g_main_cp_state.array_bases[i]); + if (IsIndexed(g_main_cp_state.vtx_desc.high.TexCoord[i])) + cached_arraybases[ARRAY_TEXCOORD0 + i] = + Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_TEXCOORD0 + i]); } g_main_cp_state.bases_dirty = false; @@ -317,15 +332,13 @@ void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess) break; case VCD_LO: - state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits - state->vtx_desc.Hex |= value; + state->vtx_desc.low.Hex = value; state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); state->bases_dirty = true; break; case VCD_HI: - state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits - state->vtx_desc.Hex |= (u64)value << 17; + state->vtx_desc.high.Hex = value; state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG); state->bases_dirty = true; break; @@ -371,8 +384,8 @@ void FillCPMemoryArray(u32* memory) { memory[MATINDEX_A] = g_main_cp_state.matrix_index_a.Hex; memory[MATINDEX_B] = g_main_cp_state.matrix_index_b.Hex; - memory[VCD_LO] = (u32)g_main_cp_state.vtx_desc.Hex; - memory[VCD_HI] = (u32)(g_main_cp_state.vtx_desc.Hex >> 17); + memory[VCD_LO] = g_main_cp_state.vtx_desc.low.Hex; + memory[VCD_HI] = g_main_cp_state.vtx_desc.high.Hex; for (int i = 0; i < CP_NUM_VAT_REG; ++i) { -- cgit v1.2.3 From 70f9fc4e7526fc9cfc008a43cd33229f62be99b6 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 10 Feb 2021 18:11:31 -0800 Subject: Convert BPMemory to BitField and enum class Additional changes: - For TevStageCombiner's ColorCombiner and AlphaCombiner, op/comparison and scale/compare_mode have been split as there are different meanings and enums if bias is set to compare. (Shift has also been renamed to scale) - In TexMode0, min_filter has been split into min_mip and min_filter. - In TexImage1, image_type is now cache_manually_managed. - The unused bit in GenMode is now exposed. - LPSize's lineaspect is now named adjust_for_aspect_ratio. --- Source/Core/VideoCommon/VertexLoaderManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 4dcc211178..fdb63679f5 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -293,7 +293,7 @@ int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bo // if cull mode is CULL_ALL, tell VertexManager to skip triangles and quads. // They still need to go through vertex loading, because we need to calculate a zfreeze refrence // slope. - bool cullall = (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5); + bool cullall = (bpmem.genMode.cullmode == CullMode::All && primitive < 5); DataReader dst = g_vertex_manager->PrepareForAdditionalData( primitive, count, loader->m_native_vtx_decl.stride, cullall); -- cgit v1.2.3