[PATCH 4/5] wined3d: Add support for initial UAV counters values.

Józef Kucia jkucia at codeweavers.com
Fri Aug 4 12:53:50 CDT 2017


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/d3d11/device.c            | 23 ++++++-----------------
 dlls/d3d11/tests/d3d11.c       | 10 +++++-----
 dlls/wined3d/cs.c              |  7 ++++++-
 dlls/wined3d/device.c          | 19 ++++++++++---------
 dlls/wined3d/view.c            | 17 +++++++++++++++++
 dlls/wined3d/wined3d.spec      |  4 ++--
 dlls/wined3d/wined3d_private.h |  5 ++++-
 include/wine/wined3d.h         |  4 ++--
 8 files changed, 52 insertions(+), 37 deletions(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 3fea1bb8c1..0f268dfed2 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -661,27 +661,21 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnord
         wined3d_mutex_lock();
         for (i = 0; i < unordered_access_view_start_slot; ++i)
         {
-            wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
+            wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL, ~0u);
         }
         for (i = 0; i < unordered_access_view_count; ++i)
         {
             struct d3d11_unordered_access_view *view
                     = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
 
-        if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
-                && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
-                && initial_counts[i] != ~(UINT)0)
-            FIXME("Ignoring initial count %u for slot %u.\n",
-                    initial_counts[i], unordered_access_view_start_slot + i);
-
             wined3d_device_set_unordered_access_view(device->wined3d_device,
                     unordered_access_view_start_slot + i,
-                    view ? view->wined3d_view : NULL);
+                    view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
         }
         for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
         {
             wined3d_device_set_unordered_access_view(device->wined3d_device,
-                    unordered_access_view_start_slot + i, NULL);
+                    unordered_access_view_start_slot + i, NULL, ~0u);
         }
         wined3d_mutex_unlock();
     }
@@ -1333,13 +1327,8 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(
     {
         struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
 
-        if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
-                && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
-                && initial_counts[i] != ~(UINT)0)
-            FIXME("Ignoring initial count %u for slot %u.\n", initial_counts[i], start_slot + i);
-
         wined3d_device_set_cs_uav(device->wined3d_device, start_slot + i,
-                view ? view->wined3d_view : NULL);
+                view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
     }
     wined3d_mutex_unlock();
 }
@@ -2481,8 +2470,8 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceCon
     wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
     for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
     {
-        wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
-        wined3d_device_set_cs_uav(device->wined3d_device, i, NULL);
+        wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL, ~0u);
+        wined3d_device_set_cs_uav(device->wined3d_device, i, NULL, ~0u);
     }
     ID3D11DeviceContext_OMSetDepthStencilState(iface, NULL, 0);
     ID3D11DeviceContext_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 73269ed97f..3ee36c9285 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -17971,7 +17971,7 @@ static void test_uav_counters(void)
     data = 8;
     ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
     data = read_uav_counter(context, staging_buffer, uav);
-    todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
+    ok(data == 8, "Got unexpected value %u.\n", data);
 
     ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
     data = 0;
@@ -18019,20 +18019,20 @@ static void test_uav_counters(void)
     data = 8;
     ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
     data = read_uav_counter(context, staging_buffer, uav);
-    todo_wine ok(data == 8, "Got unexpected value %u.\n", data);
+    ok(data == 8, "Got unexpected value %u.\n", data);
 
     /* consume */
     ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
     data = read_uav_counter(context, staging_buffer, uav);
-    todo_wine ok(data == 4, "Got unexpected value %u.\n", data);
+    ok(data == 4, "Got unexpected value %u.\n", data);
     ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
     data = read_uav_counter(context, staging_buffer, uav);
-    todo_wine ok(!data, "Got unexpected value %u.\n", data);
+    ok(!data, "Got unexpected value %u.\n", data);
     get_buffer_readback(buffer2, &rb);
     for (i = 0; i < 8; ++i)
     {
         data = get_readback_color(&rb, i, 0);
-        todo_wine ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
+        ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
     }
     release_resource_readback(&rb);
 
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 307cb577c9..bc1bf17c10 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -244,6 +244,7 @@ struct wined3d_cs_set_unordered_access_view
     enum wined3d_pipeline pipeline;
     unsigned int view_idx;
     struct wined3d_unordered_access_view *view;
+    unsigned int initial_count;
 };
 
 struct wined3d_cs_set_sampler
