ReactOS 0.4.17-dev-966-gf06eace
buffer.c
Go to the documentation of this file.
1/*
2 * Copyright 2002-2005 Jason Edmeades
3 * Copyright 2002-2005 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2007-2011, 2013-2014 Stefan Dösinger for CodeWeavers
7 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 *
23 */
24
25#include "wined3d_private.h"
26#include "wined3d_gl.h"
27#include "wined3d_vk.h"
28
30
31#define WINED3D_BUFFER_HASDESC 0x01 /* A vertex description has been found. */
32#define WINED3D_BUFFER_USE_BO 0x02 /* Use a buffer object for this buffer. */
33
34#define SB_MIN_SIZE (512 * 1024) /* Minimum size of an allocated streaming buffer. */
35
37{
39 struct wined3d_context *context, unsigned int location);
41 struct wined3d_context *context, unsigned int location);
42};
43
45{
46 if (buffer->resource.pin_sysmem)
47 {
48 TRACE("Not evicting system memory for buffer %p.\n", buffer);
49 return;
50 }
51
52 TRACE("Evicting system memory for buffer %p.\n", buffer);
55}
56
57static void buffer_invalidate_bo_range(struct wined3d_buffer *buffer, unsigned int offset, unsigned int size)
58{
59 if (!offset && (!size || size == buffer->resource.size))
60 goto invalidate_all;
61
62 if (offset > buffer->resource.size || size > buffer->resource.size - offset)
63 {
64 WARN("Invalid range specified, invalidating entire buffer.\n");
65 goto invalidate_all;
66 }
67
68 if (!wined3d_array_reserve((void **)&buffer->dirty_ranges, &buffer->dirty_ranges_capacity,
69 buffer->dirty_range_count + 1, sizeof(*buffer->dirty_ranges)))
70 {
71 ERR("Failed to allocate dirty ranges array, invalidating entire buffer.\n");
72 goto invalidate_all;
73 }
74
75 buffer->dirty_ranges[buffer->dirty_range_count].offset = offset;
76 buffer->dirty_ranges[buffer->dirty_range_count].size = size;
77 ++buffer->dirty_range_count;
78 return;
79
80invalidate_all:
81 buffer->dirty_range_count = 1;
82 buffer->dirty_ranges[0].offset = 0;
83 buffer->dirty_ranges[0].size = buffer->resource.size;
84}
85
87{
88 buffer->dirty_range_count = 0;
89}
90
92{
93 return !!buffer->dirty_range_count;
94}
95
97{
98 return buffer->dirty_range_count == 1
99 && !buffer->dirty_ranges[0].offset && buffer->dirty_ranges[0].size == buffer->resource.size;
100}
101
103{
104 TRACE("buffer %p, location %s.\n", buffer, wined3d_debug_location(location));
105
108
109 buffer->locations |= location;
110
111 TRACE("New locations flags are %s.\n", wined3d_debug_location(buffer->locations));
112}
113
115 unsigned int offset, unsigned int size)
116{
117 TRACE("buffer %p, location %s, offset %u, size %u.\n",
119
122
123 buffer->locations &= ~location;
124
125 TRACE("New locations flags are %s.\n", wined3d_debug_location(buffer->locations));
126
127 if (!buffer->locations)
128 ERR("Buffer %p does not have any up to date location.\n", buffer);
129}
130
132{
134}
135
137{
138 if (!bind_flags)
140
141 /* We must always return GL_ELEMENT_ARRAY_BUFFER here;
142 * wined3d_device_gl_create_bo() checks the GL binding to see whether we
143 * can suballocate, and we cannot suballocate if this BO might be used for
144 * an index buffer. */
145 if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
147
150 return GL_TEXTURE_BUFFER;
151
152 if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
153 return GL_UNIFORM_BUFFER;
154
155 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
157
158 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER
159 && gl_info->supported[ARB_DRAW_INDIRECT])
161
163 FIXME("Unhandled bind flags %#x.\n", bind_flags);
164
165 return GL_ARRAY_BUFFER;
166}
167
168/* Context activation is done by the caller. */
170 struct wined3d_context_gl *context_gl)
171{
172 struct wined3d_resource *resource = &buffer_gl->b.resource;
173 struct wined3d_bo_gl *bo_gl;
174
175 if (!buffer_gl->b.buffer_object)
176 return;
177 bo_gl = wined3d_bo_gl(buffer_gl->b.buffer_object);
178
179 if (context_gl->c.transform_feedback_active && (resource->bind_flags & WINED3D_BIND_STREAM_OUTPUT)
181 {
182 /* It's illegal to (un)bind GL_TRANSFORM_FEEDBACK_BUFFER while transform
183 * feedback is active. Deleting a buffer implicitly unbinds it, so we
184 * need to end transform feedback here if this buffer was bound.
185 *
186 * This should only be possible if STATE_STREAM_OUTPUT is dirty; if we
187 * do a draw call before destroying this buffer then the draw call will
188 * already rebind the GL target. */
189 WARN("Deleting buffer object for buffer %p, disabling transform feedback.\n", buffer_gl);
191 }
192
193 if (buffer_gl->b.bo_user.valid)
194 {
195 buffer_gl->b.bo_user.valid = false;
196 list_remove(&buffer_gl->b.bo_user.entry);
197 }
198 if (!--bo_gl->b.refcount)
199 {
200 wined3d_context_gl_destroy_bo(context_gl, bo_gl);
201 free(bo_gl);
202 }
203 buffer_gl->b.buffer_object = NULL;
204}
205
206/* Context activation is done by the caller. */
208 struct wined3d_context_gl *context_gl)
209{
210 struct wined3d_device_gl *device_gl = wined3d_device_gl(buffer_gl->b.resource.device);
211 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
213 GLbitfield gl_storage_flags;
214 struct wined3d_bo_gl *bo;
215 bool coherent = true;
218
219 TRACE("Creating an OpenGL buffer object for wined3d buffer %p with usage %s.\n",
220 buffer_gl, debug_d3dusage(buffer_gl->b.resource.usage));
221
222 if (!(bo = malloc(sizeof(*bo))))
223 return FALSE;
224
225 size = buffer_gl->b.resource.size;
226 binding = wined3d_buffer_gl_binding_from_bind_flags(gl_info, buffer_gl->b.resource.bind_flags);
227 if (buffer_gl->b.resource.usage & WINED3DUSAGE_DYNAMIC)
228 {
230 coherent = false;
231 }
232 gl_storage_flags = wined3d_resource_gl_storage_flags(&buffer_gl->b.resource);
233 if (!wined3d_device_gl_create_bo(device_gl, context_gl, size, binding, usage, coherent, gl_storage_flags, bo))
234 {
235 ERR("Failed to create OpenGL buffer object.\n");
236 buffer_gl->b.flags &= ~WINED3D_BUFFER_USE_BO;
237 buffer_clear_dirty_areas(&buffer_gl->b);
238 free(bo);
239 return FALSE;
240 }
241
242 buffer_gl->b.buffer_object = &bo->b;
243 buffer_invalidate_bo_range(&buffer_gl->b, 0, 0);
244
245 return TRUE;
246}
247
249{
250 unsigned int refcount = InterlockedIncrement(&buffer->resource.ref);
251
252 TRACE("%p increasing refcount to %u.\n", buffer, refcount);
253
254 return refcount;
255}
256
258 struct wined3d_context *context, unsigned int location)
259{
260 return buffer->buffer_ops->buffer_prepare_location(buffer, context, location);
261}
262
264 struct wined3d_context *context, unsigned int location)
265{
266 buffer->buffer_ops->buffer_unload_location(buffer, context, location);
267}
268
271{
272 struct wined3d_bo_address src, dst;
273 struct wined3d_range range;
274
275 TRACE("buffer %p, context %p, location %s.\n",
277
278 if (buffer->locations & location)
279 {
280 TRACE("Location (%#x) is already up to date.\n", location);
281 return TRUE;
282 }
283
284 if (!buffer->locations)
285 {
286 ERR("Buffer %p does not have any up to date location.\n", buffer);
289 }
290
291 TRACE("Current buffer location %s.\n", wined3d_debug_location(buffer->locations));
292
294 return FALSE;
295
296 if (buffer->locations & WINED3D_LOCATION_DISCARDED)
297 {
298 TRACE("Buffer previously discarded, nothing to do.\n");
301 return TRUE;
302 }
303
304 switch (location)
305 {
307 if (buffer->locations & WINED3D_LOCATION_CLEARED)
308 {
309 memset(buffer->resource.heap_memory, 0, buffer->resource.size);
310 }
311 else
312 {
313 dst.buffer_object = NULL;
314 dst.addr = buffer->resource.heap_memory;
315 src.buffer_object = buffer->buffer_object;
316 src.addr = NULL;
317 range.offset = 0;
318 range.size = buffer->resource.size;
320 }
321 break;
322
324 {
325 uint32_t map_flags = WINED3D_MAP_WRITE;
326
327 if (buffer->locations & WINED3D_LOCATION_CLEARED)
328 {
329 /* FIXME: Clear the buffer on the GPU if possible. */
331 return FALSE;
332 memset(buffer->resource.heap_memory, 0, buffer->resource.size);
333 }
334
335 dst.buffer_object = buffer->buffer_object;
336 dst.addr = NULL;
337 src.buffer_object = NULL;
338 src.addr = buffer->resource.heap_memory;
339
341 map_flags |= WINED3D_MAP_DISCARD;
342
344 buffer->dirty_range_count, buffer->dirty_ranges, map_flags);
345 break;
346 }
347
348 default:
349 ERR("Invalid location %s.\n", wined3d_debug_location(location));
350 return FALSE;
351 }
352
354 if (buffer->resource.heap_memory && location == WINED3D_LOCATION_BUFFER
355 && !(buffer->resource.usage & WINED3DUSAGE_DYNAMIC))
357
358 return TRUE;
359}
360
361/* Context activation is done by the caller. */
363{
365 buffer->resource.pin_sysmem = 1;
366 return buffer->resource.heap_memory;
367}
368
370 struct wined3d_bo_address *data)
371{
372 unsigned int locations = buffer->locations;
373
374 TRACE("buffer %p, context %p, data %p, locations %s.\n",
376
378 {
381 {
382 data->buffer_object = 0;
383 data->addr = NULL;
384 return 0;
385 }
386 }
388 {
389 data->buffer_object = buffer->buffer_object;
390 data->addr = NULL;
392 }
394 {
395 data->buffer_object = 0;
396 data->addr = buffer->resource.heap_memory;
398 }
399
400 ERR("Unexpected locations %s.\n", wined3d_debug_location(locations));
401 data->buffer_object = 0;
402 data->addr = NULL;
403 return 0;
404}
405
407{
409
410 TRACE("buffer %p.\n", buffer);
411
412 if (buffer->buffer_object)
413 {
414 struct wined3d_context *context;
415
416 context = context_acquire(resource->device, NULL, 0);
417
422
424
425 buffer->flags &= ~WINED3D_BUFFER_HASDESC;
426 }
427
429}
430
432{
433 buffer->flags &= ~WINED3D_BUFFER_USE_BO;
434 buffer_resource_unload(&buffer->resource);
435}
436
437static void wined3d_buffer_destroy_object(void *object)
438{
439 struct wined3d_buffer *buffer = object;
440 struct wined3d_context *context;
441
442 TRACE("buffer %p.\n", buffer);
443
444 if (buffer->buffer_object)
445 {
446 context = context_acquire(buffer->resource.device, NULL, 0);
449 }
450 free(buffer->dirty_ranges);
451}
452
454{
456 resource_cleanup(&buffer->resource);
457}
458
460{
461 unsigned int refcount = InterlockedDecrement(&buffer->resource.ref);
462
463 TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
464
465 if (!refcount)
466 {
468 buffer->resource.parent_ops->wined3d_object_destroyed(buffer->resource.parent);
469 buffer->resource.device->adapter->adapter_ops->adapter_destroy_buffer(buffer);
471 }
472
473 return refcount;
474}
475
477{
478 TRACE("buffer %p.\n", buffer);
479
480 return buffer->resource.parent;
481}
482
483/* Context activation is done by the caller. */
485 const struct wined3d_state *state)
486{
487 TRACE("buffer %p.\n", buffer);
488
489 if (buffer->resource.map_count && buffer->map_ptr)
490 {
491 FIXME("Buffer is mapped through buffer object, not loading.\n");
492 return;
493 }
494 else if (buffer->resource.map_count)
495 {
496 WARN("Loading mapped buffer.\n");
497 }
498
499 if (!(buffer->flags & WINED3D_BUFFER_USE_BO))
500 return;
501
503 {
504 ERR("Failed to prepare buffer location.\n");
505 return;
506 }
507
508 /* Reading the declaration makes only sense if we have valid state information
509 * (i.e., if this function is called during draws). */
510 if (state)
512
514 return;
515
517 ERR("Failed to load buffer location.\n");
518}
519
521{
522 TRACE("buffer %p.\n", buffer);
523
524 return &buffer->resource;
525}
526
528 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
529{
530 if (sub_resource_idx)
531 {
532 WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
533 return E_INVALIDARG;
534 }
535
536 desc->format = WINED3DFMT_R8_UNORM;
537 desc->multisample_type = WINED3D_MULTISAMPLE_NONE;
538 desc->multisample_quality = 0;
539 desc->usage = resource->usage;
540 desc->bind_flags = resource->bind_flags;
541 desc->access = resource->access;
542 desc->width = resource->size;
543 desc->height = 1;
544 desc->depth = 1;
545 desc->size = resource->size;
546 return S_OK;
547}
548
550 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
551{
552 *row_pitch = *slice_pitch = resource->size;
553}
554
555static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
556 void **map_ptr, const struct wined3d_box *box, uint32_t flags)
557{
559 unsigned int offset, size, dirty_offset, dirty_size;
560 struct wined3d_device *device = resource->device;
561 struct wined3d_context *context;
563 uint8_t *base;
564 LONG count;
565
566 TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
567 resource, sub_resource_idx, map_ptr, debug_box(box), flags);
568
569 dirty_offset = offset = box->left;
570 dirty_size = size = box->right - box->left;
571
572 count = ++resource->map_count;
573
574 /* DISCARD invalidates the entire buffer, regardless of the specified
575 * offset and size. Some applications also depend on the entire buffer
576 * being uploaded in that case. Two such applications are Port Royale
577 * and Darkstar One. */
579 {
580 dirty_offset = 0;
581 dirty_size = 0;
582 }
583
585 || (!(flags & WINED3D_MAP_WRITE) && (buffer->locations & WINED3D_LOCATION_SYSMEM))
586 || buffer->resource.pin_sysmem
587 || !(buffer->flags & WINED3D_BUFFER_USE_BO))
588 {
589 if (!(buffer->locations & WINED3D_LOCATION_SYSMEM))
590 {
594 }
595
598 }
599 else
600 {
602
604 {
606 {
608 return E_OUTOFMEMORY;
609 }
611 }
612 else
613 {
615 }
616
618 {
621 buffer_invalidate_bo_range(buffer, dirty_offset, dirty_size);
622 }
623
624 if ((flags & WINED3D_MAP_DISCARD) && resource->heap_memory)
626
627 if (count == 1)
628 {
629 addr.buffer_object = buffer->buffer_object;
630 addr.addr = 0;
632
633 /* We are accessing buffer->resource.client from the CS thread,
634 * but it's safe because the client thread will wait for the
635 * map to return, thus completely serializing this call with
636 * other client code. */
637 if (context->d3d_info->persistent_map)
638 buffer->resource.client.addr = addr;
639
640 if (((DWORD_PTR)buffer->map_ptr) & (RESOURCE_ALIGNMENT - 1))
641 {
642 WARN("Pointer %p is not %u byte aligned.\n", buffer->map_ptr, RESOURCE_ALIGNMENT);
643
645 buffer->map_ptr = NULL;
646
647 if (resource->usage & WINED3DUSAGE_DYNAMIC)
648 {
649 /* The extra copy is more expensive than not using VBOs
650 * at all on the NVIDIA Linux driver, which is the
651 * only driver that returns unaligned pointers. */
652 TRACE("Dynamic buffer, dropping VBO.\n");
654 }
655 else
656 {
657 TRACE("Falling back to doublebuffered operation.\n");
659 buffer->resource.pin_sysmem = 1;
660 }
661 TRACE("New pointer is %p.\n", resource->heap_memory);
662 }
663 }
664
666 }
667
668 base = buffer->map_ptr ? buffer->map_ptr : resource->heap_memory;
669 *map_ptr = base + offset;
670
671 TRACE("Returning memory at %p (base %p, offset %u).\n", *map_ptr, base, offset);
672
673 return WINED3D_OK;
674}
675
676static HRESULT buffer_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
677{
679 struct wined3d_device *device = resource->device;
680 struct wined3d_context *context;
682
683 TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
684
685 if (sub_resource_idx)
686 {
687 WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
688 return E_INVALIDARG;
689 }
690
691 if (!resource->map_count)
692 {
693 WARN("Unmap called without a previous map call.\n");
694 return WINED3D_OK;
695 }
696
697 if (--resource->map_count)
698 {
699 /* Delay loading the buffer until everything is unmapped. */
700 TRACE("Ignoring unmap.\n");
701 return WINED3D_OK;
702 }
703
704 if (!buffer->map_ptr)
705 return WINED3D_OK;
706
708
709 addr.buffer_object = buffer->buffer_object;
710 addr.addr = 0;
711 wined3d_context_unmap_bo_address(context, &addr, buffer->dirty_range_count, buffer->dirty_ranges);
712
714
716 buffer->map_ptr = NULL;
717
718 return WINED3D_OK;
719}
720
722{
723 struct wined3d_bo *prev_bo = buffer->buffer_object;
724
725 TRACE("buffer %p, context %p, bo %p.\n", buffer, context, bo);
726
727 if (prev_bo)
728 {
729 struct wined3d_bo_user *bo_user;
730
731 /* The previous BO might have users in other buffers which were valid,
732 * and should in theory remain valid. The problem is that it's not easy
733 * to tell which users belong to this buffer and which don't. We could
734 * add a field, but for now it's easier and probably fine to just
735 * invalidate every user. */
736 LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->users, struct wined3d_bo_user, entry)
737 bo_user->valid = false;
738 list_init(&prev_bo->users);
739
740 if (!--prev_bo->refcount)
741 {
743 free(prev_bo);
744 }
745 }
746
747 buffer->buffer_object = bo;
748}
749
751{
752 const struct wined3d_range range = {.size = buffer->resource.size};
753 struct wined3d_bo_address dst, src;
754 struct wined3d_bo *bo;
755
756 if (!(bo = buffer->buffer_object))
757 return;
758
759 /* If we are the only owner of this BO, there is nothing to do. */
760 if (bo->refcount == 1)
761 return;
762
763 TRACE("Performing copy-on-write for BO %p.\n", bo);
764
765 /* Grab a reference to the current BO. It's okay if this overflows, because
766 * the following unload will release it. */
767 ++bo->refcount;
768
769 /* Unload and re-prepare to get a new buffer. This is a bit cheap and not
770 * perfectly idiomatic—we should really just factor out an adapter-agnostic
771 * function to create a BO and then use wined3d_buffer_set_bo()—but it'll
772 * do nonetheless. */
775
776 /* And finally, perform the actual copy. */
777 assert(buffer->buffer_object != bo);
778 dst.buffer_object = buffer->buffer_object;
779 dst.addr = NULL;
780 src.buffer_object = bo;
781 src.addr = NULL;
783}
784
786 unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size)
787{
788 uint32_t map_flags = WINED3D_MAP_WRITE;
789 struct wined3d_bo_address dst_addr;
790 struct wined3d_range range;
791 DWORD dst_location;
792
793 if (!dst_offset && size == dst_buffer->resource.size)
794 map_flags |= WINED3D_MAP_DISCARD;
795
796 if (map_flags & WINED3D_MAP_DISCARD)
798
799 dst_location = wined3d_buffer_get_memory(dst_buffer, context, &dst_addr);
800 dst_addr.addr += dst_offset;
801
802 range.offset = 0;
803 range.size = size;
804 wined3d_context_copy_bo_address(context, &dst_addr, (const struct wined3d_bo_address *)src_addr, 1, &range, map_flags);
805 wined3d_buffer_invalidate_range(dst_buffer, ~dst_location, dst_offset, size);
806}
807
808void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset,
809 struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size)
810{
811 struct wined3d_context *context;
812 struct wined3d_bo_address src;
813
814 TRACE("dst_buffer %p, dst_offset %u, src_buffer %p, src_offset %u, size %u.\n",
815 dst_buffer, dst_offset, src_buffer, src_offset, size);
816
817 context = context_acquire(dst_buffer->resource.device, NULL, 0);
818
820 src.addr += src_offset;
821
823
825}
826
828 const struct upload_bo *upload_bo, unsigned int offset, unsigned int size)
829{
830 struct wined3d_bo *bo = upload_bo->addr.buffer_object;
832
833 /* Try to take this buffer for COW. Don't take it if we've saturated the
834 * refcount. */
835 if (!offset && size == buffer->resource.size
837 {
839 ++bo->refcount;
840 }
841
843 {
844 /* Don't increment the refcount. UPLOAD_BO_RENAME_ON_UNMAP transfers an
845 * existing reference.
846 *
847 * FIXME: We could degenerate RENAME to a copy + free and rely on the
848 * COW logic to detect this case.
849 */
853 }
854
855 if (upload_bo->addr.buffer_object && upload_bo->addr.buffer_object == buffer->buffer_object)
856 {
857 struct wined3d_range range;
858
859 /* We need to flush changes, which is implicitly done by
860 * wined3d_context_unmap_bo_address() even if we aren't actually going
861 * to unmap.
862 *
863 * We would also like to free up virtual address space used by this BO
864 * if it's at a premium—note that this BO was allocated for an
865 * accelerated map. Hence we unmap the BO instead of merely flushing it;
866 * if we don't care about unmapping BOs then
867 * wined3d_context_unmap_bo_address() will flush and return.
868 */
870 range.size = size;
871 if (upload_bo->addr.buffer_object->map_ptr)
873 }
874 else
875 {
877 }
878}
879
882{
883 struct wined3d_resource *resource = &buffer->resource;
884 struct wined3d_box box;
885
886 if (buffer->flags & WINED3D_BUFFER_USE_BO)
887 {
888 wined3d_box_set(&box, 0, 0, resource->size, 1, 0, 1);
890 0, &box, data->data, data->row_pitch, data->slice_pitch);
891 }
892 else
893 {
894 memcpy(buffer->resource.heap_memory, data->data, resource->size);
897 }
898}
899
901{
903}
904
906{
908}
909
911{
912 struct wined3d_context *context;
913
914 context = context_acquire(resource->device, NULL, 0);
917}
918
920{
929};
930
932 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
933 void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_buffer_ops *buffer_ops)
934{
935 const struct wined3d_format *format = wined3d_get_format(device->adapter, WINED3DFMT_R8_UNORM, desc->bind_flags);
936 struct wined3d_resource *resource = &buffer->resource;
937 unsigned int access;
938 HRESULT hr;
939
940 TRACE("buffer %p, device %p, desc byte_width %u, usage %s, bind_flags %s, "
941 "access %s, data %p, parent %p, parent_ops %p.\n",
942 buffer, device, desc->byte_width, debug_d3dusage(desc->usage), wined3d_debug_bind_flags(desc->bind_flags),
944
945 if (!desc->byte_width)
946 {
947 WARN("Size 0 requested, returning E_INVALIDARG.\n");
948 return E_INVALIDARG;
949 }
950
951 if (desc->bind_flags & WINED3D_BIND_CONSTANT_BUFFER && desc->byte_width & (WINED3D_CONSTANT_BUFFER_ALIGNMENT - 1))
952 {
953 WARN("Size %#x is not suitably aligned for constant buffers.\n", desc->byte_width);
954 return E_INVALIDARG;
955 }
956
957 if (data && !data->data)
958 {
959 WARN("Invalid sub-resource data specified.\n");
960 return E_INVALIDARG;
961 }
962
963 access = desc->access;
966
968 WINED3D_MULTISAMPLE_NONE, 0, desc->usage, desc->bind_flags, access,
969 desc->byte_width, 1, 1, desc->byte_width, parent, parent_ops, &buffer_resource_ops)))
970 {
971 WARN("Failed to initialize resource, hr %#lx.\n", hr);
972 return hr;
973 }
974 buffer->buffer_ops = buffer_ops;
975 buffer->structure_byte_stride = desc->structure_byte_stride;
976 buffer->locations = WINED3D_LOCATION_CLEARED;
977
978 TRACE("buffer %p, size %#x, usage %#x, memory @ %p.\n",
979 buffer, buffer->resource.size, buffer->resource.usage, buffer->resource.heap_memory);
980
981 if (device->create_parms.flags & WINED3DCREATE_SOFTWARE_VERTEXPROCESSING
982 || (desc->usage & WINED3DUSAGE_MANAGED))
983 {
984 /* SWvp and managed buffers always return the same pointer in buffer
985 * maps and retain data in DISCARD maps. Keep a system memory copy of
986 * the buffer to provide the same behavior to the application. */
987 TRACE("Pinning system memory.\n");
988 buffer->resource.pin_sysmem = 1;
989 buffer->locations = WINED3D_LOCATION_SYSMEM;
990 }
991
992 if (buffer->locations & WINED3D_LOCATION_SYSMEM || !(buffer->flags & WINED3D_BUFFER_USE_BO))
993 {
995 return E_OUTOFMEMORY;
996 }
997
998 if ((buffer->flags & WINED3D_BUFFER_USE_BO) && !wined3d_array_reserve((void **)&buffer->dirty_ranges,
999 &buffer->dirty_ranges_capacity, 1, sizeof(*buffer->dirty_ranges)))
1000 {
1001 ERR("Out of memory.\n");
1005 return E_OUTOFMEMORY;
1006 }
1007
1008 if (buffer->locations & WINED3D_LOCATION_DISCARDED)
1009 buffer->resource.client.addr.buffer_object = CLIENT_BO_DISCARDED;
1010
1011 if (data)
1013
1014 return WINED3D_OK;
1015}
1016
1018 struct wined3d_context *context, unsigned int location)
1019{
1021 return wined3d_resource_prepare_sysmem(&buffer->resource);
1022
1023 FIXME("Unhandled location %s.\n", wined3d_debug_location(location));
1024
1025 return FALSE;
1026}
1027
1029 struct wined3d_context *context, unsigned int location)
1030{
1031 TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location));
1032}
1033
1035{
1038};
1039
1041 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
1042 void *parent, const struct wined3d_parent_ops *parent_ops)
1043{
1044 TRACE("buffer_no3d %p, device %p, desc %p, data %p, parent %p, parent_ops %p.\n",
1045 buffer_no3d, device, desc, data, parent, parent_ops);
1046
1047 return wined3d_buffer_init(buffer_no3d, device, desc, data, parent, parent_ops, &wined3d_buffer_no3d_ops);
1048}
1049
1051 struct wined3d_context *context, unsigned int location)
1052{
1053 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
1054 struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(buffer);
1055
1056 switch (location)
1057 {
1059 return wined3d_resource_prepare_sysmem(&buffer->resource);
1060
1062 if (buffer->buffer_object)
1063 return TRUE;
1064
1065 if (!(buffer->flags & WINED3D_BUFFER_USE_BO))
1066 {
1067 WARN("Trying to create BO for buffer %p with no WINED3D_BUFFER_USE_BO.\n", buffer);
1068 return FALSE;
1069 }
1070 return wined3d_buffer_gl_create_buffer_object(buffer_gl, context_gl);
1071
1072 default:
1073 ERR("Invalid location %s.\n", wined3d_debug_location(location));
1074 return FALSE;
1075 }
1076}
1077
1079 struct wined3d_context *context, unsigned int location)
1080{
1081 TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location));
1082
1083 switch (location)
1084 {
1087 break;
1088
1089 default:
1090 ERR("Unhandled location %s.\n", wined3d_debug_location(location));
1091 break;
1092 }
1093}
1094
1096{
1099};
1100
1102 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
1103 void *parent, const struct wined3d_parent_ops *parent_ops)
1104{
1105 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl(device->adapter)->gl_info;
1106
1107 TRACE("buffer_gl %p, device %p, desc %p, data %p, parent %p, parent_ops %p.\n",
1108 buffer_gl, device, desc, data, parent, parent_ops);
1109
1110 /* Observations show that draw_primitive_immediate_mode() is faster on
1111 * dynamic vertex buffers than converting + draw_primitive_arrays().
1112 * (Half-Life 2 and others.) */
1113 if (!(desc->access & WINED3D_RESOURCE_ACCESS_GPU))
1114 TRACE("Not creating a BO because the buffer is not GPU accessible.\n");
1115 else if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT])
1116 TRACE("Not creating a BO because GL_ARB_vertex_buffer is not supported.\n");
1117 else if (!(gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] || gl_info->supported[ARB_MAP_BUFFER_RANGE])
1118 && (desc->usage & WINED3DUSAGE_DYNAMIC))
1119 TRACE("Not creating a BO because the buffer has dynamic usage and no GL support.\n");
1120 else
1121 buffer_gl->b.flags |= WINED3D_BUFFER_USE_BO;
1122
1123 return wined3d_buffer_init(&buffer_gl->b, device, desc, data, parent, parent_ops, &wined3d_buffer_gl_ops);
1124}
1125
1127{
1129
1131 if (bind_flags & WINED3D_BIND_VERTEX_BUFFER)
1133 if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
1135 if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
1137 if (bind_flags & WINED3D_BIND_SHADER_RESOURCE)
1139 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
1141 if (bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
1143 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
1146 FIXME("Ignoring some bind flags %#x.\n", bind_flags);
1147 return usage;
1148}
1149
1151{
1152 VkMemoryPropertyFlags memory_type = 0;
1153
1158 else if (!(usage & WINED3DUSAGE_DYNAMIC))
1160 return memory_type;
1161}
1162
1164 struct wined3d_context_vk *context_vk)
1165{
1166 struct wined3d_resource *resource = &buffer_vk->b.resource;
1167 struct wined3d_bo_vk *bo_vk;
1168
1169 if (!(bo_vk = malloc(sizeof(*bo_vk))))
1170 return FALSE;
1171
1172 if (!(wined3d_context_vk_create_bo(context_vk, resource->size,
1174 vk_memory_type_from_access_flags(resource->access, resource->usage), bo_vk)))
1175 {
1176 WARN("Failed to create Vulkan buffer.\n");
1177 free(bo_vk);
1178 return FALSE;
1179 }
1180
1181 buffer_vk->b.buffer_object = &bo_vk->b;
1182 buffer_invalidate_bo_range(&buffer_vk->b, 0, 0);
1183
1184 return TRUE;
1185}
1186
1188{
1189 struct wined3d_bo_vk *bo = wined3d_bo_vk(buffer_vk->b.buffer_object);
1190
1191 if (buffer_vk->b.bo_user.valid)
1192 return &buffer_vk->buffer_info;
1193
1194 buffer_vk->buffer_info.buffer = bo->vk_buffer;
1195 buffer_vk->buffer_info.offset = bo->b.buffer_offset;
1196 buffer_vk->buffer_info.range = buffer_vk->b.resource.size;
1197 wined3d_buffer_validate_user(&buffer_vk->b);
1198
1199 return &buffer_vk->buffer_info;
1200}
1201
1203 struct wined3d_context *context, unsigned int location)
1204{
1205 switch (location)
1206 {
1208 return wined3d_resource_prepare_sysmem(&buffer->resource);
1209
1211 if (buffer->buffer_object)
1212 return TRUE;
1213
1215
1216 default:
1217 FIXME("Unhandled location %s.\n", wined3d_debug_location(location));
1218 return FALSE;
1219 }
1220}
1221
1223 struct wined3d_context *context, unsigned int location)
1224{
1225 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
1226 struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(buffer->buffer_object);
1227
1228 TRACE("buffer %p, context %p, location %s.\n", buffer, context, wined3d_debug_location(location));
1229
1230 switch (location)
1231 {
1233 if (buffer->bo_user.valid)
1234 {
1235 buffer->bo_user.valid = false;
1236 list_remove(&buffer->bo_user.entry);
1237 }
1238 if (!--bo_vk->b.refcount)
1239 {
1240 wined3d_context_vk_destroy_bo(context_vk, bo_vk);
1241 free(bo_vk);
1242 }
1243 buffer->buffer_object = NULL;
1244 break;
1245
1246 default:
1247 ERR("Unhandled location %s.\n", wined3d_debug_location(location));
1248 break;
1249 }
1250}
1251
1253{
1256};
1257
1259 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
1260 void *parent, const struct wined3d_parent_ops *parent_ops)
1261{
1262 const struct wined3d_vk_info *vk_info = &wined3d_adapter_vk(device->adapter)->vk_info;
1263
1264 TRACE("buffer_vk %p, device %p, desc %p, data %p, parent %p, parent_ops %p.\n",
1265 buffer_vk, device, desc, data, parent, parent_ops);
1266
1267 if ((desc->bind_flags & WINED3D_BIND_STREAM_OUTPUT)
1269 {
1270 WARN("The Vulkan implementation does not support transform feedback.\n");
1272 }
1273
1274 if (desc->access & WINED3D_RESOURCE_ACCESS_GPU)
1275 buffer_vk->b.flags |= WINED3D_BUFFER_USE_BO;
1276
1277 return wined3d_buffer_init(&buffer_vk->b, device, desc, data, parent, parent_ops, &wined3d_buffer_vk_ops);
1278}
1279
1281 struct wined3d_context_vk *context_vk, uint32_t bind_mask)
1282{
1283 uint32_t src_bind_mask = 0;
1284
1285 TRACE("buffer_vk %p, context_vk %p, bind_mask %s.\n",
1286 buffer_vk, context_vk, wined3d_debug_bind_flags(bind_mask));
1287
1288 if (bind_mask & ~WINED3D_READ_ONLY_BIND_MASK)
1289 {
1290 src_bind_mask = buffer_vk->bind_mask & WINED3D_READ_ONLY_BIND_MASK;
1291 if (!src_bind_mask)
1292 src_bind_mask = buffer_vk->bind_mask;
1293
1294 buffer_vk->bind_mask = bind_mask;
1295 }
1296 else if ((buffer_vk->bind_mask & bind_mask) != bind_mask)
1297 {
1298 src_bind_mask = buffer_vk->bind_mask & ~WINED3D_READ_ONLY_BIND_MASK;
1299 buffer_vk->bind_mask |= bind_mask;
1300 }
1301
1302 if (src_bind_mask)
1303 {
1304 const struct wined3d_bo_vk *bo = wined3d_bo_vk(buffer_vk->b.buffer_object);
1305 const struct wined3d_vk_info *vk_info = context_vk->vk_info;
1306 VkBufferMemoryBarrier vk_barrier;
1307
1308 TRACE(" %s -> %s.\n",
1309 wined3d_debug_bind_flags(src_bind_mask), wined3d_debug_bind_flags(bind_mask));
1310
1312
1314 vk_barrier.pNext = NULL;
1315 vk_barrier.srcAccessMask = vk_access_mask_from_bind_flags(src_bind_mask);
1316 vk_barrier.dstAccessMask = vk_access_mask_from_bind_flags(bind_mask);
1319 vk_barrier.buffer = bo->vk_buffer;
1320 vk_barrier.offset = bo->b.buffer_offset;
1321 vk_barrier.size = buffer_vk->b.resource.size;
1325 0, 0, NULL, 1, &vk_barrier, 0, NULL));
1326 }
1327}
1328
1330 const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops,
1331 struct wined3d_buffer **buffer)
1332{
1333 TRACE("device %p, desc %p, data %p, parent %p, parent_ops %p, buffer %p.\n",
1334 device, desc, data, parent, parent_ops, buffer);
1335
1336 return device->adapter->adapter_ops->adapter_create_buffer(device, desc, data, parent, parent_ops, buffer);
1337}
1338
1340 struct wined3d_streaming_buffer *buffer, unsigned int min_size)
1341{
1344 unsigned int old_size = 0;
1345 unsigned int size;
1346 HRESULT hr;
1347
1348 if (buffer->buffer)
1349 {
1350 old_size = buffer->buffer->resource.size;
1351 if (old_size >= min_size)
1352 return S_OK;
1353 }
1354
1355 size = max(SB_MIN_SIZE, max(old_size * 2, min_size));
1356 TRACE("Growing buffer to %u bytes.\n", size);
1357
1358 desc.byte_width = size;
1359 desc.usage = WINED3DUSAGE_DYNAMIC;
1360 desc.bind_flags = buffer->bind_flags;
1362 desc.misc_flags = 0;
1363 desc.structure_byte_stride = 0;
1364
1366 {
1367 if (buffer->buffer)
1369 buffer->buffer = wined3d_buffer;
1370 buffer->pos = 0;
1371 }
1372 return hr;
1373}
1374
1376 struct wined3d_streaming_buffer *buffer, unsigned int size, unsigned int stride,
1377 unsigned int *ret_pos, void **ret_data)
1378{
1379 unsigned int map_flags = WINED3D_MAP_WRITE;
1380 struct wined3d_resource *resource;
1381 struct wined3d_map_desc map_desc;
1382 unsigned int pos, align;
1383 struct wined3d_box box;
1384 HRESULT hr;
1385
1386 TRACE("device %p, buffer %p, size %u, stride %u, ret_pos %p, ret_data %p.\n",
1387 device, buffer, size, stride, ret_pos, ret_data);
1388
1390 return hr;
1391 resource = &buffer->buffer->resource;
1392
1393 pos = buffer->pos;
1394 if ((align = pos % stride))
1395 align = stride - align;
1396 if (pos + size + align > resource->size)
1397 {
1398 pos = 0;
1399 map_flags |= WINED3D_MAP_DISCARD;
1400 }
1401 else
1402 {
1403 pos += align;
1404 map_flags |= WINED3D_MAP_NOOVERWRITE;
1405 }
1406
1407 wined3d_box_set(&box, pos, 0, pos + size, 1, 0, 1);
1408 if (SUCCEEDED(hr = wined3d_resource_map(resource, 0, &map_desc, &box, map_flags)))
1409 {
1410 *ret_pos = pos;
1411 *ret_data = map_desc.data;
1412 buffer->pos = pos + size;
1413 }
1414 return hr;
1415}
1416
1418{
1419 wined3d_resource_unmap(&buffer->buffer->resource, 0);
1420}
1421
1423 const void *data, unsigned int size, unsigned int stride, unsigned int *ret_pos)
1424{
1425 void *dst_data;
1426 HRESULT hr;
1427
1428 if (SUCCEEDED(hr = wined3d_streaming_buffer_map(device, buffer, size, stride, ret_pos, &dst_data)))
1429 {
1430 memcpy(dst_data, data, size);
1432 }
1433 return hr;
1434}
static int state
Definition: maze.c:121
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_init(struct list_entry *head)
Definition: list.h:51
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
void wined3d_context_gl_destroy_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo)
Definition: context_gl.c:3097
void wined3d_context_gl_end_transform_feedback(struct wined3d_context_gl *context_gl)
Definition: context_gl.c:4228
BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo)
Definition: context_vk.c:528
void wined3d_context_vk_end_current_render_pass(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1564
VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1805
void wined3d_context_vk_destroy_bo(struct wined3d_context_vk *context_vk, const struct wined3d_bo_vk *bo)
Definition: context_vk.c:1106
void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch, unsigned int slice_pitch)
Definition: cs.c:2766
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:2299
range
Definition: d3dx9_private.h:58
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT32 uint32_t
Definition: types.h:75
static void wined3d_buffer_set_bo(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo *bo)
Definition: buffer.c:721
static HRESULT wined3d_buffer_init(struct wined3d_buffer *buffer, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_buffer_ops *buffer_ops)
Definition: buffer.c:931
static void wined3d_buffer_init_data(struct wined3d_buffer *buffer, struct wined3d_device *device, const struct wined3d_sub_resource_data *data)
Definition: buffer.c:880
HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops)
Definition: buffer.c:1101
static void buffer_resource_unload(struct wined3d_resource *resource)
Definition: buffer.c:406
BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:257
const VkDescriptorBufferInfo * wined3d_buffer_vk_get_buffer_info(struct wined3d_buffer_vk *buffer_vk)
Definition: buffer.c:1187
static void buffer_resource_sub_resource_get_map_pitch(struct wined3d_resource *resource, unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: buffer.c:549
HRESULT CDECL wined3d_streaming_buffer_upload(struct wined3d_device *device, struct wined3d_streaming_buffer *buffer, const void *data, unsigned int size, unsigned int stride, unsigned int *ret_pos)
Definition: buffer.c:1422
static void wined3d_buffer_destroy_object(void *object)
Definition: buffer.c:437
void wined3d_buffer_update_sub_resource(struct wined3d_buffer *buffer, struct wined3d_context *context, const struct upload_bo *upload_bo, unsigned int offset, unsigned int size)
Definition: buffer.c:827
static BOOL wined3d_buffer_vk_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1202
static void wined3d_buffer_evict_sysmem(struct wined3d_buffer *buffer)
Definition: buffer.c:44
static BOOL wined3d_buffer_gl_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1050
BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, struct wined3d_context *context, uint32_t location)
Definition: buffer.c:269
static BOOL buffer_is_fully_dirty(const struct wined3d_buffer *buffer)
Definition: buffer.c:96
static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl)
Definition: buffer.c:169
GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info, uint32_t bind_flags)
Definition: buffer.c:136
VkMemoryPropertyFlags vk_memory_type_from_access_flags(uint32_t access, uint32_t usage)
Definition: buffer.c:1150
static void buffer_resource_preload(struct wined3d_resource *resource)
Definition: buffer.c:910
static BOOL buffer_is_dirty(const struct wined3d_buffer *buffer)
Definition: buffer.c:91
static void buffer_clear_dirty_areas(struct wined3d_buffer *buffer)
Definition: buffer.c:86
void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context, const struct wined3d_state *state)
Definition: buffer.c:484
static void wined3d_buffer_drop_bo(struct wined3d_buffer *buffer)
Definition: buffer.c:431
HRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
Definition: buffer.c:1329
static ULONG buffer_resource_decref(struct wined3d_resource *resource)
Definition: buffer.c:905
static HRESULT buffer_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
Definition: buffer.c:676
void wined3d_buffer_acquire_bo_for_write(struct wined3d_buffer *buffer, struct wined3d_context *context)
Definition: buffer.c:750
void *CDECL wined3d_buffer_get_parent(const struct wined3d_buffer *buffer)
Definition: buffer.c:476
DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo_address *data)
Definition: buffer.c:369
ULONG CDECL wined3d_buffer_incref(struct wined3d_buffer *buffer)
Definition: buffer.c:248
ULONG CDECL wined3d_buffer_decref(struct wined3d_buffer *buffer)
Definition: buffer.c:459
static BOOL wined3d_buffer_no3d_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1017
void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, uint32_t location)
Definition: buffer.c:131
static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, uint32_t flags)
Definition: buffer.c:555
static void wined3d_buffer_gl_unload_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1078
static HRESULT wined3d_streaming_buffer_prepare(struct wined3d_device *device, struct wined3d_streaming_buffer *buffer, unsigned int min_size)
Definition: buffer.c:1339
void wined3d_buffer_validate_location(struct wined3d_buffer *buffer, uint32_t location)
Definition: buffer.c:102
static const struct wined3d_resource_ops buffer_resource_ops
Definition: buffer.c:919
HRESULT wined3d_buffer_vk_init(struct wined3d_buffer_vk *buffer_vk, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops)
Definition: buffer.c:1258
#define WINED3D_BUFFER_HASDESC
Definition: buffer.c:31
void wined3d_buffer_vk_barrier(struct wined3d_buffer_vk *buffer_vk, struct wined3d_context_vk *context_vk, uint32_t bind_mask)
Definition: buffer.c:1280
static void wined3d_buffer_no3d_unload_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1028
struct wined3d_resource *CDECL wined3d_buffer_get_resource(struct wined3d_buffer *buffer)
Definition: buffer.c:520
static void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, unsigned int offset, unsigned int size)
Definition: buffer.c:114
static void buffer_invalidate_bo_range(struct wined3d_buffer *buffer, unsigned int offset, unsigned int size)
Definition: buffer.c:57
static const struct wined3d_buffer_ops wined3d_buffer_gl_ops
Definition: buffer.c:1095
static const struct wined3d_buffer_ops wined3d_buffer_no3d_ops
Definition: buffer.c:1034
static const struct wined3d_buffer_ops wined3d_buffer_vk_ops
Definition: buffer.c:1252
void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset, struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size)
Definition: buffer.c:808
static ULONG buffer_resource_incref(struct wined3d_resource *resource)
Definition: buffer.c:900
void CDECL wined3d_streaming_buffer_unmap(struct wined3d_streaming_buffer *buffer)
Definition: buffer.c:1417
HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops)
Definition: buffer.c:1040
void wined3d_buffer_cleanup(struct wined3d_buffer *buffer)
Definition: buffer.c:453
void * wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context)
Definition: buffer.c:362
static void wined3d_buffer_unload_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:263
static BOOL wined3d_buffer_vk_create_buffer_object(struct wined3d_buffer_vk *buffer_vk, struct wined3d_context_vk *context_vk)
Definition: buffer.c:1163
void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wined3d_context *context, unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size)
Definition: buffer.c:785
static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl)
Definition: buffer.c:207
static void wined3d_buffer_vk_unload_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:1222
#define WINED3D_BUFFER_USE_BO
Definition: buffer.c:32
VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags)
Definition: buffer.c:1126
HRESULT CDECL wined3d_streaming_buffer_map(struct wined3d_device *device, struct wined3d_streaming_buffer *buffer, unsigned int size, unsigned int stride, unsigned int *ret_pos, void **ret_data)
Definition: buffer.c:1375
static HRESULT buffer_resource_sub_resource_get_desc(struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
Definition: buffer.c:527
#define SB_MIN_SIZE
Definition: buffer.c:34
bool wined3d_device_gl_create_bo(struct wined3d_device_gl *device_gl, struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding, GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo)
Definition: device.c:1335
VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags)
Definition: resource.c:552
GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource)
Definition: resource.c:355
VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags)
Definition: resource.c:526
HRESULT CDECL wined3d_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
Definition: resource.c:304
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device, enum wined3d_resource_type type, const struct wined3d_format *format, enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, uint32_t usage, unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth, unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops)
Definition: resource.c:54
HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, uint32_t flags)
Definition: resource.c:295
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
Definition: resource.c:345
void resource_cleanup(struct wined3d_resource *resource)
Definition: resource.c:224
BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource)
Definition: resource.c:337
void resource_unload(struct wined3d_resource *resource)
Definition: resource.c:241
const char * debug_d3dusage(uint32_t usage)
Definition: utils.c:4895
const char * wined3d_debug_bind_flags(uint32_t bind_flags)
Definition: utils.c:4845
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:4552
const char * wined3d_debug_location(uint32_t location)
Definition: utils.c:6588
const char * wined3d_debug_resource_access(uint32_t access)
Definition: utils.c:4828
const struct wined3d_format * wined3d_get_format(const struct wined3d_adapter *adapter, enum wined3d_format_id format_id, unsigned int bind_flags)
Definition: utils.c:4428
BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
Definition: utils.c:6740
#define CDECL
Definition: compat.h:29
#define assert(_expr)
Definition: assert.h:32
unsigned char uint8_t
Definition: stdint.h:33
#define UINT8_MAX
Definition: stdint.h:83
r parent
Definition: btrfs.c:3010
size_t const old_size
Definition: expand.cpp:65
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int GLbitfield
Definition: gl.h:152
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int GLenum
Definition: gl.h:150
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizei stride
Definition: glext.h:5848
#define GL_UNIFORM_BUFFER
Definition: glext.h:1846
GLenum src
Definition: glext.h:6340
GLsizei const GLint * locations
Definition: glext.h:10542
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
#define GL_ARRAY_BUFFER
Definition: glext.h:336
#define GL_TEXTURE_BUFFER
Definition: glext.h:748
GLenum GLenum dst
Definition: glext.h:6340
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define GL_TRANSFORM_FEEDBACK_BUFFER
Definition: glext.h:557
ptrdiff_t GLsizeiptr
Definition: glext.h:5499
#define GL_STATIC_DRAW
Definition: glext.h:350
#define GL_ELEMENT_ARRAY_BUFFER
Definition: glext.h:337
#define GL_STREAM_DRAW_ARB
Definition: glext.h:1506
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define GL_DRAW_INDIRECT_BUFFER
Definition: glext.h:2046
#define GL_PIXEL_UNPACK_BUFFER
Definition: glext.h:477
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
#define resource
Definition: kernel32.h:9
#define location(file, line)
Definition: kmtest.h:18
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
static RPC_BINDING_HANDLE binding
Definition: server.c:166
#define BOOL
Definition: nt_native.h:43
long LONG
Definition: pedump.c:60
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
VkAccessFlags srcAccessMask
Definition: vulkan.h:7632
VkAccessFlags dstAccessMask
Definition: vulkan.h:7633
uint32_t srcQueueFamilyIndex
Definition: vulkan.h:7634
const void * pNext
Definition: vulkan.h:7631
VkStructureType sType
Definition: vulkan.h:7630
uint32_t dstQueueFamilyIndex
Definition: vulkan.h:7635
Definition: palette.c:466
Definition: http.c:7252
Definition: devices.h:37
size_t size
Definition: utils.c:170
struct wined3d_const_bo_address addr
uint32_t flags
struct wined3d_gl_info gl_info
Definition: wined3d_gl.h:800
struct wined3d_vk_info vk_info
Definition: wined3d_vk.h:728
struct wined3d_bo b
Definition: wined3d_gl.h:415
struct wined3d_bo b
Definition: wined3d_vk.h:310
VkBuffer vk_buffer
Definition: wined3d_vk.h:312
struct list users
uint8_t refcount
struct wined3d_buffer b
Definition: wined3d_gl.h:1046
BOOL(* buffer_prepare_location)(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:38
void(* buffer_unload_location)(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location)
Definition: buffer.c:40
struct wined3d_buffer b
Definition: wined3d_vk.h:920
uint32_t bind_mask
Definition: wined3d_vk.h:923
VkDescriptorBufferInfo buffer_info
Definition: wined3d_vk.h:922
struct wined3d_resource resource
struct wined3d_context c
Definition: wined3d_gl.h:601
const struct wined3d_gl_info * gl_info
Definition: wined3d_gl.h:603
const struct wined3d_vk_info * vk_info
Definition: wined3d_vk.h:590
BOOL supported[WINED3D_GL_EXT_COUNT]
Definition: wined3d_gl.h:347
unsigned int size
unsigned int offset
const struct wined3d_parent_ops * parent_ops
BOOL supported[WINED3D_VK_EXT_COUNT]
Definition: wined3d_vk.h:261
#define max(a, b)
Definition: svc.c:63
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
VkFlags VkMemoryPropertyFlags
Definition: vulkan.h:1063
@ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
Definition: vulkan.h:3770
@ VK_MEMORY_PROPERTY_HOST_CACHED_BIT
Definition: vulkan.h:3773
@ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Definition: vulkan.h:3771
VkFlags VkBufferUsageFlags
Definition: vulkan.h:965
@ VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
Definition: vulkan.h:1918
@ VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
Definition: vulkan.h:1917
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:1916
@ VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
Definition: vulkan.h:1923
@ VK_BUFFER_USAGE_INDEX_BUFFER_BIT
Definition: vulkan.h:1921
@ VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT
Definition: vulkan.h:1926
@ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
Definition: vulkan.h:1919
@ VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
Definition: vulkan.h:1922
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT
Definition: vulkan.h:1915
void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers)
#define VK_QUEUE_FAMILY_IGNORED
Definition: vulkan.h:57
@ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
Definition: vulkan.h:5008
const struct wined3d_parent_ops wined3d_null_parent_ops
Definition: directx.c:3472
@ WINED3D_MULTISAMPLE_NONE
Definition: wined3d.h:573
#define WINED3D_OK
Definition: wined3d.h:33
#define WINED3D_BIND_VERTEX_BUFFER
Definition: wined3d.h:909
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:51
@ WINED3D_RTYPE_BUFFER
Definition: wined3d.h:718
#define WINED3D_BIND_UNORDERED_ACCESS
Definition: wined3d.h:916
#define WINED3D_BIND_SHADER_RESOURCE
Definition: wined3d.h:912
@ WINED3DFMT_R8_UNORM
Definition: wined3d.h:218
#define WINED3D_BIND_INDIRECT_BUFFER
Definition: wined3d.h:917
#define WINED3D_BIND_DEPTH_STENCIL
Definition: wined3d.h:915
static void wined3d_box_set(struct wined3d_box *box, unsigned int left, unsigned int top, unsigned int right, unsigned int bottom, unsigned int front, unsigned int back)
Definition: wined3d.h:3006
#define WINED3D_RESOURCE_ACCESS_MAP_R
Definition: wined3d.h:53
#define WINED3DUSAGE_MANAGED
Definition: wined3d.h:938
#define WINED3D_MAP_DISCARD
Definition: wined3d.h:953
#define WINED3D_MAP_WRITE
Definition: wined3d.h:956
#define WINED3D_MAP_NOOVERWRITE
Definition: wined3d.h:952
#define WINED3D_BIND_RENDER_TARGET
Definition: wined3d.h:914
#define WINED3DCREATE_SOFTWARE_VERTEXPROCESSING
Definition: wined3d.h:1023
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:924
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:44
#define WINED3D_BIND_CONSTANT_BUFFER
Definition: wined3d.h:911
#define WINED3D_BIND_STREAM_OUTPUT
Definition: wined3d.h:913
#define WINED3D_BIND_INDEX_BUFFER
Definition: wined3d.h:910
#define WINED3D_RESOURCE_ACCESS_MAP_W
Definition: wined3d.h:54
@ ARB_TEXTURE_BUFFER_OBJECT
Definition: wined3d_gl.h:125
@ APPLE_FLUSH_BUFFER_RANGE
Definition: wined3d_gl.h:48
@ ARB_VERTEX_BUFFER_OBJECT
Definition: wined3d_gl.h:153
@ ARB_DRAW_INDIRECT
Definition: wined3d_gl.h:73
@ ARB_MAP_BUFFER_RANGE
Definition: wined3d_gl.h:94
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
static bool wined3d_context_is_graphics_state_dirty(const struct wined3d_context *context, unsigned int state_id)
#define UPLOAD_BO_RENAME_ON_UNMAP
#define WINED3D_CONSTANT_BUFFER_ALIGNMENT
#define WINED3D_LOCATION_SYSMEM
#define STATE_STREAM_OUTPUT
static void wined3d_resource_wait_idle(const struct wined3d_resource *resource)
#define WINED3D_LOCATION_BUFFER
static void context_release(struct wined3d_context *context)
#define RESOURCE_ALIGNMENT
static void wined3d_buffer_validate_user(struct wined3d_buffer *buffer)
#define CLIENT_BO_DISCARDED
static size_t align(size_t addr, size_t alignment)
static void wined3d_context_unmap_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
#define WINED3D_LOCATION_CLEARED
#define WINED3D_LOCATION_DISCARDED
static void * wined3d_context_map_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
static void wined3d_context_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)
static struct wined3d_context * context_acquire(struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)
static void wined3d_context_copy_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags)
static struct wined3d_buffer * buffer_from_resource(struct wined3d_resource *resource)
static const uint32_t WINED3D_READ_ONLY_BIND_MASK
#define VK_CALL(f)
Definition: wined3d_vk.h:272
@ WINED3D_VK_EXT_TRANSFORM_FEEDBACK
Definition: wined3d_vk.h:245