[D3D12] DXBC internal r# stack allocation

This commit is contained in:
Triang3l 2018-09-01 22:19:29 +03:00
parent da9f153a29
commit b404f227b1
2 changed files with 39 additions and 15 deletions

View File

@ -35,11 +35,29 @@ void DxbcShaderTranslator::Reset() {
shader_code_.clear(); shader_code_.clear();
rdef_constants_used_ = 0; rdef_constants_used_ = 0;
system_temp_count_current_ = 0;
system_temp_count_max_ = 0;
writes_depth_ = false; writes_depth_ = false;
std::memset(&stat_, 0, sizeof(stat_)); std::memset(&stat_, 0, sizeof(stat_));
} }
uint32_t DxbcShaderTranslator::PushSystemTemp() {
uint32_t register_index = system_temp_count_current_;
if (!uses_register_relative_addressing()) {
// Guest shader registers first if they're not in x0.
register_index += register_count();
}
++system_temp_count_current_;
system_temp_count_max_ =
std::max(system_temp_count_max_, system_temp_count_current_);
}
void DxbcShaderTranslator::PopSystemTemp(uint32_t count) {
assert_true(count <= system_temp_count_current_);
system_temp_count_current_ -= std::min(count, system_temp_count_current_);
}
void DxbcShaderTranslator::CompleteVertexShaderCode() {} void DxbcShaderTranslator::CompleteVertexShaderCode() {}
void DxbcShaderTranslator::CompletePixelShaderCode() {} void DxbcShaderTranslator::CompletePixelShaderCode() {}
@ -869,15 +887,17 @@ void DxbcShaderTranslator::WriteShaderCode() {
} }
} }
// Temporary registers - system registers, and also Xbox 360 general-purpose // Temporary registers - guest general-purpose registers if not using dynamic
// registers if not using dynamic indexing. // indexing and Xenia internal registers.
stat_.temp_register_count = stat_.temp_register_count =
uint32_t(TempRegister::kCount) + (uses_register_relative_addressing() ? 0 : register_count()) +
(uses_register_relative_addressing() ? 0 : register_count()); system_temp_count_max_;
if (stat_.temp_register_count != 0) {
shader_object_.push_back( shader_object_.push_back(
ENCODE_D3D10_SB_OPCODE_TYPE(D3D10_SB_OPCODE_DCL_TEMPS) | ENCODE_D3D10_SB_OPCODE_TYPE(D3D10_SB_OPCODE_DCL_TEMPS) |
ENCODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(2)); ENCODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(2));
shader_object_.push_back(stat_.temp_register_count); shader_object_.push_back(stat_.temp_register_count);
}
// General-purpose registers if using dynamic indexing (x0). // General-purpose registers if using dynamic indexing (x0).
if (uses_register_relative_addressing()) { if (uses_register_relative_addressing()) {

View File

@ -129,12 +129,10 @@ class DxbcShaderTranslator : public ShaderTranslator {
static constexpr uint32_t kPSInPositionRegister = static constexpr uint32_t kPSInPositionRegister =
kPSInPointParametersRegister + 1; kPSInPointParametersRegister + 1;
enum class TempRegister { // Allocates a new r# register for internal use and returns its index.
// Color output map in pixel shader epilogue. uint32_t PushSystemTemp();
kColorOutputMap, // Frees the last allocated internal r# registers for later reuse.
void PopSystemTemp(uint32_t count = 1);
kCount,
};
// Writing the epilogue. // Writing the epilogue.
void CompleteVertexShaderCode(); void CompleteVertexShaderCode();
@ -268,6 +266,12 @@ class DxbcShaderTranslator : public ShaderTranslator {
static const RdefConstantBufferIndex static const RdefConstantBufferIndex
constant_buffer_dcl_order_[size_t(RdefConstantBufferIndex::kCount)]; constant_buffer_dcl_order_[size_t(RdefConstantBufferIndex::kCount)];
// Number of currently allocated Xenia internal r# registers.
uint32_t system_temp_count_current_;
// Total maximum number of temporary registers ever used during this
// translation (for the declaration).
uint32_t system_temp_count_max_;
bool writes_depth_; bool writes_depth_;
// The STAT chunk (based on Wine d3dcompiler_parse_stat). // The STAT chunk (based on Wine d3dcompiler_parse_stat).
@ -294,7 +298,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
uint32_t texture_comp_instructions; uint32_t texture_comp_instructions;
uint32_t texture_bias_instructions; uint32_t texture_bias_instructions;
uint32_t texture_gradient_instructions; uint32_t texture_gradient_instructions;
// Moving to outputs only. // Not including indexable temp load/store.
uint32_t mov_instruction_count; uint32_t mov_instruction_count;
// Unknown in Wine. // Unknown in Wine.
uint32_t movc_instruction_count; uint32_t movc_instruction_count;