Code cleanup: moving poly/ into xenia/base/

This commit is contained in:
Ben Vanik
2015-05-02 03:42:51 -07:00
parent 99816056be
commit e3220f7ae6
223 changed files with 1758 additions and 1881 deletions

View File

@@ -11,8 +11,8 @@
#include <string>
#include "poly/assert.h"
#include "poly/math.h"
#include "xenia/base/assert.h"
#include "xenia/base/math.h"
namespace xe {
namespace gpu {

View File

@@ -9,8 +9,8 @@
#include "xenia/gpu/gl4/circular_buffer.h"
#include "poly/assert.h"
#include "poly/math.h"
#include "xenia/base/assert.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gpu-private.h"
@@ -67,13 +67,13 @@ void CircularBuffer::Shutdown() {
}
bool CircularBuffer::CanAcquire(size_t length) {
size_t aligned_length = poly::round_up(length, alignment_);
size_t aligned_length = xe::round_up(length, alignment_);
return write_head_ + aligned_length <= capacity_;
}
CircularBuffer::Allocation CircularBuffer::Acquire(size_t length) {
// Addresses must always be % 256.
size_t aligned_length = poly::round_up(length, alignment_);
size_t aligned_length = xe::round_up(length, alignment_);
assert_true(aligned_length <= capacity_, "Request too large");
if (write_head_ + aligned_length > capacity_) {
// Flush and wait.
@@ -97,7 +97,7 @@ bool CircularBuffer::AcquireCached(uint32_t key, size_t length,
auto& it = allocation_cache_.find(full_key);
if (it != allocation_cache_.end()) {
uintptr_t write_head = it->second;
size_t aligned_length = poly::round_up(length, alignment_);
size_t aligned_length = xe::round_up(length, alignment_);
out_allocation->host_ptr = host_base_ + write_head;
out_allocation->gpu_ptr = gpu_base_ + write_head;
out_allocation->offset = write_head;

View File

@@ -11,14 +11,14 @@
#include <algorithm>
#include "poly/math.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gl4/gl4_graphics_system.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/gpu/sampler_info.h"
#include "xenia/gpu/texture_info.h"
#include "xenia/gpu/xenos.h"
#include "xenia/logging.h"
#include "xenia/profiling.h"
#include "third_party/xxhash/xxhash.h"
@@ -100,7 +100,7 @@ bool CommandProcessor::Initialize(std::unique_ptr<GLContext> context) {
worker_running_ = true;
worker_thread_ = std::thread([this]() {
poly::threading::set_name("GL4 Worker");
xe::threading::set_name("GL4 Worker");
xe::Profiler::ThreadEnter("GL4 Worker");
WorkerMain();
xe::Profiler::ThreadExit();
@@ -212,7 +212,7 @@ void CommandProcessor::WorkerMain() {
// TODO(benvanik): use reader->Read_update_freq_ and only issue after moving
// that many indices.
if (read_ptr_writeback_ptr_) {
poly::store_and_swap<uint32_t>(
xe::store_and_swap<uint32_t>(
memory_->TranslatePhysical(read_ptr_writeback_ptr_), read_ptr_index_);
}
}
@@ -488,8 +488,7 @@ void CommandProcessor::WriteRegister(uint32_t index, uint32_t value) {
// Enabled - write to address.
uint32_t scratch_addr = regs->values[XE_GPU_REG_SCRATCH_ADDR].u32;
uint32_t mem_addr = scratch_addr + (scratch_reg * 4);
poly::store_and_swap<uint32_t>(memory_->TranslatePhysical(mem_addr),
value);
xe::store_and_swap<uint32_t>(memory_->TranslatePhysical(mem_addr), value);
}
}
}
@@ -602,14 +601,14 @@ class CommandProcessor::RingbufferReader {
uint32_t offset() const { return offset_; }
bool can_read() const { return ptr_ != end_ptr_; }
uint32_t Peek() { return poly::load_and_swap<uint32_t>(membase_ + ptr_); }
uint32_t Peek() { return xe::load_and_swap<uint32_t>(membase_ + ptr_); }
void CheckRead(uint32_t words) {
assert_true(ptr_ + words * sizeof(uint32_t) <= end_ptr_);
}
uint32_t Read() {
uint32_t value = poly::load_and_swap<uint32_t>(membase_ + ptr_);
uint32_t value = xe::load_and_swap<uint32_t>(membase_ + ptr_);
Advance(1);
return value;
}
@@ -992,7 +991,7 @@ bool CommandProcessor::ExecutePacketType3_WAIT_REG_MEM(RingbufferReader* reader,
// Memory.
auto endianness = static_cast<Endian>(poll_reg_addr & 0x3);
poll_reg_addr &= ~0x3;
value = poly::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
value = xe::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
value = GpuSwap(value, endianness);
trace_writer_.WriteMemoryRead(poll_reg_addr, 4);
} else {
@@ -1095,7 +1094,7 @@ bool CommandProcessor::ExecutePacketType3_COND_WRITE(RingbufferReader* reader,
auto endianness = static_cast<Endian>(poll_reg_addr & 0x3);
poll_reg_addr &= ~0x3;
trace_writer_.WriteMemoryRead(poll_reg_addr, 4);
value = poly::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
value = xe::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
value = GpuSwap(value, endianness);
} else {
// Register.
@@ -1136,7 +1135,7 @@ bool CommandProcessor::ExecutePacketType3_COND_WRITE(RingbufferReader* reader,
auto endianness = static_cast<Endian>(write_reg_addr & 0x3);
write_reg_addr &= ~0x3;
write_data = GpuSwap(write_data, endianness);
poly::store(memory_->TranslatePhysical(write_reg_addr), write_data);
xe::store(memory_->TranslatePhysical(write_reg_addr), write_data);
trace_writer_.WriteMemoryWrite(write_reg_addr, 4);
} else {
// Register.
@@ -1182,7 +1181,7 @@ bool CommandProcessor::ExecutePacketType3_EVENT_WRITE_SHD(
auto endianness = static_cast<Endian>(address & 0x3);
address &= ~0x3;
data_value = GpuSwap(data_value, endianness);
poly::store(memory_->TranslatePhysical(address), data_value);
xe::store(memory_->TranslatePhysical(address), data_value);
trace_writer_.WriteMemoryWrite(address, 4);
return true;
}
@@ -1206,9 +1205,9 @@ bool CommandProcessor::ExecutePacketType3_EVENT_WRITE_EXT(
1, // max z
};
assert_true(endianness == xenos::Endian::k8in16);
poly::copy_and_swap_16_aligned(
xe::copy_and_swap_16_aligned(
reinterpret_cast<uint16_t*>(memory_->TranslatePhysical(address)), extents,
poly::countof(extents));
xe::countof(extents));
trace_writer_.WriteMemoryWrite(address, sizeof(extents));
return true;
}
@@ -1367,7 +1366,7 @@ bool CommandProcessor::ExecutePacketType3_LOAD_ALU_CONSTANT(
}
trace_writer_.WriteMemoryRead(address, size_dwords * 4);
for (uint32_t n = 0; n < size_dwords; n++, index++) {
uint32_t data = poly::load_and_swap<uint32_t>(
uint32_t data = xe::load_and_swap<uint32_t>(
memory_->TranslatePhysical(address + n * 4));
WriteRegister(index, data);
}
@@ -1626,7 +1625,7 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateShaders(
if (!cached_pipeline->handles.default_pipeline) {
// Perhaps it's a bit wasteful to do all of these, but oh well.
GLuint pipelines[5];
glCreateProgramPipelines(GLsizei(poly::countof(pipelines)), pipelines);
glCreateProgramPipelines(GLsizei(xe::countof(pipelines)), pipelines);
glUseProgramStages(pipelines[0], GL_VERTEX_SHADER_BIT, vertex_program);
glUseProgramStages(pipelines[0], GL_FRAGMENT_SHADER_BIT, fragment_program);
@@ -1748,7 +1747,7 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateRenderTargets() {
regs.rb_color3_info,
};
// A2XX_RB_COLOR_MASK_WRITE_* == D3DRS_COLORWRITEENABLE
for (int n = 0; n < poly::countof(color_info); n++) {
for (int n = 0; n < xe::countof(color_info); n++) {
uint32_t write_mask = (regs.rb_color_mask >> (n * 4)) & 0xF;
if (!write_mask || !shader_targets[n]) {
// Unused, so keep disabled and set to wildcard so we'll take any
@@ -2133,7 +2132,7 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateBlendState() {
/* 3 */ GL_MAX,
/* 4 */ GL_FUNC_REVERSE_SUBTRACT,
};
for (int i = 0; i < poly::countof(regs.rb_blendcontrol); ++i) {
for (int i = 0; i < xe::countof(regs.rb_blendcontrol); ++i) {
uint32_t blend_control = regs.rb_blendcontrol[i];
// A2XX_RB_BLEND_CONTROL_COLOR_SRCBLEND
auto src_blend = blend_map[(blend_control & 0x0000001F) >> 0];
@@ -2299,11 +2298,11 @@ CommandProcessor::UpdateStatus CommandProcessor::PopulateIndexBuffer() {
if (info.format == IndexFormat::kInt32) {
auto dest = reinterpret_cast<uint32_t*>(allocation.host_ptr);
auto src = memory_->TranslatePhysical<const uint32_t*>(info.guest_base);
poly::copy_and_swap_32_aligned(dest, src, info.count);
xe::copy_and_swap_32_aligned(dest, src, info.count);
} else {
auto dest = reinterpret_cast<uint16_t*>(allocation.host_ptr);
auto src = memory_->TranslatePhysical<const uint16_t*>(info.guest_base);
poly::copy_and_swap_16_aligned(dest, src, info.count);
xe::copy_and_swap_16_aligned(dest, src, info.count);
}
draw_batcher_.set_index_buffer(allocation);
scratch_buffer_.Commit(std::move(allocation));
@@ -2354,7 +2353,7 @@ CommandProcessor::UpdateStatus CommandProcessor::PopulateVertexBuffers() {
// We could be smart about this to save GPU bandwidth by building a CRC
// as we copy and only if it differs from the previous value committing
// it (and if it matches just discard and reuse).
poly::copy_and_swap_32_aligned(
xe::copy_and_swap_32_aligned(
reinterpret_cast<uint32_t*>(allocation.host_ptr),
memory_->TranslatePhysical<const uint32_t*>(fetch->address << 2),
valid_range / 4);
@@ -2663,8 +2662,8 @@ bool CommandProcessor::IssueCopy() {
// but I can't seem to find something similar.
uint32_t dest_logical_width = copy_dest_pitch;
uint32_t dest_logical_height = copy_dest_height;
uint32_t dest_block_width = poly::round_up(dest_logical_width, 32);
uint32_t dest_block_height = poly::round_up(dest_logical_height, 32);
uint32_t dest_block_width = xe::round_up(dest_logical_width, 32);
uint32_t dest_block_height = xe::round_up(dest_logical_height, 32);
uint32_t window_offset = regs[XE_GPU_REG_PA_SC_WINDOW_OFFSET].u32;
int16_t window_offset_x = window_offset & 0x7FFF;
@@ -2700,24 +2699,24 @@ bool CommandProcessor::IssueCopy() {
trace_writer_.WriteMemoryRead(fetch->address << 2, fetch->size * 4);
int32_t dest_min_x = int32_t((std::min(
std::min(
GpuSwap(poly::load<float>(vertex_addr + 0), Endian(fetch->endian)),
GpuSwap(poly::load<float>(vertex_addr + 8), Endian(fetch->endian))),
GpuSwap(poly::load<float>(vertex_addr + 16), Endian(fetch->endian)))));
GpuSwap(xe::load<float>(vertex_addr + 0), Endian(fetch->endian)),
GpuSwap(xe::load<float>(vertex_addr + 8), Endian(fetch->endian))),
GpuSwap(xe::load<float>(vertex_addr + 16), Endian(fetch->endian)))));
int32_t dest_max_x = int32_t((std::max(
std::max(
GpuSwap(poly::load<float>(vertex_addr + 0), Endian(fetch->endian)),
GpuSwap(poly::load<float>(vertex_addr + 8), Endian(fetch->endian))),
GpuSwap(poly::load<float>(vertex_addr + 16), Endian(fetch->endian)))));
GpuSwap(xe::load<float>(vertex_addr + 0), Endian(fetch->endian)),
GpuSwap(xe::load<float>(vertex_addr + 8), Endian(fetch->endian))),
GpuSwap(xe::load<float>(vertex_addr + 16), Endian(fetch->endian)))));
int32_t dest_min_y = int32_t((std::min(
std::min(
GpuSwap(poly::load<float>(vertex_addr + 4), Endian(fetch->endian)),
GpuSwap(poly::load<float>(vertex_addr + 12), Endian(fetch->endian))),
GpuSwap(poly::load<float>(vertex_addr + 20), Endian(fetch->endian)))));
GpuSwap(xe::load<float>(vertex_addr + 4), Endian(fetch->endian)),
GpuSwap(xe::load<float>(vertex_addr + 12), Endian(fetch->endian))),
GpuSwap(xe::load<float>(vertex_addr + 20), Endian(fetch->endian)))));
int32_t dest_max_y = int32_t((std::max(
std::max(
GpuSwap(poly::load<float>(vertex_addr + 4), Endian(fetch->endian)),
GpuSwap(poly::load<float>(vertex_addr + 12), Endian(fetch->endian))),
GpuSwap(poly::load<float>(vertex_addr + 20), Endian(fetch->endian)))));
GpuSwap(xe::load<float>(vertex_addr + 4), Endian(fetch->endian)),
GpuSwap(xe::load<float>(vertex_addr + 12), Endian(fetch->endian))),
GpuSwap(xe::load<float>(vertex_addr + 20), Endian(fetch->endian)))));
Rect2D dest_rect(dest_min_x, dest_min_y, dest_max_x - dest_min_x,
dest_max_y - dest_min_y);
Rect2D src_rect(0, 0, dest_rect.width, dest_rect.height);

View File

@@ -9,11 +9,11 @@
#include "xenia/gpu/gl4/draw_batcher.h"
#include "poly/cxx_compat.h"
#include "poly/math.h"
#include "xenia/base/cxx_compat.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/logging.h"
namespace xe {
namespace gpu {
@@ -168,7 +168,7 @@ bool DrawBatcher::BeginDraw() {
}
}
batch_state_.command_stride =
poly::round_up(command_size, GLsizei(kCommandBufferAlignment));
xe::round_up(command_size, GLsizei(kCommandBufferAlignment));
GLsizei header_size = sizeof(CommonHeader);

View File

@@ -9,13 +9,13 @@
#include "xenia/gpu/gl4/gl4_graphics_system.h"
#include "poly/threading.h"
#include "xenia/base/logging.h"
#include "xenia/base/threading.h"
#include "xenia/cpu/processor.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gl4/gl4_profiler_display.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/gpu/tracing.h"
#include "xenia/logging.h"
namespace xe {
namespace gpu {
@@ -38,7 +38,7 @@ X_STATUS GL4GraphicsSystem::Setup(cpu::Processor* processor,
// Create rendering control.
// This must happen on the UI thread.
poly::threading::Fence control_ready_fence;
xe::threading::Fence control_ready_fence;
std::unique_ptr<GLContext> processor_context;
target_loop_->Post([&]() {
// Setup the GL control that actually does the drawing.
@@ -128,12 +128,11 @@ void GL4GraphicsSystem::RequestSwap() {
}
void GL4GraphicsSystem::RequestFrameTrace() {
command_processor_->RequestFrameTrace(
poly::to_wstring(FLAGS_trace_gpu_prefix));
command_processor_->RequestFrameTrace(xe::to_wstring(FLAGS_trace_gpu_prefix));
}
void GL4GraphicsSystem::BeginTracing() {
command_processor_->BeginTracing(poly::to_wstring(FLAGS_trace_gpu_prefix));
command_processor_->BeginTracing(xe::to_wstring(FLAGS_trace_gpu_prefix));
}
void GL4GraphicsSystem::EndTracing() { command_processor_->EndTracing(); }
@@ -149,7 +148,7 @@ void GL4GraphicsSystem::PlayTrace(const uint8_t* trace_data, size_t trace_size,
const PacketStartCommand* pending_packet = nullptr;
while (trace_ptr < trace_data + trace_size) {
auto type =
static_cast<TraceCommandType>(poly::load<uint32_t>(trace_ptr));
static_cast<TraceCommandType>(xe::load<uint32_t>(trace_ptr));
switch (type) {
case TraceCommandType::kPrimaryBufferStart: {
auto cmd =

View File

@@ -11,9 +11,9 @@
#include "third_party/microprofile/microprofileui.h"
#include "poly/assert.h"
#include "poly/cxx_compat.h"
#include "poly/math.h"
#include "xenia/base/assert.h"
#include "xenia/base/cxx_compat.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gpu-private.h"
namespace xe {
@@ -182,7 +182,7 @@ GL4ProfilerDisplay::GL4ProfilerDisplay(WGLControl* control)
bool GL4ProfilerDisplay::SetupFont() {
// Setup font lookup table.
for (uint32_t i = 0; i < poly::countof(font_description_.char_offsets); ++i) {
for (uint32_t i = 0; i < xe::countof(font_description_.char_offsets); ++i) {
font_description_.char_offsets[i] = 206;
}
for (uint32_t i = 'A'; i <= 'Z'; ++i) {

View File

@@ -9,12 +9,12 @@
#include "xenia/gpu/gl4/gl4_shader.h"
#include "poly/cxx_compat.h"
#include "poly/math.h"
#include "xenia/base/cxx_compat.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gl4/gl4_shader_translator.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/logging.h"
namespace xe {
namespace gpu {
@@ -355,8 +355,8 @@ bool GL4Shader::CompileProgram(std::string source) {
// Save to disk, if we asked for it.
auto base_path = FLAGS_dump_shaders.c_str();
char file_name[poly::max_path];
snprintf(file_name, poly::countof(file_name), "%s/gl4_gen_%.16llX.%s",
char file_name[xe::max_path];
snprintf(file_name, xe::countof(file_name), "%s/gl4_gen_%.16llX.%s",
base_path, data_hash_,
shader_type_ == ShaderType::kVertex ? "vert" : "frag");
if (FLAGS_dump_shaders.size()) {

View File

@@ -9,10 +9,10 @@
#include "xenia/gpu/gl4/gl4_shader_translator.h"
#include "poly/assert.h"
#include "poly/math.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/logging.h"
namespace xe {
namespace gpu {

View File

@@ -12,7 +12,7 @@
#include <string>
#include "poly/string_buffer.h"
#include "xenia/base/string_buffer.h"
#include "xenia/gpu/gl4/gl_context.h"
#include "xenia/gpu/gl4/gl4_shader.h"
#include "xenia/gpu/ucode.h"
@@ -41,7 +41,7 @@ class GL4ShaderTranslator {
const uint32_t* dwords_;
static const int kOutputCapacity = 64 * 1024;
poly::StringBuffer output_;
StringBuffer output_;
bool is_vertex_shader() const { return shader_type_ == ShaderType::kVertex; }
bool is_pixel_shader() const { return shader_type_ == ShaderType::kPixel; }

View File

@@ -11,11 +11,11 @@
#include <mutex>
#include "poly/assert.h"
#include "poly/cxx_compat.h"
#include "poly/math.h"
#include "xenia/base/assert.h"
#include "xenia/base/cxx_compat.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/logging.h"
#include "xenia/profiling.h"
namespace xe {
@@ -306,7 +306,7 @@ void GLContext::SetupDebugging() {
// intended to be used as an offset into a buffer object?
};
glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_OTHER, GL_DONT_CARE,
GLsizei(poly::countof(disable_message_ids)),
GLsizei(xe::countof(disable_message_ids)),
disable_message_ids, GL_FALSE);
// Callback will be made from driver threads.

View File

@@ -9,11 +9,11 @@
#include "xenia/gpu/gl4/texture_cache.h"
#include "poly/assert.h"
#include "poly/math.h"
#include "poly/memory.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
#include "xenia/gpu/gpu-private.h"
#include "xenia/logging.h"
namespace xe {
namespace gpu {
@@ -652,14 +652,14 @@ void TextureSwap(Endian endianness, void* dest, const void* src,
size_t length) {
switch (endianness) {
case Endian::k8in16:
poly::copy_and_swap_16_aligned(reinterpret_cast<uint16_t*>(dest),
reinterpret_cast<const uint16_t*>(src),
length / 2);
xe::copy_and_swap_16_aligned(reinterpret_cast<uint16_t*>(dest),
reinterpret_cast<const uint16_t*>(src),
length / 2);
break;
case Endian::k8in32:
poly::copy_and_swap_32_aligned(reinterpret_cast<uint32_t*>(dest),
reinterpret_cast<const uint32_t*>(src),
length / 4);
xe::copy_and_swap_32_aligned(reinterpret_cast<uint32_t*>(dest),
reinterpret_cast<const uint32_t*>(src),
length / 4);
break;
case Endian::k16in32:
// TODO(benvanik): make more efficient.

View File

@@ -9,9 +9,9 @@
#include "xenia/gpu/gl4/wgl_control.h"
#include "poly/assert.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/logging.h"
#include "xenia/profiling.h"
namespace xe {

View File

@@ -12,7 +12,7 @@
#include <functional>
#include "poly/threading.h"
#include "xenia/base/threading.h"
#include "xenia/gpu/gl4/gl_context.h"
#include "xenia/ui/loop.h"
#include "xenia/ui/win32/win32_control.h"