Fixing overlapping texture fetches.

This commit is contained in:
Ben Vanik 2014-11-02 09:45:13 -08:00
parent 8c314225bb
commit 36f30b3374
2 changed files with 37 additions and 26 deletions

View File

@ -1500,6 +1500,23 @@ int D3D11ShaderTranslator::TranslateVertexFetch(const instr_fetch_vtx_t* vtx,
int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex, int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex,
int sync) { 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. // Disassemble.
static const char *filter[] = { static const char *filter[] = {
"POINT", // TEX_FILTER_POINT "POINT", // TEX_FILTER_POINT
@ -1533,7 +1550,7 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex,
} }
PrintDestFecth(tex->dst_reg, tex->dst_swiz); PrintDestFecth(tex->dst_reg, tex->dst_swiz);
append(" = R%u.", tex->src_reg); 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]); append("%c", chan_names[src_swiz & 0x3]);
src_swiz >>= 2; src_swiz >>= 2;
} }
@ -1581,27 +1598,8 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex,
} }
append("\n"); 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. // Translate.
append(" "); append(" t = ");
append("r%u.xyzw", tex->dst_reg);
append(" = ");
append( append(
"x_texture_%d.Sample(x_sampler_%d, r%u.", "x_texture_%d.Sample(x_sampler_%d, r%u.",
tex->const_idx, tex->const_idx,
@ -1622,15 +1620,27 @@ int D3D11ShaderTranslator::TranslateTextureFetch(const instr_fetch_tex_t* tex,
dst_swiz >>= 3; dst_swiz >>= 3;
} }
append(";\n"); append(";\n");
// Do another pass to set constant values.
append(" r%u.xyzw = float4(", tex->dst_reg);
dst_swiz = tex->dst_swiz; dst_swiz = tex->dst_swiz;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (i) {
append(", ");
}
if ((dst_swiz & 0x7) == 4) { 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) { } 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; dst_swiz >>= 3;
} }
append(");\n");
return 0; return 0;
} }

View File

@ -197,8 +197,9 @@ int GraphicsDriver::PopulateInputAssembly(DrawCommand& command) {
break; break;
} }
assert_not_null(fetch); assert_not_null(fetch);
// If this assert doesn't hold, maybe we just abort? assert_true(fetch->type == 0x3); // must be of type vertex
assert_true(fetch->type == 0x3); // TODO(benvanik): some games have type 2, which is texture - maybe
// fetch_slot wrong?
assert_not_zero(fetch->size); assert_not_zero(fetch->size);
const auto& info = desc.info; const auto& info = desc.info;