[PATCH 1/5] d3d10: Implement D3D10StateBlockMaskEnableCapture().

Henri Verbeet hverbeet at codeweavers.com
Wed Nov 16 13:08:03 CST 2011


---
 dlls/d3d10/d3d10.spec     |    2 +-
 dlls/d3d10/stateblock.c   |  106 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/d3d10/tests/device.c |   58 +++++++++++++++++--------
 include/d3d10effect.h     |    2 +
 4 files changed, 149 insertions(+), 19 deletions(-)

diff --git a/dlls/d3d10/d3d10.spec b/dlls/d3d10/d3d10.spec
index 865ded5..b507d6d 100644
--- a/dlls/d3d10/d3d10.spec
+++ b/dlls/d3d10/d3d10.spec
@@ -23,7 +23,7 @@
 @ stdcall D3D10StateBlockMaskDisableAll(ptr)
 @ stdcall D3D10StateBlockMaskDisableCapture(ptr long long long)
 @ stdcall D3D10StateBlockMaskEnableAll(ptr)
-@ stub D3D10StateBlockMaskEnableCapture
+@ stdcall D3D10StateBlockMaskEnableCapture(ptr long long long)
 @ stub D3D10StateBlockMaskGetSetting
 @ stub D3D10StateBlockMaskIntersect
 @ stub D3D10StateBlockMaskUnion
diff --git a/dlls/d3d10/stateblock.c b/dlls/d3d10/stateblock.c
index 7fd2aa2..0dae718 100644
--- a/dlls/d3d10/stateblock.c
+++ b/dlls/d3d10/stateblock.c
@@ -144,6 +144,37 @@ HRESULT WINAPI D3D10CreateStateBlock(ID3D10Device *device,
     return S_OK;
 }
 
+static HRESULT stateblock_mask_set_bits(BYTE *field, UINT field_size, UINT start_bit, UINT count)
+{
+    UINT end_bit = start_bit + count;
+    BYTE start_mask = 0xff << (start_bit & 7);
+    BYTE end_mask = 0x7f >> (~end_bit & 7);
+    UINT start_idx = start_bit >> 3;
+    UINT end_idx = end_bit >> 3;
+
+    if (start_bit >= field_size || field_size - start_bit < count)
+        return E_INVALIDARG;
+
+    if (start_idx == end_idx)
+    {
+        field[start_idx] |= start_mask & end_mask;
+        return S_OK;
+    }
+
+    if (start_bit & 7)
+    {
+        field[start_idx] |= start_mask;
+        ++start_idx;
+    }
+
+    memset(&field[start_idx], 0xff, end_idx - start_idx);
+
+    if (end_bit & 7)
+        field[end_idx] |= end_mask;
+
+    return S_OK;
+}
+
 static HRESULT stateblock_mask_clear_bits(BYTE *field, UINT field_size, UINT start_bit, UINT count)
 {
     UINT end_bit = start_bit + count;
@@ -296,3 +327,78 @@ HRESULT WINAPI D3D10StateBlockMaskEnableAll(D3D10_STATE_BLOCK_MASK *mask)
 
     return S_OK;
 }
