[v4 1/4] d3dx9: Remove redundant parameter size check in set_constants().

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[v4 1/4] d3dx9: Remove redundant parameter size check in set_constants().

Paul Gofman
Signed-off-by: Paul Gofman <[hidden email]>
---
v4:
    - added assert() for parameter size.
---
 dlls/d3dx9_36/preshader.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlls/d3dx9_36/preshader.c b/dlls/d3dx9_36/preshader.c
index 2785ca3..76d6de9 100644
--- a/dlls/d3dx9_36/preshader.c
+++ b/dlls/d3dx9_36/preshader.c
@@ -1178,11 +1178,6 @@ static void set_constants(struct d3dx_regstore *rs, struct d3dx_const_tab *const
                         param_offset = i + j * info.major;
                     else
                         param_offset = i * info.minor + j;
-                    if (param_offset * sizeof(unsigned int) >= param->bytes)
-                    {
-                        WARN("Parameter data is too short, name %s, component %u.\n", debugstr_a(param->name), i);
-                        break;
-                    }
                     out[offset] = data[param_offset];
                 }
             }
@@ -1303,6 +1298,11 @@ static HRESULT merge_const_set_entries(struct d3dx_const_tab *const_tab,
             memmove(&const_tab->const_set[index + 1], &const_tab->const_set[i],
                     sizeof(*const_tab->const_set) * (const_tab->const_set_count - i));
             const_tab->const_set_count -= i - index - 1;
+            assert(param->bytes >= table_info[first_const->table].component_size
+                    * first_const->element_count
+                    * (first_const->direct_copy ? get_reg_components(first_const->table)
+                    * first_const->register_count
+                    : first_const->param->rows * first_const->param->columns));
         }
         else
         {
--
2.9.4



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[v4 2/4] d3dx9/tests: Modify transpose boolean matrix test to reproduce the case of incomplete last row.

Paul Gofman
Signed-off-by: Paul Gofman <[hidden email]>
---
v4:
    - added patch.
---
 dlls/d3dx9_36/tests/effect.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c
index d75c5ce..2a78074 100644
--- a/dlls/d3dx9_36/tests/effect.c
+++ b/dlls/d3dx9_36/tests/effect.c
@@ -3230,7 +3230,7 @@ PS_OUTPUT RenderScenePS( VS_OUTPUT In, uniform bool2x3 mb)
         Output.RGBColor.xy += mul(Output.RGBColor, m3x2column);
         Output.RGBColor.xy += mul(Output.RGBColor, m3x2row);
     }
-    if (mb2x3column[0][1])
+    if (mb2x3column[0][0])
     {
         Output.RGBColor += sin(Output.RGBColor);
         Output.RGBColor += cos(Output.RGBColor);
@@ -3486,7 +3486,7 @@ static const DWORD test_effect_preshader_effect_blob[] =
     0x00000002, 0x00000118, 0x00000128, 0x00000148, 0x00060002, 0x00000002, 0x00000150, 0x00000160,
     0x00000180, 0x00000002, 0x00000003, 0x0000018c, 0x0000019c, 0x000001cc, 0x000a0002, 0x00000002,
     0x000001d4, 0x000001e4, 0x00000204, 0x000c0002, 0x00000002, 0x00000210, 0x00000220, 0x00000240,
-    0x00030002, 0x00000003, 0x00000248, 0x00000258, 0x00000288, 0x00050000, 0x00000002, 0x00000294,
+    0x00030002, 0x00000003, 0x00000248, 0x00000258, 0x00000288, 0x00050000, 0x00000001, 0x00000294,
     0x000002a4, 0x000002bc, 0x00000000, 0x00000005, 0x000002c8, 0x000002a4, 0x000002d8, 0x00000003,
     0x00000001, 0x000002e4, 0x00000000, 0x56695f67, 0x00746365, 0x00020001, 0x00040001, 0x00000001,
     0x00000000, 0x00000004, 0x00000003, 0x00000002, 0x00000001, 0x3278326d, 0x756c6f63, 0xab006e6d,
@@ -3543,7 +3543,7 @@ static const DWORD test_effect_preshader_effect_blob[] =
     0x80e40003, 0xa0e4000d, 0x03000002, 0x80030000, 0x80e40000, 0x80e40003, 0x03000005, 0x800c0000,
     0x80550000, 0xa0440004, 0x04000004, 0x800c0000, 0x80000000, 0xa0440003, 0x80e40000, 0x04000004,
     0x800c0000, 0x80aa0003, 0xa0440005, 0x80e40000, 0x03000002, 0x80030003, 0x80ee0000, 0x80e40000,
-    0x0000002a, 0x02000001, 0x80080003, 0x90ff0001, 0x0000002b, 0x01000028, 0xe0e40806, 0x04000004,
+    0x0000002a, 0x02000001, 0x80080003, 0x90ff0001, 0x0000002b, 0x01000028, 0xe0e40805, 0x04000004,
     0x800f0000, 0x80e40003, 0xa0550010, 0xa0aa0010, 0x02000013, 0x800f0000, 0x80e40000, 0x04000004,
     0x800f0000, 0x80e40000, 0xa000000f, 0xa055000f, 0x03000005, 0x800f0000, 0x80e40000, 0x80e40000,
     0x04000004, 0x800f0002, 0x80e40000, 0xa0aa000f, 0xa0ff000f, 0x04000004, 0x800f0002, 0x80e40000,
@@ -4317,7 +4317,7 @@ got (%g, %g, %g, %g), parameter %s.\n",
 
 static const BOOL test_effect_preshader_bconsts[] =
 {
-    TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE
+    TRUE, FALSE, TRUE, FALSE, TRUE, TRUE
 };
 
 static void test_effect_preshader_clear_pbool_consts(IDirect3DDevice9 *device)
@@ -6057,7 +6057,7 @@ static void test_effect_state_manager(IDirect3DDevice9 *device)
         {14, 0, 0},
         {15, 0, 14},
         {16, 0, 1},
-        {17, 0, 7},
+        {17, 0, 6},
     };
     static D3DLIGHT9 light_filler =
             {D3DLIGHT_DIRECTIONAL, {0.5f, 0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f, 0.5f}};
