From 36f30b33743b981c67cd15abefccb93bcc02696e Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 2 Nov 2014 09:45:13 -0800 Subject: [PATCH] Fixing overlapping texture fetches. --- .../gpu/d3d11/d3d11_shader_translator.cc | 58 +++++++++++-------- src/xenia/gpu/graphics_driver.cc | 5 +- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/xenia/gpu/d3d11/d3d11_shader_translator.cc b/src/xenia/gpu/d3d11/d3d11_shader_translator.cc index 92a3d856d..32fd1aad5 100644 --- a/src/xenia/gpu/d3d11/d3d11_shader_translator.cc +++ b/src/xenia/gpu/d3d11/d3d11_shader_translator.cc @@ -1500,6 +1500,23 @@ int D3D11ShaderTranslator::TranslateVertexFetch(const instr_fetch_vtx_t* vtx, int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex, int sync) { + int src_component_count = 0; + switch (tex->dimension) { + case DIMENSION_1D: + src_component_count = 1; + break; + default: + case DIMENSION_2D: + src_component_count = 2; + break; + case DIMENSION_3D: + src_component_count = 3; + break; + case DIMENSION_CUBE: + src_component_count = 3; + break; + } + // Disassemble. static const char *filter[] = { "POINT", // TEX_FILTER_POINT @@ -1533,7 +1550,7 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex, } PrintDestFecth(tex->dst_reg, tex->dst_swiz); append(" = R%u.", tex->src_reg); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < src_component_count; i++) { append("%c", chan_names[src_swiz & 0x3]); src_swiz >>= 2; } @@ -1581,27 +1598,8 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex, } append("\n"); - int src_component_count = 0; - switch (tex->dimension) { - case DIMENSION_1D: - src_component_count = 1; - break; - default: - case DIMENSION_2D: - src_component_count = 2; - break; - case DIMENSION_3D: - src_component_count = 3; - break; - case DIMENSION_CUBE: - src_component_count = 3; - break; - } - // Translate. - append(" "); - append("r%u.xyzw", tex->dst_reg); - append(" = "); + append(" t = "); append( "x_texture_%d.Sample(x_sampler_%d, r%u.", tex->const_idx, @@ -1622,15 +1620,27 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex, dst_swiz >>= 3; } append(";\n"); - // Do another pass to set constant values. + + append(" r%u.xyzw = float4(", tex->dst_reg); dst_swiz = tex->dst_swiz; for (int i = 0; i < 4; i++) { + if (i) { + append(", "); + } if ((dst_swiz & 0x7) == 4) { - append(" r%u.%c = 0.0;\n", tex->dst_reg, chan_names[i]); + append("0.0"); } else if ((dst_swiz & 0x7) == 5) { - append(" r%u.%c = 1.0;\n", tex->dst_reg, chan_names[i]); + append("1.0"); + } else if ((dst_swiz & 0x7) == 6) { + // ? + append("?"); + } else if ((dst_swiz & 0x7) == 7) { + append("r%u.%c", tex->dst_reg, chan_names[i]); + } else { + append("t.%c", chan_names[dst_swiz & 0x3]); } dst_swiz >>= 3; } + append(");\n"); return 0; } diff --git a/src/xenia/gpu/graphics_driver.cc b/src/xenia/gpu/graphics_driver.cc index c87508f12..d5a631f28 100644 --- a/src/xenia/gpu/graphics_driver.cc +++ b/src/xenia/gpu/graphics_driver.cc @@ -197,8 +197,9 @@ int GraphicsDriver::PopulateInputAssembly(DrawCommand& command) { break; } assert_not_null(fetch); - // If this assert doesn't hold, maybe we just abort? - assert_true(fetch->type == 0x3); + assert_true(fetch->type == 0x3); // must be of type vertex + // TODO(benvanik): some games have type 2, which is texture - maybe + // fetch_slot wrong? assert_not_zero(fetch->size); const auto& info = desc.info;