2014-07-26 18:12:46 +05:30
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 11:08:14 +05:30
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-26 18:12:46 +05:30
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-09-11 16:50:02 +05:30
|
|
|
#include <cmath>
|
2015-01-03 01:10:52 +05:30
|
|
|
#include <boost/range/algorithm/fill.hpp>
|
|
|
|
|
2015-08-18 02:55:21 +05:30
|
|
|
#include "common/microprofile.h"
|
2015-02-05 22:23:25 +05:30
|
|
|
#include "common/profiler.h"
|
|
|
|
|
2015-09-11 16:50:02 +05:30
|
|
|
#include "core/settings.h"
|
2015-06-21 19:28:59 +05:30
|
|
|
#include "core/hle/service/gsp_gpu.h"
|
|
|
|
#include "core/hw/gpu.h"
|
|
|
|
|
2015-09-11 16:50:02 +05:30
|
|
|
#include "video_core/clipper.h"
|
|
|
|
#include "video_core/command_processor.h"
|
|
|
|
#include "video_core/pica.h"
|
|
|
|
#include "video_core/primitive_assembly.h"
|
|
|
|
#include "video_core/renderer_base.h"
|
|
|
|
#include "video_core/video_core.h"
|
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
|
|
|
#include "video_core/shader/shader_interpreter.h"
|
2014-07-26 18:12:46 +05:30
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
namespace CommandProcessor {
|
|
|
|
|
2014-07-26 22:47:09 +05:30
|
|
|
static int float_regs_counter = 0;
|
|
|
|
|
|
|
|
static u32 uniform_write_buffer[4];
|
|
|
|
|
2015-04-12 00:23:35 +05:30
|
|
|
static int default_attr_counter = 0;
|
|
|
|
|
|
|
|
static u32 default_attr_write_buffer[3];
|
|
|
|
|
2015-02-05 22:23:25 +05:30
|
|
|
Common::Profiling::TimingCategory category_drawing("Drawing");
|
|
|
|
|
2015-07-26 01:30:40 +05:30
|
|
|
// Expand a 4-bit mask to 4-byte mask, e.g. 0b0101 -> 0x00FF00FF
|
|
|
|
static const u32 expand_bits_to_bytes[] = {
|
|
|
|
0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
|
|
|
|
0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
|
|
|
|
0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
|
|
|
|
0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
|
|
|
|
};
|
|
|
|
|
2015-08-18 02:55:21 +05:30
|
|
|
MICROPROFILE_DEFINE(GPU_Drawing, "GPU", "Drawing", MP_RGB(50, 50, 240));
|
|
|
|
|
2015-07-26 01:30:40 +05:30
|
|
|
static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
2015-05-14 08:59:27 +05:30
|
|
|
auto& regs = g_state.regs;
|
2014-08-15 02:53:55 +05:30
|
|
|
|
2015-05-14 08:59:27 +05:30
|
|
|
if (id >= regs.NumIds())
|
2014-08-15 02:53:55 +05:30
|
|
|
return;
|
|
|
|
|
2014-12-27 08:10:17 +05:30
|
|
|
// If we're skipping this frame, only allow trigger IRQ
|
|
|
|
if (GPU::g_skip_frame && id != PICA_REG_INDEX(trigger_irq))
|
|
|
|
return;
|
|
|
|
|
2015-03-22 05:01:40 +05:30
|
|
|
// TODO: Figure out how register masking acts on e.g. vs.uniform_setup.set_value
|
2015-05-14 08:59:27 +05:30
|
|
|
u32 old_value = regs[id];
|
2015-07-26 01:30:40 +05:30
|
|
|
|
|
|
|
const u32 write_mask = expand_bits_to_bytes[mask];
|
|
|
|
|
|
|
|
regs[id] = (old_value & ~write_mask) | (value & write_mask);
|
|
|
|
|
|
|
|
DebugUtils::OnPicaRegWrite({ (u16)id, (u16)mask, regs[id] });
|
2014-07-26 18:12:46 +05:30
|
|
|
|
2014-10-25 21:32:26 +05:30
|
|
|
if (g_debug_context)
|
2015-07-23 04:50:54 +05:30
|
|
|
g_debug_context->OnEvent(DebugContext::Event::PicaCommandLoaded, reinterpret_cast<void*>(&id));
|
2014-10-25 21:32:26 +05:30
|
|
|
|
2014-07-26 18:12:46 +05:30
|
|
|
switch(id) {
|
2014-12-03 11:34:22 +05:30
|
|
|
// Trigger IRQ
|
|
|
|
case PICA_REG_INDEX(trigger_irq):
|
|
|
|
GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::P3D);
|
2015-05-24 10:25:35 +05:30
|
|
|
break;
|
|
|
|
|
2015-05-27 20:03:59 +05:30
|
|
|
// Load default vertex input attributes
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[0], 0x233):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[1], 0x234):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[2], 0x235):
|
|
|
|
{
|
|
|
|
// TODO: Does actual hardware indeed keep an intermediate buffer or does
|
|
|
|
// it directly write the values?
|
|
|
|
default_attr_write_buffer[default_attr_counter++] = value;
|
|
|
|
|
|
|
|
// Default attributes are written in a packed format such that four float24 values are encoded in
|
|
|
|
// three 32-bit numbers. We write to internal memory once a full such vector is
|
|
|
|
// written.
|
|
|
|
if (default_attr_counter >= 3) {
|
|
|
|
default_attr_counter = 0;
|
|
|
|
|
|
|
|
auto& setup = regs.vs_default_attributes_setup;
|
|
|
|
|
|
|
|
if (setup.index >= 16) {
|
|
|
|
LOG_ERROR(HW_GPU, "Invalid VS default attribute index %d", (int)setup.index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Math::Vec4<float24>& attribute = g_state.vs.default_attributes[setup.index];
|
|
|
|
|
|
|
|
// NOTE: The destination component order indeed is "backwards"
|
|
|
|
attribute.w = float24::FromRawFloat24(default_attr_write_buffer[0] >> 8);
|
|
|
|
attribute.z = float24::FromRawFloat24(((default_attr_write_buffer[0] & 0xFF) << 16) | ((default_attr_write_buffer[1] >> 16) & 0xFFFF));
|
|
|
|
attribute.y = float24::FromRawFloat24(((default_attr_write_buffer[1] & 0xFFFF) << 8) | ((default_attr_write_buffer[2] >> 24) & 0xFF));
|
|
|
|
attribute.x = float24::FromRawFloat24(default_attr_write_buffer[2] & 0xFFFFFF);
|
|
|
|
|
|
|
|
LOG_TRACE(HW_GPU, "Set default VS attribute %x to (%f %f %f %f)", (int)setup.index,
|
|
|
|
attribute.x.ToFloat32(), attribute.y.ToFloat32(), attribute.z.ToFloat32(),
|
|
|
|
attribute.w.ToFloat32());
|
|
|
|
|
|
|
|
// TODO: Verify that this actually modifies the register!
|
|
|
|
setup.index = setup.index + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-24 10:25:35 +05:30
|
|
|
case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[0], 0x23c):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[1], 0x23d):
|
|
|
|
{
|
2015-06-30 00:02:53 +05:30
|
|
|
unsigned index = static_cast<unsigned>(id - PICA_REG_INDEX(command_buffer.trigger[0]));
|
2015-05-24 10:25:35 +05:30
|
|
|
u32* head_ptr = (u32*)Memory::GetPhysicalPointer(regs.command_buffer.GetPhysicalAddress(index));
|
|
|
|
g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = head_ptr;
|
|
|
|
g_state.cmd_list.length = regs.command_buffer.GetSize(index) / sizeof(u32);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-03 11:34:22 +05:30
|
|
|
|
2014-07-26 19:49:11 +05:30
|
|
|
// It seems like these trigger vertex rendering
|
|
|
|
case PICA_REG_INDEX(trigger_draw):
|
|
|
|
case PICA_REG_INDEX(trigger_draw_indexed):
|
|
|
|
{
|
2015-02-05 22:23:25 +05:30
|
|
|
Common::Profiling::ScopeTimer scope_timer(category_drawing);
|
2015-08-18 02:55:21 +05:30
|
|
|
MICROPROFILE_SCOPE(GPU_Drawing);
|
2015-02-05 22:23:25 +05:30
|
|
|
|
2015-07-26 15:25:47 +05:30
|
|
|
#if PICA_LOG_TEV
|
2015-05-14 08:59:27 +05:30
|
|
|
DebugUtils::DumpTevStageConfig(regs.GetTevStages());
|
2015-07-26 15:25:47 +05:30
|
|
|
#endif
|
2014-08-17 15:47:32 +05:30
|
|
|
|
2014-10-25 21:32:26 +05:30
|
|
|
if (g_debug_context)
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
|
|
|
|
|
2015-05-14 08:59:27 +05:30
|
|
|
const auto& attribute_config = regs.vertex_attributes;
|
2014-12-07 04:55:51 +05:30
|
|
|
const u32 base_address = attribute_config.GetPhysicalBaseAddress();
|
2014-07-26 19:49:11 +05:30
|
|
|
|
|
|
|
// Information about internal vertex attributes
|
2014-12-07 04:55:51 +05:30
|
|
|
u32 vertex_attribute_sources[16];
|
2015-01-03 01:10:52 +05:30
|
|
|
boost::fill(vertex_attribute_sources, 0xdeadbeef);
|
2015-05-17 22:22:17 +05:30
|
|
|
u32 vertex_attribute_strides[16] = {};
|
|
|
|
Regs::VertexAttributeFormat vertex_attribute_formats[16] = {};
|
2015-01-03 01:10:52 +05:30
|
|
|
|
2015-05-17 22:22:17 +05:30
|
|
|
u32 vertex_attribute_elements[16] = {};
|
|
|
|
u32 vertex_attribute_element_size[16] = {};
|
2014-07-26 19:49:11 +05:30
|
|
|
|
|
|
|
// Setup attribute data from loaders
|
|
|
|
for (int loader = 0; loader < 12; ++loader) {
|
|
|
|
const auto& loader_config = attribute_config.attribute_loaders[loader];
|
|
|
|
|
2014-12-07 04:55:51 +05:30
|
|
|
u32 load_address = base_address + loader_config.data_offset;
|
2014-07-26 19:49:11 +05:30
|
|
|
|
|
|
|
// TODO: What happens if a loader overwrites a previous one's data?
|
2014-11-30 13:14:30 +05:30
|
|
|
for (unsigned component = 0; component < loader_config.component_count; ++component) {
|
2014-07-26 19:49:11 +05:30
|
|
|
u32 attribute_index = loader_config.GetComponent(component);
|
|
|
|
vertex_attribute_sources[attribute_index] = load_address;
|
2014-09-28 20:50:06 +05:30
|
|
|
vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count);
|
2015-04-12 00:23:35 +05:30
|
|
|
vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index);
|
2014-07-26 19:49:11 +05:30
|
|
|
vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index);
|
|
|
|
vertex_attribute_element_size[attribute_index] = attribute_config.GetElementSizeInBytes(attribute_index);
|
|
|
|
load_address += attribute_config.GetStride(attribute_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load vertices
|
|
|
|
bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
|
|
|
|
|
2015-05-14 08:59:27 +05:30
|
|
|
const auto& index_info = regs.index_array;
|
2015-05-09 12:32:32 +05:30
|
|
|
const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
|
2014-07-26 19:49:11 +05:30
|
|
|
const u16* index_address_16 = (u16*)index_address_8;
|
2014-12-21 04:58:17 +05:30
|
|
|
bool index_u16 = index_info.format != 0;
|
2014-07-26 19:49:11 +05:30
|
|
|
|
2015-07-26 15:25:47 +05:30
|
|
|
#if PICA_DUMP_GEOMETRY
|
2014-08-17 17:36:58 +05:30
|
|
|
DebugUtils::GeometryDumper geometry_dumper;
|
2015-05-14 08:59:27 +05:30
|
|
|
PrimitiveAssembler<DebugUtils::GeometryDumper::Vertex> dumping_primitive_assembler(regs.triangle_topology.Value());
|
2015-07-26 15:25:47 +05:30
|
|
|
#endif
|
2015-07-22 04:34:05 +05:30
|
|
|
PrimitiveAssembler<Shader::OutputVertex> primitive_assembler(regs.triangle_topology.Value());
|
2014-08-17 17:36:58 +05:30
|
|
|
|
2015-04-04 16:27:31 +05:30
|
|
|
if (g_debug_context) {
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
const auto texture = regs.GetTextures()[i];
|
|
|
|
if (!texture.enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
u8* texture_data = Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
|
|
|
|
if (g_debug_context && Pica::g_debug_context->recorder)
|
|
|
|
g_debug_context->recorder->MemoryAccessed(texture_data, Pica::Regs::NibblesPerPixel(texture.format) * texture.config.width / 2 * texture.config.height, texture.config.GetPhysicalAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 05:54:24 +05:30
|
|
|
class {
|
|
|
|
/// Combine overlapping and close ranges
|
|
|
|
void SimplifyRanges() {
|
|
|
|
for (auto it = ranges.begin(); it != ranges.end(); ++it) {
|
|
|
|
// NOTE: We add 32 to the range end address to make sure "close" ranges are combined, too
|
|
|
|
auto it2 = std::next(it);
|
|
|
|
while (it2 != ranges.end() && it->first + it->second + 32 >= it2->first) {
|
|
|
|
it->second = std::max(it->second, it2->first + it2->second - it->first);
|
|
|
|
it2 = ranges.erase(it2);
|
|
|
|
}
|
2015-04-04 16:27:31 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 05:54:24 +05:30
|
|
|
public:
|
|
|
|
/// Record a particular memory access in the list
|
|
|
|
void AddAccess(u32 paddr, u32 size) {
|
|
|
|
// Create new range or extend existing one
|
|
|
|
ranges[paddr] = std::max(ranges[paddr], size);
|
|
|
|
|
|
|
|
// Simplify ranges...
|
|
|
|
SimplifyRanges();
|
|
|
|
}
|
2015-04-04 16:27:31 +05:30
|
|
|
|
2015-05-21 05:54:24 +05:30
|
|
|
/// Map of accessed ranges (mapping start address to range size)
|
|
|
|
std::map<u32, u32> ranges;
|
|
|
|
} memory_accesses;
|
2015-04-04 16:27:31 +05:30
|
|
|
|
2015-07-25 11:49:17 +05:30
|
|
|
// Simple circular-replacement vertex cache
|
|
|
|
// The size has been tuned for optimal balance between hit-rate and the cost of lookup
|
|
|
|
const size_t VERTEX_CACHE_SIZE = 32;
|
|
|
|
std::array<u16, VERTEX_CACHE_SIZE> vertex_cache_ids;
|
2015-07-22 04:34:05 +05:30
|
|
|
std::array<Shader::OutputVertex, VERTEX_CACHE_SIZE> vertex_cache;
|
2015-07-25 11:49:17 +05:30
|
|
|
|
|
|
|
unsigned int vertex_cache_pos = 0;
|
|
|
|
vertex_cache_ids.fill(-1);
|
|
|
|
|
2015-07-12 05:27:59 +05:30
|
|
|
Shader::UnitState<false> shader_unit;
|
2015-07-22 05:08:59 +05:30
|
|
|
Shader::Setup(shader_unit);
|
|
|
|
|
2015-05-14 08:59:27 +05:30
|
|
|
for (unsigned int index = 0; index < regs.num_vertices; ++index)
|
2014-07-26 19:49:11 +05:30
|
|
|
{
|
2015-08-23 08:39:00 +05:30
|
|
|
// Indexed rendering doesn't use the start offset
|
|
|
|
unsigned int vertex = is_indexed ? (index_u16 ? index_address_16[index] : index_address_8[index]) : (index + regs.vertex_offset);
|
2014-07-26 19:49:11 +05:30
|
|
|
|
2015-07-25 11:49:17 +05:30
|
|
|
// -1 is a common special value used for primitive restart. Since it's unknown if
|
|
|
|
// the PICA supports it, and it would mess up the caching, guard against it here.
|
|
|
|
ASSERT(vertex != -1);
|
|
|
|
|
|
|
|
bool vertex_cache_hit = false;
|
2015-07-22 04:34:05 +05:30
|
|
|
Shader::OutputVertex output;
|
2015-07-25 11:49:17 +05:30
|
|
|
|
2014-07-26 19:49:11 +05:30
|
|
|
if (is_indexed) {
|
2015-04-04 16:27:31 +05:30
|
|
|
if (g_debug_context && Pica::g_debug_context->recorder) {
|
|
|
|
int size = index_u16 ? 2 : 1;
|
2015-05-21 05:54:24 +05:30
|
|
|
memory_accesses.AddAccess(base_address + index_info.offset + size * index, size);
|
2015-04-04 16:27:31 +05:30
|
|
|
}
|
2015-07-25 11:49:17 +05:30
|
|
|
|
|
|
|
for (unsigned int i = 0; i < VERTEX_CACHE_SIZE; ++i) {
|
|
|
|
if (vertex == vertex_cache_ids[i]) {
|
|
|
|
output = vertex_cache[i];
|
|
|
|
vertex_cache_hit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-07-26 19:49:11 +05:30
|
|
|
}
|
|
|
|
|
2015-07-25 11:49:17 +05:30
|
|
|
if (!vertex_cache_hit) {
|
|
|
|
// Initialize data for the current vertex
|
2015-07-22 04:34:05 +05:30
|
|
|
Shader::InputVertex input;
|
2015-07-25 11:49:17 +05:30
|
|
|
|
|
|
|
for (int i = 0; i < attribute_config.GetNumTotalAttributes(); ++i) {
|
|
|
|
if (vertex_attribute_elements[i] != 0) {
|
|
|
|
// Default attribute values set if array elements have < 4 components. This
|
|
|
|
// is *not* carried over from the default attribute settings even if they're
|
|
|
|
// enabled for this attribute.
|
|
|
|
static const float24 zero = float24::FromFloat32(0.0f);
|
|
|
|
static const float24 one = float24::FromFloat32(1.0f);
|
|
|
|
input.attr[i] = Math::Vec4<float24>(zero, zero, zero, one);
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
const u8* srcdata = Memory::GetPhysicalPointer(source_addr);
|
|
|
|
|
|
|
|
if (g_debug_context && Pica::g_debug_context->recorder) {
|
|
|
|
memory_accesses.AddAccess(source_addr,
|
|
|
|
(vertex_attribute_formats[i] == Regs::VertexAttributeFormat::FLOAT) ? 4
|
|
|
|
: (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT) ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const float srcval = (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::BYTE) ? *(s8*)srcdata :
|
|
|
|
(vertex_attribute_formats[i] == Regs::VertexAttributeFormat::UBYTE) ? *(u8*)srcdata :
|
|
|
|
(vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT) ? *(s16*)srcdata :
|
|
|
|
*(float*)srcdata;
|
|
|
|
|
|
|
|
input.attr[i][comp] = float24::FromFloat32(srcval);
|
2015-09-02 11:49:11 +05:30
|
|
|
LOG_TRACE(HW_GPU, "Loaded component %x of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08x + 0x%04x: %f",
|
2015-07-25 11:49:17 +05:30
|
|
|
comp, i, vertex, index,
|
|
|
|
attribute_config.GetPhysicalBaseAddress(),
|
|
|
|
vertex_attribute_sources[i] - base_address,
|
|
|
|
vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i],
|
|
|
|
input.attr[i][comp].ToFloat32());
|
2015-07-21 11:56:04 +05:30
|
|
|
}
|
2015-07-25 11:49:17 +05:30
|
|
|
} else if (attribute_config.IsDefaultAttribute(i)) {
|
|
|
|
// Load the default attribute if we're configured to do so
|
|
|
|
input.attr[i] = g_state.vs.default_attributes[i];
|
|
|
|
LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
|
|
|
|
i, vertex, index,
|
|
|
|
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
|
|
|
|
input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
|
|
|
|
} else {
|
|
|
|
// TODO(yuriks): In this case, no data gets loaded and the vertex
|
|
|
|
// remains with the last value it had. This isn't currently maintained
|
|
|
|
// as global state, however, and so won't work in Citra yet.
|
2015-07-21 11:56:04 +05:30
|
|
|
}
|
2014-07-26 19:49:11 +05:30
|
|
|
}
|
2014-08-17 17:36:58 +05:30
|
|
|
|
2015-07-25 11:49:17 +05:30
|
|
|
if (g_debug_context)
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::VertexLoaded, (void*)&input);
|
2014-12-10 22:01:50 +05:30
|
|
|
|
2015-07-26 15:25:47 +05:30
|
|
|
#if PICA_DUMP_GEOMETRY
|
2015-07-25 11:49:17 +05:30
|
|
|
// NOTE: When dumping geometry, we simply assume that the first input attribute
|
|
|
|
// corresponds to the position for now.
|
|
|
|
DebugUtils::GeometryDumper::Vertex dumped_vertex = {
|
|
|
|
input.attr[0][0].ToFloat32(), input.attr[0][1].ToFloat32(), input.attr[0][2].ToFloat32()
|
|
|
|
};
|
|
|
|
using namespace std::placeholders;
|
|
|
|
dumping_primitive_assembler.SubmitVertex(dumped_vertex,
|
|
|
|
std::bind(&DebugUtils::GeometryDumper::AddTriangle,
|
|
|
|
&geometry_dumper, _1, _2, _3));
|
2015-07-26 15:25:47 +05:30
|
|
|
#endif
|
2015-07-25 11:49:17 +05:30
|
|
|
// Send to vertex shader
|
2015-07-22 05:08:59 +05:30
|
|
|
output = Shader::Run(shader_unit, input, attribute_config.GetNumTotalAttributes());
|
2014-07-26 19:49:11 +05:30
|
|
|
|
2015-07-25 11:49:17 +05:30
|
|
|
if (is_indexed) {
|
|
|
|
vertex_cache[vertex_cache_pos] = output;
|
|
|
|
vertex_cache_ids[vertex_cache_pos] = vertex;
|
|
|
|
vertex_cache_pos = (vertex_cache_pos + 1) % VERTEX_CACHE_SIZE;
|
|
|
|
}
|
2014-07-26 19:49:11 +05:30
|
|
|
}
|
|
|
|
|
2015-05-19 09:51:33 +05:30
|
|
|
if (Settings::values.use_hw_renderer) {
|
|
|
|
// Send to hardware renderer
|
2015-07-22 04:34:05 +05:30
|
|
|
static auto AddHWTriangle = [](const Pica::Shader::OutputVertex& v0,
|
|
|
|
const Pica::Shader::OutputVertex& v1,
|
|
|
|
const Pica::Shader::OutputVertex& v2) {
|
2015-05-19 09:51:33 +05:30
|
|
|
VideoCore::g_renderer->hw_rasterizer->AddTriangle(v0, v1, v2);
|
|
|
|
};
|
2015-05-26 00:04:09 +05:30
|
|
|
|
2015-05-19 09:51:33 +05:30
|
|
|
primitive_assembler.SubmitVertex(output, AddHWTriangle);
|
|
|
|
} else {
|
|
|
|
// Send to triangle clipper
|
|
|
|
primitive_assembler.SubmitVertex(output, Clipper::ProcessTriangle);
|
|
|
|
}
|
2014-07-26 19:49:11 +05:30
|
|
|
}
|
2015-05-19 09:51:33 +05:30
|
|
|
|
2015-05-21 05:54:24 +05:30
|
|
|
for (auto& range : memory_accesses.ranges) {
|
2015-04-04 16:27:31 +05:30
|
|
|
g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first),
|
|
|
|
range.second, range.first);
|
|
|
|
}
|
|
|
|
|
2015-05-19 09:51:33 +05:30
|
|
|
if (Settings::values.use_hw_renderer) {
|
|
|
|
VideoCore::g_renderer->hw_rasterizer->DrawTriangles();
|
|
|
|
}
|
|
|
|
|
2015-07-26 15:25:47 +05:30
|
|
|
#if PICA_DUMP_GEOMETRY
|
2014-08-17 17:36:58 +05:30
|
|
|
geometry_dumper.Dump();
|
2015-07-26 15:25:47 +05:30
|
|
|
#endif
|
2014-10-25 21:32:26 +05:30
|
|
|
|
2015-04-04 16:27:31 +05:30
|
|
|
if (g_debug_context) {
|
2014-10-25 21:32:26 +05:30
|
|
|
g_debug_context->OnEvent(DebugContext::Event::FinishedPrimitiveBatch, nullptr);
|
2015-04-04 16:27:31 +05:30
|
|
|
}
|
2014-10-25 21:32:26 +05:30
|
|
|
|
2014-07-26 19:49:11 +05:30
|
|
|
break;
|
|
|
|
}
|
2014-07-26 18:12:46 +05:30
|
|
|
|
2015-03-22 05:01:40 +05:30
|
|
|
case PICA_REG_INDEX(vs.bool_uniforms):
|
2014-12-14 01:50:47 +05:30
|
|
|
for (unsigned i = 0; i < 16; ++i)
|
2015-03-22 05:01:40 +05:30
|
|
|
g_state.vs.uniforms.b[i] = (regs.vs.bool_uniforms.Value() & (1 << i)) != 0;
|
2014-12-14 01:50:47 +05:30
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-03-22 05:01:40 +05:30
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[1], 0x2b2):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[2], 0x2b3):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[3], 0x2b4):
|
2014-12-21 07:19:45 +05:30
|
|
|
{
|
2015-03-22 05:01:40 +05:30
|
|
|
int index = (id - PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1));
|
|
|
|
auto values = regs.vs.int_uniforms[index];
|
2015-05-14 08:59:27 +05:30
|
|
|
g_state.vs.uniforms.i[index] = Math::Vec4<u8>(values.x, values.y, values.z, values.w);
|
2014-12-31 19:31:50 +05:30
|
|
|
LOG_TRACE(HW_GPU, "Set integer uniform %d to %02x %02x %02x %02x",
|
2014-12-21 07:19:45 +05:30
|
|
|
index, values.x.Value(), values.y.Value(), values.z.Value(), values.w.Value());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-22 05:01:40 +05:30
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[0], 0x2c1):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[1], 0x2c2):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[2], 0x2c3):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[3], 0x2c4):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[4], 0x2c5):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[5], 0x2c6):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[6], 0x2c7):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.uniform_setup.set_value[7], 0x2c8):
|
2014-07-26 22:47:09 +05:30
|
|
|
{
|
2015-03-22 05:01:40 +05:30
|
|
|
auto& uniform_setup = regs.vs.uniform_setup;
|
2014-07-26 22:47:09 +05:30
|
|
|
|
|
|
|
// TODO: Does actual hardware indeed keep an intermediate buffer or does
|
|
|
|
// it directly write the values?
|
|
|
|
uniform_write_buffer[float_regs_counter++] = value;
|
|
|
|
|
2015-04-12 00:23:35 +05:30
|
|
|
// Uniforms are written in a packed format such that four float24 values are encoded in
|
2014-07-26 22:47:09 +05:30
|
|
|
// three 32-bit numbers. We write to internal memory once a full such vector is
|
|
|
|
// written.
|
|
|
|
if ((float_regs_counter >= 4 && uniform_setup.IsFloat32()) ||
|
|
|
|
(float_regs_counter >= 3 && !uniform_setup.IsFloat32())) {
|
|
|
|
float_regs_counter = 0;
|
|
|
|
|
2015-05-14 08:59:27 +05:30
|
|
|
auto& uniform = g_state.vs.uniforms.f[uniform_setup.index];
|
2014-07-26 22:47:09 +05:30
|
|
|
|
|
|
|
if (uniform_setup.index > 95) {
|
2014-12-06 07:23:49 +05:30
|
|
|
LOG_ERROR(HW_GPU, "Invalid VS uniform index %d", (int)uniform_setup.index);
|
2014-07-26 22:47:09 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: The destination component order indeed is "backwards"
|
|
|
|
if (uniform_setup.IsFloat32()) {
|
|
|
|
for (auto i : {0,1,2,3})
|
|
|
|
uniform[3 - i] = float24::FromFloat32(*(float*)(&uniform_write_buffer[i]));
|
|
|
|
} else {
|
|
|
|
// TODO: Untested
|
|
|
|
uniform.w = float24::FromRawFloat24(uniform_write_buffer[0] >> 8);
|
|
|
|
uniform.z = float24::FromRawFloat24(((uniform_write_buffer[0] & 0xFF)<<16) | ((uniform_write_buffer[1] >> 16) & 0xFFFF));
|
|
|
|
uniform.y = float24::FromRawFloat24(((uniform_write_buffer[1] & 0xFFFF)<<8) | ((uniform_write_buffer[2] >> 24) & 0xFF));
|
|
|
|
uniform.x = float24::FromRawFloat24(uniform_write_buffer[2] & 0xFFFFFF);
|
|
|
|
}
|
|
|
|
|
2014-12-06 07:23:49 +05:30
|
|
|
LOG_TRACE(HW_GPU, "Set uniform %x to (%f %f %f %f)", (int)uniform_setup.index,
|
2014-07-26 22:47:09 +05:30
|
|
|
uniform.x.ToFloat32(), uniform.y.ToFloat32(), uniform.z.ToFloat32(),
|
|
|
|
uniform.w.ToFloat32());
|
|
|
|
|
|
|
|
// TODO: Verify that this actually modifies the register!
|
|
|
|
uniform_setup.index = uniform_setup.index + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-05-26 00:04:09 +05:30
|
|
|
|
2014-07-26 22:47:09 +05:30
|
|
|
// Load shader program code
|
2015-03-22 05:01:40 +05:30
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[0], 0x2cc):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[1], 0x2cd):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[2], 0x2ce):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[3], 0x2cf):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[4], 0x2d0):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[5], 0x2d1):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[6], 0x2d2):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[7], 0x2d3):
|
2014-07-26 22:47:09 +05:30
|
|
|
{
|
2015-03-22 05:01:40 +05:30
|
|
|
g_state.vs.program_code[regs.vs.program.offset] = value;
|
|
|
|
regs.vs.program.offset++;
|
2014-07-26 22:47:09 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load swizzle pattern data
|
2015-03-22 05:01:40 +05:30
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[0], 0x2d6):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[1], 0x2d7):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[2], 0x2d8):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[3], 0x2d9):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[4], 0x2da):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[5], 0x2db):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[6], 0x2dc):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs.swizzle_patterns.set_word[7], 0x2dd):
|
2014-07-26 22:47:09 +05:30
|
|
|
{
|
2015-03-22 05:01:40 +05:30
|
|
|
g_state.vs.swizzle_data[regs.vs.swizzle_patterns.offset] = value;
|
|
|
|
regs.vs.swizzle_patterns.offset++;
|
2014-07-26 22:47:09 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-26 18:12:46 +05:30
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-10-25 21:32:26 +05:30
|
|
|
|
2015-05-19 09:51:33 +05:30
|
|
|
VideoCore::g_renderer->hw_rasterizer->NotifyPicaRegisterChanged(id);
|
|
|
|
|
2014-10-25 21:32:26 +05:30
|
|
|
if (g_debug_context)
|
2015-07-23 04:50:54 +05:30
|
|
|
g_debug_context->OnEvent(DebugContext::Event::PicaCommandProcessed, reinterpret_cast<void*>(&id));
|
2014-07-26 18:12:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessCommandList(const u32* list, u32 size) {
|
2015-05-24 10:25:35 +05:30
|
|
|
g_state.cmd_list.head_ptr = g_state.cmd_list.current_ptr = list;
|
|
|
|
g_state.cmd_list.length = size / sizeof(u32);
|
|
|
|
|
|
|
|
while (g_state.cmd_list.current_ptr < g_state.cmd_list.head_ptr + g_state.cmd_list.length) {
|
|
|
|
|
|
|
|
// Align read pointer to 8 bytes
|
|
|
|
if ((g_state.cmd_list.head_ptr - g_state.cmd_list.current_ptr) % 2 != 0)
|
|
|
|
++g_state.cmd_list.current_ptr;
|
|
|
|
|
|
|
|
u32 value = *g_state.cmd_list.current_ptr++;
|
|
|
|
const CommandHeader header = { *g_state.cmd_list.current_ptr++ };
|
|
|
|
u32 cmd = header.cmd_id;
|
|
|
|
|
2015-07-26 01:30:40 +05:30
|
|
|
WritePicaReg(cmd, value, header.parameter_mask);
|
2015-05-24 10:25:35 +05:30
|
|
|
|
|
|
|
for (unsigned i = 0; i < header.extra_data_length; ++i) {
|
|
|
|
u32 cmd = header.cmd_id + (header.group_commands ? i + 1 : 0);
|
2015-07-26 01:30:40 +05:30
|
|
|
WritePicaReg(cmd, *g_state.cmd_list.current_ptr++, header.parameter_mask);
|
2015-05-24 10:25:35 +05:30
|
|
|
}
|
2014-07-26 18:12:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
} // namespace
|