[v3 6/6] d3dx9: imlement setting named shader constants in effect.

Paul Gofman gofmanp at gmail.com
Thu Mar 10 08:23:12 CST 2016


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
 dlls/d3dx9_36/effect.c       | 58 +++++++++++++++++++++++++++++++++++++++-----
 dlls/d3dx9_36/tests/effect.c |  5 ++--
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/dlls/d3dx9_36/effect.c b/dlls/d3dx9_36/effect.c
index d5b362b..aec656d 100644
--- a/dlls/d3dx9_36/effect.c
+++ b/dlls/d3dx9_36/effect.c
@@ -2735,7 +2735,51 @@ HRESULT d3dx_set_shader_const_state(IDirect3DDevice9 *device, enum SHADER_CONSTA
 }
 
 static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
-        struct d3dx_state *state, int parent_index)
+        struct d3dx_state *state, unsigned int parent_index);
+
+HRESULT d3dx_set_shader_const_fxlc(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
+        struct d3dx_parameter *param, unsigned int vs)
+{
+    IDirect3DDevice9 *device = effect->device;
+    HRESULT hr, ret;
+    struct d3dx_parameter **params;
+    D3DXCONSTANT_DESC *cdesc;
+    unsigned int parameters_count;
+    unsigned i, j;
+
+    if (!param->param_eval)
+    {
+        FIXME("Preshader structure is null.\n");
+        return D3DERR_INVALIDCALL;
+    }
+    hr = d3dx_param_eval_set_shader_constants(device, param->param_eval);
+    if (FAILED(hr))
+        return hr;
+    hr = d3dx_param_eval_get_shader_parameters(param->param_eval, &params, &parameters_count, &cdesc);
+    if (FAILED(hr))
+        return hr;
+    ret = D3D_OK;
+    for (i = 0; i < parameters_count; i++)
+        if (params[i] && params[i]->class == D3DXPC_OBJECT && params[i]->type == D3DXPT_SAMPLER)
+        {
+            struct d3dx_sampler *sampler;
+
+            sampler = (struct d3dx_sampler *)params[i]->data;
+            TRACE("sampler %s, register index %u, state count %u.\n", params[i]->name,
+                    cdesc[i].RegisterIndex, sampler->state_count);
+            for (j = 0; j < sampler->state_count; j++)
+            {
+                hr = d3dx9_apply_state(effect, pass, &sampler->states[j],
+                        cdesc[i].RegisterIndex + (vs ? D3DVERTEXTEXTURESAMPLER0 : 0));
+                if (FAILED(hr))
+                    ret = hr;
+            }
+        }
+    return ret;
+}
+
+static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pass *pass,
+        struct d3dx_state *state, unsigned int parent_index)
 {
     IDirect3DDevice9 *device = effect->device;
     struct d3dx_parameter *param;
@@ -2762,7 +2806,7 @@ static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pas
         {
             UINT unit;
 
-            unit = parent_index == -1 ? state->index : parent_index;
+            unit = parent_index == ~0u ? state->index : parent_index;
             TRACE("%s, unit %u, value %p.\n", state_table[state->operation].name, unit,
                     *(IDirect3DBaseTexture9 **)param_value);
             return IDirect3DDevice9_SetTexture(device, unit, *(IDirect3DBaseTexture9 **)param_value);
@@ -2793,7 +2837,7 @@ static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pas
         {
             UINT sampler;
 
-            sampler = parent_index == -1 ? state->index : parent_index;
+            sampler = parent_index == ~0u ? state->index : parent_index;
             TRACE("%s, sampler %u, value %u.\n", state_table[state->operation].name, sampler, *(DWORD *)param_value);
             return IDirect3DDevice9_SetSamplerState(device, sampler, state_table[state->operation].op,
                     *(DWORD *)param_value);
@@ -2803,14 +2847,16 @@ static HRESULT d3dx9_apply_state(struct ID3DXEffectImpl *effect, struct d3dx_pas
             hr = IDirect3DDevice9_SetVertexShader(device, *(IDirect3DVertexShader9 **)param_value);
             if (FAILED(hr))
                 ERR("Could not set vertex shader, hr %#x.\n", hr);
-            FIXME("Not executing preshader and not setting constants.\n");
+            else if (*(IDirect3DVertexShader9 **)param_value)
+                hr = d3dx_set_shader_const_fxlc(effect, pass, param, 1);
             return hr;
         case SC_PIXELSHADER:
             TRACE("%s, shader %p.\n", state_table[state->operation].name, *(IDirect3DPixelShader9 **)param_value);
             hr = IDirect3DDevice9_SetPixelShader(device, *(IDirect3DPixelShader9 **)param_value);
             if (FAILED(hr))
                 ERR("Could not set pixel shader, hr %#x.\n", hr);
-            FIXME("Not executing preshader and not setting constants.\n");
+            else if (*(IDirect3DPixelShader9 **)param_value)
+                hr = d3dx_set_shader_const_fxlc(effect, pass, param, 0);
             return hr;
         case SC_TRANSFORM:
             TRACE("%s, state %u.\n", state_table[state->operation].name, state->index);
@@ -2876,7 +2922,7 @@ static HRESULT d3dx9_apply_pass_states(struct ID3DXEffectImpl *effect, struct d3
     {
         HRESULT hr;
 
-        hr = d3dx9_apply_state(effect, pass, &pass->states[i], -1);
+        hr = d3dx9_apply_state(effect, pass, &pass->states[i], ~0u);
         if (FAILED(hr))
         {
             WARN("Error applying state, hr %#x.\n", hr);
diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c
index b4b9154..bc3bd46 100644
--- a/dlls/d3dx9_36/tests/effect.c
+++ b/dlls/d3dx9_36/tests/effect.c
@@ -3688,17 +3688,16 @@ static void test_effect_preshader(IDirect3DDevice9 *device)
 
     hr = IDirect3DDevice9_GetVertexShaderConstantF(device, 0, (float *)fdata, TEST_EFFECT_PRES_NFLOATV);
     ok(hr == D3D_OK, "Got result %#x.\n", hr);
-    todo_wine ok(!memcmp(fdata, test_effect_preshader_fconstsv, sizeof(test_effect_preshader_fconstsv)),
+    ok(!memcmp(fdata, test_effect_preshader_fconstsv, sizeof(test_effect_preshader_fconstsv)),
             "Vertex shader float constants do not match.\n");
     hr = IDirect3DDevice9_GetPixelShaderConstantF(device, 0, (float *)fdata, TEST_EFFECT_PRES_NFLOATP);
     ok(hr == D3D_OK, "Got result %#x.\n", hr);
-    todo_wine ok(!memcmp(fdata, test_effect_preshader_fconstsp, sizeof(test_effect_preshader_fconstsp)),
+    ok(!memcmp(fdata, test_effect_preshader_fconstsp, sizeof(test_effect_preshader_fconstsp)),
             "Pixel shader float constants do not match.\n");
 
     hr = IDirect3DDevice9_GetPixelShaderConstantB(device, 0, bdata, TEST_EFFECT_PRES_NBOOL);
     ok(hr == D3D_OK, "Got result %#x.\n", hr);
     for (i = 0; i < TEST_EFFECT_PRES_NBOOL; i++)
-        todo_wine_if(!bdata[i] != !test_effect_preshader_bconsts[i])
         ok(!bdata[i] == !test_effect_preshader_bconsts[i],
                 "Pixel shader boolean constants do not match.\n");
 
-- 
2.5.0




More information about the wine-patches mailing list