[PATCH 2/3] d3dx9: Use magic number instead of parameter tables for parameter handles.

Paul Gofman gofmanp at gmail.com
Tue Apr 11 08:22:34 CDT 2017


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
 dlls/d3dx9_36/d3dx9_private.h |  3 +-
 dlls/d3dx9_36/effect.c        | 95 ++++++++-----------------------------------
 dlls/d3dx9_36/tests/effect.c  |  2 -
 3 files changed, 18 insertions(+), 82 deletions(-)

diff --git a/dlls/d3dx9_36/d3dx9_private.h b/dlls/d3dx9_36/d3dx9_private.h
index e50f4d3..145ab80 100644
--- a/dlls/d3dx9_36/d3dx9_private.h
+++ b/dlls/d3dx9_36/d3dx9_private.h
@@ -196,6 +196,7 @@ struct d3dx_param_eval
 
 struct d3dx_parameter
 {
+    char magic_string[4];
     char *name;
     char *semantic;
     void *data;
@@ -211,8 +212,6 @@ struct d3dx_parameter
     DWORD runtime_flags;
     DWORD object_id;
 
-    D3DXHANDLE handle;
-
     struct d3dx_parameter *annotations;
     struct d3dx_parameter *members;
 
diff --git a/dlls/d3dx9_36/effect.c b/dlls/d3dx9_36/effect.c
index 9d363bc..50db9c7 100644
--- a/dlls/d3dx9_36/effect.c
+++ b/dlls/d3dx9_36/effect.c
@@ -27,7 +27,7 @@
 #define INT_FLOAT_MULTI 255.0f
 #define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
 
-#define INITIAL_PARAM_TABLE_SIZE 16
+static const char parameter_magic_string[4] = {'@', '!', '#', '\xFF'};
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
 
@@ -137,12 +137,6 @@ struct d3dx_technique
     struct IDirect3DStateBlock9 *saved_state;
 };
 
-struct param_table
-{
-    struct d3dx_parameter **table;
-    unsigned int count, size;
-};
-
 struct d3dx9_base_effect
 {
     struct ID3DXEffectImpl *effect;
@@ -154,8 +148,6 @@ struct d3dx9_base_effect
     struct d3dx_parameter *parameters;
     struct d3dx_technique *techniques;
     struct d3dx_object *objects;
-
-    struct param_table param_table;
 };
 
 struct ID3DXEffectImpl
@@ -419,17 +411,17 @@ static void skip_dword_unknown(const char **ptr, unsigned int count)
 
 static inline D3DXHANDLE get_parameter_handle(struct d3dx_parameter *parameter)
 {
-    return parameter ? parameter->handle : NULL;
+    return (D3DXHANDLE)parameter;
 }
 
 static inline D3DXHANDLE get_technique_handle(struct d3dx_technique *technique)
 {
-    return (D3DXHANDLE) technique;
+    return (D3DXHANDLE)technique;
 }
 
 static inline D3DXHANDLE get_pass_handle(struct d3dx_pass *pass)
 {
-    return (D3DXHANDLE) pass;
+    return (D3DXHANDLE)pass;
 }
 
 static struct d3dx_technique *get_technique_by_name(struct d3dx9_base_effect *base, const char *name)