@@ -1293,10 +1294,13 @@ static void wined3d_cs_exec_set_unordered_access_view(struct wined3d_cs *cs, con
         InterlockedDecrement(&prev->resource->bind_count);
 
     device_invalidate_state(cs->device, STATE_UNORDERED_ACCESS_VIEW_BINDING(op->pipeline));
+
+    if (op->initial_count != ~0u)
+        wined3d_unordered_access_view_set_counter(op->view, op->initial_count);
 }
 
 void wined3d_cs_emit_set_unordered_access_view(struct wined3d_cs *cs, enum wined3d_pipeline pipeline,
-        unsigned int view_idx, struct wined3d_unordered_access_view *view)
+        unsigned int view_idx, struct wined3d_unordered_access_view *view, unsigned int initial_count)
 {
     struct wined3d_cs_set_unordered_access_view *op;
 
@@ -1305,6 +1309,7 @@ void wined3d_cs_emit_set_unordered_access_view(struct wined3d_cs *cs, enum wined
     op->pipeline = pipeline;
     op->view_idx = view_idx;
     op->view = view;
+    op->initial_count = initial_count;
 
     cs->ops->submit(cs, WINED3D_CS_QUEUE_DEFAULT);
 }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 18e1b010f0..30e7fbed02 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2950,7 +2950,8 @@ struct wined3d_sampler * CDECL wined3d_device_get_cs_sampler(const struct wined3
 }
 
 static void wined3d_device_set_pipeline_unordered_access_view(struct wined3d_device *device,
-        enum wined3d_pipeline pipeline, unsigned int idx, struct wined3d_unordered_access_view *uav)
+        enum wined3d_pipeline pipeline, unsigned int idx, struct wined3d_unordered_access_view *uav,
+        unsigned int initial_count)
 {
     struct wined3d_unordered_access_view *prev;
 
@@ -2961,14 +2962,14 @@ static void wined3d_device_set_pipeline_unordered_access_view(struct wined3d_dev
     }
 
     prev = device->update_state->unordered_access_view[pipeline][idx];
-    if (uav == prev)
+    if (uav == prev && initial_count == ~0u)
         return;
 
     if (uav)
         wined3d_unordered_access_view_incref(uav);
     device->update_state->unordered_access_view[pipeline][idx] = uav;
     if (!device->recording)
-        wined3d_cs_emit_set_unordered_access_view(device->cs, pipeline, idx, uav);
+        wined3d_cs_emit_set_unordered_access_view(device->cs, pipeline, idx, uav, initial_count);
     if (prev)
         wined3d_unordered_access_view_decref(prev);
 }
