[D3D12] Fetch constants in PS for exp bias and 3D/stacked

This commit is contained in:
Triang3l 2018-08-04 17:08:27 +03:00
parent 991b120454
commit 7d80b5ae0d
4 changed files with 47 additions and 51 deletions

View File

@ -86,10 +86,10 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature(
parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
parameter.DescriptorTable.NumDescriptorRanges = 1; parameter.DescriptorTable.NumDescriptorRanges = 1;
parameter.DescriptorTable.pDescriptorRanges = ⦥ parameter.DescriptorTable.pDescriptorRanges = ⦥
parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
range.NumDescriptors = 1; range.NumDescriptors = 1;
range.BaseShaderRegister = 10; range.BaseShaderRegister = 2;
range.RegisterSpace = 0; range.RegisterSpace = 0;
range.OffsetInDescriptorsFromTableStart = 0; range.OffsetInDescriptorsFromTableStart = 0;
} }
@ -104,7 +104,7 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature(
parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX;
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
range.NumDescriptors = 8; range.NumDescriptors = 8;
range.BaseShaderRegister = 2; range.BaseShaderRegister = 3;
range.RegisterSpace = 0; range.RegisterSpace = 0;
range.OffsetInDescriptorsFromTableStart = 0; range.OffsetInDescriptorsFromTableStart = 0;
} }
@ -119,7 +119,7 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature(
parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV; range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
range.NumDescriptors = 8; range.NumDescriptors = 8;
range.BaseShaderRegister = 2; range.BaseShaderRegister = 3;
range.RegisterSpace = 0; range.RegisterSpace = 0;
range.OffsetInDescriptorsFromTableStart = 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[0] = ssaa_inv_scale_x;
system_constants_.ssaa_inv_scale[1] = ssaa_inv_scale_y; 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; cbuffer_bindings_system_.up_to_date &= dirty;
} }
@ -1129,9 +1127,9 @@ bool D3D12CommandProcessor::UpdateBindings(
// Begin updating descriptors. // Begin updating descriptors.
bool write_common_constant_views = false; bool write_common_constant_views = false;
bool write_fetch_constant_view = false;
bool write_vertex_float_constant_views = false; bool write_vertex_float_constant_views = false;
bool write_pixel_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 // TODO(Triang3l): Update textures and samplers only if shaders or binding
// hash change. // hash change.
bool write_textures = texture_count != 0; bool write_textures = texture_count != 0;
@ -1171,6 +1169,18 @@ bool D3D12CommandProcessor::UpdateBindings(
cbuffer_bindings_bool_loop_.up_to_date = true; cbuffer_bindings_bool_loop_.up_to_date = true;
write_common_constant_views = 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,
&regs[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) { for (uint32_t i = 0; i < 16; ++i) {
ConstantBufferBinding& float_binding = cbuffer_bindings_float_[i]; ConstantBufferBinding& float_binding = cbuffer_bindings_float_[i];
if (float_binding.up_to_date) { if (float_binding.up_to_date) {
@ -1191,18 +1201,6 @@ bool D3D12CommandProcessor::UpdateBindings(
write_pixel_float_constant_views = true; 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,
&regs[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. // Allocate the descriptors.
uint32_t view_count_partial_update = 0; uint32_t view_count_partial_update = 0;
@ -1210,6 +1208,10 @@ bool D3D12CommandProcessor::UpdateBindings(
// System and bool/loop constants. // System and bool/loop constants.
view_count_partial_update += 2; view_count_partial_update += 2;
} }
if (write_fetch_constant_view) {
// Fetch constants.
++view_count_partial_update;
}
if (write_vertex_float_constant_views) { if (write_vertex_float_constant_views) {
// Vertex float constants. // Vertex float constants.
view_count_partial_update += 8; view_count_partial_update += 8;
@ -1218,10 +1220,6 @@ bool D3D12CommandProcessor::UpdateBindings(
// Pixel float constants. // Pixel float constants.
view_count_partial_update += 8; view_count_partial_update += 8;
} }
if (write_fetch_constant_view) {
// Fetch constants.
++view_count_partial_update;
}
if (write_textures) { if (write_textures) {
view_count_partial_update += texture_count; view_count_partial_update += texture_count;
} }
@ -1254,9 +1252,9 @@ bool D3D12CommandProcessor::UpdateBindings(
// Need to update all view descriptors. // Need to update all view descriptors.
draw_view_full_update_ = view_full_update_index; draw_view_full_update_ = view_full_update_index;
write_common_constant_views = true; write_common_constant_views = true;
write_fetch_constant_view = true;
write_vertex_float_constant_views = true; write_vertex_float_constant_views = true;
write_pixel_float_constant_views = true; write_pixel_float_constant_views = true;
write_fetch_constant_view = true;
write_textures = texture_count != 0; write_textures = texture_count != 0;
// If updating fully, write the shared memory descriptor (t0, space1). // If updating fully, write the shared memory descriptor (t0, space1).
shared_memory_->CreateSRV(view_cpu_handle); shared_memory_->CreateSRV(view_cpu_handle);
@ -1293,9 +1291,20 @@ bool D3D12CommandProcessor::UpdateBindings(
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << kRootParameter_CommonConstants); ~(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) { if (write_vertex_float_constant_views) {
gpu_handle_vertex_float_constants_ = view_gpu_handle; 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) { for (uint32_t i = 0; i < 8; ++i) {
constant_buffer_desc.BufferLocation = constant_buffer_desc.BufferLocation =
cbuffer_bindings_float_[i].buffer_address; cbuffer_bindings_float_[i].buffer_address;
@ -1309,7 +1318,7 @@ bool D3D12CommandProcessor::UpdateBindings(
} }
if (write_pixel_float_constant_views) { if (write_pixel_float_constant_views) {
gpu_handle_pixel_float_constants_ = view_gpu_handle; 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) { for (uint32_t i = 0; i < 8; ++i) {
constant_buffer_desc.BufferLocation = constant_buffer_desc.BufferLocation =
cbuffer_bindings_float_[8 + i].buffer_address; cbuffer_bindings_float_[8 + i].buffer_address;
@ -1321,17 +1330,6 @@ bool D3D12CommandProcessor::UpdateBindings(
current_graphics_root_up_to_date_ &= current_graphics_root_up_to_date_ &=
~(1u << kRootParameter_PixelFloatConstants); ~(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 (write_textures) {
if (pixel_texture_count != 0) { if (pixel_texture_count != 0) {
assert_true(current_graphics_root_extras_.pixel_textures != assert_true(current_graphics_root_extras_.pixel_textures !=

View File

@ -95,14 +95,14 @@ class D3D12CommandProcessor : public CommandProcessor {
// These are always present. // These are always present.
// Very frequently changed, especially for UI draws, and for models drawn in // 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, kRootParameter_FetchConstants,
// Quite frequently changed (for one object drawn multiple times, for // Quite frequently changed (for one object drawn multiple times, for
// instance - may contain projection matrices) - 8 pages of float constants // instance - may contain projection matrices) - 8 pages of float constants
// (b2-b9). // (b3-b10).
kRootParameter_VertexFloatConstants, kRootParameter_VertexFloatConstants,
// Less frequently changed (per-material) - 8 pages of float constants // Less frequently changed (per-material) - 8 pages of float constants
// (b2-b9). // (b3-b10).
kRootParameter_PixelFloatConstants, kRootParameter_PixelFloatConstants,
// Rarely changed - system constants like viewport and alpha testing (b0) // Rarely changed - system constants like viewport and alpha testing (b0)
// and loop and bool constants (b1). // and loop and bool constants (b1).
@ -223,9 +223,9 @@ class D3D12CommandProcessor : public CommandProcessor {
// Latest descriptor handles used for handling Xenos draw calls. // Latest descriptor handles used for handling Xenos draw calls.
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_common_constants_; 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_vertex_float_constants_;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_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_shared_memory_;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_textures_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_textures_;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_samplers_; D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle_pixel_samplers_;

View File

@ -176,7 +176,6 @@ std::vector<uint8_t> HlslShaderTranslator::CompleteTranslation() {
" float xe_pixel_half_pixel_offset;\n" " float xe_pixel_half_pixel_offset;\n"
" float2 xe_ssaa_inv_scale;\n" " float2 xe_ssaa_inv_scale;\n"
" uint xe_pixel_pos_reg;\n" " uint xe_pixel_pos_reg;\n"
" uint xe_textures_are_3d;\n"
"};\n" "};\n"
"\n" "\n"
"cbuffer xe_loop_bool_constants : register(b1) {\n" "cbuffer xe_loop_bool_constants : register(b1) {\n"
@ -184,11 +183,15 @@ std::vector<uint8_t> HlslShaderTranslator::CompleteTranslation() {
" uint4 xe_loop_constants[32];\n" " uint4 xe_loop_constants[32];\n"
"};\n" "};\n"
"\n" "\n"
"cbuffer xe_fetch_constants : register(b2) {\n"
" uint4 xe_fetch[48];\n"
"};\n"
"\n"
"struct XeFloatConstantPage {\n" "struct XeFloatConstantPage {\n"
" float4 c[32];\n" " float4 c[32];\n"
"};\n" "};\n"
"ConstantBuffer<XeFloatConstantPage> " "ConstantBuffer<XeFloatConstantPage> "
"xe_float_constants[8] : register(b2);\n" "xe_float_constants[8] : register(b3);\n"
"\n"); "\n");
// Textures and samplers. // Textures and samplers.
@ -232,10 +235,6 @@ std::vector<uint8_t> HlslShaderTranslator::CompleteTranslation() {
// -1 point size means the geometry shader will use the global setting by // -1 point size means the geometry shader will use the global setting by
// default. // default.
source.AppendFormat( 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" "ByteAddressBuffer xe_shared_memory : register(t0, space1);\n"
"\n" "\n"
"#define XE_BYTE_SWAP_OVERLOAD(XeByteSwapType) \\\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", EmitSourceDepth("xe_vertex_element%s = XeByteSwap(xe_shared_memory.Load%s(\n",
load_swizzle, load_function_suffix); load_swizzle, load_function_suffix);
EmitSourceDepth(" (xe_vertex_fetch[%uu].%c & 0x1FFFFFFCu)", EmitSourceDepth(" (xe_fetch[%uu].%c & 0x1FFFFFFCu)", vfetch_index >> 1,
vfetch_index >> 1, (vfetch_index & 1) ? 'z' : 'x'); (vfetch_index & 1) ? 'z' : 'x');
if (instr.attributes.stride != 0) { if (instr.attributes.stride != 0) {
EmitSource(" + uint(xe_src0.x) * %uu", instr.attributes.stride * 4); EmitSource(" + uint(xe_src0.x) * %uu", instr.attributes.stride * 4);
} }
@ -912,7 +911,7 @@ void HlslShaderTranslator::ProcessVertexFetchInstruction(
EmitSource(" + %uu", instr.attributes.offset * 4); EmitSource(" + %uu", instr.attributes.offset * 4);
} }
EmitSource("),\n"); 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'); (vfetch_index & 1) ? 'w' : 'y');
// Convert to the target format. // Convert to the target format.

View File

@ -37,7 +37,6 @@ class HlslShaderTranslator : public ShaderTranslator {
// vec4 3 // vec4 3
float ssaa_inv_scale[2]; float ssaa_inv_scale[2];
uint32_t pixel_pos_reg; uint32_t pixel_pos_reg;
uint32_t textures_are_3d;
}; };
struct TextureSRV { struct TextureSRV {