2018-02-12 02:34:20 +00:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-03-19 23:00:29 +00:00
|
|
|
#include <cinttypes>
|
2018-10-26 03:42:39 +00:00
|
|
|
#include <cstring>
|
2018-02-12 17:34:41 +00:00
|
|
|
#include "common/assert.h"
|
2018-03-25 04:35:06 +00:00
|
|
|
#include "core/core.h"
|
2018-09-01 03:25:18 +00:00
|
|
|
#include "core/core_timing.h"
|
2018-08-31 16:21:34 +00:00
|
|
|
#include "core/memory.h"
|
2018-03-22 20:25:17 +00:00
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2018-02-12 02:34:20 +00:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-03-24 06:41:16 +00:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
|
|
|
#include "video_core/renderer_base.h"
|
2018-03-19 23:00:29 +00:00
|
|
|
#include "video_core/textures/texture.h"
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2018-10-20 19:58:06 +00:00
|
|
|
namespace Tegra::Engines {
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2018-03-18 08:13:22 +00:00
|
|
|
/// First register id that is actually a Macro call.
|
|
|
|
constexpr u32 MacroRegistersStart = 0xE00;
|
|
|
|
|
2018-08-03 16:55:58 +00:00
|
|
|
Maxwell3D::Maxwell3D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager)
|
2018-10-26 03:42:39 +00:00
|
|
|
: memory_manager(memory_manager), rasterizer{rasterizer}, macro_interpreter(*this) {
|
|
|
|
InitializeRegisterDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::InitializeRegisterDefaults() {
|
|
|
|
// Initializes registers to their default values - what games expect them to be at boot. This is
|
|
|
|
// for certain registers that may not be explicitly set by games.
|
|
|
|
|
|
|
|
// Reset all registers to zero
|
|
|
|
std::memset(®s, 0, sizeof(regs));
|
|
|
|
|
|
|
|
// Depth range near/far is not always set, but is expected to be the default 0.0f, 1.0f. This is
|
|
|
|
// needed for ARMS.
|
|
|
|
for (std::size_t viewport{}; viewport < Regs::NumViewports; ++viewport) {
|
|
|
|
regs.viewport[viewport].depth_range_near = 0.0f;
|
|
|
|
regs.viewport[viewport].depth_range_far = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 02:34:20 +00:00
|
|
|
|
2018-03-28 20:20:18 +00:00
|
|
|
void Maxwell3D::CallMacroMethod(u32 method, std::vector<u32> parameters) {
|
2018-08-09 03:22:45 +00:00
|
|
|
// Reset the current macro.
|
|
|
|
executing_macro = 0;
|
|
|
|
|
2018-03-18 09:17:10 +00:00
|
|
|
// The requested macro must have been uploaded already.
|
2018-08-09 03:22:45 +00:00
|
|
|
auto macro_code = uploaded_macros.find(method);
|
|
|
|
if (macro_code == uploaded_macros.end()) {
|
|
|
|
LOG_ERROR(HW_GPU, "Macro {:04X} was not uploaded", method);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-18 08:13:22 +00:00
|
|
|
|
2018-08-09 03:22:45 +00:00
|
|
|
// Execute the current macro.
|
2018-03-28 20:20:18 +00:00
|
|
|
macro_interpreter.Execute(macro_code->second, std::move(parameters));
|
2018-03-17 01:32:44 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 09:17:10 +00:00
|
|
|
void Maxwell3D::WriteReg(u32 method, u32 value, u32 remaining_params) {
|
2018-03-25 04:35:06 +00:00
|
|
|
auto debug_context = Core::System::GetInstance().GetGPUDebugContext();
|
|
|
|
|
2018-03-18 08:13:22 +00:00
|
|
|
// It is an error to write to a register other than the current macro's ARG register before it
|
|
|
|
// has finished execution.
|
|
|
|
if (executing_macro != 0) {
|
|
|
|
ASSERT(method == executing_macro + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods after 0xE00 are special, they're actually triggers for some microcode that was
|
|
|
|
// uploaded to the GPU during initialization.
|
|
|
|
if (method >= MacroRegistersStart) {
|
|
|
|
// We're trying to execute a macro
|
|
|
|
if (executing_macro == 0) {
|
|
|
|
// A macro call must begin by writing the macro method's register, not its argument.
|
|
|
|
ASSERT_MSG((method % 2) == 0,
|
|
|
|
"Can't start macro execution by writing to the ARGS register");
|
|
|
|
executing_macro = method;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_params.push_back(value);
|
|
|
|
|
2018-03-18 09:17:10 +00:00
|
|
|
// Call the macro when there are no more parameters in the command buffer
|
|
|
|
if (remaining_params == 0) {
|
2018-03-28 20:20:18 +00:00
|
|
|
CallMacroMethod(executing_macro, std::move(macro_params));
|
2018-03-18 09:17:10 +00:00
|
|
|
}
|
2018-03-18 08:13:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-24 01:03:50 +00:00
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS,
|
|
|
|
"Invalid Maxwell3D register, increase the size of the Regs structure");
|
|
|
|
|
2018-03-25 04:35:06 +00:00
|
|
|
if (debug_context) {
|
|
|
|
debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandLoaded, nullptr);
|
2018-03-22 20:25:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 17:34:41 +00:00
|
|
|
regs.reg_array[method] = value;
|
|
|
|
|
|
|
|
switch (method) {
|
2018-04-24 01:01:29 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(macros.data): {
|
|
|
|
ProcessMacroUpload(value);
|
|
|
|
break;
|
|
|
|
}
|
2018-03-18 20:19:47 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[0]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[1]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[2]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[3]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[4]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[5]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[6]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[7]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[8]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[9]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[10]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[11]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[12]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[13]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[14]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[15]): {
|
|
|
|
ProcessCBData(value);
|
|
|
|
break;
|
|
|
|
}
|
2018-03-17 22:06:23 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[0].raw_config): {
|
2018-03-17 22:08:26 +00:00
|
|
|
ProcessCBBind(Regs::ShaderStage::Vertex);
|
2018-03-17 22:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[1].raw_config): {
|
2018-03-17 22:08:26 +00:00
|
|
|
ProcessCBBind(Regs::ShaderStage::TesselationControl);
|
2018-03-17 22:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[2].raw_config): {
|
2018-03-17 22:08:26 +00:00
|
|
|
ProcessCBBind(Regs::ShaderStage::TesselationEval);
|
2018-03-17 22:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[3].raw_config): {
|
2018-03-17 22:08:26 +00:00
|
|
|
ProcessCBBind(Regs::ShaderStage::Geometry);
|
2018-03-17 22:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[4].raw_config): {
|
2018-03-17 22:08:26 +00:00
|
|
|
ProcessCBBind(Regs::ShaderStage::Fragment);
|
2018-03-17 22:06:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-03-05 00:13:15 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(draw.vertex_end_gl): {
|
|
|
|
DrawArrays();
|
|
|
|
break;
|
|
|
|
}
|
2018-06-07 04:54:25 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(clear_buffers): {
|
|
|
|
ProcessClearBuffers();
|
|
|
|
break;
|
|
|
|
}
|
2018-02-12 17:34:41 +00:00
|
|
|
case MAXWELL3D_REG_INDEX(query.query_get): {
|
|
|
|
ProcessQueryGet();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-25 04:35:06 +00:00
|
|
|
if (debug_context) {
|
|
|
|
debug_context->OnEvent(Tegra::DebugContext::Event::MaxwellCommandProcessed, nullptr);
|
2018-03-22 20:25:17 +00:00
|
|
|
}
|
2018-02-12 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 01:01:29 +00:00
|
|
|
void Maxwell3D::ProcessMacroUpload(u32 data) {
|
|
|
|
// Store the uploaded macro code to interpret them when they're called.
|
|
|
|
auto& macro = uploaded_macros[regs.macros.entry * 2 + MacroRegistersStart];
|
|
|
|
macro.push_back(data);
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:34:41 +00:00
|
|
|
void Maxwell3D::ProcessQueryGet() {
|
|
|
|
GPUVAddr sequence_address = regs.query.QueryAddress();
|
|
|
|
// Since the sequence address is given as a GPU VAddr, we have to convert it to an application
|
|
|
|
// VAddr before writing.
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<VAddr> address = memory_manager.GpuToCpuAddress(sequence_address);
|
2018-02-12 17:34:41 +00:00
|
|
|
|
2018-04-23 22:06:57 +00:00
|
|
|
// TODO(Subv): Support the other query units.
|
|
|
|
ASSERT_MSG(regs.query.query_get.unit == Regs::QueryUnit::Crop,
|
|
|
|
"Units other than CROP are unimplemented");
|
|
|
|
|
2018-06-04 00:17:31 +00:00
|
|
|
u64 result = 0;
|
2018-04-23 22:06:57 +00:00
|
|
|
|
|
|
|
// TODO(Subv): Support the other query variables
|
|
|
|
switch (regs.query.query_get.select) {
|
|
|
|
case Regs::QuerySelect::Zero:
|
2018-06-04 00:17:31 +00:00
|
|
|
// This seems to actually write the query sequence to the query address.
|
|
|
|
result = regs.query.query_sequence;
|
2018-04-23 22:06:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-04-27 11:54:05 +00:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query select type {}",
|
2018-04-23 22:06:57 +00:00
|
|
|
static_cast<u32>(regs.query.query_get.select.Value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(Subv): Research and implement how query sync conditions work.
|
|
|
|
|
2018-06-04 00:17:31 +00:00
|
|
|
struct LongQueryResult {
|
|
|
|
u64_le value;
|
|
|
|
u64_le timestamp;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(LongQueryResult) == 16, "LongQueryResult has wrong size");
|
|
|
|
|
2018-02-12 17:34:41 +00:00
|
|
|
switch (regs.query.query_get.mode) {
|
2018-04-23 22:06:57 +00:00
|
|
|
case Regs::QueryMode::Write:
|
|
|
|
case Regs::QueryMode::Write2: {
|
2018-02-12 17:34:41 +00:00
|
|
|
u32 sequence = regs.query.query_sequence;
|
2018-06-04 00:17:31 +00:00
|
|
|
if (regs.query.query_get.short_query) {
|
|
|
|
// Write the current query sequence to the sequence address.
|
|
|
|
// TODO(Subv): Find out what happens if you use a long query type but mark it as a short
|
|
|
|
// query.
|
|
|
|
Memory::Write32(*address, sequence);
|
|
|
|
} else {
|
|
|
|
// Write the 128-bit result structure in long mode. Note: We emulate an infinitely fast
|
|
|
|
// GPU, this command may actually take a while to complete in real hardware due to GPU
|
|
|
|
// wait queues.
|
|
|
|
LongQueryResult query_result{};
|
|
|
|
query_result.value = result;
|
2018-09-01 03:25:18 +00:00
|
|
|
// TODO(Subv): Generate a real GPU timestamp and write it here instead of CoreTiming
|
|
|
|
query_result.timestamp = CoreTiming::GetTicks();
|
2018-06-04 00:17:31 +00:00
|
|
|
Memory::WriteBlock(*address, &query_result, sizeof(query_result));
|
|
|
|
}
|
2018-02-12 17:34:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-04-27 11:54:05 +00:00
|
|
|
UNIMPLEMENTED_MSG("Query mode {} not implemented",
|
2018-03-19 16:53:35 +00:00
|
|
|
static_cast<u32>(regs.query.query_get.mode.Value()));
|
2018-02-12 17:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-05 00:13:15 +00:00
|
|
|
|
|
|
|
void Maxwell3D::DrawArrays() {
|
2018-07-02 16:20:50 +00:00
|
|
|
LOG_DEBUG(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
|
|
|
|
regs.vertex_buffer.count);
|
2018-04-13 18:18:37 +00:00
|
|
|
ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
|
2018-03-24 06:41:16 +00:00
|
|
|
|
2018-03-25 04:35:06 +00:00
|
|
|
auto debug_context = Core::System::GetInstance().GetGPUDebugContext();
|
|
|
|
|
|
|
|
if (debug_context) {
|
|
|
|
debug_context->OnEvent(Tegra::DebugContext::Event::IncomingPrimitiveBatch, nullptr);
|
2018-03-19 23:00:29 +00:00
|
|
|
}
|
2018-03-22 20:27:28 +00:00
|
|
|
|
2018-08-12 00:21:31 +00:00
|
|
|
// Both instance configuration registers can not be set at the same time.
|
|
|
|
ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
|
|
|
|
"Illegal combination of instancing parameters");
|
|
|
|
|
|
|
|
if (regs.draw.instance_next) {
|
|
|
|
// Increment the current instance *before* drawing.
|
|
|
|
state.current_instance += 1;
|
|
|
|
} else if (!regs.draw.instance_cont) {
|
|
|
|
// Reset the current instance to 0.
|
|
|
|
state.current_instance = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:18:37 +00:00
|
|
|
const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count};
|
2018-08-03 16:55:58 +00:00
|
|
|
rasterizer.AccelerateDrawBatch(is_indexed);
|
2018-04-29 20:23:31 +00:00
|
|
|
|
2018-08-24 23:58:02 +00:00
|
|
|
if (debug_context) {
|
|
|
|
debug_context->OnEvent(Tegra::DebugContext::Event::FinishedPrimitiveBatch, nullptr);
|
|
|
|
}
|
|
|
|
|
2018-04-29 20:23:31 +00:00
|
|
|
// TODO(bunnei): Below, we reset vertex count so that we can use these registers to determine if
|
|
|
|
// the game is trying to draw indexed or direct mode. This needs to be verified on HW still -
|
|
|
|
// it's possible that it is incorrect and that there is some other register used to specify the
|
|
|
|
// drawing mode.
|
|
|
|
if (is_indexed) {
|
|
|
|
regs.index_array.count = 0;
|
|
|
|
} else {
|
|
|
|
regs.vertex_buffer.count = 0;
|
|
|
|
}
|
2018-03-05 00:13:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 22:08:26 +00:00
|
|
|
void Maxwell3D::ProcessCBBind(Regs::ShaderStage stage) {
|
2018-03-17 22:06:23 +00:00
|
|
|
// Bind the buffer currently in CB_ADDRESS to the specified index in the desired shader stage.
|
2018-09-15 13:21:06 +00:00
|
|
|
auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
|
|
|
|
auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)];
|
2018-03-17 22:06:23 +00:00
|
|
|
|
|
|
|
auto& buffer = shader.const_buffers[bind_data.index];
|
|
|
|
|
2018-08-08 06:07:44 +00:00
|
|
|
ASSERT(bind_data.index < Regs::MaxConstBuffers);
|
|
|
|
|
2018-03-17 22:06:23 +00:00
|
|
|
buffer.enabled = bind_data.valid.Value() != 0;
|
|
|
|
buffer.index = bind_data.index;
|
|
|
|
buffer.address = regs.const_buffer.BufferAddress();
|
|
|
|
buffer.size = regs.const_buffer.cb_size;
|
2018-03-17 03:06:24 +00:00
|
|
|
}
|
2018-03-17 01:32:44 +00:00
|
|
|
|
2018-03-18 20:19:47 +00:00
|
|
|
void Maxwell3D::ProcessCBData(u32 value) {
|
|
|
|
// Write the input value to the current const buffer at the current position.
|
|
|
|
GPUVAddr buffer_address = regs.const_buffer.BufferAddress();
|
|
|
|
ASSERT(buffer_address != 0);
|
|
|
|
|
|
|
|
// Don't allow writing past the end of the buffer.
|
|
|
|
ASSERT(regs.const_buffer.cb_pos + sizeof(u32) <= regs.const_buffer.cb_size);
|
|
|
|
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<VAddr> address =
|
2018-04-21 16:31:30 +00:00
|
|
|
memory_manager.GpuToCpuAddress(buffer_address + regs.const_buffer.cb_pos);
|
2018-03-18 20:19:47 +00:00
|
|
|
|
2018-04-21 16:31:30 +00:00
|
|
|
Memory::Write32(*address, value);
|
2018-03-18 20:19:47 +00:00
|
|
|
|
|
|
|
// Increment the current buffer position.
|
|
|
|
regs.const_buffer.cb_pos = regs.const_buffer.cb_pos + 4;
|
|
|
|
}
|
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
Texture::TICEntry Maxwell3D::GetTICEntry(u32 tic_index) const {
|
|
|
|
GPUVAddr tic_base_address = regs.tic.TICAddress();
|
|
|
|
|
|
|
|
GPUVAddr tic_address_gpu = tic_base_address + tic_index * sizeof(Texture::TICEntry);
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<VAddr> tic_address_cpu = memory_manager.GpuToCpuAddress(tic_address_gpu);
|
2018-03-26 20:46:49 +00:00
|
|
|
|
|
|
|
Texture::TICEntry tic_entry;
|
2018-04-21 16:31:30 +00:00
|
|
|
Memory::ReadBlock(*tic_address_cpu, &tic_entry, sizeof(Texture::TICEntry));
|
2018-03-26 20:46:49 +00:00
|
|
|
|
2018-04-16 00:56:07 +00:00
|
|
|
ASSERT_MSG(tic_entry.header_version == Texture::TICHeaderVersion::BlockLinear ||
|
|
|
|
tic_entry.header_version == Texture::TICHeaderVersion::Pitch,
|
|
|
|
"TIC versions other than BlockLinear or Pitch are unimplemented");
|
2018-03-26 20:46:49 +00:00
|
|
|
|
|
|
|
auto r_type = tic_entry.r_type.Value();
|
|
|
|
auto g_type = tic_entry.g_type.Value();
|
|
|
|
auto b_type = tic_entry.b_type.Value();
|
|
|
|
auto a_type = tic_entry.a_type.Value();
|
|
|
|
|
|
|
|
// TODO(Subv): Different data types for separate components are not supported
|
|
|
|
ASSERT(r_type == g_type && r_type == b_type && r_type == a_type);
|
|
|
|
|
|
|
|
return tic_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture::TSCEntry Maxwell3D::GetTSCEntry(u32 tsc_index) const {
|
|
|
|
GPUVAddr tsc_base_address = regs.tsc.TSCAddress();
|
|
|
|
|
|
|
|
GPUVAddr tsc_address_gpu = tsc_base_address + tsc_index * sizeof(Texture::TSCEntry);
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<VAddr> tsc_address_cpu = memory_manager.GpuToCpuAddress(tsc_address_gpu);
|
2018-03-26 20:46:49 +00:00
|
|
|
|
|
|
|
Texture::TSCEntry tsc_entry;
|
2018-04-21 16:31:30 +00:00
|
|
|
Memory::ReadBlock(*tsc_address_cpu, &tsc_entry, sizeof(Texture::TSCEntry));
|
2018-03-26 20:46:49 +00:00
|
|
|
return tsc_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Texture::FullTextureInfo> Maxwell3D::GetStageTextures(Regs::ShaderStage stage) const {
|
|
|
|
std::vector<Texture::FullTextureInfo> textures;
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-09-15 13:21:06 +00:00
|
|
|
auto& fragment_shader = state.shader_stages[static_cast<std::size_t>(stage)];
|
2018-03-23 23:56:27 +00:00
|
|
|
auto& tex_info_buffer = fragment_shader.const_buffers[regs.tex_cb_index];
|
|
|
|
ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0);
|
|
|
|
|
|
|
|
GPUVAddr tex_info_buffer_end = tex_info_buffer.address + tex_info_buffer.size;
|
|
|
|
|
|
|
|
// Offset into the texture constbuffer where the texture info begins.
|
2018-09-15 13:21:06 +00:00
|
|
|
static constexpr std::size_t TextureInfoOffset = 0x20;
|
2018-03-23 23:56:27 +00:00
|
|
|
|
|
|
|
for (GPUVAddr current_texture = tex_info_buffer.address + TextureInfoOffset;
|
2018-03-26 20:46:49 +00:00
|
|
|
current_texture < tex_info_buffer_end; current_texture += sizeof(Texture::TextureHandle)) {
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
Texture::TextureHandle tex_handle{
|
2018-04-21 16:31:30 +00:00
|
|
|
Memory::Read32(*memory_manager.GpuToCpuAddress(current_texture))};
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
Texture::FullTextureInfo tex_info{};
|
|
|
|
// TODO(Subv): Use the shader to determine which textures are actually accessed.
|
2018-06-20 16:39:10 +00:00
|
|
|
tex_info.index =
|
|
|
|
static_cast<u32>(current_texture - tex_info_buffer.address - TextureInfoOffset) /
|
|
|
|
sizeof(Texture::TextureHandle);
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
// Load the TIC data.
|
|
|
|
if (tex_handle.tic_id != 0) {
|
|
|
|
tex_info.enabled = true;
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
auto tic_entry = GetTICEntry(tex_handle.tic_id);
|
|
|
|
// TODO(Subv): Workaround for BitField's move constructor being deleted.
|
|
|
|
std::memcpy(&tex_info.tic, &tic_entry, sizeof(tic_entry));
|
|
|
|
}
|
2018-03-23 23:56:27 +00:00
|
|
|
|
2018-03-26 20:46:49 +00:00
|
|
|
// Load the TSC data
|
|
|
|
if (tex_handle.tsc_id != 0) {
|
|
|
|
auto tsc_entry = GetTSCEntry(tex_handle.tsc_id);
|
|
|
|
// TODO(Subv): Workaround for BitField's move constructor being deleted.
|
|
|
|
std::memcpy(&tex_info.tsc, &tsc_entry, sizeof(tsc_entry));
|
2018-03-23 23:56:27 +00:00
|
|
|
}
|
2018-03-26 20:46:49 +00:00
|
|
|
|
|
|
|
if (tex_info.enabled)
|
|
|
|
textures.push_back(tex_info);
|
2018-03-23 23:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return textures;
|
|
|
|
}
|
|
|
|
|
2018-09-15 13:21:06 +00:00
|
|
|
Texture::FullTextureInfo Maxwell3D::GetStageTexture(Regs::ShaderStage stage,
|
|
|
|
std::size_t offset) const {
|
|
|
|
auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
|
2018-06-06 17:58:16 +00:00
|
|
|
auto& tex_info_buffer = shader.const_buffers[regs.tex_cb_index];
|
|
|
|
ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0);
|
|
|
|
|
|
|
|
GPUVAddr tex_info_address = tex_info_buffer.address + offset * sizeof(Texture::TextureHandle);
|
|
|
|
|
|
|
|
ASSERT(tex_info_address < tex_info_buffer.address + tex_info_buffer.size);
|
|
|
|
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<VAddr> tex_address_cpu = memory_manager.GpuToCpuAddress(tex_info_address);
|
2018-06-06 17:58:16 +00:00
|
|
|
Texture::TextureHandle tex_handle{Memory::Read32(*tex_address_cpu)};
|
|
|
|
|
|
|
|
Texture::FullTextureInfo tex_info{};
|
|
|
|
tex_info.index = static_cast<u32>(offset);
|
|
|
|
|
|
|
|
// Load the TIC data.
|
|
|
|
if (tex_handle.tic_id != 0) {
|
|
|
|
tex_info.enabled = true;
|
|
|
|
|
|
|
|
auto tic_entry = GetTICEntry(tex_handle.tic_id);
|
|
|
|
// TODO(Subv): Workaround for BitField's move constructor being deleted.
|
|
|
|
std::memcpy(&tex_info.tic, &tic_entry, sizeof(tic_entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the TSC data
|
|
|
|
if (tex_handle.tsc_id != 0) {
|
|
|
|
auto tsc_entry = GetTSCEntry(tex_handle.tsc_id);
|
|
|
|
// TODO(Subv): Workaround for BitField's move constructor being deleted.
|
|
|
|
std::memcpy(&tex_info.tsc, &tsc_entry, sizeof(tsc_entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex_info;
|
|
|
|
}
|
|
|
|
|
2018-03-28 20:14:47 +00:00
|
|
|
u32 Maxwell3D::GetRegisterValue(u32 method) const {
|
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS, "Invalid Maxwell3D register");
|
|
|
|
return regs.reg_array[method];
|
|
|
|
}
|
|
|
|
|
2018-06-07 04:54:25 +00:00
|
|
|
void Maxwell3D::ProcessClearBuffers() {
|
2018-07-03 00:09:03 +00:00
|
|
|
ASSERT(regs.clear_buffers.R == regs.clear_buffers.G &&
|
|
|
|
regs.clear_buffers.R == regs.clear_buffers.B &&
|
|
|
|
regs.clear_buffers.R == regs.clear_buffers.A);
|
2018-06-07 04:54:25 +00:00
|
|
|
|
2018-08-03 16:55:58 +00:00
|
|
|
rasterizer.Clear();
|
2018-06-07 04:54:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 19:58:06 +00:00
|
|
|
} // namespace Tegra::Engines
|