@@ -480,10 +472,11 @@ static struct d3dx_pass *get_valid_pass(struct d3dx9_base_effect *base, D3DXHAND
 
 static struct d3dx_parameter *get_valid_parameter(struct d3dx9_base_effect *base, D3DXHANDLE parameter)
 {
-    struct d3dx_parameter **handle_param = (struct d3dx_parameter **)parameter;
+    struct d3dx_parameter *handle_param = (struct d3dx_parameter *)parameter;
 
-    if (handle_param >= base->param_table.table && handle_param < base->param_table.table + base->param_table.count)
-        return *handle_param;
+    if (handle_param && !strncmp(handle_param->magic_string, parameter_magic_string,
+            sizeof(parameter_magic_string)))
+        return handle_param;
 
     return get_parameter_by_name(base, NULL, parameter);
 }
@@ -655,8 +648,6 @@ static void d3dx9_base_effect_cleanup(struct d3dx9_base_effect *base)
 
     TRACE("base %p.\n", base);
 
-    HeapFree(GetProcessHeap(), 0, base->param_table.table);
-
     if (base->parameters)
     {
         for (i = 0; i < base->parameter_count; ++i)
@@ -2573,7 +2564,7 @@ static HRESULT d3dx9_get_param_value_ptr(struct ID3DXEffectImpl *effect, struct
         {
             unsigned int array_idx;
             static const struct d3dx_parameter array_idx_param =
-                {NULL, NULL, NULL, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 0, 0, 0, 0, sizeof(array_idx)};
+                {"", NULL, NULL, NULL, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 0, 0, 0, 0, sizeof(array_idx)};
             HRESULT hr;
             struct d3dx_parameter *ref_param, *selected_param;
 
@@ -5077,59 +5068,9 @@ static HRESULT d3dx9_copy_data(struct d3dx9_base_effect *base, unsigned int obje
     return D3D_OK;
 }
 
-static void add_param_to_table(struct d3dx9_base_effect *base, struct d3dx_parameter *param)
+static void param_set_magic_number(struct d3dx_parameter *param)
 {
-    struct param_table *table = &base->param_table;
-
-    if (table->count >= table->size)
-    {
-        unsigned int new_size;
-        struct d3dx_parameter **new_alloc;
-
-        if (!table->size)
-        {
-            new_size = INITIAL_PARAM_TABLE_SIZE;
-            new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*table->table) * new_size);
-            if (!new_alloc)
-            {
-                ERR("Out of memory.\n");
-                return;
-            }
-        }
-        else
-        {
-            new_size = table->size * 2;
-            new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * new_size);
-            if (!new_alloc)
-            {
-                ERR("Out of memory.\n");
-                return;
-            }
-        }
-        table->table = new_alloc;
-        table->size = new_size;
-    }
-
-    table->table[table->count++] = param;
-}
-
-static void sync_param_handles(struct d3dx9_base_effect *base)
-{
-    struct param_table *table = &base->param_table;
-    struct d3dx_parameter **new_alloc;
-    unsigned int i;
-
-    if (table->count)
-    {
-        new_alloc = HeapReAlloc(GetProcessHeap(), 0, table->table, sizeof(*table->table) * table->count);
-        if (new_alloc)
-            table->table = new_alloc;
-        else
-            ERR("Out of memory.\n");
-    }
-
-    for (i = 0; i < table->count; ++i)
-        table->table[i]->handle = (D3DXHANDLE)&table->table[i];
+    memcpy(param->magic_string, parameter_magic_string, sizeof(parameter_magic_string));
 }
 
 static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct d3dx_parameter *param,
@@ -5266,7 +5207,7 @@ static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct
         {
             *ptr = save_ptr;
 
-            add_param_to_table(base, &param->members[i]);
+            param_set_magic_number(&param->members[i]);
             hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, param, flags);
             if (hr != D3D_OK)
             {
@@ -5291,7 +5232,7 @@ static HRESULT d3dx9_parse_effect_typedef(struct d3dx9_base_effect *base, struct
 
         for (i = 0; i < param->member_count; ++i)
         {
-            add_param_to_table(base, &param->members[i]);
+            param_set_magic_number(&param->members[i]);
             hr = d3dx9_parse_effect_typedef(base, &param->members[i], data, ptr, NULL, flags);
             if (hr != D3D_OK)
             {
@@ -5449,7 +5390,7 @@ static HRESULT d3dx9_parse_effect_parameter(struct d3dx9_base_effect *base, stru
 
         for (i = 0; i < param->annotation_count; ++i)
         {
-            add_param_to_table(base, &param->annotations[i]);
+            param_set_magic_number(&param->annotations[i]);
             hr = d3dx9_parse_effect_annotation(base, &param->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
@@ -5511,7 +5452,7 @@ static HRESULT d3dx9_parse_effect_pass(struct d3dx9_base_effect *base, struct d3
 
         for (i = 0; i < pass->annotation_count; ++i)
         {
-            add_param_to_table(base, &pass->annotations[i]);
+            param_set_magic_number(&pass->annotations[i]);
             hr = d3dx9_parse_effect_annotation(base, &pass->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
@@ -5607,7 +5548,7 @@ static HRESULT d3dx9_parse_effect_technique(struct d3dx9_base_effect *base, stru
 
         for (i = 0; i < technique->annotation_count; ++i)
         {
-            add_param_to_table(base, &technique->annotations[i]);
+            param_set_magic_number(&technique->annotations[i]);
             hr = d3dx9_parse_effect_annotation(base, &technique->annotations[i], data, ptr, objects);
             if (hr != D3D_OK)
             {
@@ -5972,7 +5913,7 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
 
         for (i = 0; i < base->parameter_count; ++i)
         {
-            add_param_to_table(base, &base->parameters[i]);
+            param_set_magic_number(&base->parameters[i]);
             hr = d3dx9_parse_effect_parameter(base, &base->parameters[i], data, &ptr, base->objects);
             if (hr != D3D_OK)
             {
@@ -6005,8 +5946,6 @@ static HRESULT d3dx9_parse_effect(struct d3dx9_base_effect *base, const char *da
         }
     }
 
-    sync_param_handles(base);
-
     read_dword(&ptr, &stringcount);
     TRACE("String count: %u\n", stringcount);
 
diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c
index 62da636..7c9f43f 100644
--- a/dlls/d3dx9_36/tests/effect.c
+++ b/dlls/d3dx9_36/tests/effect.c
@@ -5730,13 +5730,11 @@ static void test_cross_effect_handle(IDirect3DDevice9 *device)
     ok(!!param2, "GetParameterByName failed.\n");
 
     hr = effect2->lpVtbl->SetValue(effect2, param1, expected_ivect, sizeof(expected_ivect));
-    todo_wine
     ok(hr == D3D_OK, "Got result %#x.\n", hr);
 
     hr = effect1->lpVtbl->GetValue(effect1, param1, ivect, sizeof(ivect));
     ok(hr == D3D_OK, "Got result %#x.\n", hr);
 
-    todo_wine
     ok(!memcmp(ivect, expected_ivect, sizeof(expected_ivect)), "Vector value mismatch.\n");
 
     effect2->lpVtbl->Release(effect2);
-- 
2.9.3




More information about the wine-patches mailing list