Skip to content

Commit

Permalink
Merge branch 'd3d12' into Goedzo-2018-Dec
Browse files Browse the repository at this point in the history
  • Loading branch information
goedzo committed Dec 7, 2018
2 parents 4f95b96 + 9427667 commit 61bb8bd
Show file tree
Hide file tree
Showing 177 changed files with 16,631 additions and 4,895 deletions.
14 changes: 8 additions & 6 deletions src/xenia/cpu/mmio_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ void* MMIOHandler::RegisterPhysicalWriteWatch(

void MMIOHandler::UnregisterPhysicalWriteWatch(void* watch_handle) {
auto entry = reinterpret_cast<PhysicalWriteWatchEntry*>(watch_handle);
auto lock = global_critical_region_.Acquire();

auto it = std::find(physical_write_watches_.begin(),
physical_write_watches_.end(), entry);
assert_false(it == physical_write_watches_.end());
if (it != physical_write_watches_.end()) {
physical_write_watches_.erase(it);
{
auto lock = global_critical_region_.Acquire();
auto it = std::find(physical_write_watches_.begin(),
physical_write_watches_.end(), entry);
assert_false(it == physical_write_watches_.end());
if (it != physical_write_watches_.end()) {
physical_write_watches_.erase(it);
}
}

delete entry;
Expand Down
79 changes: 57 additions & 22 deletions src/xenia/gpu/d3d12/d3d12_command_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,19 @@ void D3D12CommandProcessor::SetExternalGraphicsPipeline(
}
}

std::wstring D3D12CommandProcessor::GetWindowTitleText() const {
if (IsROVUsedForEDRAM()) {
// Currently scaling is only supported with ROV.
if (texture_cache_ != nullptr && texture_cache_->IsResolutionScale2X()) {
return L"Direct3D 12 - ROV 2x";
} else {
return L"Direct3D 12 - ROV";
}
} else {
return L"Direct3D 12 - RT";
}
}

bool D3D12CommandProcessor::SetupContext() {
if (!CommandProcessor::SetupContext()) {
XELOGE("Failed to initialize base command processor context");
Expand Down Expand Up @@ -671,7 +684,7 @@ bool D3D12CommandProcessor::SetupContext() {

render_target_cache_ =
std::make_unique<RenderTargetCache>(this, register_file_);
if (!render_target_cache_->Initialize()) {
if (!render_target_cache_->Initialize(texture_cache_.get())) {
XELOGE("Failed to initialize the render target cache");
return false;
}
Expand Down Expand Up @@ -740,6 +753,10 @@ bool D3D12CommandProcessor::SetupContext() {
swap_texture_desc.Alignment = 0;
swap_texture_desc.Width = kSwapTextureWidth;
swap_texture_desc.Height = kSwapTextureHeight;
if (texture_cache_->IsResolutionScale2X()) {
swap_texture_desc.Width *= 2;
swap_texture_desc.Height *= 2;
}
swap_texture_desc.DepthOrArraySize = 1;
swap_texture_desc.MipLevels = 1;
swap_texture_desc.Format = ui::d3d12::D3D12Context::kSwapChainFormat;
Expand Down Expand Up @@ -1010,21 +1027,28 @@ void D3D12CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
gamma_ramp_texture_state_ = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
SubmitBarriers();

uint32_t swap_texture_width = kSwapTextureWidth;
uint32_t swap_texture_height = kSwapTextureHeight;
if (texture_cache_->IsResolutionScale2X()) {
swap_texture_width *= 2;
swap_texture_height *= 2;
}

// Draw the stretching rectangle.
command_list->OMSetRenderTargets(1, &swap_texture_rtv_, TRUE, nullptr);
D3D12_VIEWPORT viewport;
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
viewport.Width = float(kSwapTextureWidth);
viewport.Height = float(kSwapTextureHeight);
viewport.Width = float(swap_texture_width);
viewport.Height = float(swap_texture_height);
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 0.0f;
command_list->RSSetViewports(1, &viewport);
D3D12_RECT scissor;
scissor.left = 0;
scissor.top = 0;
scissor.right = kSwapTextureWidth;
scissor.bottom = kSwapTextureHeight;
scissor.right = swap_texture_width;
scissor.bottom = swap_texture_height;
command_list->RSSetScissorRects(1, &scissor);
D3D12GraphicsSystem* graphics_system =
static_cast<D3D12GraphicsSystem*>(graphics_system_);
Expand All @@ -1041,8 +1065,8 @@ void D3D12CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
// Don't care about graphics state because the frame is ending anyway.
{
std::lock_guard<std::mutex> lock(swap_state_.mutex);
swap_state_.width = kSwapTextureWidth;
swap_state_.height = kSwapTextureHeight;
swap_state_.width = swap_texture_width;
swap_state_.height = swap_texture_height;
swap_state_.front_buffer_texture =
reinterpret_cast<uintptr_t>(swap_texture_srv_descriptor_heap_);
}
Expand Down Expand Up @@ -1484,16 +1508,21 @@ void D3D12CommandProcessor::UpdateFixedFunctionState(
}

// Supersampling replacing multisampling due to difficulties of emulating
// EDRAM with multisampling with RTV/DSV (with ROV, there's MSAA).
uint32_t ssaa_scale_x, ssaa_scale_y;
// EDRAM with multisampling with RTV/DSV (with ROV, there's MSAA), and also
// resolution scale.
uint32_t pixel_size_x, pixel_size_y;
if (IsROVUsedForEDRAM()) {
ssaa_scale_x = 1;
ssaa_scale_y = 1;
pixel_size_x = 1;
pixel_size_y = 1;
} else {
MsaaSamples msaa_samples =
MsaaSamples((regs[XE_GPU_REG_RB_SURFACE_INFO].u32 >> 16) & 0x3);
ssaa_scale_x = msaa_samples >= MsaaSamples::k4X ? 2 : 1;
ssaa_scale_y = msaa_samples >= MsaaSamples::k2X ? 2 : 1;
pixel_size_x = msaa_samples >= MsaaSamples::k4X ? 2 : 1;
pixel_size_y = msaa_samples >= MsaaSamples::k2X ? 2 : 1;
}
if (texture_cache_->IsResolutionScale2X()) {
pixel_size_x *= 2;
pixel_size_y *= 2;
}

// Viewport.
Expand Down Expand Up @@ -1534,11 +1563,11 @@ void D3D12CommandProcessor::UpdateFixedFunctionState(
}
D3D12_VIEWPORT viewport;
viewport.TopLeftX =
(viewport_offset_x - viewport_scale_x) * float(ssaa_scale_x);
(viewport_offset_x - viewport_scale_x) * float(pixel_size_x);
viewport.TopLeftY =
(viewport_offset_y - viewport_scale_y) * float(ssaa_scale_y);
viewport.Width = viewport_scale_x * 2.0f * float(ssaa_scale_x);
viewport.Height = viewport_scale_y * 2.0f * float(ssaa_scale_y);
(viewport_offset_y - viewport_scale_y) * float(pixel_size_y);
viewport.Width = viewport_scale_x * 2.0f * float(pixel_size_x);
viewport.Height = viewport_scale_y * 2.0f * float(pixel_size_y);
viewport.MinDepth = viewport_offset_z;
viewport.MaxDepth = viewport_offset_z + viewport_scale_z;
if (viewport_scale_z < 0.0f) {
Expand Down Expand Up @@ -1575,10 +1604,10 @@ void D3D12CommandProcessor::UpdateFixedFunctionState(
scissor.right = std::max(scissor.right + window_offset_x, LONG(0));
scissor.bottom = std::max(scissor.bottom + window_offset_y, LONG(0));
}
scissor.left *= ssaa_scale_x;
scissor.top *= ssaa_scale_y;
scissor.right *= ssaa_scale_x;
scissor.bottom *= ssaa_scale_y;
scissor.left *= pixel_size_x;
scissor.top *= pixel_size_y;
scissor.right *= pixel_size_x;
scissor.bottom *= pixel_size_y;
ff_scissor_update_needed_ |= ff_scissor_.left != scissor.left;
ff_scissor_update_needed_ |= ff_scissor_.top != scissor.top;
ff_scissor_update_needed_ |= ff_scissor_.right != scissor.right;
Expand Down Expand Up @@ -2041,8 +2070,14 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(
}
}

// Depth/stencil testing and blend constant for ROV blending.
// Resolution scale, depth/stencil testing and blend constant for ROV.
if (IsROVUsedForEDRAM()) {
uint32_t resolution_scale_log2 =
texture_cache_->IsResolutionScale2X() ? 1 : 0;
dirty |=
system_constants_.edram_resolution_scale_log2 != resolution_scale_log2;
system_constants_.edram_resolution_scale_log2 = resolution_scale_log2;

uint32_t depth_base_dwords = (rb_depth_info & 0xFFF) * 1280;
dirty |= system_constants_.edram_depth_base_dwords != depth_base_dwords;
system_constants_.edram_depth_base_dwords = depth_base_dwords;
Expand Down
4 changes: 4 additions & 0 deletions src/xenia/gpu/d3d12/d3d12_command_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <atomic>
#include <deque>
#include <memory>
#include <string>
#include <unordered_map>

#include "xenia/gpu/command_processor.h"
Expand Down Expand Up @@ -128,6 +129,9 @@ class D3D12CommandProcessor : public CommandProcessor {
bool reset_blend_factor = false,
bool reset_stencil_ref = false);

// Returns the text to display in the GPU backend name in the window title.
std::wstring GetWindowTitleText() const;

protected:
bool SetupContext() override;
void ShutdownContext() override;
Expand Down
3 changes: 1 addition & 2 deletions src/xenia/gpu/d3d12/d3d12_graphics_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ std::wstring D3D12GraphicsSystem::name() const {
auto d3d12_command_processor =
static_cast<D3D12CommandProcessor*>(command_processor());
if (d3d12_command_processor != nullptr) {
return d3d12_command_processor->IsROVUsedForEDRAM() ? L"Direct3D 12 - ROV"
: L"Direct3D 12 - RT";
return d3d12_command_processor->GetWindowTitleText();
}
return L"Direct3D 12";
}
Expand Down
5 changes: 4 additions & 1 deletion src/xenia/gpu/d3d12/pipeline_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ PipelineCache::PipelineCache(D3D12CommandProcessor* command_processor,
: command_processor_(command_processor),
register_file_(register_file),
edram_rov_used_(edram_rov_used) {
shader_translator_ = std::make_unique<DxbcShaderTranslator>(edram_rov_used_);
auto provider = command_processor_->GetD3D12Context()->GetD3D12Provider();

shader_translator_ = std::make_unique<DxbcShaderTranslator>(
provider->GetAdapterVendorID(), edram_rov_used_);

if (edram_rov_used_) {
depth_only_pixel_shader_ =
Expand Down
Loading

0 comments on commit 61bb8bd

Please sign in to comment.