1
0
Fork 0
forked from suyu/suyu

Don't keep base_address in the loader, it doesn't belong there (with it, the loader can't be cached).

This commit is contained in:
Henrik Rydgard 2016-04-28 20:17:35 +02:00
parent d00e2340c6
commit 2403e86cbb
3 changed files with 10 additions and 11 deletions

View file

@ -199,13 +199,14 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
// Processes information about internal vertex attributes to figure out how a vertex is loaded.
// Later, these can be compiled and cached.
VertexLoader loader;
const u32 base_address = regs.vertex_attributes.GetPhysicalBaseAddress();
loader.Setup(regs);
// Load vertices
bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
const auto& index_info = regs.index_array;
const u8* index_address_8 = Memory::GetPhysicalPointer(loader.GetPhysicalBaseAddress() + index_info.offset);
const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
bool index_u16 = index_info.format != 0;
@ -252,7 +253,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
if (is_indexed) {
if (g_debug_context && Pica::g_debug_context->recorder) {
int size = index_u16 ? 2 : 1;
memory_accesses.AddAccess(loader.GetPhysicalBaseAddress() + index_info.offset + size * index, size);
memory_accesses.AddAccess(base_address + index_info.offset + size * index, size);
}
for (unsigned int i = 0; i < VERTEX_CACHE_SIZE; ++i) {
@ -267,7 +268,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
if (!vertex_cache_hit) {
// Initialize data for the current vertex
Shader::InputVertex input;
loader.LoadVertex(index, vertex, input, memory_accesses);
loader.LoadVertex(base_address, index, vertex, input, memory_accesses);
if (g_debug_context)
g_debug_context->OnEvent(DebugContext::Event::VertexLoaded, (void*)&input);

View file

@ -23,7 +23,6 @@ namespace Pica {
void VertexLoader::Setup(const Pica::Regs& regs) {
const auto& attribute_config = regs.vertex_attributes;
base_address = attribute_config.GetPhysicalBaseAddress();
num_total_attributes = attribute_config.GetNumTotalAttributes();
boost::fill(vertex_attribute_sources, 0xdeadbeef);
@ -49,7 +48,7 @@ void VertexLoader::Setup(const Pica::Regs& regs) {
if (attribute_index < 12) {
int element_size = attribute_config.GetElementSizeInBytes(attribute_index);
offset = Common::AlignUp(offset, element_size);
vertex_attribute_sources[attribute_index] = base_address + loader_config.data_offset + offset;
vertex_attribute_sources[attribute_index] = loader_config.data_offset + offset;
vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count);
vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index);
vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index);
@ -66,7 +65,7 @@ void VertexLoader::Setup(const Pica::Regs& regs) {
}
}
void VertexLoader::LoadVertex(int index, int vertex, Shader::InputVertex& input, MemoryAccesses& memory_accesses) {
void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input, MemoryAccesses& memory_accesses) {
for (int i = 0; i < num_total_attributes; ++i) {
if (vertex_attribute_elements[i] != 0) {
// Default attribute values set if array elements have < 4 components. This
@ -78,7 +77,7 @@ void VertexLoader::LoadVertex(int index, int vertex, Shader::InputVertex& input,
// Load per-vertex data from the loader arrays
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
u32 source_addr = vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i];
u32 source_addr = base_address + vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i];
const u8* srcdata = Memory::GetPhysicalPointer(source_addr);
if (g_debug_context && Pica::g_debug_context->recorder) {
@ -97,7 +96,7 @@ void VertexLoader::LoadVertex(int index, int vertex, Shader::InputVertex& input,
LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08x + 0x%04x: %f",
comp, i, vertex, index,
base_address,
vertex_attribute_sources[i] - base_address,
vertex_attribute_sources[i],
vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i],
input.attr[i][comp].ToFloat32());
}

View file

@ -38,10 +38,10 @@ public:
class VertexLoader {
public:
void Setup(const Pica::Regs& regs);
void LoadVertex(int index, int vertex, Shader::InputVertex& input, MemoryAccesses& memory_accesses);
void LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input, MemoryAccesses& memory_accesses);
u32 GetPhysicalBaseAddress() const { return base_address; }
int GetNumTotalAttributes() const { return num_total_attributes; }
private:
u32 vertex_attribute_sources[16];
u32 vertex_attribute_strides[16] = {};
@ -49,7 +49,6 @@ private:
u32 vertex_attribute_elements[16] = {};
u32 vertex_attribute_element_size[16] = {};
bool vertex_attribute_is_default[16];
u32 base_address;
int num_total_attributes;
};