[D3D12] Switch from gflags to cvars

This commit is contained in:
Triang3l
2019-08-03 16:53:23 +03:00
127 changed files with 959 additions and 647 deletions

View File

@@ -393,7 +393,7 @@ void CommandProcessor::IssueSwap(uint32_t frontbuffer_ptr,
// This prevents the display from pulling the backbuffer out from under us.
// If we skip a lot then we may need to buffer more, but as the display
// thread should be fairly idle that shouldn't happen.
if (!FLAGS_vsync) {
if (!cvars::vsync) {
std::lock_guard<std::mutex> lock(swap_state_.mutex);
if (swap_state_.pending) {
swap_state_.pending = false;
@@ -895,7 +895,7 @@ bool CommandProcessor::ExecutePacketType3_WAIT_REG_MEM(RingBuffer* reader,
// Wait.
if (wait >= 0x100) {
PrepareForWait();
if (!FLAGS_vsync) {
if (!cvars::vsync) {
// User wants it fast and dangerous.
xe::threading::MaybeYield();
} else {

View File

@@ -7,18 +7,17 @@
******************************************************************************
*/
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
#include <gflags/gflags.h>
#include "third_party/xxhash/xxhash.h"
#include <algorithm>
#include <cstring>
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/profiling.h"
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
#include "xenia/gpu/d3d12/d3d12_graphics_system.h"
#include "xenia/gpu/d3d12/d3d12_shader.h"
#include "xenia/gpu/xenos.h"
@@ -26,27 +25,31 @@
DEFINE_bool(d3d12_edram_rov, true,
"Use rasterizer-ordered views for render target emulation where "
"available.");
"available.",
"D3D12");
// Some games (such as Banjo-Kazooie) are not aware of the half-pixel offset and
// may be blurry or have texture sampling artifacts, in this case the user may
// disable half-pixel offset by setting this to false.
DEFINE_bool(d3d12_half_pixel_offset, true,
"Enable half-pixel vertex and VPOS offset.");
"Enable half-pixel vertex and VPOS offset.", "D3D12");
DEFINE_bool(d3d12_readback_memexport, false,
"Read data written by memory export in shaders on the CPU. This "
"may be needed in some games (but many only access exported data "
"on the GPU, and this flag isn't needed to handle such behavior), "
"but causes mid-frame synchronization, so it has a huge "
"performance impact.");
"performance impact.",
"D3D12");
DEFINE_bool(d3d12_readback_resolve, false,
"Read render-to-texture results on the CPU. This may be needed in "
"some games, for instance, for screenshots in saved games, but "
"causes mid-frame synchronization, so it has a huge performance "
"impact.");
"impact.",
"D3D12");
DEFINE_bool(d3d12_ssaa_custom_sample_positions, false,
"Enable custom SSAA sample positions for the RTV/DSV rendering "
"path where available instead of centers (experimental, not very "
"high-quality).");
"high-quality).",
"D3D12");
namespace xe {
namespace gpu {
@@ -78,7 +81,7 @@ void D3D12CommandProcessor::RequestFrameTrace(const std::wstring& root_path) {
}
bool D3D12CommandProcessor::IsROVUsedForEDRAM() const {
if (!FLAGS_d3d12_edram_rov) {
if (!cvars::d3d12_edram_rov) {
return false;
}
auto provider = GetD3D12Context()->GetD3D12Provider();
@@ -540,7 +543,7 @@ void D3D12CommandProcessor::SetSamplePositions(MsaaSamples sample_positions) {
// for ROV output. There's hardly any difference between 2,6 (of 0 and 3 with
// 4x MSAA) and 4,4 anyway.
// https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12graphicscommandlist1-setsamplepositions
if (FLAGS_d3d12_ssaa_custom_sample_positions && !IsROVUsedForEDRAM()) {
if (cvars::d3d12_ssaa_custom_sample_positions && !IsROVUsedForEDRAM()) {
auto provider = GetD3D12Context()->GetD3D12Provider();
auto tier = provider->GetProgrammableSamplePositionsTier();
if (tier >= 2 &&
@@ -1611,7 +1614,7 @@ bool D3D12CommandProcessor::IssueDraw(PrimitiveType primitive_type,
memexport_range.base_address_dwords << 2,
memexport_range.size_dwords << 2);
}
if (FLAGS_d3d12_readback_memexport) {
if (cvars::d3d12_readback_memexport) {
// Read the exported data on the CPU.
uint32_t memexport_total_size = 0;
for (uint32_t i = 0; i < memexport_range_count; ++i) {
@@ -1672,7 +1675,7 @@ bool D3D12CommandProcessor::IssueCopy() {
written_length)) {
return false;
}
if (FLAGS_d3d12_readback_resolve && !texture_cache_->IsResolutionScale2X() &&
if (cvars::d3d12_readback_resolve && !texture_cache_->IsResolutionScale2X() &&
written_length) {
// Read the resolved data on the CPU.
ID3D12Resource* readback_buffer = RequestReadbackBuffer(written_length);
@@ -2274,7 +2277,7 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
// TODO(Triang3l): Check if ps_param_gen should give center positions in
// OpenGL mode on the Xbox 360.
float pixel_half_pixel_offset = 0.5f;
if (FLAGS_d3d12_half_pixel_offset && !(pa_su_vtx_cntl & (1 << 0))) {
if (cvars::d3d12_half_pixel_offset && !(pa_su_vtx_cntl & (1 << 0))) {
// Signs are hopefully correct here, tested in GTA IV on both clearing
// (without a viewport) and drawing things near the edges of the screen.
if (pa_cl_vte_cntl & (1 << 0)) {
@@ -2406,7 +2409,7 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
// be incorrect in this case, but there's no other way without using ROV,
// though there's an option to limit the range to -1...1).
// http://www.students.science.uu.nl/~3220516/advancedgraphics/papers/inferred_lighting.pdf
if (!IsROVUsedForEDRAM() && FLAGS_d3d12_16bit_rtv_full_range) {
if (!IsROVUsedForEDRAM() && cvars::d3d12_16bit_rtv_full_range) {
color_exp_bias -= 5;
}
}

View File

@@ -9,8 +9,6 @@
#include "xenia/gpu/d3d12/pipeline_cache.h"
#include <gflags/gflags.h>
#include <algorithm>
#include <cinttypes>
#include <cmath>
@@ -20,6 +18,7 @@
#include "third_party/xxhash/xxhash.h"
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/profiling.h"
@@ -28,21 +27,24 @@
#include "xenia/gpu/gpu_flags.h"
DEFINE_bool(d3d12_dxbc_disasm, false,
"Disassemble DXBC shaders after generation.");
"Disassemble DXBC shaders after generation.", "D3D12");
DEFINE_int32(
d3d12_pipeline_creation_threads, -1,
"Number of threads used for graphics pipeline state creation. -1 to "
"calculate automatically (75% of logical CPU cores), 1-16 to specify the "
"number of threads explicitly, 0 to disable multithreaded pipeline state "
"creation.");
"creation.",
"D3D12");
DEFINE_bool(
d3d12_tessellation_adaptive, false,
"Allow games to use adaptive tessellation - may be disabled if the game "
"has issues with memexport, the maximum factor will be used in this case. "
"Temporarily disabled by default since there are visible cracks currently "
"in Halo 3.");
"in Halo 3.",
"D3D12");
DEFINE_bool(d3d12_tessellation_wireframe, false,
"Display tessellated surfaces as wireframe for debugging.");
"Display tessellated surfaces as wireframe for debugging.",
"D3D12");
namespace xe {
namespace gpu {
@@ -81,18 +83,18 @@ PipelineCache::PipelineCache(D3D12CommandProcessor* command_processor,
PipelineCache::~PipelineCache() { Shutdown(); }
bool PipelineCache::Initialize() {
if (FLAGS_d3d12_pipeline_creation_threads != 0) {
if (cvars::d3d12_pipeline_creation_threads != 0) {
creation_threads_busy_ = 0;
creation_completion_event_ =
xe::threading::Event::CreateManualResetEvent(true);
creation_completion_set_event_ = false;
creation_threads_shutdown_ = false;
uint32_t creation_thread_count;
if (FLAGS_d3d12_pipeline_creation_threads < 0) {
if (cvars::d3d12_pipeline_creation_threads < 0) {
creation_thread_count = std::max(
xe::threading::logical_processor_count() * 3 / 4, uint32_t(1));
} else {
creation_thread_count = uint32_t(FLAGS_d3d12_pipeline_creation_threads);
creation_thread_count = uint32_t(cvars::d3d12_pipeline_creation_threads);
}
creation_thread_count = std::min(creation_thread_count, uint32_t(16));
for (uint32_t i = 0; i < creation_thread_count; ++i) {
@@ -331,7 +333,7 @@ bool PipelineCache::TranslateShader(D3D12Shader* shader,
}
// Disassemble the shader for dumping.
if (FLAGS_d3d12_dxbc_disasm) {
if (cvars::d3d12_dxbc_disasm) {
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();
if (!shader->DisassembleDxbc(provider)) {
XELOGE("Failed to disassemble DXBC shader %.16" PRIX64,
@@ -340,8 +342,8 @@ bool PipelineCache::TranslateShader(D3D12Shader* shader,
}
// Dump shader files if desired.
if (!FLAGS_dump_shaders.empty()) {
shader->Dump(FLAGS_dump_shaders, "d3d12");
if (!cvars::dump_shaders.empty()) {
shader->Dump(cvars::dump_shaders, "d3d12");
}
return shader->is_valid();
@@ -390,7 +392,7 @@ bool PipelineCache::GetCurrentStateDescription(
break;
case TessellationMode::kAdaptive:
description_out.tessellation_mode =
FLAGS_d3d12_tessellation_adaptive
cvars::d3d12_tessellation_adaptive
? PipelineTessellationMode::kAdaptive
: PipelineTessellationMode::kContinuous;
break;
@@ -549,7 +551,7 @@ bool PipelineCache::GetCurrentStateDescription(
description_out.depth_bias_slope_scaled =
poly_offset_scale * (1.0f / 16.0f);
}
if (FLAGS_d3d12_tessellation_wireframe && tessellated &&
if (cvars::d3d12_tessellation_wireframe && tessellated &&
(primitive_type == PrimitiveType::kTrianglePatch ||
primitive_type == PrimitiveType::kQuadPatch)) {
description_out.fill_mode_wireframe = 1;

View File

@@ -9,11 +9,10 @@
#include "xenia/gpu/d3d12/primitive_converter.h"
#include <gflags/gflags.h>
#include <algorithm>
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -26,7 +25,8 @@ DEFINE_bool(d3d12_convert_quads_to_triangles, false,
"Convert quad lists to triangle lists on the CPU instead of using "
"a geometry shader. Not recommended for playing, for debugging "
"primarily (because PIX fails to display vertices when a geometry "
"shader is used).");
"shader is used).",
"D3D12");
namespace xe {
namespace gpu {
@@ -176,7 +176,7 @@ PrimitiveType PrimitiveConverter::GetReplacementPrimitiveType(
case PrimitiveType::kLineLoop:
return PrimitiveType::kLineStrip;
case PrimitiveType::kQuadList:
if (FLAGS_d3d12_convert_quads_to_triangles) {
if (cvars::d3d12_convert_quads_to_triangles) {
return PrimitiveType::kTriangleList;
}
break;
@@ -213,7 +213,7 @@ PrimitiveConverter::ConversionResult PrimitiveConverter::ConvertPrimitives(
return ConversionResult::kConversionNotNeeded;
}
} else if (source_type == PrimitiveType::kQuadList) {
if (!FLAGS_d3d12_convert_quads_to_triangles) {
if (!cvars::d3d12_convert_quads_to_triangles) {
return ConversionResult::kConversionNotNeeded;
}
} else if (source_type != PrimitiveType::kTriangleFan &&
@@ -731,7 +731,7 @@ D3D12_GPU_VIRTUAL_ADDRESS PrimitiveConverter::GetStaticIndexBuffer(
kStaticIBTriangleFanOffset * sizeof(uint16_t);
}
if (source_type == PrimitiveType::kQuadList &&
FLAGS_d3d12_convert_quads_to_triangles) {
cvars::d3d12_convert_quads_to_triangles) {
index_count_out = (index_count >> 2) * 6;
return static_ib_gpu_address_ + kStaticIBQuadOffset * sizeof(uint16_t);
}

View File

@@ -9,13 +9,12 @@
#include "xenia/gpu/d3d12/render_target_cache.h"
#include <gflags/gflags.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -27,12 +26,14 @@
DEFINE_bool(d3d12_16bit_rtv_full_range, true,
"Use full -32...32 range for RG16 and RGBA16 render targets "
"(at the expense of blending correctness) without ROV.");
"(at the expense of blending correctness) without ROV.",
"D3D12");
DEFINE_bool(d3d12_resolution_scale_resolve_edge_clamp, true,
"When using resolution scale, apply the hack that duplicates the "
"right/lower subpixel in the left and top sides of render target "
"resolve areas to eliminate the gap caused by half-pixel offset "
"(this is necessary for certain games like GTA IV to work).");
"(this is necessary for certain games like GTA IV to work).",
"D3D12");
DECLARE_bool(d3d12_half_pixel_offset);
namespace xe {
@@ -1303,7 +1304,7 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// there on the guest side.
// http://www.students.science.uu.nl/~3220516/advancedgraphics/papers/inferred_lighting.pdf
if (command_processor_->IsROVUsedForEDRAM() ||
FLAGS_d3d12_16bit_rtv_full_range) {
cvars::d3d12_16bit_rtv_full_range) {
dest_exp_bias += 5;
}
}
@@ -1340,8 +1341,9 @@ bool RenderTargetCache::ResolveCopy(SharedMemory* shared_memory,
// sides of the screen caused by half-pixel offset becoming whole pixel offset
// with scaled rendering resolution.
bool resolution_scale_edge_clamp =
resolution_scale_2x_ && FLAGS_d3d12_resolution_scale_resolve_edge_clamp &&
FLAGS_d3d12_half_pixel_offset &&
resolution_scale_2x_ &&
cvars::d3d12_resolution_scale_resolve_edge_clamp &&
cvars::d3d12_half_pixel_offset &&
!(regs[XE_GPU_REG_PA_SU_VTX_CNTL].u32 & 0x1);
if (sample_select <= xenos::CopySampleSelect::k3 &&
src_texture_format == dest_format && dest_exp_bias == 0) {

View File

@@ -10,10 +10,9 @@
#ifndef XENIA_GPU_D3D12_RENDER_TARGET_CACHE_H_
#define XENIA_GPU_D3D12_RENDER_TARGET_CACHE_H_
#include <gflags/gflags.h>
#include <unordered_map>
#include "xenia/base/cvar.h"
#include "xenia/gpu/d3d12/d3d12_shader.h"
#include "xenia/gpu/d3d12/shared_memory.h"
#include "xenia/gpu/d3d12/texture_cache.h"

View File

@@ -9,12 +9,11 @@
#include "xenia/gpu/d3d12/shared_memory.h"
#include <gflags/gflags.h>
#include <algorithm>
#include <cstring>
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -26,7 +25,8 @@ DEFINE_bool(d3d12_tiled_shared_memory, true,
"Enable tiled resources for shared memory emulation. Disabling "
"them greatly increases video memory usage - a 512 MB buffer is "
"created - but allows graphics debuggers that don't support tiled "
"resources to work.");
"resources to work.",
"D3D12");
namespace xe {
namespace gpu {
@@ -453,7 +453,7 @@ void SharedMemory::RangeWrittenByGPU(uint32_t start, uint32_t length) {
}
bool SharedMemory::AreTiledResourcesUsed() const {
if (!FLAGS_d3d12_tiled_shared_memory) {
if (!cvars::d3d12_tiled_shared_memory) {
return false;
}
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();

View File

@@ -9,7 +9,6 @@
#include "xenia/gpu/d3d12/texture_cache.h"
#include <gflags/gflags.h>
#include "third_party/xxhash/xxhash.h"
#include <algorithm>
@@ -17,6 +16,7 @@
#include "xenia/base/assert.h"
#include "xenia/base/clock.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/profiling.h"
@@ -27,20 +27,24 @@
DEFINE_int32(d3d12_resolution_scale, 1,
"Scale of rendering width and height (currently only 1 and 2 "
"are available).");
"are available).",
"D3D12");
DEFINE_int32(d3d12_texture_cache_limit_soft, 384,
"Maximum host texture memory usage (in megabytes) above which old "
"textures will be destroyed (lifetime configured with "
"d3d12_texture_cache_limit_soft_lifetime). If using 2x resolution "
"scale, 1.25x of this is used.");
"scale, 1.25x of this is used.",
"D3D12");
DEFINE_int32(d3d12_texture_cache_limit_soft_lifetime, 30,
"Seconds a texture should be unused to be considered old enough "
"to be deleted if texture memory usage exceeds "
"d3d12_texture_cache_limit_soft.");
"d3d12_texture_cache_limit_soft.",
"D3D12");
DEFINE_int32(d3d12_texture_cache_limit_hard, 768,
"Maximum host texture memory usage (in megabytes) above which "
"textures will be destroyed as soon as possible. If using 2x "
"resolution scale, 1.25x of this is used.");
"resolution scale, 1.25x of this is used.",
"D3D12");
namespace xe {
namespace gpu {
@@ -484,7 +488,7 @@ bool TextureCache::Initialize() {
// Try to create the tiled buffer 2x resolution scaling.
// Not currently supported with the RTV/DSV output path for various reasons.
// As of November 27th, 2018, PIX doesn't support tiled buffers.
if (FLAGS_d3d12_resolution_scale >= 2 &&
if (cvars::d3d12_resolution_scale >= 2 &&
command_processor_->IsROVUsedForEDRAM() &&
provider->GetTiledResourcesTier() >= 1 &&
provider->GetGraphicsAnalysis() == nullptr &&
@@ -738,14 +742,14 @@ void TextureCache::BeginFrame() {
// If memory usage is too high, destroy unused textures.
uint64_t last_completed_frame =
command_processor_->GetD3D12Context()->GetLastCompletedFrame();
uint32_t limit_soft_mb = FLAGS_d3d12_texture_cache_limit_soft;
uint32_t limit_hard_mb = FLAGS_d3d12_texture_cache_limit_hard;
uint32_t limit_soft_mb = cvars::d3d12_texture_cache_limit_soft;
uint32_t limit_hard_mb = cvars::d3d12_texture_cache_limit_hard;
if (IsResolutionScale2X()) {
limit_soft_mb += limit_soft_mb >> 2;
limit_hard_mb += limit_hard_mb >> 2;
}
uint32_t limit_soft_lifetime =
std::max(FLAGS_d3d12_texture_cache_limit_soft_lifetime, 0) * 1000;
std::max(cvars::d3d12_texture_cache_limit_soft_lifetime, 0) * 1000;
bool destroyed_any = false;
while (texture_used_first_ != nullptr) {
uint64_t total_size_mb = textures_total_size_ >> 20;

View File

@@ -9,8 +9,6 @@
#include "xenia/gpu/dxbc_shader_translator.h"
#include <gflags/gflags.h>
#include <algorithm>
#include <cstring>
#include <memory>
@@ -19,6 +17,7 @@
#include "third_party/dxbc/d3d12TokenizedProgramFormat.hpp"
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
DEFINE_bool(dxbc_switch, true,
"Use switch rather than if for flow control. Turning this off or "
@@ -27,10 +26,12 @@ DEFINE_bool(dxbc_switch, true,
"Halo 3 appears to crash when if is used for flow control "
"(possibly the shader compiler tries to flatten them). On Intel "
"HD Graphics, this is ignored because of a crash with the switch "
"instruction.");
"instruction.",
"D3D12");
DEFINE_bool(dxbc_source_map, false,
"Disassemble Xenos instructions as comments in the resulting DXBC "
"for debugging.");
"for debugging.",
"D3D12");
namespace xe {
namespace gpu {
@@ -182,7 +183,7 @@ void DxbcShaderTranslator::Reset() {
bool DxbcShaderTranslator::UseSwitchForControlFlow() const {
// Xenia crashes on Intel HD Graphics 4000 with switch.
return FLAGS_dxbc_switch && vendor_id_ != 0x8086;
return cvars::dxbc_switch && vendor_id_ != 0x8086;
}
uint32_t DxbcShaderTranslator::PushSystemTemp(uint32_t zero_mask,
@@ -1861,7 +1862,7 @@ std::vector<uint8_t> DxbcShaderTranslator::CompleteTranslation() {
}
void DxbcShaderTranslator::EmitInstructionDisassembly() {
if (!FLAGS_dxbc_source_map) {
if (!cvars::dxbc_source_map) {
return;
}
@@ -3019,7 +3020,7 @@ void DxbcShaderTranslator::ProcessLabel(uint32_t cf_index) {
void DxbcShaderTranslator::ProcessExecInstructionBegin(
const ParsedExecInstruction& instr) {
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
// Will be emitted by UpdateExecConditionals.
@@ -3070,7 +3071,7 @@ void DxbcShaderTranslator::ProcessLoopStartInstruction(
// Loop control is outside execs - actually close the last exec.
CloseExecConditionals();
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
EmitInstructionDisassembly();
@@ -3182,7 +3183,7 @@ void DxbcShaderTranslator::ProcessLoopEndInstruction(
// Loop control is outside execs - actually close the last exec.
CloseExecConditionals();
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
EmitInstructionDisassembly();
@@ -3340,7 +3341,7 @@ void DxbcShaderTranslator::ProcessLoopEndInstruction(
void DxbcShaderTranslator::ProcessJumpInstruction(
const ParsedJumpInstruction& instr) {
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
// Will be emitted by UpdateExecConditionals.
@@ -3369,7 +3370,7 @@ void DxbcShaderTranslator::ProcessJumpInstruction(
void DxbcShaderTranslator::ProcessAllocInstruction(
const ParsedAllocInstruction& instr) {
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
EmitInstructionDisassembly();

View File

@@ -10,12 +10,11 @@
#ifndef XENIA_GPU_DXBC_SHADER_TRANSLATOR_H_
#define XENIA_GPU_DXBC_SHADER_TRANSLATOR_H_
#include <gflags/gflags.h>
#include <cstring>
#include <string>
#include <vector>
#include "xenia/base/cvar.h"
#include "xenia/base/math.h"
#include "xenia/base/string_buffer.h"
#include "xenia/gpu/shader_translator.h"

View File

@@ -2425,7 +2425,7 @@ void DxbcShaderTranslator::ProcessAluInstruction(
return;
}
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
// Will be emitted by UpdateInstructionPredication.

View File

@@ -322,7 +322,7 @@ void DxbcShaderTranslator::ProcessVertexFetchInstruction(
}
uint32_t result_write_mask = (1 << result_component_count) - 1;
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
// Will be emitted by UpdateInstructionPredication.
@@ -1162,7 +1162,7 @@ void DxbcShaderTranslator::ArrayCoordToCubeDirection(uint32_t reg) {
void DxbcShaderTranslator::ProcessTextureFetchInstruction(
const ParsedTextureFetchInstruction& instr) {
if (FLAGS_dxbc_source_map) {
if (cvars::dxbc_source_map) {
instruction_disassembly_buffer_.Reset();
instr.Disassemble(&instruction_disassembly_buffer_);
// Will be emitted later explicitly or by UpdateInstructionPredication.

View File

@@ -10,10 +10,10 @@
#include "xenia/gpu/gpu_flags.h"
DEFINE_string(trace_gpu_prefix, "scratch/gpu/",
"Prefix path for GPU trace files.");
DEFINE_bool(trace_gpu_stream, false, "Trace all GPU packets.");
"Prefix path for GPU trace files.", "GPU");
DEFINE_bool(trace_gpu_stream, false, "Trace all GPU packets.", "GPU");
DEFINE_string(dump_shaders, "",
"Path to write GPU shaders to as they are compiled.");
"Path to write GPU shaders to as they are compiled.", "GPU");
DEFINE_bool(vsync, true, "Enable VSYNC.");
DEFINE_bool(vsync, true, "Enable VSYNC.", "GPU");

View File

@@ -9,8 +9,7 @@
#ifndef XENIA_GPU_GPU_FLAGS_H_
#define XENIA_GPU_GPU_FLAGS_H_
#include <gflags/gflags.h>
#include "xenia/base/cvar.h"
DECLARE_string(trace_gpu_prefix);
DECLARE_bool(trace_gpu_stream);

View File

@@ -113,7 +113,7 @@ X_STATUS GraphicsSystem::Setup(cpu::Processor* processor,
vsync_worker_running_ = true;
vsync_worker_thread_ = kernel::object_ref<kernel::XHostThread>(
new kernel::XHostThread(kernel_state_, 128 * 1024, 0, [this]() {
uint64_t vsync_duration = FLAGS_vsync ? 16 : 1;
uint64_t vsync_duration = cvars::vsync ? 16 : 1;
uint64_t last_frame_time = Clock::QueryGuestTickCount();
while (vsync_worker_running_) {
uint64_t current_time = Clock::QueryGuestTickCount();
@@ -132,7 +132,7 @@ X_STATUS GraphicsSystem::Setup(cpu::Processor* processor,
vsync_worker_thread_->set_name("GraphicsSystem Vsync");
vsync_worker_thread_->Create();
if (FLAGS_trace_gpu_stream) {
if (cvars::trace_gpu_stream) {
BeginTracing();
}
@@ -270,11 +270,12 @@ void GraphicsSystem::ClearCaches() {
}
void GraphicsSystem::RequestFrameTrace() {
command_processor_->RequestFrameTrace(xe::to_wstring(FLAGS_trace_gpu_prefix));
command_processor_->RequestFrameTrace(
xe::to_wstring(cvars::trace_gpu_prefix));
}
void GraphicsSystem::BeginTracing() {
command_processor_->BeginTracing(xe::to_wstring(FLAGS_trace_gpu_prefix));
command_processor_->BeginTracing(xe::to_wstring(cvars::trace_gpu_prefix));
}
void GraphicsSystem::EndTracing() { command_processor_->EndTracing(); }

View File

@@ -15,7 +15,4 @@ project("xenia-gpu-null")
})
defines({
})
includedirs({
project_root.."/third_party/gflags/src",
})
local_platform_files()

View File

@@ -20,7 +20,6 @@ project("xenia-gpu")
})
includedirs({
project_root.."/third_party/spirv-tools/external/include",
project_root.."/third_party/gflags/src",
})
local_platform_files()
-- local_platform_files("spirv")
@@ -33,7 +32,6 @@ project("xenia-gpu-shader-compiler")
language("C++")
links({
"dxbc",
"gflags",
"glslang-spirv",
"spirv-tools",
"xenia-base",
@@ -42,9 +40,6 @@ project("xenia-gpu-shader-compiler")
})
defines({
})
includedirs({
project_root.."/third_party/gflags/src",
})
files({
"shader_compiler_main.cc",
"../base/main_"..platform_suffix..".cc",
@@ -56,7 +51,6 @@ project("xenia-gpu-shader-compiler")
if not os.isfile(user_file) then
debugdir(project_root)
debugargs({
"--flagfile=scratch/flags.txt",
"2>&1",
"1>scratch/stdout-shader-compiler.txt",
})

View File

@@ -7,13 +7,12 @@
******************************************************************************
*/
#include <gflags/gflags.h>
#include <cinttypes>
#include <cstring>
#include <string>
#include <vector>
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
#include "xenia/base/platform.h"
@@ -24,46 +23,51 @@
#include "xenia/gpu/spirv_shader_translator.h"
#include "xenia/ui/spirv/spirv_disassembler.h"
<<<<<<< HEAD
// For D3DDisassemble:
#if XE_PLATFORM_WIN32
#include "xenia/ui/d3d12/d3d12_api.h"
#endif // XE_PLATFORM_WIN32
DEFINE_string(shader_input, "", "Input shader binary file path.");
DEFINE_string(shader_input, "", "Input shader binary file path.", "GPU");
DEFINE_string(shader_input_type, "",
"'vs', 'ps', or unspecified to infer from the given filename.");
DEFINE_string(shader_output, "", "Output shader file path.");
"'vs', 'ps', or unspecified to infer from the given filename.",
"GPU");
DEFINE_string(shader_output, "", "Output shader file path.", "GPU");
DEFINE_string(shader_output_type, "ucode",
"Translator to use: [ucode, glsl45, spirv, spirvtext, dxbc].");
"Translator to use: [ucode, glsl45, spirv, spirvtext, dxbc].",
"GPU");
DEFINE_string(shader_output_patch, "",
"Tessellation patch type in the generated tessellation "
"evaluation (domain) shader, or unspecified to produce a vertex "
"shader: [line, triangle, quad].");
"shader: [line, triangle, quad].",
"GPU");
DEFINE_bool(shader_output_dxbc_rov, false,
"Output ROV-based output-merger code in DXBC pixel shaders.");
"Output ROV-based output-merger code in DXBC pixel shaders.",
"GPU");
namespace xe {
namespace gpu {
int shader_compiler_main(const std::vector<std::wstring>& args) {
ShaderType shader_type;
if (!FLAGS_shader_input_type.empty()) {
if (FLAGS_shader_input_type == "vs") {
if (!cvars::shader_input_type.empty()) {
if (cvars::shader_input_type == "vs") {
shader_type = ShaderType::kVertex;
} else if (FLAGS_shader_input_type == "ps") {
} else if (cvars::shader_input_type == "ps") {
shader_type = ShaderType::kPixel;
} else {
XELOGE("Invalid --shader_input_type; must be 'vs' or 'ps'.");
return 1;
}
} else {
auto last_dot = FLAGS_shader_input.find_last_of('.');
auto last_dot = cvars::shader_input.find_last_of('.');
bool valid_type = false;
if (last_dot != std::string::npos) {
if (FLAGS_shader_input.substr(last_dot) == ".vs") {
if (cvars::shader_input.substr(last_dot) == ".vs") {
shader_type = ShaderType::kVertex;
valid_type = true;
} else if (FLAGS_shader_input.substr(last_dot) == ".ps") {
} else if (cvars::shader_input.substr(last_dot) == ".ps") {
shader_type = ShaderType::kPixel;
valid_type = true;
}
@@ -76,9 +80,9 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
}
auto input_file = fopen(FLAGS_shader_input.c_str(), "rb");
auto input_file = fopen(cvars::shader_input.c_str(), "rb");
if (!input_file) {
XELOGE("Unable to open input file: %s", FLAGS_shader_input.c_str());
XELOGE("Unable to open input file: %s", cvars::shader_input.c_str());
return 1;
}
fseek(input_file, 0, SEEK_END);
@@ -89,7 +93,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
fclose(input_file);
XELOGI("Opened %s as a %s shader, %" PRId64 " words (%" PRId64 " bytes).",
FLAGS_shader_input.c_str(),
cvars::shader_input.c_str(),
shader_type == ShaderType::kVertex ? "vertex" : "pixel",
ucode_dwords.size(), ucode_dwords.size() * 4);
@@ -99,26 +103,26 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
shader_type, ucode_data_hash, ucode_dwords.data(), ucode_dwords.size());
std::unique_ptr<ShaderTranslator> translator;
if (FLAGS_shader_output_type == "spirv" ||
FLAGS_shader_output_type == "spirvtext") {
if (cvars::shader_output_type == "spirv" ||
cvars::shader_output_type == "spirvtext") {
translator = std::make_unique<SpirvShaderTranslator>();
} else if (FLAGS_shader_output_type == "glsl45") {
} else if (cvars::shader_output_type == "glsl45") {
translator = std::make_unique<GlslShaderTranslator>(
GlslShaderTranslator::Dialect::kGL45);
} else if (FLAGS_shader_output_type == "dxbc") {
translator =
std::make_unique<DxbcShaderTranslator>(0, FLAGS_shader_output_dxbc_rov);
} else if (cvars::shader_output_type == "dxbc") {
translator = std::make_unique<DxbcShaderTranslator>(
0, cvars::shader_output_dxbc_rov);
} else {
translator = std::make_unique<UcodeShaderTranslator>();
}
PrimitiveType patch_primitive_type = PrimitiveType::kNone;
if (shader_type == ShaderType::kVertex) {
if (FLAGS_shader_output_patch == "line") {
if (cvars::shader_output_patch == "line") {
patch_primitive_type = PrimitiveType::kLinePatch;
} else if (FLAGS_shader_output_patch == "triangle") {
} else if (cvars::shader_output_patch == "triangle") {
patch_primitive_type = PrimitiveType::kTrianglePatch;
} else if (FLAGS_shader_output_patch == "quad") {
} else if (cvars::shader_output_patch == "quad") {
patch_primitive_type = PrimitiveType::kQuadPatch;
}
}
@@ -129,7 +133,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
size_t source_data_size = shader->translated_binary().size();
std::unique_ptr<xe::ui::spirv::SpirvDisassembler::Result> spirv_disasm_result;
if (FLAGS_shader_output_type == "spirvtext") {
if (cvars::shader_output_type == "spirvtext") {
// Disassemble SPIRV.
spirv_disasm_result = xe::ui::spirv::SpirvDisassembler().Disassemble(
reinterpret_cast<const uint32_t*>(source_data), source_data_size / 4);
@@ -138,7 +142,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
#if XE_PLATFORM_WIN32
ID3DBlob* dxbc_disasm_blob = nullptr;
if (FLAGS_shader_output_type == "dxbc") {
if (cvars::shader_output_type == "dxbc") {
HMODULE d3d_compiler = LoadLibrary(L"D3DCompiler_47.dll");
if (d3d_compiler != nullptr) {
pD3DDisassemble d3d_disassemble =
@@ -158,8 +162,8 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
#endif // XE_PLATFORM_WIN32
if (!FLAGS_shader_output.empty()) {
auto output_file = fopen(FLAGS_shader_output.c_str(), "wb");
if (!cvars::shader_output.empty()) {
auto output_file = fopen(cvars::shader_output.c_str(), "wb");
fwrite(source_data, 1, source_data_size, output_file);
fclose(output_file);
}

View File

@@ -9,19 +9,20 @@
#include "xenia/gpu/spirv_shader_translator.h"
#include <gflags/gflags.h>
#include <algorithm>
#include <cfloat>
#include <cstddef>
#include <cstring>
#include <vector>
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
DEFINE_bool(spv_validate, false, "Validate SPIR-V shaders after generation");
DEFINE_bool(spv_disasm, false, "Disassemble SPIR-V shaders after generation");
DEFINE_bool(spv_validate, false, "Validate SPIR-V shaders after generation",
"GPU");
DEFINE_bool(spv_disasm, false, "Disassemble SPIR-V shaders after generation",
"GPU");
namespace xe {
namespace gpu {
@@ -666,7 +667,7 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
void SpirvShaderTranslator::PostTranslation(Shader* shader) {
// Validation.
if (FLAGS_spv_validate) {
if (cvars::spv_validate) {
auto validation = validator_.Validate(
reinterpret_cast<const uint32_t*>(shader->translated_binary().data()),
shader->translated_binary().size() / sizeof(uint32_t));
@@ -676,7 +677,7 @@ void SpirvShaderTranslator::PostTranslation(Shader* shader) {
}
}
if (FLAGS_spv_disasm) {
if (cvars::spv_disasm) {
// TODO(benvanik): only if needed? could be slowish.
auto disasm = disassembler_.Disassemble(
reinterpret_cast<const uint32_t*>(shader->translated_binary().data()),

View File

@@ -7,13 +7,12 @@
******************************************************************************
*/
#include <gflags/gflags.h>
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/gpu/texture_info.h"
DEFINE_bool(texture_dump, false, "Dump textures to DDS");
DEFINE_bool(texture_dump, false, "Dump textures to DDS", "GPU");
namespace xe {
namespace gpu {

View File

@@ -9,8 +9,6 @@
#include "xenia/gpu/trace_dump.h"
#include <gflags/gflags.h>
#include "third_party/stb/stb_image_write.h"
#include "xenia/base/logging.h"
#include "xenia/base/profiling.h"
@@ -28,8 +26,9 @@
#undef _CRT_NONSTDC_NO_DEPRECATE
#include "third_party/stb/stb_image_write.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.");
DEFINE_string(trace_dump_path, "", "Output path for dumped files.");
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
"GPU");
DEFINE_string(trace_dump_path, "", "Output path for dumped files.", "GPU");
namespace xe {
namespace gpu {
@@ -44,11 +43,11 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
std::wstring output_path;
if (!FLAGS_target_trace_file.empty()) {
if (!cvars::target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(FLAGS_target_trace_file);
path = xe::to_wstring(cvars::target_trace_file);
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];
@@ -79,7 +78,7 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
// Root file name for outputs.
if (output_path.empty()) {
base_output_path_ =
xe::fix_path_separators(xe::to_wstring(FLAGS_trace_dump_path));
xe::fix_path_separators(xe::to_wstring(cvars::trace_dump_path));
std::wstring output_name =
xe::find_name_from_path(xe::fix_path_separators(path));

View File

@@ -9,8 +9,6 @@
#include "xenia/gpu/trace_viewer.h"
#include <gflags/gflags.h>
#include <cinttypes>
#include "third_party/half/include/half.hpp"
@@ -32,7 +30,8 @@
#include "xenia/ui/window.h"
#include "xenia/xbox.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.");
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
"GPU");
namespace xe {
namespace gpu {
@@ -53,11 +52,11 @@ TraceViewer::~TraceViewer() = default;
int TraceViewer::Main(const std::vector<std::wstring>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
if (!FLAGS_target_trace_file.empty()) {
if (!cvars::target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(FLAGS_target_trace_file);
path = xe::to_wstring(cvars::target_trace_file);
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];

View File

@@ -347,7 +347,7 @@ VkPipeline PipelineCache::GetPipeline(const RenderState* render_state,
}
// Dump shader disassembly.
if (FLAGS_vulkan_dump_disasm) {
if (cvars::vulkan_dump_disasm) {
if (device_->HasEnabledExtension(VK_AMD_SHADER_INFO_EXTENSION_NAME)) {
DumpShaderDisasmAMD(pipeline);
} else if (device_->device_info().properties.vendorID == 0x10DE) {
@@ -387,8 +387,8 @@ bool PipelineCache::TranslateShader(VulkanShader* shader,
}
// Dump shader files if desired.
if (!FLAGS_dump_shaders.empty()) {
shader->Dump(FLAGS_dump_shaders, "vk");
if (!cvars::dump_shaders.empty()) {
shader->Dump(cvars::dump_shaders, "vk");
}
return shader->is_valid();
@@ -1396,7 +1396,7 @@ PipelineCache::UpdateStatus PipelineCache::UpdateMultisampleState() {
// PA_SU_SC_MODE_CNTL MSAA_ENABLE (0x10000)
// If set, all samples will be sampled at set locations. Otherwise, they're
// all sampled from the pixel center.
if (FLAGS_vulkan_native_msaa) {
if (cvars::vulkan_native_msaa) {
auto msaa_num_samples =
static_cast<MsaaSamples>((regs.rb_surface_info >> 16) & 0x3);
switch (msaa_num_samples) {

View File

@@ -17,9 +17,6 @@ project("xenia-gpu-vulkan")
})
defines({
})
includedirs({
project_root.."/third_party/gflags/src",
})
local_platform_files()
files({
"shaders/bin/*.h",
@@ -34,7 +31,6 @@ project("xenia-gpu-vulkan-trace-viewer")
links({
"aes_128",
"capstone",
"gflags",
"glslang-spirv",
"imgui",
"libavcodec",
@@ -62,9 +58,6 @@ project("xenia-gpu-vulkan-trace-viewer")
})
defines({
})
includedirs({
project_root.."/third_party/gflags/src",
})
files({
"vulkan_trace_viewer_main.cc",
"../../base/main_"..platform_suffix..".cc",
@@ -91,7 +84,6 @@ project("xenia-gpu-vulkan-trace-viewer")
if not os.isfile(user_file) then
debugdir(project_root)
debugargs({
"--flagfile=scratch/flags.txt",
"2>&1",
"1>scratch/stdout-trace-viewer.txt",
})
@@ -105,7 +97,6 @@ project("xenia-gpu-vulkan-trace-dump")
links({
"aes_128",
"capstone",
"gflags",
"glslang-spirv",
"imgui",
"libavcodec",
@@ -133,9 +124,6 @@ project("xenia-gpu-vulkan-trace-dump")
})
defines({
})
includedirs({
project_root.."/third_party/gflags/src",
})
files({
"vulkan_trace_dump_main.cc",
"../../base/main_"..platform_suffix..".cc",
@@ -156,7 +144,6 @@ project("xenia-gpu-vulkan-trace-dump")
if not os.isfile(user_file) then
debugdir(project_root)
debugargs({
"--flagfile=scratch/flags.txt",
"2>&1",
"1>scratch/stdout-trace-dump.txt",
})

View File

@@ -194,7 +194,7 @@ VkResult CachedTileView::Initialize(VkCommandBuffer command_buffer) {
image_info.extent.depth = 1;
image_info.mipLevels = 1;
image_info.arrayLayers = 1;
if (FLAGS_vulkan_native_msaa) {
if (cvars::vulkan_native_msaa) {
auto msaa_samples = static_cast<MsaaSamples>(key.msaa_samples);
switch (msaa_samples) {
case MsaaSamples::k1X:
@@ -422,7 +422,7 @@ CachedRenderPass::~CachedRenderPass() {
VkResult CachedRenderPass::Initialize() {
VkSampleCountFlagBits sample_count;
if (FLAGS_vulkan_native_msaa) {
if (cvars::vulkan_native_msaa) {
switch (config.surface_msaa) {
case MsaaSamples::k1X:
sample_count = VK_SAMPLE_COUNT_1_BIT;
@@ -534,7 +534,7 @@ VkResult CachedRenderPass::Initialize() {
bool CachedRenderPass::IsCompatible(
const RenderConfiguration& desired_config) const {
if (config.surface_msaa != desired_config.surface_msaa &&
FLAGS_vulkan_native_msaa) {
cvars::vulkan_native_msaa) {
return false;
}

View File

@@ -1040,7 +1040,7 @@ bool TextureCache::UploadTexture(VkCommandBuffer command_buffer,
unpack_offset += ComputeMipStorage(src, mip);
}
if (FLAGS_texture_dump) {
if (cvars::texture_dump) {
TextureDump(src, unpack_buffer, unpack_length);
}

View File

@@ -356,7 +356,7 @@ void VulkanCommandProcessor::BeginFrame() {
// The capture will end when these commands are submitted to the queue.
static uint32_t frame = 0;
if (device_->is_renderdoc_attached() && !capturing_ &&
(FLAGS_vulkan_renderdoc_capture_all || trace_requested_)) {
(cvars::vulkan_renderdoc_capture_all || trace_requested_)) {
if (queue_mutex_) {
queue_mutex_->lock();
}

View File

@@ -10,7 +10,7 @@
#include "xenia/gpu/vulkan/vulkan_gpu_flags.h"
DEFINE_bool(vulkan_renderdoc_capture_all, false,
"Capture everything with RenderDoc.");
DEFINE_bool(vulkan_native_msaa, false, "Use native MSAA");
"Capture everything with RenderDoc.", "Vulkan");
DEFINE_bool(vulkan_native_msaa, false, "Use native MSAA", "Vulkan");
DEFINE_bool(vulkan_dump_disasm, false,
"Dump shader disassembly. NVIDIA only supported.");
"Dump shader disassembly. NVIDIA only supported.", "Vulkan");

View File

@@ -10,9 +10,8 @@
#ifndef XENIA_GPU_VULKAN_VULKAN_GPU_FLAGS_H_
#define XENIA_GPU_VULKAN_VULKAN_GPU_FLAGS_H_
#include <gflags/gflags.h>
#define FINE_GRAINED_DRAW_SCOPES 1
#include "xenia/base/cvar.h"
DECLARE_bool(vulkan_renderdoc_capture_all);
DECLARE_bool(vulkan_native_msaa);