From 645f450321385419934e62e6224cae90c9210f59 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Sat, 22 Dec 2018 14:26:18 +0300 Subject: [PATCH] [D3D12] DXBC: Fix UAV and sampler operands --- src/xenia/gpu/dxbc_shader_translator.cc | 2 +- src/xenia/gpu/dxbc_shader_translator.h | 9 +++++++++ src/xenia/gpu/dxbc_shader_translator_alu.cc | 10 ++++------ src/xenia/gpu/dxbc_shader_translator_fetch.cc | 16 ++++++++-------- src/xenia/gpu/dxbc_shader_translator_om.cc | 4 +--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/xenia/gpu/dxbc_shader_translator.cc b/src/xenia/gpu/dxbc_shader_translator.cc index 7b05fb5f8..510288517 100644 --- a/src/xenia/gpu/dxbc_shader_translator.cc +++ b/src/xenia/gpu/dxbc_shader_translator.cc @@ -4024,7 +4024,7 @@ void DxbcShaderTranslator::WriteShaderCode() { D3D11_SB_RASTERIZER_ORDERED_ACCESS | ENCODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(7)); shader_object_.push_back(EncodeVectorSwizzledOperand( - D3D10_SB_OPERAND_TYPE_RESOURCE, kSwizzleXYZW, 3)); + D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW, kSwizzleXYZW, 3)); shader_object_.push_back(0); shader_object_.push_back(0); shader_object_.push_back(0); diff --git a/src/xenia/gpu/dxbc_shader_translator.h b/src/xenia/gpu/dxbc_shader_translator.h index 8dbc2bdf8..be7c3dfa0 100644 --- a/src/xenia/gpu/dxbc_shader_translator.h +++ b/src/xenia/gpu/dxbc_shader_translator.h @@ -727,6 +727,15 @@ class DxbcShaderTranslator : public ShaderTranslator { // Operand encoding, with 32-bit immediate indices by default. None of the // arguments must be shifted when calling. + static constexpr uint32_t EncodeZeroComponentOperand( + uint32_t type, uint32_t index_dimension, + uint32_t index_representation_0 = 0, uint32_t index_representation_1 = 0, + uint32_t index_representation_2 = 0) { + // D3D10_SB_OPERAND_0_COMPONENT. + return 0 | (type << 12) | (index_dimension << 20) | + (index_representation_0 << 22) | (index_representation_1 << 25) | + (index_representation_0 << 28); + } static constexpr uint32_t EncodeScalarOperand( uint32_t type, uint32_t index_dimension, uint32_t index_representation_0 = 0, uint32_t index_representation_1 = 0, diff --git a/src/xenia/gpu/dxbc_shader_translator_alu.cc b/src/xenia/gpu/dxbc_shader_translator_alu.cc index fbe88cc8f..4486a2201 100644 --- a/src/xenia/gpu/dxbc_shader_translator_alu.cc +++ b/src/xenia/gpu/dxbc_shader_translator_alu.cc @@ -2387,18 +2387,16 @@ void DxbcShaderTranslator::ProcessScalarAluInstruction( ENCODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(4 + operand_lengths[0])); // sincos ps, null, src0.x for sin // sincos null, ps, src0.x for cos - const uint32_t null_operand_token = - ENCODE_D3D10_SB_OPERAND_NUM_COMPONENTS(D3D10_SB_OPERAND_0_COMPONENT) | - ENCODE_D3D10_SB_OPERAND_TYPE(D3D10_SB_OPERAND_TYPE_NULL) | - ENCODE_D3D10_SB_OPERAND_INDEX_DIMENSION(D3D10_SB_OPERAND_INDEX_0D); if (instr.scalar_opcode != AluScalarOpcode::kSin) { - shader_code_.push_back(null_operand_token); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_NULL, 0)); } shader_code_.push_back( EncodeVectorMaskedOperand(D3D10_SB_OPERAND_TYPE_TEMP, 0b0001, 1)); shader_code_.push_back(system_temp_ps_pc_p0_a0_); if (instr.scalar_opcode != AluScalarOpcode::kCos) { - shader_code_.push_back(null_operand_token); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_NULL, 0)); } UseDxbcSourceOperand(dxbc_operands[0], kSwizzleXYZW, 0); ++stat_.instruction_count; diff --git a/src/xenia/gpu/dxbc_shader_translator_fetch.cc b/src/xenia/gpu/dxbc_shader_translator_fetch.cc index 3f2b634e8..54e28b7a3 100644 --- a/src/xenia/gpu/dxbc_shader_translator_fetch.cc +++ b/src/xenia/gpu/dxbc_shader_translator_fetch.cc @@ -1807,8 +1807,8 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction( D3D10_SB_OPERAND_TYPE_RESOURCE, kSwizzleXYZW, 2)); shader_code_.push_back(srv_register_current); shader_code_.push_back(srv_register_current); - shader_code_.push_back(EncodeVectorSwizzledOperand( - D3D10_SB_OPERAND_TYPE_SAMPLER, kSwizzleXYZW, 2)); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_SAMPLER, 2)); shader_code_.push_back(sampler_register); shader_code_.push_back(sampler_register); ++stat_.instruction_count; @@ -1848,8 +1848,8 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction( D3D10_SB_OPERAND_TYPE_RESOURCE, kSwizzleXYZW, 2)); shader_code_.push_back(srv_register_current); shader_code_.push_back(srv_register_current); - shader_code_.push_back(EncodeVectorSwizzledOperand( - D3D10_SB_OPERAND_TYPE_SAMPLER, kSwizzleXYZW, 2)); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_SAMPLER, 2)); shader_code_.push_back(sampler_register); shader_code_.push_back(sampler_register); shader_code_.push_back(EncodeVectorSelectOperand( @@ -1874,8 +1874,8 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction( D3D10_SB_OPERAND_TYPE_RESOURCE, kSwizzleXYZW, 2)); shader_code_.push_back(srv_register_current); shader_code_.push_back(srv_register_current); - shader_code_.push_back(EncodeVectorSwizzledOperand( - D3D10_SB_OPERAND_TYPE_SAMPLER, kSwizzleXYZW, 2)); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_SAMPLER, 2)); shader_code_.push_back(sampler_register); shader_code_.push_back(sampler_register); shader_code_.push_back(EncodeVectorSwizzledOperand( @@ -1921,8 +1921,8 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction( D3D10_SB_OPERAND_TYPE_RESOURCE, kSwizzleXYZW, 2)); shader_code_.push_back(srv_register_current); shader_code_.push_back(srv_register_current); - shader_code_.push_back(EncodeVectorSwizzledOperand( - D3D10_SB_OPERAND_TYPE_SAMPLER, kSwizzleXYZW, 2)); + shader_code_.push_back( + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_SAMPLER, 2)); shader_code_.push_back(sampler_register); shader_code_.push_back(sampler_register); if (explicit_lod || instr.attributes.lod_bias != 0.0f) { diff --git a/src/xenia/gpu/dxbc_shader_translator_om.cc b/src/xenia/gpu/dxbc_shader_translator_om.cc index 404ff7e6a..fe40f0f32 100644 --- a/src/xenia/gpu/dxbc_shader_translator_om.cc +++ b/src/xenia/gpu/dxbc_shader_translator_om.cc @@ -4208,9 +4208,7 @@ void DxbcShaderTranslator::CompletePixelShader_WriteToROV() { EncodeVectorMaskedOperand(D3D10_SB_OPERAND_TYPE_TEMP, 0b0100, 1)); shader_code_.push_back(edram_coord_pixel_temp); shader_code_.push_back( - ENCODE_D3D10_SB_OPERAND_NUM_COMPONENTS(D3D10_SB_OPERAND_0_COMPONENT) | - ENCODE_D3D10_SB_OPERAND_TYPE(D3D10_SB_OPERAND_TYPE_NULL) | - ENCODE_D3D10_SB_OPERAND_INDEX_DIMENSION(D3D10_SB_OPERAND_INDEX_0D)); + EncodeZeroComponentOperand(D3D10_SB_OPERAND_TYPE_NULL, 0)); shader_code_.push_back( EncodeVectorSelectOperand(D3D10_SB_OPERAND_TYPE_TEMP, 0, 1)); shader_code_.push_back(edram_coord_pixel_temp);