@@ -2986,11 +2987,11 @@ static struct wined3d_unordered_access_view *wined3d_device_get_pipeline_unorder
 }
 
 void CDECL wined3d_device_set_cs_uav(struct wined3d_device *device, unsigned int idx,
-        struct wined3d_unordered_access_view *uav)
+        struct wined3d_unordered_access_view *uav, unsigned int initial_count)
 {
-    TRACE("device %p, idx %u, uav %p.\n", device, idx, uav);
+    TRACE("device %p, idx %u, uav %p, initial_count %#x.\n", device, idx, uav, initial_count);
 
-    wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_COMPUTE, idx, uav);
+    wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_COMPUTE, idx, uav, initial_count);
 }
 
 struct wined3d_unordered_access_view * CDECL wined3d_device_get_cs_uav(const struct wined3d_device *device,
@@ -3002,11 +3003,11 @@ struct wined3d_unordered_access_view * CDECL wined3d_device_get_cs_uav(const str
 }
 
 void CDECL wined3d_device_set_unordered_access_view(struct wined3d_device *device,
-        unsigned int idx, struct wined3d_unordered_access_view *uav)
+        unsigned int idx, struct wined3d_unordered_access_view *uav, unsigned int initial_count)
 {
-    TRACE("device %p, idx %u, uav %p.\n", device, idx, uav);
+    TRACE("device %p, idx %u, uav %p, initial_count %#x.\n", device, idx, uav, initial_count);
 
-    wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_GRAPHICS, idx, uav);
+    wined3d_device_set_pipeline_unordered_access_view(device, WINED3D_PIPELINE_GRAPHICS, idx, uav, initial_count);
 }
 
 struct wined3d_unordered_access_view * CDECL wined3d_device_get_unordered_access_view(
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index da915ea946..f4f3b35f20 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -898,6 +898,23 @@ void wined3d_unordered_access_view_clear_uint(struct wined3d_unordered_access_vi
     checkGLcall("clear unordered access view");
 }
 
+void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_view *view,
+        unsigned int value)
+{
+    const struct wined3d_gl_info *gl_info;
+    struct wined3d_context *context;
+
+    if (!view->counter_bo)
+        return;
+
+    context = context_acquire(view->resource->device, NULL, 0);
+    gl_info = context->gl_info;
+    GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, view->counter_bo));
+    GL_EXTCALL(glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(value), &value));
+    checkGLcall("set atomic counter");
+    context_release(context);
+}
+
 void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_view *view,
         struct wined3d_buffer *buffer, unsigned int offset, struct wined3d_context *context)
 {
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index fa33c5750e..c0724abb2c 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -130,7 +130,7 @@
 @ cdecl wined3d_device_set_cs_cb(ptr long ptr)
 @ cdecl wined3d_device_set_cs_resource_view(ptr long ptr)
 @ cdecl wined3d_device_set_cs_sampler(ptr long ptr)
-@ cdecl wined3d_device_set_cs_uav(ptr long ptr)
+@ cdecl wined3d_device_set_cs_uav(ptr long ptr long)
 @ cdecl wined3d_device_set_cursor_position(ptr long long long)
 @ cdecl wined3d_device_set_cursor_properties(ptr long long ptr long)
 @ cdecl wined3d_device_set_depth_stencil_view(ptr ptr)
@@ -175,7 +175,7 @@
 @ cdecl wined3d_device_set_texture(ptr long ptr)
 @ cdecl wined3d_device_set_texture_stage_state(ptr long long long)
 @ cdecl wined3d_device_set_transform(ptr long ptr)
-@ cdecl wined3d_device_set_unordered_access_view(ptr long ptr)
+@ cdecl wined3d_device_set_unordered_access_view(ptr long ptr long)
 @ cdecl wined3d_device_set_vertex_declaration(ptr ptr)
 @ cdecl wined3d_device_set_vertex_shader(ptr ptr)
 @ cdecl wined3d_device_set_viewport(ptr ptr)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 7d3e697058..f17cc765cf 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3481,7 +3481,8 @@ void wined3d_cs_emit_set_texture_state(struct wined3d_cs *cs, UINT stage,
 void wined3d_cs_emit_set_transform(struct wined3d_cs *cs, enum wined3d_transform_state state,
         const struct wined3d_matrix *matrix) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_unordered_access_view(struct wined3d_cs *cs, enum wined3d_pipeline pipeline,
-        unsigned int view_idx, struct wined3d_unordered_access_view *view) DECLSPEC_HIDDEN;
+        unsigned int view_idx, struct wined3d_unordered_access_view *view,
+        unsigned int initial_count) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_vertex_declaration(struct wined3d_cs *cs,
         struct wined3d_vertex_declaration *declaration) DECLSPEC_HIDDEN;
 void wined3d_cs_emit_set_viewport(struct wined3d_cs *cs, const struct wined3d_viewport *viewport) DECLSPEC_HIDDEN;
@@ -3654,6 +3655,8 @@ void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_
         struct wined3d_buffer *buffer, unsigned int offset, struct wined3d_context *context) DECLSPEC_HIDDEN;
 void wined3d_unordered_access_view_invalidate_location(struct wined3d_unordered_access_view *view,
         DWORD location) DECLSPEC_HIDDEN;
+void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_view *view,
+        unsigned int value) DECLSPEC_HIDDEN;
 
 struct wined3d_swapchain_ops
 {
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index f83217b48f..b92ada083b 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2349,7 +2349,7 @@ void __cdecl wined3d_device_set_cs_resource_view(struct wined3d_device *device,
 void __cdecl wined3d_device_set_cs_sampler(struct wined3d_device *device,
         unsigned int idx, struct wined3d_sampler *sampler);
 void __cdecl wined3d_device_set_cs_uav(struct wined3d_device *device, unsigned int idx,
-        struct wined3d_unordered_access_view *uav);
+        struct wined3d_unordered_access_view *uav, unsigned int initial_count);
 void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device,
         int x_screen_space, int y_screen_space, DWORD flags);
 HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device,
@@ -2420,7 +2420,7 @@ void __cdecl wined3d_device_set_texture_stage_state(struct wined3d_device *devic
 void __cdecl wined3d_device_set_transform(struct wined3d_device *device,
         enum wined3d_transform_state state, const struct wined3d_matrix *matrix);
 void __cdecl wined3d_device_set_unordered_access_view(struct wined3d_device *device,
-        unsigned int idx, struct wined3d_unordered_access_view *uav);
+        unsigned int idx, struct wined3d_unordered_access_view *uav, unsigned int initial_count);
 void __cdecl wined3d_device_set_vertex_declaration(struct wined3d_device *device,
         struct wined3d_vertex_declaration *declaration);
 void __cdecl wined3d_device_set_vertex_shader(struct wined3d_device *device, struct wined3d_shader *shader);
-- 
2.13.0




More information about the wine-patches mailing list