Signed-off-by: Jan Sikorski jsikorski@codeweavers.com --- This is meant to be followed by more patches that manage references to all the other objects that need to be kept alive for command lists.
That includes: all the ones handled similarly to samplers (i.e. the ones that we put into dedicated arrays); wined3d_resources, which are currently acquired on every draw/dispatch call; and views on these resources, which are not handled at all at this point.
Apart from simplifying the code to some degree, it will fix the size problem of wined3d_resources arrays, which can get pretty large when the application is doing many repeated draw/dispatch calls. --- dlls/wined3d/cs.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-)
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index 9bdd2c8ed98..9c7ec1edbf8 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -103,6 +103,8 @@ ULONG CDECL wined3d_command_list_incref(struct wined3d_command_list *list) return refcount; }
+static void wined3d_decref_packet_stream_objects(const uint8_t *data, size_t data_size); + ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list) { ULONG refcount = InterlockedDecrement(&list->refcount); @@ -133,6 +135,8 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list) for (i = 0; i < list->sampler_count; ++i) wined3d_sampler_decref(list->samplers[i]);
+ wined3d_decref_packet_stream_objects(list->data, list->data_size); + wined3d_mutex_lock(); wined3d_cs_destroy_object(device->cs, wined3d_command_list_destroy_object, list); wined3d_mutex_unlock(); @@ -3627,6 +3631,62 @@ void wined3d_cs_destroy(struct wined3d_cs *cs) heap_free(cs); }
+static void wined3d_decref_packet_stream_objects(const uint8_t *data, size_t data_size) +{ + size_t start = 0; + unsigned int i; + + while (start < data_size) + { + const struct wined3d_cs_packet *packet = (const struct wined3d_cs_packet *)&data[start]; + enum wined3d_cs_op opcode = *(const enum wined3d_cs_op *)packet->data; + + switch (opcode) + { + case WINED3D_CS_OP_SET_SAMPLERS: + { + struct wined3d_cs_set_samplers *cs_set + = (struct wined3d_cs_set_samplers *)packet->data; + for (i = 0; i < cs_set->count; ++i) + { + if (cs_set->samplers[i]) + wined3d_sampler_decref(cs_set->samplers[i]); + } + break; + } + default: + break; + } + + start += offsetof(struct wined3d_cs_packet, data[packet->size]); + } +} + +static void wined3d_incref_packet_objects(struct wined3d_cs_packet *packet) +{ + enum wined3d_cs_op opcode; + unsigned int i; + + opcode = *(const enum wined3d_cs_op *)packet->data; + + switch (opcode) + { + case WINED3D_CS_OP_SET_SAMPLERS: + { + struct wined3d_cs_set_samplers *cs_set + = (struct wined3d_cs_set_samplers *)packet->data; + for (i = 0; i < cs_set->count; ++i) + { + if (cs_set->samplers[i]) + wined3d_sampler_incref(cs_set->samplers[i]); + } + break; + } + default: + break; + } +} + struct wined3d_deferred_context { struct wined3d_device_context c; @@ -3689,16 +3749,19 @@ static void *wined3d_deferred_context_require_space(struct wined3d_device_contex
packet = (struct wined3d_cs_packet *)((BYTE *)deferred->data + deferred->data_size); TRACE("size was %zu, adding %zu\n", (size_t)deferred->data_size, packet_size); - deferred->data_size += packet_size; packet->size = packet_size - header_size; return &packet->data; }
static void wined3d_deferred_context_submit(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id) { - assert(queue_id == WINED3D_CS_QUEUE_DEFAULT); + struct wined3d_deferred_context *deferred = wined3d_deferred_context_from_context(context); + struct wined3d_cs_packet *packet;
- /* Nothing to do. */ + assert(queue_id == WINED3D_CS_QUEUE_DEFAULT); + packet = (struct wined3d_cs_packet *)((BYTE *)deferred->data + deferred->data_size); + deferred->data_size += packet->size + offsetof(struct wined3d_cs_packet, data[0]); + wined3d_incref_packet_objects(packet); }
static void wined3d_deferred_context_finish(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id) @@ -4023,6 +4086,8 @@ void CDECL wined3d_deferred_context_destroy(struct wined3d_device_context *conte wined3d_sampler_decref(deferred->samplers[i]); heap_free(deferred->samplers);
+ wined3d_decref_packet_stream_objects(deferred->data, deferred->data_size); + wined3d_state_destroy(deferred->c.state); heap_free(deferred->data); heap_free(deferred);