From: Paul Gofman Subject: [PATCH 4/5] d3dx9: Get rid of constant's length checking for matrix in set_constants(). Message-Id: <20170606122836.27124-4-gofmanp@gmail.com> Date: Tue, 6 Jun 2017 15:28:35 +0300 In-Reply-To: <20170606122836.27124-1-gofmanp@gmail.com> References: <20170606122836.27124-1-gofmanp@gmail.com> When count in const_upload_info is calculated precisely (considering actual constant set length), boolean matrix setting always fall in direct copy path. The test has both row_major and column_major qualified boolean matrices, but the qualifier is ignored by compiler. If change the type of matrix to int, the matrix goes to float constants and not to bool constants. So it looks like the case of incomplete last row for matrix should now never happen. Signed-off-by: Paul Gofman --- dlls/d3dx9_36/preshader.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/dlls/d3dx9_36/preshader.c b/dlls/d3dx9_36/preshader.c index 22fbc72..2973386 100644 --- a/dlls/d3dx9_36/preshader.c +++ b/dlls/d3dx9_36/preshader.c @@ -268,6 +268,7 @@ struct const_upload_info unsigned int major_stride; unsigned int major_count; unsigned int count; + unsigned int minor_remainder; }; static enum pres_value_type table_type_from_param_type(D3DXPARAMETER_TYPE type) @@ -1026,10 +1027,22 @@ static void get_const_upload_info(struct d3dx_const_param_eval_output *const_set info->major = param->rows; info->minor = param->columns; } - info->major_stride = max(info->minor, get_offset_reg(table, 1)); - info->major_count = min(info->major * info->major_stride, - get_offset_reg(table, const_set->register_count) + info->major_stride - 1) / info->major_stride; - info->count = info->major_count * info->minor; + + if (table == PRES_REGTAB_OBCONST) + { + unsigned int const_length = get_offset_reg(table, const_set->register_count); + + info->major_stride = info->minor; + info->major_count = const_length / info->major_stride; + info->minor_remainder = const_length % info->major_stride; + } + else + { + info->major_stride = get_offset_reg(table, 1); + info->major_count = const_set->register_count; + info->minor_remainder = 0; + } + info->count = info->major_count * info->minor + info->minor_remainder; } static void pres_float_to_int(void *in, void *out, unsigned int count) @@ -1158,16 +1171,12 @@ static void set_constants(struct d3dx_regstore *rs, struct d3dx_const_tab *const { for (j = 0; j < info.minor; ++j) { - unsigned int offset; - offset = i * info.major_stride + j; - if (get_reg_offset(table, offset) >= const_set->register_count) - break; if (info.transpose) param_offset = i + j * info.major; else param_offset = i * info.minor + j; - out[offset] = data[param_offset]; + out[i * info.major_stride + j] = data[param_offset]; } } start_offset += get_offset_reg(table, const_set->register_count); @@ -1397,6 +1406,9 @@ static HRESULT init_set_constants_param(struct d3dx_const_tab *const_tab, ID3DXC && !info.transpose && info.minor == info.major_stride && info.count == get_offset_reg(const_set.table, const_set.register_count) && info.count * sizeof(unsigned int) <= param->bytes; + if (info.minor_remainder && !const_set.direct_copy) + FIXME("Incomplete last row of matrix for non direct copy constant, parameter %s.\n", + debugstr_a(param->name)); if (FAILED(hr = append_const_set(const_tab, &const_set))) return hr; -- 2.9.4