+
+HRESULT WINAPI D3D10StateBlockMaskEnableCapture(D3D10_STATE_BLOCK_MASK *mask,
+        D3D10_DEVICE_STATE_TYPES state_type, UINT start_idx, UINT count)
+{
+    TRACE("mask %p state_type %s, start_idx %u, count %u.\n",
+            mask, debug_d3d10_device_state_types(state_type), start_idx, count);
+
+    if (!mask)
+        return E_INVALIDARG;
+
+    switch (state_type)
+    {
+        case D3D10_DST_SO_BUFFERS:
+            return stateblock_mask_set_bits(&mask->SOBuffers, 1, start_idx, count);
+        case D3D10_DST_OM_RENDER_TARGETS:
+            return stateblock_mask_set_bits(&mask->OMRenderTargets, 1, start_idx, count);
+        case D3D10_DST_DEPTH_STENCIL_STATE:
+            return stateblock_mask_set_bits(&mask->OMDepthStencilState, 1, start_idx, count);
+        case D3D10_DST_BLEND_STATE:
+            return stateblock_mask_set_bits(&mask->OMBlendState, 1, start_idx, count);
+        case D3D10_DST_VS:
+            return stateblock_mask_set_bits(&mask->VS, 1, start_idx, count);
+        case D3D10_DST_VS_SAMPLERS:
+            return stateblock_mask_set_bits(mask->VSSamplers,
+                    D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_VS_SHADER_RESOURCES:
+            return stateblock_mask_set_bits(mask->VSShaderResources,
+                    D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_VS_CONSTANT_BUFFERS:
+            return stateblock_mask_set_bits(mask->VSConstantBuffers,
+                    D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_GS:
+            return stateblock_mask_set_bits(&mask->GS, 1, start_idx, count);
+        case D3D10_DST_GS_SAMPLERS:
+            return stateblock_mask_set_bits(mask->GSSamplers,
+                    D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_GS_SHADER_RESOURCES:
+            return stateblock_mask_set_bits(mask->GSShaderResources,
+                    D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_GS_CONSTANT_BUFFERS:
+            return stateblock_mask_set_bits(mask->GSConstantBuffers,
+                    D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_PS:
+            return stateblock_mask_set_bits(&mask->PS, 1, start_idx, count);
+        case D3D10_DST_PS_SAMPLERS:
+            return stateblock_mask_set_bits(mask->PSSamplers,
+                    D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_PS_SHADER_RESOURCES:
+            return stateblock_mask_set_bits(mask->PSShaderResources,
+                    D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_PS_CONSTANT_BUFFERS:
+            return stateblock_mask_set_bits(mask->PSConstantBuffers,
+                    D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_IA_VERTEX_BUFFERS:
+            return stateblock_mask_set_bits(mask->IAVertexBuffers,
+                    D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, start_idx, count);
+        case D3D10_DST_IA_INDEX_BUFFER:
+            return stateblock_mask_set_bits(&mask->IAIndexBuffer, 1, start_idx, count);
+        case D3D10_DST_IA_INPUT_LAYOUT:
+            return stateblock_mask_set_bits(&mask->IAInputLayout, 1, start_idx, count);
+        case D3D10_DST_IA_PRIMITIVE_TOPOLOGY:
+            return stateblock_mask_set_bits(&mask->IAPrimitiveTopology, 1, start_idx, count);
+        case D3D10_DST_RS_VIEWPORTS:
+            return stateblock_mask_set_bits(&mask->RSViewports, 1, start_idx, count);
+        case D3D10_DST_RS_SCISSOR_RECTS:
+            return stateblock_mask_set_bits(&mask->RSScissorRects, 1, start_idx, count);
+        case D3D10_DST_RS_RASTERIZER_STATE:
+            return stateblock_mask_set_bits(&mask->RSRasterizerState, 1, start_idx, count);
+        case D3D10_DST_PREDICATION:
+            return stateblock_mask_set_bits(&mask->Predication, 1, start_idx, count);
+        default:
+            FIXME("Unhandled state_type %#x.\n", state_type);
+            return E_INVALIDARG;
+    }
+}
diff --git a/dlls/d3d10/tests/device.c b/dlls/d3d10/tests/device.c
index 894fd1d..fd7a6a2 100644
--- a/dlls/d3d10/tests/device.c
+++ b/dlls/d3d10/tests/device.c
@@ -70,26 +70,27 @@ static void test_stateblock_mask(void)
     {
         UINT start_idx;
         UINT count;
-        BYTE expected[5];
+        BYTE expected_disable[5];
+        BYTE expected_enable[5];
     }
     capture_test[] =
     {
-        { 8,  4, {0xff, 0xf0, 0xff, 0xff, 0xff}},
-        { 9,  4, {0xff, 0xe1, 0xff, 0xff, 0xff}},
-        {10,  4, {0xff, 0xc3, 0xff, 0xff, 0xff}},
-        {11,  4, {0xff, 0x87, 0xff, 0xff, 0xff}},
-        {12,  4, {0xff, 0x0f, 0xff, 0xff, 0xff}},
-        {13,  4, {0xff, 0x1f, 0xfe, 0xff, 0xff}},
-        {14,  4, {0xff, 0x3f, 0xfc, 0xff, 0xff}},
-        {15,  4, {0xff, 0x7f, 0xf8, 0xff, 0xff}},
-        { 8, 12, {0xff, 0x00, 0xf0, 0xff, 0xff}},
-        { 9, 12, {0xff, 0x01, 0xe0, 0xff, 0xff}},
-        {10, 12, {0xff, 0x03, 0xc0, 0xff, 0xff}},
-        {11, 12, {0xff, 0x07, 0x80, 0xff, 0xff}},
-        {12, 12, {0xff, 0x0f, 0x00, 0xff, 0xff}},
-        {13, 12, {0xff, 0x1f, 0x00, 0xfe, 0xff}},
-        {14, 12, {0xff, 0x3f, 0x00, 0xfc, 0xff}},
-        {15, 12, {0xff, 0x7f, 0x00, 0xf8, 0xff}},
+        { 8,  4, {0xff, 0xf0, 0xff, 0xff, 0xff}, {0x00, 0x0f, 0x00, 0x00, 0x00}},
+        { 9,  4, {0xff, 0xe1, 0xff, 0xff, 0xff}, {0x00, 0x1e, 0x00, 0x00, 0x00}},
+        {10,  4, {0xff, 0xc3, 0xff, 0xff, 0xff}, {0x00, 0x3c, 0x00, 0x00, 0x00}},
+        {11,  4, {0xff, 0x87, 0xff, 0xff, 0xff}, {0x00, 0x78, 0x00, 0x00, 0x00}},
+        {12,  4, {0xff, 0x0f, 0xff, 0xff, 0xff}, {0x00, 0xf0, 0x00, 0x00, 0x00}},
+        {13,  4, {0xff, 0x1f, 0xfe, 0xff, 0xff}, {0x00, 0xe0, 0x01, 0x00, 0x00}},
+        {14,  4, {0xff, 0x3f, 0xfc, 0xff, 0xff}, {0x00, 0xc0, 0x03, 0x00, 0x00}},
+        {15,  4, {0xff, 0x7f, 0xf8, 0xff, 0xff}, {0x00, 0x80, 0x07, 0x00, 0x00}},
+        { 8, 12, {0xff, 0x00, 0xf0, 0xff, 0xff}, {0x00, 0xff, 0x0f, 0x00, 0x00}},
+        { 9, 12, {0xff, 0x01, 0xe0, 0xff, 0xff}, {0x00, 0xfe, 0x1f, 0x00, 0x00}},
+        {10, 12, {0xff, 0x03, 0xc0, 0xff, 0xff}, {0x00, 0xfc, 0x3f, 0x00, 0x00}},
+        {11, 12, {0xff, 0x07, 0x80, 0xff, 0xff}, {0x00, 0xf8, 0x7f, 0x00, 0x00}},
+        {12, 12, {0xff, 0x0f, 0x00, 0xff, 0xff}, {0x00, 0xf0, 0xff, 0x00, 0x00}},
+        {13, 12, {0xff, 0x1f, 0x00, 0xfe, 0xff}, {0x00, 0xe0, 0xff, 0x01, 0x00}},
+        {14, 12, {0xff, 0x3f, 0x00, 0xfc, 0xff}, {0x00, 0xc0, 0xff, 0x03, 0x00}},
+        {15, 12, {0xff, 0x7f, 0x00, 0xf8, 0xff}, {0x00, 0x80, 0xff, 0x07, 0x00}},
     };
     D3D10_STATE_BLOCK_MASK mask_x, mask_y, result;
     HRESULT hr;
@@ -141,6 +142,16 @@ static void test_stateblock_mask(void)
     ok(hr == E_INVALIDARG, "Got unexpect hr %#x.\n", hr);
     hr = D3D10StateBlockMaskDisableCapture(NULL, D3D10_DST_VS, 0, 1);
     ok(hr == E_INVALIDARG, "Got unexpect hr %#x.\n", hr);
+    result.VS = 0;
+    hr = D3D10StateBlockMaskEnableCapture(&result, D3D10_DST_VS, 0, 1);
+    ok(SUCCEEDED(hr), "D3D10StateBlockMaskEnableCapture failed, hr %#x.\n", hr);
+    ok(result.VS == 0x01, "Got unexpected result.VS %#x.\n", result.VS);
+    hr = D3D10StateBlockMaskEnableCapture(&result, D3D10_DST_VS, 0, 4);
+    ok(hr == E_INVALIDARG, "Got unexpect hr %#x.\n", hr);
+    hr = D3D10StateBlockMaskEnableCapture(&result, D3D10_DST_VS, 1, 1);
+    ok(hr == E_INVALIDARG, "Got unexpect hr %#x.\n", hr);
+    hr = D3D10StateBlockMaskEnableCapture(NULL, D3D10_DST_VS, 0, 1);
+    ok(hr == E_INVALIDARG, "Got unexpect hr %#x.\n", hr);
     for (i = 0; i < sizeof(capture_test) / sizeof(*capture_test); ++i)
     {
         memset(&result, 0xff, sizeof(result));
@@ -148,7 +159,18 @@ static void test_stateblock_mask(void)
                 capture_test[i].start_idx, capture_test[i].count);
         ok(SUCCEEDED(hr), "D3D10StateBlockMaskDisableCapture failed, hr %#x.\n", hr);
 
-        ok(!memcmp(result.VSShaderResources, capture_test[i].expected, 5),
+        ok(!memcmp(result.VSShaderResources, capture_test[i].expected_disable, 5),
+                "Got unexpect result.VSShaderResources[0..4] {%#x, %#x, %#x, %#x, %#x} for test %u.\n",
+                result.VSShaderResources[0], result.VSShaderResources[1],
+                result.VSShaderResources[2], result.VSShaderResources[3],
+                result.VSShaderResources[4], i);
+
+        memset(&result, 0, sizeof(result));
+        hr = D3D10StateBlockMaskEnableCapture(&result, D3D10_DST_VS_SHADER_RESOURCES,
+                capture_test[i].start_idx, capture_test[i].count);
+        ok(SUCCEEDED(hr), "D3D10StateBlockMaskEnableCapture failed, hr %#x.\n", hr);
+
+        ok(!memcmp(result.VSShaderResources, capture_test[i].expected_enable, 5),
                 "Got unexpect result.VSShaderResources[0..4] {%#x, %#x, %#x, %#x, %#x} for test %u.\n",
                 result.VSShaderResources[0], result.VSShaderResources[1],
                 result.VSShaderResources[2], result.VSShaderResources[3],
diff --git a/include/d3d10effect.h b/include/d3d10effect.h
index 697d1c4..d9f2f5e 100644
--- a/include/d3d10effect.h
+++ b/include/d3d10effect.h
@@ -838,6 +838,8 @@ HRESULT WINAPI D3D10StateBlockMaskDisableAll(D3D10_STATE_BLOCK_MASK *mask);
 HRESULT WINAPI D3D10StateBlockMaskDisableCapture(D3D10_STATE_BLOCK_MASK *mask,
         D3D10_DEVICE_STATE_TYPES state_type, UINT start_idx, UINT count);
 HRESULT WINAPI D3D10StateBlockMaskEnableAll(D3D10_STATE_BLOCK_MASK *mask);
+HRESULT WINAPI D3D10StateBlockMaskEnableCapture(D3D10_STATE_BLOCK_MASK *mask,
+        D3D10_DEVICE_STATE_TYPES state_type, UINT start_idx, UINT count);
 
 #ifdef __cplusplus
 }
-- 
1.7.3.4




More information about the wine-patches mailing list