dllhost: Add ISurrogate stub implementation.
[wine.git] / dlls / wined3d / resource.c
blobd599e1d7711dbc29922c4e198eb9a3d436918d40
1 /*
2 * Copyright 2002-2004 Jason Edmeades
3 * Copyright 2003-2004 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
7 * Copyright 2006-2008, 2013 Stefan Dösinger for CodeWeavers
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.
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.
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
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
29 static void resource_check_usage(DWORD usage, unsigned int access)
31 static const DWORD handled = WINED3DUSAGE_DYNAMIC
32 | WINED3DUSAGE_STATICDECL
33 | WINED3DUSAGE_OVERLAY
34 | WINED3DUSAGE_SCRATCH
35 | WINED3DUSAGE_PRIVATE
36 | WINED3DUSAGE_LEGACY_CUBEMAP
37 | ~WINED3DUSAGE_MASK;
39 /* Write-only CPU access is supposed to result in write-combined mappings
40 * being returned. OpenGL doesn't give us explicit control over that, but
41 * the hints and access flags we set for typical access patterns on
42 * dynamic resources should in theory have the same effect on the OpenGL
43 * driver. */
45 if (usage & ~handled)
46 FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
47 if (usage & WINED3DUSAGE_DYNAMIC && access & WINED3D_RESOURCE_ACCESS_MAP_R)
48 WARN_(d3d_perf)("WINED3DUSAGE_DYNAMIC used with WINED3D_RESOURCE_ACCESS_MAP_R.\n");
51 HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
52 enum wined3d_resource_type type, const struct wined3d_format *format,
53 enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, unsigned int usage,
54 unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
55 unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
56 const struct wined3d_resource_ops *resource_ops)
58 const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
59 enum wined3d_gl_resource_type base_type = WINED3D_GL_RES_TYPE_COUNT;
60 enum wined3d_gl_resource_type gl_type = WINED3D_GL_RES_TYPE_COUNT;
61 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
62 BOOL tex_2d_ok = FALSE;
63 unsigned int i;
65 static const struct
67 enum wined3d_resource_type type;
68 DWORD cube_usage;
69 enum wined3d_gl_resource_type gl_type;
71 resource_types[] =
73 {WINED3D_RTYPE_BUFFER, 0, WINED3D_GL_RES_TYPE_BUFFER},
74 {WINED3D_RTYPE_TEXTURE_1D, 0, WINED3D_GL_RES_TYPE_TEX_1D},
75 {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_2D},
76 {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_RECT},
77 {WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_RB},
78 {WINED3D_RTYPE_TEXTURE_2D, WINED3DUSAGE_LEGACY_CUBEMAP, WINED3D_GL_RES_TYPE_TEX_CUBE},
79 {WINED3D_RTYPE_TEXTURE_3D, 0, WINED3D_GL_RES_TYPE_TEX_3D},
82 resource_check_usage(usage, access);
84 if (usage & WINED3DUSAGE_SCRATCH && access & WINED3D_RESOURCE_ACCESS_GPU)
86 ERR("Trying to create a scratch resource with access flags %s.\n",
87 wined3d_debug_resource_access(access));
88 return WINED3DERR_INVALIDCALL;
91 if (bind_flags & (WINED3D_BIND_RENDER_TARGET | WINED3D_BIND_DEPTH_STENCIL))
93 if ((access & (WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_GPU)) != WINED3D_RESOURCE_ACCESS_GPU)
95 WARN("Bind flags %s are incompatible with resource access %s.\n",
96 wined3d_debug_bind_flags(bind_flags), wined3d_debug_resource_access(access));
97 return WINED3DERR_INVALIDCALL;
100 /* Dynamic usage is incompatible with GPU writes. */
101 if (usage & WINED3DUSAGE_DYNAMIC)
103 WARN("Bind flags %s are incompatible with resource usage %s.\n",
104 wined3d_debug_bind_flags(bind_flags), debug_d3dusage(usage));
105 return WINED3DERR_INVALIDCALL;
109 if (!size)
110 ERR("Attempting to create a zero-sized resource.\n");
112 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
114 if (resource_types[i].type != type
115 || resource_types[i].cube_usage != (usage & WINED3DUSAGE_LEGACY_CUBEMAP))
116 continue;
118 gl_type = resource_types[i].gl_type;
119 if (base_type == WINED3D_GL_RES_TYPE_COUNT)
120 base_type = gl_type;
122 if (type == WINED3D_RTYPE_BUFFER)
123 break;
125 if ((bind_flags & WINED3D_BIND_RENDER_TARGET)
126 && !(format->flags[gl_type] & WINED3DFMT_FLAG_RENDERTARGET))
128 WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
129 continue;
131 if ((bind_flags & WINED3D_BIND_DEPTH_STENCIL)
132 && !(format->flags[gl_type] & WINED3DFMT_FLAG_DEPTH_STENCIL))
134 WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
135 continue;
137 if ((bind_flags & WINED3D_BIND_SHADER_RESOURCE)
138 && !(format->flags[gl_type] & WINED3DFMT_FLAG_TEXTURE))
140 WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
141 continue;
143 if (((width & (width - 1)) || (height & (height - 1)))
144 && !d3d_info->texture_npot
145 && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]
146 && gl_type == WINED3D_GL_RES_TYPE_TEX_2D)
148 TRACE("Skipping 2D texture type to try texture rectangle.\n");
149 tex_2d_ok = TRUE;
150 continue;
152 break;
155 if (base_type != WINED3D_GL_RES_TYPE_COUNT && i == ARRAY_SIZE(resource_types))
157 if (tex_2d_ok)
159 /* Non power of 2 texture and rectangle textures or renderbuffers do not work.
160 * Use 2D textures, the texture code will pad to a power of 2 size. */
161 gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
163 else if (usage & WINED3DUSAGE_SCRATCH)
165 /* Needed for proper format information. */
166 gl_type = base_type;
168 else
170 WARN("Did not find a suitable GL resource type for resource type %s.\n",
171 debug_d3dresourcetype(type));
172 return WINED3DERR_INVALIDCALL;
176 if (base_type != WINED3D_GL_RES_TYPE_COUNT
177 && (format->flags[base_type] & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BLOCKS_NO_VERIFY))
178 == WINED3DFMT_FLAG_BLOCKS)
180 UINT width_mask = format->block_width - 1;
181 UINT height_mask = format->block_height - 1;
182 if (width & width_mask || height & height_mask)
183 return WINED3DERR_INVALIDCALL;
186 resource->ref = 1;
187 resource->device = device;
188 resource->type = type;
189 resource->gl_type = gl_type;
190 resource->format = format;
191 if (gl_type < WINED3D_GL_RES_TYPE_COUNT)
192 resource->format_flags = format->flags[gl_type];
193 resource->multisample_type = multisample_type;
194 resource->multisample_quality = multisample_quality;
195 resource->usage = usage;
196 resource->bind_flags = bind_flags;
197 if (resource->format_flags & WINED3DFMT_FLAG_MAPPABLE)
198 access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
199 resource->access = access;
200 resource->width = width;
201 resource->height = height;
202 resource->depth = depth;
203 resource->size = size;
204 resource->priority = 0;
205 resource->parent = parent;
206 resource->parent_ops = parent_ops;
207 resource->resource_ops = resource_ops;
208 resource->map_binding = WINED3D_LOCATION_SYSMEM;
209 resource->heap_memory = NULL;
211 if (!(usage & WINED3DUSAGE_PRIVATE))
213 /* Check that we have enough video ram left */
214 if (!(access & WINED3D_RESOURCE_ACCESS_CPU) && device->wined3d->flags & WINED3D_VIDMEM_ACCOUNTING)
216 if (size > wined3d_device_get_available_texture_mem(device))
218 ERR("Out of adapter memory.\n");
219 return WINED3DERR_OUTOFVIDEOMEMORY;
221 adapter_adjust_memory(device->adapter, size);
224 device_resource_add(device, resource);
227 return WINED3D_OK;
230 static void wined3d_resource_destroy_object(void *object)
232 struct wined3d_resource *resource = object;
234 TRACE("resource %p.\n", resource);
236 wined3d_resource_free_sysmem(resource);
237 context_resource_released(resource->device, resource);
238 wined3d_resource_release(resource);
241 void resource_cleanup(struct wined3d_resource *resource)
243 const struct wined3d *d3d = resource->device->wined3d;
245 TRACE("Cleaning up resource %p.\n", resource);
247 if (!(resource->usage & WINED3DUSAGE_PRIVATE))
249 if (!(resource->access & WINED3D_RESOURCE_ACCESS_CPU) && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
251 TRACE("Decrementing device memory pool by %u.\n", resource->size);
252 adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
255 device_resource_released(resource->device, resource);
257 wined3d_resource_acquire(resource);
258 wined3d_cs_destroy_object(resource->device->cs, wined3d_resource_destroy_object, resource);
261 void resource_unload(struct wined3d_resource *resource)
263 if (resource->map_count)
264 ERR("Resource %p is being unloaded while mapped.\n", resource);
267 DWORD CDECL wined3d_resource_set_priority(struct wined3d_resource *resource, DWORD priority)
269 DWORD prev;
271 if (!wined3d_resource_access_is_managed(resource->access))
273 WARN("Called on non-managed resource %p, ignoring.\n", resource);
274 return 0;
277 prev = resource->priority;
278 resource->priority = priority;
279 TRACE("resource %p, new priority %u, returning old priority %u.\n", resource, priority, prev);
280 return prev;
283 DWORD CDECL wined3d_resource_get_priority(const struct wined3d_resource *resource)
285 TRACE("resource %p, returning %u.\n", resource, resource->priority);
286 return resource->priority;
289 void * CDECL wined3d_resource_get_parent(const struct wined3d_resource *resource)
291 return resource->parent;
294 void CDECL wined3d_resource_set_parent(struct wined3d_resource *resource, void *parent)
296 resource->parent = parent;
299 void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, struct wined3d_resource_desc *desc)
301 desc->resource_type = resource->type;
302 desc->format = resource->format->id;
303 desc->multisample_type = resource->multisample_type;
304 desc->multisample_quality = resource->multisample_quality;
305 desc->usage = resource->usage;
306 desc->bind_flags = resource->bind_flags;
307 desc->access = resource->access;
308 desc->width = resource->width;
309 desc->height = resource->height;
310 desc->depth = resource->depth;
311 desc->size = resource->size;
314 HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
315 struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
317 TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
318 resource, sub_resource_idx, map_desc, debug_box(box), flags);
320 return wined3d_device_context_map(&resource->device->cs->c, resource, sub_resource_idx, map_desc, box, flags);
323 HRESULT CDECL wined3d_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
325 TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
327 return wined3d_device_context_unmap(&resource->device->cs->c, resource, sub_resource_idx);
330 void CDECL wined3d_resource_preload(struct wined3d_resource *resource)
332 wined3d_cs_emit_preload_resource(resource->device->cs, resource);
335 static BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource)
337 void **p;
338 SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
339 void *mem;
341 if (!(mem = heap_alloc_zero(resource->size + align)))
343 ERR("Failed to allocate system memory.\n");
344 return FALSE;
347 p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
348 *p = mem;
350 resource->heap_memory = ++p;
352 return TRUE;
355 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource)
357 if (resource->heap_memory)
358 return TRUE;
360 return wined3d_resource_allocate_sysmem(resource);
363 void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
365 void **p = resource->heap_memory;
367 if (!p)
368 return;
370 heap_free(*(--p));
371 resource->heap_memory = NULL;
374 GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource)
376 uint32_t access = resource->access;
377 GLbitfield flags = 0;
379 if (resource->usage & WINED3DUSAGE_DYNAMIC)
380 flags |= GL_CLIENT_STORAGE_BIT;
381 if (access & WINED3D_RESOURCE_ACCESS_MAP_W)
382 flags |= GL_MAP_WRITE_BIT;
383 if (access & WINED3D_RESOURCE_ACCESS_MAP_R)
384 flags |= GL_MAP_READ_BIT;
386 return flags;
389 GLbitfield wined3d_resource_gl_map_flags(const struct wined3d_bo_gl *bo, DWORD d3d_flags)
391 GLbitfield ret = 0;
393 if (d3d_flags & WINED3D_MAP_WRITE)
395 ret |= GL_MAP_WRITE_BIT;
396 if (!bo->b.coherent)
397 ret |= GL_MAP_FLUSH_EXPLICIT_BIT;
399 if (d3d_flags & WINED3D_MAP_READ)
400 ret |= GL_MAP_READ_BIT;
401 else
402 ret |= GL_MAP_UNSYNCHRONIZED_BIT;
404 return ret;
407 GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags)
409 switch (d3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE))
411 case WINED3D_MAP_READ:
412 return GL_READ_ONLY_ARB;
414 case WINED3D_MAP_WRITE:
415 return GL_WRITE_ONLY_ARB;
417 default:
418 return GL_READ_WRITE_ARB;
422 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
424 struct wined3d_swapchain *swapchain;
426 /* Only 2D texture resources can be onscreen. */
427 if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
428 return TRUE;
430 /* Not on a swapchain - must be offscreen */
431 if (!(swapchain = texture_from_resource(resource)->swapchain))
432 return TRUE;
434 /* The front buffer is always onscreen */
435 if (resource == &swapchain->front_buffer->resource)
436 return FALSE;
438 /* If the swapchain is rendered to an FBO, the backbuffer is
439 * offscreen, otherwise onscreen */
440 return wined3d_settings.offscreen_rendering_mode == ORM_FBO;
443 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource)
445 const struct wined3d_d3d_info *d3d_info = &resource->device->adapter->d3d_info;
447 if (!wined3d_resource_is_offscreen(resource) || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
449 resource->draw_binding = WINED3D_LOCATION_DRAWABLE;
451 else if (resource->multisample_type)
453 resource->draw_binding = d3d_info->multisample_draw_location;
455 else if (resource->gl_type == WINED3D_GL_RES_TYPE_RB)
457 resource->draw_binding = WINED3D_LOCATION_RB_RESOLVED;
459 else
461 resource->draw_binding = WINED3D_LOCATION_TEXTURE_RGB;
465 const struct wined3d_format *wined3d_resource_get_decompress_format(const struct wined3d_resource *resource)
467 const struct wined3d_adapter *adapter = resource->device->adapter;
468 if (resource->format_flags & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE)
469 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
470 return wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM_SRGB, resource->bind_flags);
471 return wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM, resource->bind_flags);
474 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource)
476 const struct wined3d_format *format = resource->format;
478 /* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
479 * feature through type == MULTISAMPLE_XX and quality != 0. This could
480 * be mapped to GL_NV_framebuffer_multisample_coverage.
482 * AMD have a similar feature called Enhanced Quality Anti-Aliasing
483 * (EQAA), but it does not have an equivalent OpenGL extension. */
485 /* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
486 * levels as the count of advertised multisample types for the texture
487 * format. */
488 if (resource->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
490 unsigned int i, count = 0;
492 for (i = 0; i < sizeof(format->multisample_types) * CHAR_BIT; ++i)
494 if (format->multisample_types & 1u << i)
496 if (resource->multisample_quality == count++)
497 break;
500 return i + 1;
503 return resource->multisample_type;
506 HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource,
507 unsigned int sub_resource_idx, const struct wined3d_box *box)
509 const struct wined3d_format *format = resource->format;
510 struct wined3d_sub_resource_desc desc;
511 unsigned int width_mask, height_mask;
513 wined3d_resource_get_sub_resource_desc(resource, sub_resource_idx, &desc);
515 if (box->left >= box->right || box->right > desc.width
516 || box->top >= box->bottom || box->bottom > desc.height
517 || box->front >= box->back || box->back > desc.depth)
519 WARN("Box %s is invalid.\n", debug_box(box));
520 return WINEDDERR_INVALIDRECT;
523 if (resource->format_flags & WINED3DFMT_FLAG_BLOCKS)
525 /* This assumes power of two block sizes, but NPOT block sizes would
526 * be silly anyway.
528 * This also assumes that the format's block depth is 1. */
529 width_mask = format->block_width - 1;
530 height_mask = format->block_height - 1;
532 if ((box->left & width_mask) || (box->top & height_mask)
533 || (box->right & width_mask && box->right != desc.width)
534 || (box->bottom & height_mask && box->bottom != desc.height))
536 WARN("Box %s is misaligned for %ux%u blocks.\n", debug_box(box), format->block_width, format->block_height);
537 return WINED3DERR_INVALIDCALL;
541 return WINED3D_OK;
544 VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags)
546 VkAccessFlags flags = 0;
548 if (bind_flags & WINED3D_BIND_VERTEX_BUFFER)
549 flags |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
550 if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
551 flags |= VK_ACCESS_INDEX_READ_BIT;
552 if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
553 flags |= VK_ACCESS_UNIFORM_READ_BIT;
554 if (bind_flags & WINED3D_BIND_SHADER_RESOURCE)
555 flags |= VK_ACCESS_SHADER_READ_BIT;
556 if (bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
557 flags |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
558 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
559 flags |= VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
560 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
561 flags |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
562 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
563 flags |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
564 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
565 flags |= VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT;
567 return flags;
570 VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags)
572 VkPipelineStageFlags flags = 0;
574 if (bind_flags & (WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER))
575 flags |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
576 if (bind_flags & (WINED3D_BIND_CONSTANT_BUFFER | WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_UNORDERED_ACCESS))
577 flags |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
578 | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT | VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
579 | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
580 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
581 flags |= VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT;
582 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
583 flags |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
584 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
585 flags |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
586 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
587 flags |= VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT;
589 return flags;
592 void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
593 uint8_t *base_memory, const struct wined3d_box *box)
595 const struct wined3d_format *format = resource->format;
596 unsigned int row_pitch, slice_pitch;
598 wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
600 if ((resource->format_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
602 /* Compressed textures are block based, so calculate the offset of
603 * the block that contains the top-left pixel of the mapped box. */
604 return base_memory
605 + (box->front * slice_pitch)
606 + ((box->top / format->block_height) * row_pitch)
607 + ((box->left / format->block_width) * format->block_byte_count);
609 else
611 return base_memory
612 + (box->front * slice_pitch)
613 + (box->top * row_pitch)
614 + (box->left * format->byte_count);