use Sleep(0) instead of SwitchToThread, should waste less power and help the os with scheduling.

PM4 buffer handling made a virtual member of commandprocessor, place the implementation/declaration into reusable macro files. this is probably the biggest boost here.
Optimized SET_CONSTANT/ LOAD_CONSTANT pm4 ops based on the register range they start writing at, this was also a nice boost

Expose X64 extension flags to code outside of x64 backend, so we can detect and use things like avx512, xop, avx2, etc in normal code
Add freelists for HIR structures to try to reduce the number of last level cache misses during optimization (currently disabled... fixme later)

Analyzed PGO feedback and reordered branches, uninlined functions, moved code out into different functions based on info from it in the PM4 functions, this gave like a 2% boost at best.

Added support for the db16cyc opcode, which is used often in xb360 spinlocks. before it was just being translated to nop, now on x64 we translate it to _mm_pause but may change that in the future to reduce cpu time wasted

texture util - all our divisors were powers of 2, instead we look up a shift. this made texture scaling slightly faster, more so on intel processors which seem to be worse at int divs. GetGuestTextureLayout is now a little faster, although it is still one of the heaviest functions in the emulator when scaling is on.

xe_unlikely_mutex was not a good choice for the guest clock lock, (running theory) on intel processors another thread may take a significant time to update the clock? maybe because of the uint64 division? really not sure, but switched it to xe_mutex. This fixed audio stutter that i had introduced to 1 or 2 games, fixed performance on that n64 rare game with the monkeys.
Took another crack at DMA implementation, another failure.
Instead of passing as a parameter, keep the ringbuffer reader as the first member of commandprocessor so it can be accessed through this
Added macro for noalias
Applied noalias to Memory::LookupHeap. This reduced the size of the executable by 7 kb.
Reworked kernel shim template, this shaved like 100kb off the exe and eliminated the indirect calls from the shim to the actual implementation. We still unconditionally generate string representations of kernel calls though :(, unless it is kHighFrequency

Add nvapi extensions support, currently unused. Will use CPUVISIBLE memory at some point
Inserted prefetches in a few places based on feedback from vtune.
Add native implementation of SHA int8 if all elements are the same

Vectorized comparisons for SetViewport, SetScissorRect
Vectorized ranged comparisons for WriteRegister
Add XE_MSVC_ASSUME
Move FormatInfo::name out of the structure, instead look up the name in a different table. Debug related data and critical runtime data are best kept apart
Templated UpdateSystemConstantValues based on ROV/RTV and primitive_polygonal
Add ArchFloatMask functions, these are for storing the results of floating point comparisons without doing costly float->int pipeline transfers (vucomiss/setb)
Use floatmasks in UpdateSystemConstantValues for checking if dirty, only transfer to int at end of function.
Instead of dirty |= (x == y) in UpdateSystemConstantValues, now we do dirty_u32 |= (x^y). if any of them are not equal, dirty_u32 will be nz, else if theyre all equal it will be zero. This is more friendly to register renaming and the lack of dependencies on EFLAGS lets the compiler reorder better
Add PrefetchSamplerParameters to D3D12TextureCache
use PrefetchSamplerParameters in UpdateBindings to eliminate cache misses that vtune detected

Add PrefetchTextureBinding to D3D12TextureCache
Prefetch texture bindings to get rid of more misses vtune detected (more accesses out of order with random strides)
Rewrote DMAC, still terrible though and have disabled it for now.
Replace tiny memcmp of 6 U64 in render_target_cache with inline loop, msvc fails to make it a loop and instead does a thunk to their memcmp function, which is optimized for larger sizes

PrefetchTextureBinding in AreActiveTextureSRVKeysUpToDate
Replace memcmp calls for pipelinedescription with handwritten cmp
Directly write some registers that dont have special handling in PM4 functions
Changed EstimateMaxY to try to eliminate mispredictions that vtune was reporting, msvc ended up turning the changed code into a series of blends

in ExecutePacketType3_EVENT_WRITE_EXT, instead of writing extents to an array on the stack and then doing xe_copy_and_swap_16 of the data to its dest, pre-swap each constant and then store those. msvc manages to unroll that into wider stores
stop logging XE_SWAP every time we receive XE_SWAP, stop logging the start and end of each viz query

Prefetch watch nodes in FireWatches based on feedback from vtune
Removed dead code from texture_info.cc
NOINLINE on GpuSwap, PGO builds did it so we should too.
This commit is contained in:
chss95cs@gmail.com
2022-09-11 14:14:48 -07:00
parent 9a6dd4cd6f
commit 20638c2e61
67 changed files with 3369 additions and 2184 deletions

View File

@@ -17,7 +17,7 @@
#include "xenia/base/math.h"
#include "xenia/ui/d3d12/d3d12_immediate_drawer.h"
#include "xenia/ui/d3d12/d3d12_presenter.h"
#include "xenia/ui/d3d12/d3d12_util.h"
DEFINE_bool(d3d12_debug, false, "Enable Direct3D 12 and DXGI debug layer.",
"D3D12");
DEFINE_bool(d3d12_break_on_error, false,
@@ -35,6 +35,8 @@ DEFINE_int32(
"system responsibility)",
"D3D12");
DEFINE_bool(d3d12_nvapi_use_driver_heap_priorities, false, "nvidia stuff",
"D3D12");
namespace xe {
namespace ui {
namespace d3d12 {
@@ -61,6 +63,7 @@ std::unique_ptr<D3D12Provider> D3D12Provider::Create() {
"supported GPUs.");
return nullptr;
}
return provider;
}
@@ -476,10 +479,69 @@ bool D3D12Provider::Initialize() {
// Get the graphics analysis interface, will silently fail if PIX is not
// attached.
pfn_dxgi_get_debug_interface1_(0, IID_PPV_ARGS(&graphics_analysis_));
if (GetAdapterVendorID() == ui::GraphicsProvider::GpuVendorID::kNvidia) {
nvapi_ = new lightweight_nvapi::nvapi_state_t();
if (!nvapi_->is_available()) {
delete nvapi_;
nvapi_ = nullptr;
} else {
using namespace lightweight_nvapi;
nvapi_createcommittedresource_ =
(cb_NvAPI_D3D12_CreateCommittedResource)nvapi_->query_interface<void>(
id_NvAPI_D3D12_CreateCommittedResource);
nvapi_querycpuvisiblevidmem_ =
(cb_NvAPI_D3D12_QueryCpuVisibleVidmem)nvapi_->query_interface<void>(
id_NvAPI_D3D12_QueryCpuVisibleVidmem);
nvapi_usedriverheappriorities_ =
(cb_NvAPI_D3D12_UseDriverHeapPriorities)nvapi_->query_interface<void>(
id_NvAPI_D3D12_UseDriverHeapPriorities);
if (nvapi_usedriverheappriorities_) {
if (cvars::d3d12_nvapi_use_driver_heap_priorities) {
if (nvapi_usedriverheappriorities_(device_) != 0) {
XELOGI("Failed to enable driver heap priorities");
}
}
}
}
}
return true;
}
uint32_t D3D12Provider::CreateUploadResource(
D3D12_HEAP_FLAGS HeapFlags, _In_ const D3D12_RESOURCE_DESC* pDesc,
D3D12_RESOURCE_STATES InitialResourceState, REFIID riidResource,
void** ppvResource, bool try_create_cpuvisible,
const D3D12_CLEAR_VALUE* pOptimizedClearValue) const {
auto device = GetDevice();
if (try_create_cpuvisible && nvapi_createcommittedresource_) {
lightweight_nvapi::NV_RESOURCE_PARAMS nvrp;
nvrp.NVResourceFlags =
lightweight_nvapi::NV_D3D12_RESOURCE_FLAG_CPUVISIBLE_VIDMEM;
nvrp.version = 0; // nothing checks the version
if (nvapi_createcommittedresource_(
device, &ui::d3d12::util::kHeapPropertiesUpload, HeapFlags, pDesc,
InitialResourceState, pOptimizedClearValue, &nvrp, riidResource,
ppvResource, nullptr) != 0) {
XELOGI(
"Failed to create CPUVISIBLE_VIDMEM upload resource, will just do "
"normal CreateCommittedResource");
} else {
return UPLOAD_RESULT_CREATE_CPUVISIBLE;
}
}
if (FAILED(device->CreateCommittedResource(
&ui::d3d12::util::kHeapPropertiesUpload, HeapFlags, pDesc,
InitialResourceState, pOptimizedClearValue, riidResource,
ppvResource))) {
XELOGE("Failed to create the gamma ramp upload buffer");
return UPLOAD_RESULT_CREATE_FAILED;
}
return UPLOAD_RESULT_CREATE_SUCCESS;
}
std::unique_ptr<Presenter> D3D12Provider::CreatePresenter(
Presenter::HostGpuLossCallback host_gpu_loss_callback) {
return D3D12Presenter::Create(host_gpu_loss_callback, *this);

View File

@@ -12,15 +12,19 @@
#include <memory>
#include "xenia/gpu/d3d12/d3d12_nvapi.hpp"
#include "xenia/ui/d3d12/d3d12_api.h"
#include "xenia/ui/graphics_provider.h"
#define XE_UI_D3D12_FINE_GRAINED_DRAW_SCOPES 1
namespace xe {
namespace ui {
namespace d3d12 {
enum {
UPLOAD_RESULT_CREATE_FAILED = 0,
UPLOAD_RESULT_CREATE_SUCCESS = 1,
UPLOAD_RESULT_CREATE_CPUVISIBLE = 2
};
class D3D12Provider : public GraphicsProvider {
public:
~D3D12Provider();
@@ -34,6 +38,11 @@ class D3D12Provider : public GraphicsProvider {
Presenter::FatalErrorHostGpuLossCallback) override;
std::unique_ptr<ImmediateDrawer> CreateImmediateDrawer() override;
uint32_t CreateUploadResource(
D3D12_HEAP_FLAGS HeapFlags, _In_ const D3D12_RESOURCE_DESC* pDesc,
D3D12_RESOURCE_STATES InitialResourceState, REFIID riidResource,
void** ppvResource, bool try_create_cpuvisible = false,
const D3D12_CLEAR_VALUE* pOptimizedClearValue = nullptr) const;
IDXGIFactory2* GetDXGIFactory() const { return dxgi_factory_; }
// nullptr if PIX not attached.
@@ -193,6 +202,14 @@ class D3D12Provider : public GraphicsProvider {
bool ps_specified_stencil_reference_supported_;
bool rasterizer_ordered_views_supported_;
bool unaligned_block_textures_supported_;
lightweight_nvapi::nvapi_state_t* nvapi_;
lightweight_nvapi::cb_NvAPI_D3D12_CreateCommittedResource
nvapi_createcommittedresource_ = nullptr;
lightweight_nvapi::cb_NvAPI_D3D12_UseDriverHeapPriorities
nvapi_usedriverheappriorities_ = nullptr;
lightweight_nvapi::cb_NvAPI_D3D12_QueryCpuVisibleVidmem
nvapi_querycpuvisiblevidmem_ = nullptr;
};
} // namespace d3d12

View File

@@ -81,10 +81,10 @@ D3D12UploadBufferPool::CreatePageImplementation() {
util::FillBufferResourceDesc(buffer_desc, page_size_,
D3D12_RESOURCE_FLAG_NONE);
Microsoft::WRL::ComPtr<ID3D12Resource> buffer;
if (FAILED(provider_.GetDevice()->CreateCommittedResource(
&util::kHeapPropertiesUpload, provider_.GetHeapFlagCreateNotZeroed(),
&buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS(&buffer)))) {
if (!provider_.CreateUploadResource(
provider_.GetHeapFlagCreateNotZeroed(), &buffer_desc,
D3D12_RESOURCE_STATE_GENERIC_READ, IID_PPV_ARGS(&buffer))) {
XELOGE("Failed to create a D3D upload buffer with {} bytes", page_size_);
return nullptr;
}