diff --git a/src/xenia/gpu/d3d12/d3d12_command_processor.cc b/src/xenia/gpu/d3d12/d3d12_command_processor.cc index a5c99979f..e352b9bff 100644 --- a/src/xenia/gpu/d3d12/d3d12_command_processor.cc +++ b/src/xenia/gpu/d3d12/d3d12_command_processor.cc @@ -86,10 +86,10 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature( parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; parameter.DescriptorTable.NumDescriptorRanges = 1; parameter.DescriptorTable.pDescriptorRanges = ⦥ - parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; + parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.NumDescriptors = 1; - range.BaseShaderRegister = 10; + range.BaseShaderRegister = 2; range.RegisterSpace = 0; range.OffsetInDescriptorsFromTableStart = 0; } @@ -104,7 +104,7 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature( parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.NumDescriptors = 8; - range.BaseShaderRegister = 2; + range.BaseShaderRegister = 3; range.RegisterSpace = 0; range.OffsetInDescriptorsFromTableStart = 0; } @@ -119,7 +119,7 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature( parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.NumDescriptors = 8; - range.BaseShaderRegister = 2; + range.BaseShaderRegister = 3; range.RegisterSpace = 0; range.OffsetInDescriptorsFromTableStart = 0; } @@ -1083,8 +1083,6 @@ void D3D12CommandProcessor::UpdateSystemConstantValues(Endian index_endian) { system_constants_.ssaa_inv_scale[0] = ssaa_inv_scale_x; system_constants_.ssaa_inv_scale[1] = ssaa_inv_scale_y; - // TODO(Triang3l): Whether textures are 3D or stacked. - cbuffer_bindings_system_.up_to_date &= dirty; } @@ -1129,9 +1127,9 @@ bool D3D12CommandProcessor::UpdateBindings( // Begin updating descriptors. bool write_common_constant_views = false; + bool write_fetch_constant_view = false; bool write_vertex_float_constant_views = false; bool write_pixel_float_constant_views = false; - bool write_fetch_constant_view = false; // TODO(Triang3l): Update textures and samplers only if shaders or binding // hash change. bool write_textures = texture_count != 0; @@ -1171,6 +1169,18 @@ bool D3D12CommandProcessor::UpdateBindings( cbuffer_bindings_bool_loop_.up_to_date = true; write_common_constant_views = true; } + if (!cbuffer_bindings_fetch_.up_to_date) { + uint8_t* fetch_constants = constant_buffer_pool_->RequestFull( + 768, nullptr, nullptr, &cbuffer_bindings_fetch_.buffer_address); + if (fetch_constants == nullptr) { + return false; + } + std::memcpy(fetch_constants, + ®s[XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0].u32, + 32 * 6 * sizeof(uint32_t)); + cbuffer_bindings_fetch_.up_to_date = true; + write_fetch_constant_view = true; + } for (uint32_t i = 0; i < 16; ++i) { ConstantBufferBinding& float_binding = cbuffer_bindings_float_[i]; if (float_binding.up_to_date) { @@ -1191,18 +1201,6 @@ bool D3D12CommandProcessor::UpdateBindings( write_pixel_float_constant_views = true; } } - if (!cbuffer_bindings_fetch_.up_to_date) { - uint8_t* fetch_constants = constant_buffer_pool_->RequestFull( - 768, nullptr, nullptr, &cbuffer_bindings_fetch_.buffer_address); - if (fetch_constants == nullptr) { - return false; - } - std::memcpy(fetch_constants, - ®s[XE_GPU_REG_SHADER_CONSTANT_FETCH_00_0].u32, - 32 * 6 * sizeof(uint32_t)); - cbuffer_bindings_fetch_.up_to_date = true; - write_fetch_constant_view = true; - } // Allocate the descriptors. uint32_t view_count_partial_update = 0; @@ -1210,6 +1208,10 @@ bool D3D12CommandProcessor::UpdateBindings( // System and bool/loop constants. view_count_partial_update += 2; } + if (write_fetch_constant_view) { + // Fetch constants. + ++view_count_partial_update; + } if (write_vertex_float_constant_views) { // Vertex float constants. view_count_partial_update += 8; @@ -1218,10 +1220,6 @@ bool D3D12CommandProcessor::UpdateBindings( // Pixel float constants. view_count_partial_update += 8; } - if (write_fetch_constant_view) { - // Fetch constants. - ++view_count_partial_update; - } if (write_textures) { view_count_partial_update += texture_count; } @@ -1254,9 +1252,9 @@ bool D3D12CommandProcessor::UpdateBindings( // Need to update all view descriptors. draw_view_full_update_ = view_full_update_index; write_common_constant_views = true; + write_fetch_constant_view = true; write_vertex_float_constant_views = true; write_pixel_float_constant_views = true; - write_fetch_constant_view = true; write_textures = texture_count != 0; // If updating fully, write the shared memory descriptor (t0, space1). shared_memory_->CreateSRV(view_cpu_handle); @@ -1293,9 +1291,20 @@ bool D3D12CommandProcessor::UpdateBindings( current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_CommonConstants); } + if (write_fetch_constant_view) { + gpu_handle_fetch_constants_ = view_gpu_handle; + // Fetch constants (b2). + constant_buffer_desc.BufferLocation = + cbuffer_bindings_fetch_.buffer_address; + constant_buffer_desc.SizeInBytes = 768; + device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); + view_cpu_handle.ptr += view_handle_size; + view_gpu_handle.ptr += view_handle_size; + current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_FetchConstants); + } if (write_vertex_float_constant_views) { gpu_handle_vertex_float_constants_ = view_gpu_handle; - // Vertex float constants (b2-b9). + // Vertex float constants (b3-b10). for (uint32_t i = 0; i < 8; ++i) { constant_buffer_desc.BufferLocation = cbuffer_bindings_float_[i].buffer_address; @@ -1309,7 +1318,7 @@ bool D3D12CommandProcessor::UpdateBindings( } if (write_pixel_float_constant_views) { gpu_handle_pixel_float_constants_ = view_gpu_handle; - // Pixel float constants (b2-b9). + // Pixel float constants (b3-b10). for (uint32_t i = 0; i < 8; ++i) { constant_buffer_desc.BufferLocation = cbuffer_bindings_float_[8 + i].buffer_address; @@ -1321,17 +1330,6 @@ bool D3D12CommandProcessor::UpdateBindings( current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_PixelFloatConstants); } - if (write_fetch_constant_view) { - gpu_handle_fetch_constants_ = view_gpu_handle; - // Fetch constants (b10). - constant_buffer_desc.BufferLocation = - cbuffer_bindings_fetch_.buffer_address; - constant_buffer_desc.SizeInBytes = 768; - device->CreateConstantBufferView(&constant_buffer_desc, view_cpu_handle); - view_cpu_handle.ptr += view_handle_size; - view_gpu_handle.ptr += view_handle_size; - current_graphics_root_up_to_date_ &= ~(1u << kRootParameter_FetchConstants); - } if (write_textures) { if (pixel_texture_count != 0) { assert_true(current_graphics_root_extras_.pixel_textures != diff --git a/src/xenia/gpu/d3d12/d3d12_command_processor.h b/src/xenia/gpu/d3d12/d3d12_command_processor.h index e6f3f95d3..53ce142e7 100644 --- a/src/xenia/gpu/d3d12/d3d12_command_processor.h +++ b/src/xenia/gpu/d3d12/d3d12_command_processor.h @@ -95,14 +95,14 @@ class D3D12CommandProcessor : public CommandProcessor { // These are always present. // Very frequently changed, especially for UI draws, and for models drawn in - // multiple parts - contains fetch constants with vertex addresses (b10). + // multiple parts - contains vertex and texture fetch constants (b2). kRootParameter_FetchConstants, // Quite frequently changed (for one object drawn multiple times, for // instance - may contain projection matrices) - 8 pages of float constants - // (b2-b9). + // (b3-b10). kRootParameter_VertexFloatConstants, // Less frequently changed (per-material) - 8 pages of float constants - // (b2-b9). + // (b3-b10). kRootParameter_PixelFloatConstants, // Rarely changed - system constants like viewport and alpha testing (b0) // and loop and bool constants (b1). @@ -223,9 +223,9 @@ class D3D12CommandProcessor : public CommandProcessor { // Latest descriptor handles used for handling Xenos draw calls. D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_common_constants_; + D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_fetch_constants_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_vertex_float_constants_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_float_constants_; - D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_fetch_constants_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_shared_memory_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_textures_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_samplers_; diff --git a/src/xenia/gpu/hlsl_shader_translator.cc b/src/xenia/gpu/hlsl_shader_translator.cc index 51f6ead50..6cbbab884 100644 --- a/src/xenia/gpu/hlsl_shader_translator.cc +++ b/src/xenia/gpu/hlsl_shader_translator.cc @@ -176,7 +176,6 @@ std::vector HlslShaderTranslator::CompleteTranslation() { " float xe_pixel_half_pixel_offset;\n" " float2 xe_ssaa_inv_scale;\n" " uint xe_pixel_pos_reg;\n" - " uint xe_textures_are_3d;\n" "};\n" "\n" "cbuffer xe_loop_bool_constants : register(b1) {\n" @@ -184,11 +183,15 @@ std::vector HlslShaderTranslator::CompleteTranslation() { " uint4 xe_loop_constants[32];\n" "};\n" "\n" + "cbuffer xe_fetch_constants : register(b2) {\n" + " uint4 xe_fetch[48];\n" + "};\n" + "\n" "struct XeFloatConstantPage {\n" " float4 c[32];\n" "};\n" "ConstantBuffer " - "xe_float_constants[8] : register(b2);\n" + "xe_float_constants[8] : register(b3);\n" "\n"); // Textures and samplers. @@ -232,10 +235,6 @@ std::vector HlslShaderTranslator::CompleteTranslation() { // -1 point size means the geometry shader will use the global setting by // default. source.AppendFormat( - "cbuffer xe_vertex_fetch_constants : register(b10) {\n" - " uint4 xe_vertex_fetch[48];\n" - "};\n" - "\n" "ByteAddressBuffer xe_shared_memory : register(t0, space1);\n" "\n" "#define XE_BYTE_SWAP_OVERLOAD(XeByteSwapType) \\\n" @@ -903,8 +902,8 @@ void HlslShaderTranslator::ProcessVertexFetchInstruction( } EmitSourceDepth("xe_vertex_element%s = XeByteSwap(xe_shared_memory.Load%s(\n", load_swizzle, load_function_suffix); - EmitSourceDepth(" (xe_vertex_fetch[%uu].%c & 0x1FFFFFFCu)", - vfetch_index >> 1, (vfetch_index & 1) ? 'z' : 'x'); + EmitSourceDepth(" (xe_fetch[%uu].%c & 0x1FFFFFFCu)", vfetch_index >> 1, + (vfetch_index & 1) ? 'z' : 'x'); if (instr.attributes.stride != 0) { EmitSource(" + uint(xe_src0.x) * %uu", instr.attributes.stride * 4); } @@ -912,7 +911,7 @@ void HlslShaderTranslator::ProcessVertexFetchInstruction( EmitSource(" + %uu", instr.attributes.offset * 4); } EmitSource("),\n"); - EmitSourceDepth(" xe_vertex_fetch[%uu].%c);\n", vfetch_index >> 1, + EmitSourceDepth(" xe_fetch[%uu].%c);\n", vfetch_index >> 1, (vfetch_index & 1) ? 'w' : 'y'); // Convert to the target format. diff --git a/src/xenia/gpu/hlsl_shader_translator.h b/src/xenia/gpu/hlsl_shader_translator.h index 95b3d2bc4..eaa30c86e 100644 --- a/src/xenia/gpu/hlsl_shader_translator.h +++ b/src/xenia/gpu/hlsl_shader_translator.h @@ -37,7 +37,6 @@ class HlslShaderTranslator : public ShaderTranslator { // vec4 3 float ssaa_inv_scale[2]; uint32_t pixel_pos_reg; - uint32_t textures_are_3d; }; struct TextureSRV {