--
2.9.4



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[v4 3/4] d3dx9: Get rid of constant's length checking for matrix in set_constants().

Paul Gofman
In reply to this post by Paul Gofman
When count in const_upload_info is calculated precisely (considering actual
constant set length), boolean matrix setting fall in direct copy path, unless
transpose is required. The case of incomplete last row for matrix should happen
for transposed boolean constant only.

Signed-off-by: Paul Gofman <[hidden email]>
---
v4:
    - fixed the case of transposed boolean matrix.
---
 dlls/d3dx9_36/preshader.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/dlls/d3dx9_36/preshader.c b/dlls/d3dx9_36/preshader.c
index 76d6de9..9a2ecfa 100644
--- a/dlls/d3dx9_36/preshader.c
+++ b/dlls/d3dx9_36/preshader.c
@@ -269,6 +269,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)
@@ -1035,10 +1036,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_reg_components(table));
-    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 (get_reg_components(table) == 1)
+    {
+        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_reg_components(table);
+        info->major_count = const_set->register_count;
+        info->minor_remainder = 0;
+    }
+    info->count = info->major_count * info->minor + info->minor_remainder;
 }
 
 static void pres_int_from_float(void *out, const void *in, unsigned int count)
@@ -1169,16 +1182,19 @@ 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];
+                }
+            }
+            if (info.transpose)
+            {
+                for (j = 0; j < info.minor_remainder; ++j)
+                {
+                    param_offset = i + j * info.major;
+                    out[i * info.major_stride + j] = data[param_offset];
                 }
             }
             start_offset += get_offset_reg(table, const_set->register_count);
@@ -1419,6 +1435,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 && !info.transpose)
+        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



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[v4 4/4] d3dx9: Move transpose 'if' outside of the inner loop in set_constants().

Paul Gofman
In reply to this post by Paul Gofman
Signed-off-by: Paul Gofman <[hidden email]>
---
v4:
    - updated to handle incomplete row of transposed matrix accordingly.
---
 dlls/d3dx9_36/preshader.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/dlls/d3dx9_36/preshader.c b/dlls/d3dx9_36/preshader.c
index 9a2ecfa..39bd483 100644
--- a/dlls/d3dx9_36/preshader.c
+++ b/dlls/d3dx9_36/preshader.c
@@ -1138,7 +1138,6 @@ static void set_constants(struct d3dx_regstore *rs, struct d3dx_const_tab *const
         unsigned int table = const_set->table;
         struct d3dx_parameter *param = const_set->param;
         unsigned int element, i, j, start_offset;
-        unsigned int param_offset;
         struct const_upload_info info;
         unsigned int *data = param->data;
         enum pres_value_type param_type;
@@ -1178,24 +1177,19 @@ static void set_constants(struct d3dx_regstore *rs, struct d3dx_const_tab *const
 
             /* Store reshaped but (possibly) not converted yet data temporarily in the same constants buffer.
              * All the supported types of parameters and table values have the same size. */
-            for (i = 0; i < info.major_count; ++i)
-            {
-                for (j = 0; j < info.minor; ++j)
-                {
-                    if (info.transpose)
-                        param_offset = i + j * info.major;
-                    else
-                        param_offset = i * info.minor + j;
-                    out[i * info.major_stride + j] = data[param_offset];
-                }
-            }
             if (info.transpose)
             {
+                for (i = 0; i < info.major_count; ++i)
+                    for (j = 0; j < info.minor; ++j)
+                        out[i * info.major_stride + j] = data[i + j * info.major];
+
                 for (j = 0; j < info.minor_remainder; ++j)
-                {
-                    param_offset = i + j * info.major;
-                    out[i * info.major_stride + j] = data[param_offset];
-                }
+                    out[i * info.major_stride + j] = data[i + j * info.major];            }
+            else
+            {
+                for (i = 0; i < info.major_count; ++i)
+                    for (j = 0; j < info.minor; ++j)
+                        out[i * info.major_stride + j] = data[i * info.minor + j];
             }
             start_offset += get_offset_reg(table, const_set->register_count);
             data += param->rows * param->columns;
--
2.9.4



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [v4 2/4] d3dx9/tests: Modify transpose boolean matrix test to reproduce the case of incomplete last row.

Matteo Bruni-2
In reply to this post by Paul Gofman
Signed-off-by: Matteo Bruni <[hidden email]>


Loading...