2014-07-26 05:42:46 -07:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-16 21:38:14 -08:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-26 05:42:46 -07:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-04-30 08:34:51 -07:00
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2015-01-02 11:40:52 -08:00
|
|
|
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2015-08-17 14:25:21 -07:00
|
|
|
#include "common/microprofile.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "common/vector_math.h"
|
2015-02-05 08:53:25 -08:00
|
|
|
|
2015-06-21 06:58:59 -07:00
|
|
|
#include "core/hle/service/gsp_gpu.h"
|
|
|
|
#include "core/hw/gpu.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "core/memory.h"
|
|
|
|
#include "core/tracer/recorder.h"
|
2015-06-21 06:58:59 -07:00
|
|
|
|
2015-09-11 04:20:02 -07:00
|
|
|
#include "video_core/command_processor.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2015-09-11 04:20:02 -07:00
|
|
|
#include "video_core/pica.h"
|
2016-03-02 19:16:38 -08:00
|
|
|
#include "video_core/pica_state.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "video_core/pica_types.h"
|
2015-09-11 04:20:02 -07:00
|
|
|
#include "video_core/primitive_assembly.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2015-09-11 04:20:02 -07:00
|
|
|
#include "video_core/renderer_base.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "video_core/shader/shader.h"
|
2016-04-28 10:01:47 -07:00
|
|
|
#include "video_core/vertex_loader.h"
|
2016-04-30 08:34:51 -07:00
|
|
|
#include "video_core/video_core.h"
|
2014-07-26 05:42:46 -07:00
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
namespace CommandProcessor {
|
|
|
|
|
2014-07-26 10:17:09 -07:00
|
|
|
static int float_regs_counter = 0;
|
|
|
|
|
|
|
|
static u32 uniform_write_buffer[4];
|
|
|
|
|
2015-04-11 11:53:35 -07:00
|
|
|
static int default_attr_counter = 0;
|
|
|
|
|
|
|
|
static u32 default_attr_write_buffer[3];
|
|
|
|
|
2015-07-25 13:00:40 -07:00
|
|
|
// 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-17 14:25:21 -07:00
|
|
|
MICROPROFILE_DEFINE(GPU_Drawing, "GPU", "Drawing", MP_RGB(50, 50, 240));
|
|
|
|
|
2015-07-25 13:00:40 -07:00
|
|
|
static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
2015-05-13 20:29:27 -07:00
|
|
|
auto& regs = g_state.regs;
|
2014-08-14 14:23:55 -07:00
|
|
|
|
2015-05-13 20:29:27 -07:00
|
|
|
if (id >= regs.NumIds())
|
2014-08-14 14:23:55 -07:00
|
|
|
return;
|
|
|
|
|
2014-12-26 18:40:17 -08:00
|
|
|
// If we're skipping this frame, only allow trigger IRQ
|
|
|
|
if (GPU::g_skip_frame && id != PICA_REG_INDEX(trigger_irq))
|
|
|
|
return;
|
|
|
|
|
2015-03-21 16:31:40 -07:00
|
|
|
// TODO: Figure out how register masking acts on e.g. vs.uniform_setup.set_value
|
2015-05-13 20:29:27 -07:00
|
|
|
u32 old_value = regs[id];
|
2015-07-25 13:00:40 -07:00
|
|
|
|
|
|
|
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 05:42:46 -07:00
|
|
|
|
2014-10-25 09:02:26 -07:00
|
|
|
if (g_debug_context)
|
2015-07-22 16:20:54 -07:00
|
|
|
g_debug_context->OnEvent(DebugContext::Event::PicaCommandLoaded, reinterpret_cast<void*>(&id));
|
2014-10-25 09:02:26 -07:00
|
|
|
|
2014-07-26 05:42:46 -07:00
|
|
|
switch(id) {
|
2014-12-02 22:04:22 -08:00
|
|
|
// Trigger IRQ
|
|
|
|
case PICA_REG_INDEX(trigger_irq):
|
|
|
|
GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::P3D);
|
2015-05-23 21:55:35 -07:00
|
|
|
break;
|
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(triangle_topology, 0x25E):
|
|
|
|
g_state.primitive_assembler.Reconfigure(regs.triangle_topology);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(restart_primitive, 0x25F):
|
|
|
|
g_state.primitive_assembler.Reset();
|
|
|
|
break;
|
|
|
|
|
2016-03-02 19:16:38 -08:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.index, 0x232):
|
2016-03-05 14:49:23 -08:00
|
|
|
g_state.immediate.current_attribute = 0;
|
|
|
|
default_attr_counter = 0;
|
2016-03-02 19:16:38 -08:00
|
|
|
break;
|
|
|
|
|
2015-05-27 07:33:59 -07:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
Math::Vec4<float24> attribute;
|
2015-05-27 07:33:59 -07:00
|
|
|
|
|
|
|
// NOTE: The destination component order indeed is "backwards"
|
2015-12-16 20:23:50 -08:00
|
|
|
attribute.w = float24::FromRaw(default_attr_write_buffer[0] >> 8);
|
|
|
|
attribute.z = float24::FromRaw(((default_attr_write_buffer[0] & 0xFF) << 16) | ((default_attr_write_buffer[1] >> 16) & 0xFFFF));
|
|
|
|
attribute.y = float24::FromRaw(((default_attr_write_buffer[1] & 0xFFFF) << 8) | ((default_attr_write_buffer[2] >> 24) & 0xFF));
|
|
|
|
attribute.x = float24::FromRaw(default_attr_write_buffer[2] & 0xFFFFFF);
|
2015-05-27 07:33:59 -07:00
|
|
|
|
|
|
|
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!
|
2016-03-02 19:16:38 -08:00
|
|
|
if (setup.index < 15) {
|
2016-03-05 14:49:23 -08:00
|
|
|
g_state.vs.default_attributes[setup.index] = attribute;
|
2016-03-02 19:16:38 -08:00
|
|
|
setup.index++;
|
|
|
|
} else {
|
|
|
|
// Put each attribute into an immediate input buffer.
|
|
|
|
// When all specified immediate attributes are present, the Vertex Shader is invoked and everything is
|
|
|
|
// sent to the primitive assembler.
|
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
auto& immediate_input = g_state.immediate.input_vertex;
|
|
|
|
auto& immediate_attribute_id = g_state.immediate.current_attribute;
|
2016-03-02 19:16:38 -08:00
|
|
|
|
|
|
|
immediate_input.attr[immediate_attribute_id++] = attribute;
|
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
if (immediate_attribute_id >= regs.vs.num_input_attributes+1) {
|
2016-03-02 19:16:38 -08:00
|
|
|
immediate_attribute_id = 0;
|
|
|
|
|
|
|
|
Shader::UnitState<false> shader_unit;
|
2016-03-29 17:45:18 -07:00
|
|
|
g_state.vs.Setup();
|
2016-03-02 19:16:38 -08:00
|
|
|
|
|
|
|
// Send to vertex shader
|
2016-05-04 01:21:51 -07:00
|
|
|
if (g_debug_context)
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, static_cast<void*>(&immediate_input));
|
2016-03-29 17:45:18 -07:00
|
|
|
Shader::OutputVertex output = g_state.vs.Run(shader_unit, immediate_input, regs.vs.num_input_attributes+1);
|
2016-03-02 19:16:38 -08:00
|
|
|
|
|
|
|
// Send to renderer
|
|
|
|
using Pica::Shader::OutputVertex;
|
|
|
|
auto AddTriangle = [](const OutputVertex& v0, const OutputVertex& v1, const OutputVertex& v2) {
|
2016-03-08 18:31:41 -08:00
|
|
|
VideoCore::g_renderer->Rasterizer()->AddTriangle(v0, v1, v2);
|
2016-03-02 19:16:38 -08:00
|
|
|
};
|
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
g_state.primitive_assembler.SubmitVertex(output, AddTriangle);
|
2016-03-02 19:16:38 -08:00
|
|
|
}
|
|
|
|
}
|
2015-05-27 07:33:59 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:16:38 -08:00
|
|
|
case PICA_REG_INDEX(gpu_mode):
|
2016-03-05 14:49:23 -08:00
|
|
|
if (regs.gpu_mode == Regs::GPUMode::Configuring) {
|
2016-03-02 19:16:38 -08:00
|
|
|
// Draw immediate mode triangles when GPU Mode is set to GPUMode::Configuring
|
2016-03-08 18:31:41 -08:00
|
|
|
VideoCore::g_renderer->Rasterizer()->DrawTriangles();
|
2016-03-05 14:49:23 -08:00
|
|
|
|
|
|
|
if (g_debug_context) {
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::FinishedPrimitiveBatch, nullptr);
|
|
|
|
}
|
2016-03-02 19:16:38 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-05-23 21:55:35 -07:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[0], 0x23c):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[1], 0x23d):
|
|
|
|
{
|
2015-06-29 11:32:53 -07:00
|
|
|
unsigned index = static_cast<unsigned>(id - PICA_REG_INDEX(command_buffer.trigger[0]));
|
2015-05-23 21:55:35 -07:00
|
|
|
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-02 22:04:22 -08:00
|
|
|
|
2014-07-26 07:19:11 -07:00
|
|
|
// It seems like these trigger vertex rendering
|
|
|
|
case PICA_REG_INDEX(trigger_draw):
|
|
|
|
case PICA_REG_INDEX(trigger_draw_indexed):
|
|
|
|
{
|
2015-08-17 14:25:21 -07:00
|
|
|
MICROPROFILE_SCOPE(GPU_Drawing);
|
2015-02-05 08:53:25 -08:00
|
|
|
|
2015-07-26 02:55:47 -07:00
|
|
|
#if PICA_LOG_TEV
|
2015-05-13 20:29:27 -07:00
|
|
|
DebugUtils::DumpTevStageConfig(regs.GetTevStages());
|
2015-07-26 02:55:47 -07:00
|
|
|
#endif
|
2014-10-25 09:02:26 -07:00
|
|
|
if (g_debug_context)
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
|
|
|
|
|
2016-04-28 10:01:47 -07:00
|
|
|
// Processes information about internal vertex attributes to figure out how a vertex is loaded.
|
|
|
|
// Later, these can be compiled and cached.
|
|
|
|
VertexLoader loader;
|
2016-04-28 11:17:35 -07:00
|
|
|
const u32 base_address = regs.vertex_attributes.GetPhysicalBaseAddress();
|
2016-04-28 10:01:47 -07:00
|
|
|
loader.Setup(regs);
|
2014-07-26 07:19:11 -07:00
|
|
|
|
|
|
|
// Load vertices
|
|
|
|
bool is_indexed = (id == PICA_REG_INDEX(trigger_draw_indexed));
|
|
|
|
|
2015-05-13 20:29:27 -07:00
|
|
|
const auto& index_info = regs.index_array;
|
2015-05-09 00:02:32 -07:00
|
|
|
const u8* index_address_8 = Memory::GetPhysicalPointer(base_address + index_info.offset);
|
2016-03-16 22:51:09 -07:00
|
|
|
const u16* index_address_16 = reinterpret_cast<const u16*>(index_address_8);
|
2014-12-20 15:28:17 -08:00
|
|
|
bool index_u16 = index_info.format != 0;
|
2014-07-26 07:19:11 -07:00
|
|
|
|
2016-03-05 14:49:23 -08:00
|
|
|
PrimitiveAssembler<Shader::OutputVertex>& primitive_assembler = g_state.primitive_assembler;
|
2014-08-17 05:06:58 -07:00
|
|
|
|
2015-04-04 03:57:31 -07:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 23:50:21 -07:00
|
|
|
DebugUtils::MemoryAccessTracker memory_accesses;
|
2015-04-04 03:57:31 -07:00
|
|
|
|
2015-07-24 23:19:17 -07:00
|
|
|
// 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-21 16:04:05 -07:00
|
|
|
std::array<Shader::OutputVertex, VERTEX_CACHE_SIZE> vertex_cache;
|
2015-07-24 23:19:17 -07:00
|
|
|
|
|
|
|
unsigned int vertex_cache_pos = 0;
|
|
|
|
vertex_cache_ids.fill(-1);
|
|
|
|
|
2015-07-11 16:57:59 -07:00
|
|
|
Shader::UnitState<false> shader_unit;
|
2016-03-29 17:45:18 -07:00
|
|
|
g_state.vs.Setup();
|
2015-07-21 16:38:59 -07:00
|
|
|
|
2015-05-13 20:29:27 -07:00
|
|
|
for (unsigned int index = 0; index < regs.num_vertices; ++index)
|
2014-07-26 07:19:11 -07:00
|
|
|
{
|
2015-08-22 20:09:00 -07:00
|
|
|
// 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 07:19:11 -07:00
|
|
|
|
2015-07-24 23:19:17 -07:00
|
|
|
// -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-21 16:04:05 -07:00
|
|
|
Shader::OutputVertex output;
|
2015-07-24 23:19:17 -07:00
|
|
|
|
2014-07-26 07:19:11 -07:00
|
|
|
if (is_indexed) {
|
2015-04-04 03:57:31 -07:00
|
|
|
if (g_debug_context && Pica::g_debug_context->recorder) {
|
|
|
|
int size = index_u16 ? 2 : 1;
|
2015-05-20 17:24:24 -07:00
|
|
|
memory_accesses.AddAccess(base_address + index_info.offset + size * index, size);
|
2015-04-04 03:57:31 -07:00
|
|
|
}
|
2015-07-24 23:19:17 -07:00
|
|
|
|
|
|
|
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 07:19:11 -07:00
|
|
|
}
|
|
|
|
|
2015-07-24 23:19:17 -07:00
|
|
|
if (!vertex_cache_hit) {
|
|
|
|
// Initialize data for the current vertex
|
2015-07-21 16:04:05 -07:00
|
|
|
Shader::InputVertex input;
|
2016-04-28 11:17:35 -07:00
|
|
|
loader.LoadVertex(base_address, index, vertex, input, memory_accesses);
|
2014-08-17 05:06:58 -07:00
|
|
|
|
2015-07-24 23:19:17 -07:00
|
|
|
// Send to vertex shader
|
2016-05-04 01:21:51 -07:00
|
|
|
if (g_debug_context)
|
|
|
|
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, (void*)&input);
|
2016-03-29 17:45:18 -07:00
|
|
|
output = g_state.vs.Run(shader_unit, input, loader.GetNumTotalAttributes());
|
2014-07-26 07:19:11 -07:00
|
|
|
|
2015-07-24 23:19:17 -07:00
|
|
|
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 07:19:11 -07:00
|
|
|
}
|
|
|
|
|
2015-12-06 19:06:12 -08:00
|
|
|
// Send to renderer
|
|
|
|
using Pica::Shader::OutputVertex;
|
|
|
|
auto AddTriangle = [](
|
|
|
|
const OutputVertex& v0, const OutputVertex& v1, const OutputVertex& v2) {
|
2016-03-08 18:31:41 -08:00
|
|
|
VideoCore::g_renderer->Rasterizer()->AddTriangle(v0, v1, v2);
|
2015-12-06 19:06:12 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
primitive_assembler.SubmitVertex(output, AddTriangle);
|
2014-07-26 07:19:11 -07:00
|
|
|
}
|
2015-05-18 21:21:33 -07:00
|
|
|
|
2015-05-20 17:24:24 -07:00
|
|
|
for (auto& range : memory_accesses.ranges) {
|
2015-04-04 03:57:31 -07:00
|
|
|
g_debug_context->recorder->MemoryAccessed(Memory::GetPhysicalPointer(range.first),
|
|
|
|
range.second, range.first);
|
|
|
|
}
|
|
|
|
|
2014-07-26 07:19:11 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-07-26 05:42:46 -07:00
|
|
|
|
2015-03-21 16:31:40 -07:00
|
|
|
case PICA_REG_INDEX(vs.bool_uniforms):
|
2014-12-13 12:20:47 -08:00
|
|
|
for (unsigned i = 0; i < 16; ++i)
|
2015-03-21 16:31:40 -07:00
|
|
|
g_state.vs.uniforms.b[i] = (regs.vs.bool_uniforms.Value() & (1 << i)) != 0;
|
2014-12-13 12:20:47 -08:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-03-21 16:31:40 -07:00
|
|
|
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-20 17:49:45 -08:00
|
|
|
{
|
2015-03-21 16:31:40 -07:00
|
|
|
int index = (id - PICA_REG_INDEX_WORKAROUND(vs.int_uniforms[0], 0x2b1));
|
|
|
|
auto values = regs.vs.int_uniforms[index];
|
2015-05-13 20:29:27 -07:00
|
|
|
g_state.vs.uniforms.i[index] = Math::Vec4<u8>(values.x, values.y, values.z, values.w);
|
2014-12-31 06:01:50 -08:00
|
|
|
LOG_TRACE(HW_GPU, "Set integer uniform %d to %02x %02x %02x %02x",
|
2014-12-20 17:49:45 -08:00
|
|
|
index, values.x.Value(), values.y.Value(), values.z.Value(), values.w.Value());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:31:40 -07:00
|
|
|
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 10:17:09 -07:00
|
|
|
{
|
2015-03-21 16:31:40 -07:00
|
|
|
auto& uniform_setup = regs.vs.uniform_setup;
|
2014-07-26 10:17:09 -07:00
|
|
|
|
|
|
|
// 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-11 11:53:35 -07:00
|
|
|
// Uniforms are written in a packed format such that four float24 values are encoded in
|
2014-07-26 10:17:09 -07:00
|
|
|
// 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-13 20:29:27 -07:00
|
|
|
auto& uniform = g_state.vs.uniforms.f[uniform_setup.index];
|
2014-07-26 10:17:09 -07:00
|
|
|
|
|
|
|
if (uniform_setup.index > 95) {
|
2014-12-05 17:53:49 -08:00
|
|
|
LOG_ERROR(HW_GPU, "Invalid VS uniform index %d", (int)uniform_setup.index);
|
2014-07-26 10:17:09 -07:00
|
|
|
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
|
2015-12-16 20:23:50 -08:00
|
|
|
uniform.w = float24::FromRaw(uniform_write_buffer[0] >> 8);
|
|
|
|
uniform.z = float24::FromRaw(((uniform_write_buffer[0] & 0xFF) << 16) | ((uniform_write_buffer[1] >> 16) & 0xFFFF));
|
|
|
|
uniform.y = float24::FromRaw(((uniform_write_buffer[1] & 0xFFFF) << 8) | ((uniform_write_buffer[2] >> 24) & 0xFF));
|
|
|
|
uniform.x = float24::FromRaw(uniform_write_buffer[2] & 0xFFFFFF);
|
2014-07-26 10:17:09 -07:00
|
|
|
}
|
|
|
|
|
2014-12-05 17:53:49 -08:00
|
|
|
LOG_TRACE(HW_GPU, "Set uniform %x to (%f %f %f %f)", (int)uniform_setup.index,
|
2014-07-26 10:17:09 -07:00
|
|
|
uniform.x.ToFloat32(), uniform.y.ToFloat32(), uniform.z.ToFloat32(),
|
|
|
|
uniform.w.ToFloat32());
|
|
|
|
|
|
|
|
// TODO: Verify that this actually modifies the register!
|
2016-02-11 09:41:15 -08:00
|
|
|
uniform_setup.index.Assign(uniform_setup.index + 1);
|
2014-07-26 10:17:09 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-05-25 11:34:09 -07:00
|
|
|
|
2014-07-26 10:17:09 -07:00
|
|
|
// Load shader program code
|
2015-03-21 16:31:40 -07:00
|
|
|
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 10:17:09 -07:00
|
|
|
{
|
2015-03-21 16:31:40 -07:00
|
|
|
g_state.vs.program_code[regs.vs.program.offset] = value;
|
|
|
|
regs.vs.program.offset++;
|
2014-07-26 10:17:09 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load swizzle pattern data
|
2015-03-21 16:31:40 -07:00
|
|
|
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 10:17:09 -07:00
|
|
|
{
|
2015-03-21 16:31:40 -07:00
|
|
|
g_state.vs.swizzle_data[regs.vs.swizzle_patterns.offset] = value;
|
|
|
|
regs.vs.swizzle_patterns.offset++;
|
2014-07-26 10:17:09 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-12 15:56:12 -07:00
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[0], 0x1c8):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[1], 0x1c9):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[2], 0x1ca):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[3], 0x1cb):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[4], 0x1cc):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[5], 0x1cd):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[6], 0x1ce):
|
|
|
|
case PICA_REG_INDEX_WORKAROUND(lighting.lut_data[7], 0x1cf):
|
|
|
|
{
|
|
|
|
auto& lut_config = regs.lighting.lut_config;
|
2015-12-16 15:49:20 -08:00
|
|
|
|
|
|
|
ASSERT_MSG(lut_config.index < 256, "lut_config.index exceeded maximum value of 255!");
|
|
|
|
|
2015-09-12 15:56:12 -07:00
|
|
|
g_state.lighting.luts[lut_config.type][lut_config.index].raw = value;
|
2016-02-11 09:41:15 -08:00
|
|
|
lut_config.index.Assign(lut_config.index + 1);
|
2015-09-12 15:56:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-26 05:42:46 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-10-25 09:02:26 -07:00
|
|
|
|
2016-03-08 18:31:41 -08:00
|
|
|
VideoCore::g_renderer->Rasterizer()->NotifyPicaRegisterChanged(id);
|
2015-05-18 21:21:33 -07:00
|
|
|
|
2014-10-25 09:02:26 -07:00
|
|
|
if (g_debug_context)
|
2015-07-22 16:20:54 -07:00
|
|
|
g_debug_context->OnEvent(DebugContext::Event::PicaCommandProcessed, reinterpret_cast<void*>(&id));
|
2014-07-26 05:42:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessCommandList(const u32* list, u32 size) {
|
2015-05-23 21:55:35 -07:00
|
|
|
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++ };
|
|
|
|
|
2016-01-16 23:22:51 -08:00
|
|
|
WritePicaReg(header.cmd_id, value, header.parameter_mask);
|
2015-05-23 21:55:35 -07:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < header.extra_data_length; ++i) {
|
|
|
|
u32 cmd = header.cmd_id + (header.group_commands ? i + 1 : 0);
|
2015-07-25 13:00:40 -07:00
|
|
|
WritePicaReg(cmd, *g_state.cmd_list.current_ptr++, header.parameter_mask);
|
2015-05-23 21:55:35 -07:00
|
|
|
}
|
2014-07-26 05:42:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
} // namespace
|