Signed-off-by: Paul Gofman gofmanp@gmail.com --- v2: - added test for applying block during recording; - also update current parameter on parameter block application.
dlls/d3dx9_36/effect.c | 25 ++++++++++++++-- dlls/d3dx9_36/tests/effect.c | 58 ++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 15 deletions(-)
diff --git a/dlls/d3dx9_36/effect.c b/dlls/d3dx9_36/effect.c index 746f1eb9ed..fc43cdd918 100644 --- a/dlls/d3dx9_36/effect.c +++ b/dlls/d3dx9_36/effect.c @@ -153,6 +153,7 @@ struct d3dx_technique struct d3dx_parameter_block { char magic_string[ARRAY_SIZE(parameter_block_magic_string)]; + struct d3dx_effect *effect; struct list entry; size_t buffer_size; size_t current_size; @@ -4223,6 +4224,7 @@ static HRESULT WINAPI d3dx_effect_BeginParameterBlock(ID3DXEffect *iface) effect->current_parameter_block = heap_alloc_zero(sizeof(*effect->current_parameter_block)); memcpy(effect->current_parameter_block->magic_string, parameter_block_magic_string, sizeof(parameter_block_magic_string)); + effect->current_parameter_block->effect = effect;
return D3D_OK; } @@ -4251,11 +4253,28 @@ static D3DXHANDLE WINAPI d3dx_effect_EndParameterBlock(ID3DXEffect *iface)
static HRESULT WINAPI d3dx_effect_ApplyParameterBlock(ID3DXEffect *iface, D3DXHANDLE parameter_block) { - struct d3dx_effect *This = impl_from_ID3DXEffect(iface); + struct d3dx_parameter_block *block = get_valid_parameter_block(parameter_block); + struct d3dx_recorded_parameter *record;
- FIXME("(%p)->(%p): stub\n", This, parameter_block); + TRACE("iface %p, paramater_block %p.\n", iface, parameter_block);
- return E_NOTIMPL; + if (!block || !block->current_size) + return D3DERR_INVALIDCALL; + + record = (struct d3dx_recorded_parameter *)block->buffer; + while ((BYTE *)record < block->buffer + block->current_size) + { + set_value(record->param, record + 1, record->bytes, record->param->data); + if (block->effect->current_parameter_block) + set_value(record->param, record + 1, record->bytes, + record_parameter(block->effect, record->param, record->bytes)); + + set_dirty(record->param); + + record = (struct d3dx_recorded_parameter *)((BYTE *)record + get_recorded_parameter_size(record)); + } + assert((BYTE *)record == block->buffer + block->current_size); + return D3D_OK; }
#if D3DX_SDK_VERSION >= 26 diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c index d86ae2acb5..316d874a69 100644 --- a/dlls/d3dx9_36/tests/effect.c +++ b/dlls/d3dx9_36/tests/effect.c @@ -8079,7 +8079,7 @@ static void test_effect_parameter_block(void) ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
hr = effect->lpVtbl->ApplyParameterBlock(effect, block); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); hr = effect->lpVtbl->DeleteParameterBlock(effect, block); ok(hr == D3D_OK, "Got result %#x.\n", hr);
@@ -8092,7 +8092,7 @@ static void test_effect_parameter_block(void) block = effect->lpVtbl->EndParameterBlock(effect); ok(!!block, "Got unexpected block %p.\n", block); hr = effect->lpVtbl->ApplyParameterBlock(effect, block); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = effect->lpVtbl->DeleteParameterBlock(effect2, block); ok(hr == D3DERR_INVALIDCALL, "Got result %#x.\n", hr); @@ -8100,7 +8100,7 @@ static void test_effect_parameter_block(void) ok(hr == D3D_OK, "Got result %#x.\n", hr);
hr = effect->lpVtbl->ApplyParameterBlock(effect, "parameter_block"); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture); ok(hr == D3D_OK, "Got result %#x, expected 0 (D3D_OK).\n", hr); @@ -8187,14 +8187,14 @@ static void test_effect_parameter_block(void) ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = effect->lpVtbl->ApplyParameterBlock(effect, block); - todo_wine ok(hr == D3D_OK, "Got result %#x.\n", hr); + ok(hr == D3D_OK, "Got result %#x.\n", hr);
IDirect3DTexture9_AddRef(texture); refcount = IDirect3DTexture9_Release(texture); - todo_wine ok(refcount == 3, "Got unexpected refcount %u.\n", refcount); + ok(refcount == 3, "Got unexpected refcount %u.\n", refcount);
hr = effect->lpVtbl->GetFloat(effect, "arr2[0]", &float_value); - todo_wine ok(hr == D3D_OK && float_value == 92.0f, "Got unexpected hr %#x, float_value %g.\n", hr, float_value); + ok(hr == D3D_OK && float_value == 92.0f, "Got unexpected hr %#x, float_value %g.\n", hr, float_value); hr = effect->lpVtbl->GetFloat(effect, "arr2[1]", &float_value); ok(hr == D3D_OK && float_value == 0.0f, "Got unexpected hr %#x, float_value %g.\n", hr, float_value);
@@ -8205,16 +8205,16 @@ static void test_effect_parameter_block(void)
hr = effect->lpVtbl->GetMatrix(effect, "m3x2row", &mat); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - todo_wine ok(!memcmp(&mat, &test_mat, sizeof(mat)), "Got unexpected matrix.\n"); + ok(!memcmp(&mat, &test_mat, sizeof(mat)), "Got unexpected matrix.\n"); hr = effect->lpVtbl->GetMatrix(effect, "m3x2column", &mat); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - todo_wine ok(!memcmp(&mat, &test_mat, sizeof(mat)), "Got unexpected matrix.\n"); + ok(!memcmp(&mat, &test_mat, sizeof(mat)), "Got unexpected matrix.\n");
hr = effect->lpVtbl->GetFloat(effect, "ts1[0].fv", &float_value); - todo_wine ok(hr == D3D_OK && float_value == 28.0f, "Got unexpected hr %#x, float_value %g.\n", hr, float_value); + ok(hr == D3D_OK && float_value == 28.0f, "Got unexpected hr %#x, float_value %g.\n", hr, float_value);
hr = effect->lpVtbl->GetFloatArray(effect, "ts1[0].v2", float_array, 4); - todo_wine ok(hr == D3D_OK && float_array[0] == -29.0f + ok(hr == D3D_OK && float_array[0] == -29.0f && !memcmp(float_array + 1, float_array_zero, 3 * sizeof(*float_array)), "Got unexpected hr %#x, ts1[0].v2 (%g, %g, %g, %g).\n", hr, float_array[0], float_array[1], float_array[2], float_array[3]); @@ -8250,11 +8250,45 @@ static void test_effect_parameter_block(void) hr = effect->lpVtbl->SetMatrixArray(effect, "f33_2", mat_arr, 2); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = effect->lpVtbl->ApplyParameterBlock(effect, block); - todo_wine ok(hr == D3D_OK, "Got result %#x.\n", hr); + ok(hr == D3D_OK, "Got result %#x.\n", hr); + + hr = effect->lpVtbl->GetMatrixArray(effect, "f33_2", mat_arr, 2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(!memcmp(&mat_arr[0], &test_mat, sizeof(test_mat)) + && !memcmp(&mat_arr[1], &test_mat, sizeof(test_mat)), "Got unexpected matrix array.\n"); + + hr = effect->lpVtbl->BeginParameterBlock(effect); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + memset(mat_arr, 0, sizeof(mat_arr)); + hr = effect->lpVtbl->SetMatrixArray(effect, "f33_2", mat_arr, 2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + /* Applying a block while recording another one puts the data both + * to parameter and a new block. */ + hr = effect->lpVtbl->ApplyParameterBlock(effect, block); + ok(hr == D3D_OK, "Got result %#x.\n", hr); + + hr = effect->lpVtbl->GetMatrixArray(effect, "f33_2", mat_arr, 2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(!memcmp(&mat_arr[0], &test_mat, sizeof(test_mat)) + && !memcmp(&mat_arr[1], &test_mat, sizeof(test_mat)), "Got unexpected matrix array.\n"); + + hr = effect->lpVtbl->DeleteParameterBlock(effect, block); + ok(hr == D3D_OK, "Got result %#x.\n", hr); + block = effect->lpVtbl->EndParameterBlock(effect); + ok(!!block, "Got unexpected block %p.\n", block); + + memset(mat_arr, 0, sizeof(mat_arr)); + hr = effect->lpVtbl->SetMatrixArray(effect, "f33_2", mat_arr, 2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + hr = effect->lpVtbl->ApplyParameterBlock(effect, block); + ok(hr == D3D_OK, "Got result %#x.\n", hr);
hr = effect->lpVtbl->GetMatrixArray(effect, "f33_2", mat_arr, 2); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - todo_wine ok(!memcmp(&mat_arr[0], &test_mat, sizeof(test_mat)) + ok(!memcmp(&mat_arr[0], &test_mat, sizeof(test_mat)) && !memcmp(&mat_arr[1], &test_mat, sizeof(test_mat)), "Got unexpected matrix array.\n");
refcount = effect->lpVtbl->Release(effect);