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
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
28 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf
);
30 static void resource_check_usage(DWORD usage
, unsigned int access
)
32 static const DWORD handled
= WINED3DUSAGE_DYNAMIC
33 | WINED3DUSAGE_STATICDECL
34 | WINED3DUSAGE_OVERLAY
35 | WINED3DUSAGE_SCRATCH
36 | WINED3DUSAGE_PRIVATE
37 | WINED3DUSAGE_LEGACY_CUBEMAP
40 /* Write-only CPU access is supposed to result in write-combined mappings
41 * being returned. OpenGL doesn't give us explicit control over that, but
42 * the hints and access flags we set for typical access patterns on
43 * dynamic resources should in theory have the same effect on the OpenGL
47 FIXME("Unhandled usage flags %#x.\n", usage
& ~handled
);
48 if (usage
& WINED3DUSAGE_DYNAMIC
&& access
& WINED3D_RESOURCE_ACCESS_MAP_R
)
49 WARN_(d3d_perf
)("WINED3DUSAGE_DYNAMIC used with WINED3D_RESOURCE_ACCESS_MAP_R.\n");
52 HRESULT
resource_init(struct wined3d_resource
*resource
, struct wined3d_device
*device
,
53 enum wined3d_resource_type type
, const struct wined3d_format
*format
,
54 enum wined3d_multisample_type multisample_type
, unsigned int multisample_quality
, unsigned int usage
,
55 unsigned int bind_flags
, unsigned int access
, unsigned int width
, unsigned int height
, unsigned int depth
,
56 unsigned int size
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
57 const struct wined3d_resource_ops
*resource_ops
)
59 const struct wined3d_d3d_info
*d3d_info
= &device
->adapter
->d3d_info
;
60 enum wined3d_gl_resource_type base_type
= WINED3D_GL_RES_TYPE_COUNT
;
61 enum wined3d_gl_resource_type gl_type
= WINED3D_GL_RES_TYPE_COUNT
;
62 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
63 BOOL tex_2d_ok
= FALSE
;
68 enum wined3d_resource_type type
;
70 enum wined3d_gl_resource_type gl_type
;
74 {WINED3D_RTYPE_BUFFER
, 0, WINED3D_GL_RES_TYPE_BUFFER
},
75 {WINED3D_RTYPE_TEXTURE_1D
, 0, WINED3D_GL_RES_TYPE_TEX_1D
},
76 {WINED3D_RTYPE_TEXTURE_2D
, 0, WINED3D_GL_RES_TYPE_TEX_2D
},
77 {WINED3D_RTYPE_TEXTURE_2D
, 0, WINED3D_GL_RES_TYPE_TEX_RECT
},
78 {WINED3D_RTYPE_TEXTURE_2D
, 0, WINED3D_GL_RES_TYPE_RB
},
79 {WINED3D_RTYPE_TEXTURE_2D
, WINED3DUSAGE_LEGACY_CUBEMAP
, WINED3D_GL_RES_TYPE_TEX_CUBE
},
80 {WINED3D_RTYPE_TEXTURE_3D
, 0, WINED3D_GL_RES_TYPE_TEX_3D
},
83 resource_check_usage(usage
, access
);
85 if (usage
& WINED3DUSAGE_SCRATCH
&& access
& WINED3D_RESOURCE_ACCESS_GPU
)
87 ERR("Trying to create a scratch resource with access flags %s.\n",
88 wined3d_debug_resource_access(access
));
89 return WINED3DERR_INVALIDCALL
;
92 if (bind_flags
& (WINED3D_BIND_RENDER_TARGET
| WINED3D_BIND_DEPTH_STENCIL
))
94 if ((access
& (WINED3D_RESOURCE_ACCESS_CPU
| WINED3D_RESOURCE_ACCESS_GPU
)) != WINED3D_RESOURCE_ACCESS_GPU
)
96 WARN("Bind flags %s are incompatible with resource access %s.\n",
97 wined3d_debug_bind_flags(bind_flags
), wined3d_debug_resource_access(access
));
98 return WINED3DERR_INVALIDCALL
;
101 /* Dynamic usage is incompatible with GPU writes. */
102 if (usage
& WINED3DUSAGE_DYNAMIC
)
104 WARN("Bind flags %s are incompatible with resource usage %s.\n",
105 wined3d_debug_bind_flags(bind_flags
), debug_d3dusage(usage
));
106 return WINED3DERR_INVALIDCALL
;
111 ERR("Attempting to create a zero-sized resource.\n");
113 for (i
= 0; i
< ARRAY_SIZE(resource_types
); ++i
)
115 if (resource_types
[i
].type
!= type
116 || resource_types
[i
].cube_usage
!= (usage
& WINED3DUSAGE_LEGACY_CUBEMAP
))
119 gl_type
= resource_types
[i
].gl_type
;
120 if (base_type
== WINED3D_GL_RES_TYPE_COUNT
)
123 if (type
== WINED3D_RTYPE_BUFFER
)
126 if ((bind_flags
& WINED3D_BIND_RENDER_TARGET
)
127 && !(format
->flags
[gl_type
] & WINED3DFMT_FLAG_RENDERTARGET
))
129 WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format
->id
));
132 if ((bind_flags
& WINED3D_BIND_DEPTH_STENCIL
)
133 && !(format
->flags
[gl_type
] & WINED3DFMT_FLAG_DEPTH_STENCIL
))
135 WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format
->id
));
138 if ((bind_flags
& WINED3D_BIND_SHADER_RESOURCE
)
139 && !(format
->flags
[gl_type
] & WINED3DFMT_FLAG_TEXTURE
))
141 WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format
->id
));
144 if (((width
& (width
- 1)) || (height
& (height
- 1)))
145 && !d3d_info
->texture_npot
146 && !gl_info
->supported
[WINED3D_GL_NORMALIZED_TEXRECT
]
147 && gl_type
== WINED3D_GL_RES_TYPE_TEX_2D
)
149 TRACE("Skipping 2D texture type to try texture rectangle.\n");
156 if (base_type
!= WINED3D_GL_RES_TYPE_COUNT
&& i
== ARRAY_SIZE(resource_types
))
160 /* Non power of 2 texture and rectangle textures or renderbuffers do not work.
161 * Use 2D textures, the texture code will pad to a power of 2 size. */
162 gl_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
164 else if (usage
& WINED3DUSAGE_SCRATCH
)
166 /* Needed for proper format information. */
171 WARN("Did not find a suitable GL resource type for resource type %s.\n",
172 debug_d3dresourcetype(type
));
173 return WINED3DERR_INVALIDCALL
;
177 if (base_type
!= WINED3D_GL_RES_TYPE_COUNT
178 && (format
->flags
[base_type
] & (WINED3DFMT_FLAG_BLOCKS
| WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
))
179 == WINED3DFMT_FLAG_BLOCKS
)
181 UINT width_mask
= format
->block_width
- 1;
182 UINT height_mask
= format
->block_height
- 1;
183 if (width
& width_mask
|| height
& height_mask
)
184 return WINED3DERR_INVALIDCALL
;
188 resource
->device
= device
;
189 resource
->type
= type
;
190 resource
->gl_type
= gl_type
;
191 resource
->format
= format
;
192 if (gl_type
< WINED3D_GL_RES_TYPE_COUNT
)
193 resource
->format_flags
= format
->flags
[gl_type
];
194 resource
->multisample_type
= multisample_type
;
195 resource
->multisample_quality
= multisample_quality
;
196 resource
->usage
= usage
;
197 resource
->bind_flags
= bind_flags
;
198 if (resource
->format_flags
& WINED3DFMT_FLAG_MAPPABLE
)
199 access
|= WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
200 resource
->access
= access
;
201 resource
->width
= width
;
202 resource
->height
= height
;
203 resource
->depth
= depth
;
204 resource
->size
= size
;
205 resource
->priority
= 0;
206 resource
->parent
= parent
;
207 resource
->parent_ops
= parent_ops
;
208 resource
->resource_ops
= resource_ops
;
209 resource
->map_binding
= WINED3D_LOCATION_SYSMEM
;
210 resource
->heap_memory
= NULL
;
212 if (!(usage
& WINED3DUSAGE_PRIVATE
))
214 /* Check that we have enough video ram left */
215 if (!(access
& WINED3D_RESOURCE_ACCESS_CPU
) && device
->wined3d
->flags
& WINED3D_VIDMEM_ACCOUNTING
)
217 if (size
> wined3d_device_get_available_texture_mem(device
))
219 ERR("Out of adapter memory.\n");
220 return WINED3DERR_OUTOFVIDEOMEMORY
;
222 adapter_adjust_memory(device
->adapter
, size
);
225 device_resource_add(device
, resource
);
231 static void wined3d_resource_destroy_object(void *object
)
233 struct wined3d_resource
*resource
= object
;
235 TRACE("resource %p.\n", resource
);
237 wined3d_resource_free_sysmem(resource
);
238 context_resource_released(resource
->device
, resource
);
239 wined3d_resource_release(resource
);
242 void resource_cleanup(struct wined3d_resource
*resource
)
244 const struct wined3d
*d3d
= resource
->device
->wined3d
;
246 TRACE("Cleaning up resource %p.\n", resource
);
248 if (!(resource
->usage
& WINED3DUSAGE_PRIVATE
))
250 if (!(resource
->access
& WINED3D_RESOURCE_ACCESS_CPU
) && d3d
->flags
& WINED3D_VIDMEM_ACCOUNTING
)
252 TRACE("Decrementing device memory pool by %u.\n", resource
->size
);
253 adapter_adjust_memory(resource
->device
->adapter
, (INT64
)0 - resource
->size
);
256 device_resource_released(resource
->device
, resource
);
258 wined3d_resource_acquire(resource
);
259 wined3d_cs_destroy_object(resource
->device
->cs
, wined3d_resource_destroy_object
, resource
);
262 void resource_unload(struct wined3d_resource
*resource
)
264 if (resource
->map_count
)
265 ERR("Resource %p is being unloaded while mapped.\n", resource
);
268 DWORD CDECL
wined3d_resource_set_priority(struct wined3d_resource
*resource
, DWORD priority
)
272 if (!wined3d_resource_access_is_managed(resource
->access
))
274 WARN("Called on non-managed resource %p, ignoring.\n", resource
);
278 prev
= resource
->priority
;
279 resource
->priority
= priority
;
280 TRACE("resource %p, new priority %u, returning old priority %u.\n", resource
, priority
, prev
);
284 DWORD CDECL
wined3d_resource_get_priority(const struct wined3d_resource
*resource
)
286 TRACE("resource %p, returning %u.\n", resource
, resource
->priority
);
287 return resource
->priority
;
290 void * CDECL
wined3d_resource_get_parent(const struct wined3d_resource
*resource
)
292 return resource
->parent
;
295 void CDECL
wined3d_resource_set_parent(struct wined3d_resource
*resource
, void *parent
)
297 resource
->parent
= parent
;
300 void CDECL
wined3d_resource_get_desc(const struct wined3d_resource
*resource
, struct wined3d_resource_desc
*desc
)
302 desc
->resource_type
= resource
->type
;
303 desc
->format
= resource
->format
->id
;
304 desc
->multisample_type
= resource
->multisample_type
;
305 desc
->multisample_quality
= resource
->multisample_quality
;
306 desc
->usage
= resource
->usage
;
307 desc
->bind_flags
= resource
->bind_flags
;
308 desc
->access
= resource
->access
;
309 desc
->width
= resource
->width
;
310 desc
->height
= resource
->height
;
311 desc
->depth
= resource
->depth
;
312 desc
->size
= resource
->size
;
315 HRESULT CDECL
wined3d_resource_map(struct wined3d_resource
*resource
, unsigned int sub_resource_idx
,
316 struct wined3d_map_desc
*map_desc
, const struct wined3d_box
*box
, DWORD flags
)
318 TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
319 resource
, sub_resource_idx
, map_desc
, debug_box(box
), flags
);
321 return wined3d_device_context_map(&resource
->device
->cs
->c
, resource
, sub_resource_idx
, map_desc
, box
, flags
);
324 HRESULT CDECL
wined3d_resource_unmap(struct wined3d_resource
*resource
, unsigned int sub_resource_idx
)
326 TRACE("resource %p, sub_resource_idx %u.\n", resource
, sub_resource_idx
);
328 return wined3d_device_context_unmap(&resource
->device
->cs
->c
, resource
, sub_resource_idx
);
331 void CDECL
wined3d_resource_preload(struct wined3d_resource
*resource
)
333 wined3d_cs_emit_preload_resource(resource
->device
->cs
, resource
);
336 static BOOL
wined3d_resource_allocate_sysmem(struct wined3d_resource
*resource
)
339 SIZE_T align
= RESOURCE_ALIGNMENT
- 1 + sizeof(*p
);
342 if (!(mem
= heap_alloc_zero(resource
->size
+ align
)))
344 ERR("Failed to allocate system memory.\n");
348 p
= (void **)(((ULONG_PTR
)mem
+ align
) & ~(RESOURCE_ALIGNMENT
- 1)) - 1;
351 resource
->heap_memory
= ++p
;
356 BOOL
wined3d_resource_prepare_sysmem(struct wined3d_resource
*resource
)
358 if (resource
->heap_memory
)
361 return wined3d_resource_allocate_sysmem(resource
);
364 void wined3d_resource_free_sysmem(struct wined3d_resource
*resource
)
366 void **p
= resource
->heap_memory
;
372 resource
->heap_memory
= NULL
;
375 GLbitfield
wined3d_resource_gl_storage_flags(const struct wined3d_resource
*resource
)
377 uint32_t access
= resource
->access
;
378 GLbitfield flags
= 0;
380 if (resource
->usage
& WINED3DUSAGE_DYNAMIC
)
381 flags
|= GL_CLIENT_STORAGE_BIT
;
382 if (access
& WINED3D_RESOURCE_ACCESS_MAP_W
)
383 flags
|= GL_MAP_WRITE_BIT
;
384 if (access
& WINED3D_RESOURCE_ACCESS_MAP_R
)
385 flags
|= GL_MAP_READ_BIT
;
390 GLbitfield
wined3d_resource_gl_map_flags(const struct wined3d_bo_gl
*bo
, DWORD d3d_flags
)
394 if (d3d_flags
& WINED3D_MAP_WRITE
)
396 ret
|= GL_MAP_WRITE_BIT
;
398 ret
|= GL_MAP_FLUSH_EXPLICIT_BIT
;
400 if (d3d_flags
& WINED3D_MAP_READ
)
401 ret
|= GL_MAP_READ_BIT
;
403 ret
|= GL_MAP_UNSYNCHRONIZED_BIT
;
408 GLenum
wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags
)
410 switch (d3d_flags
& (WINED3D_MAP_READ
| WINED3D_MAP_WRITE
))
412 case WINED3D_MAP_READ
:
413 return GL_READ_ONLY_ARB
;
415 case WINED3D_MAP_WRITE
:
416 return GL_WRITE_ONLY_ARB
;
419 return GL_READ_WRITE_ARB
;
423 BOOL
wined3d_resource_is_offscreen(struct wined3d_resource
*resource
)
425 struct wined3d_swapchain
*swapchain
;
427 /* Only 2D texture resources can be onscreen. */
428 if (resource
->type
!= WINED3D_RTYPE_TEXTURE_2D
)
431 /* Not on a swapchain - must be offscreen */
432 if (!(swapchain
= texture_from_resource(resource
)->swapchain
))
435 /* The front buffer is always onscreen */
436 if (resource
== &swapchain
->front_buffer
->resource
)
439 /* If the swapchain is rendered to an FBO, the backbuffer is
440 * offscreen, otherwise onscreen */
441 return wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
;
444 void wined3d_resource_update_draw_binding(struct wined3d_resource
*resource
)
446 const struct wined3d_d3d_info
*d3d_info
= &resource
->device
->adapter
->d3d_info
;
448 if (!wined3d_resource_is_offscreen(resource
) || wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
450 resource
->draw_binding
= WINED3D_LOCATION_DRAWABLE
;
452 else if (resource
->multisample_type
)
454 resource
->draw_binding
= d3d_info
->multisample_draw_location
;
456 else if (resource
->gl_type
== WINED3D_GL_RES_TYPE_RB
)
458 resource
->draw_binding
= WINED3D_LOCATION_RB_RESOLVED
;
462 resource
->draw_binding
= WINED3D_LOCATION_TEXTURE_RGB
;
466 const struct wined3d_format
*wined3d_resource_get_decompress_format(const struct wined3d_resource
*resource
)
468 const struct wined3d_adapter
*adapter
= resource
->device
->adapter
;
469 if (resource
->format_flags
& (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)
470 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
471 return wined3d_get_format(adapter
, WINED3DFMT_B8G8R8A8_UNORM_SRGB
, resource
->bind_flags
);
472 return wined3d_get_format(adapter
, WINED3DFMT_B8G8R8A8_UNORM
, resource
->bind_flags
);
475 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource
*resource
)
477 const struct wined3d_format
*format
= resource
->format
;
479 /* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
480 * feature through type == MULTISAMPLE_XX and quality != 0. This could
481 * be mapped to GL_NV_framebuffer_multisample_coverage.
483 * AMD have a similar feature called Enhanced Quality Anti-Aliasing
484 * (EQAA), but it does not have an equivalent OpenGL extension. */
486 /* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
487 * levels as the count of advertised multisample types for the texture
489 if (resource
->multisample_type
== WINED3D_MULTISAMPLE_NON_MASKABLE
)
491 unsigned int i
, count
= 0;
493 for (i
= 0; i
< sizeof(format
->multisample_types
) * CHAR_BIT
; ++i
)
495 if (format
->multisample_types
& 1u << i
)
497 if (resource
->multisample_quality
== count
++)
504 return resource
->multisample_type
;
507 HRESULT
wined3d_resource_check_box_dimensions(struct wined3d_resource
*resource
,
508 unsigned int sub_resource_idx
, const struct wined3d_box
*box
)
510 const struct wined3d_format
*format
= resource
->format
;
511 struct wined3d_sub_resource_desc desc
;
512 unsigned int width_mask
, height_mask
;
514 wined3d_resource_get_sub_resource_desc(resource
, sub_resource_idx
, &desc
);
516 if (box
->left
>= box
->right
|| box
->right
> desc
.width
517 || box
->top
>= box
->bottom
|| box
->bottom
> desc
.height
518 || box
->front
>= box
->back
|| box
->back
> desc
.depth
)
520 WARN("Box %s is invalid.\n", debug_box(box
));
521 return WINEDDERR_INVALIDRECT
;
524 if (resource
->format_flags
& WINED3DFMT_FLAG_BLOCKS
)
526 /* This assumes power of two block sizes, but NPOT block sizes would
529 * This also assumes that the format's block depth is 1. */
530 width_mask
= format
->block_width
- 1;
531 height_mask
= format
->block_height
- 1;
533 if ((box
->left
& width_mask
) || (box
->top
& height_mask
)
534 || (box
->right
& width_mask
&& box
->right
!= desc
.width
)
535 || (box
->bottom
& height_mask
&& box
->bottom
!= desc
.height
))
537 WARN("Box %s is misaligned for %ux%u blocks.\n", debug_box(box
), format
->block_width
, format
->block_height
);
538 return WINED3DERR_INVALIDCALL
;
545 VkAccessFlags
vk_access_mask_from_bind_flags(uint32_t bind_flags
)
547 VkAccessFlags flags
= 0;
549 if (bind_flags
& WINED3D_BIND_VERTEX_BUFFER
)
550 flags
|= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
;
551 if (bind_flags
& WINED3D_BIND_INDEX_BUFFER
)
552 flags
|= VK_ACCESS_INDEX_READ_BIT
;
553 if (bind_flags
& WINED3D_BIND_CONSTANT_BUFFER
)
554 flags
|= VK_ACCESS_UNIFORM_READ_BIT
;
555 if (bind_flags
& WINED3D_BIND_SHADER_RESOURCE
)
556 flags
|= VK_ACCESS_SHADER_READ_BIT
;
557 if (bind_flags
& WINED3D_BIND_UNORDERED_ACCESS
)
558 flags
|= VK_ACCESS_SHADER_READ_BIT
| VK_ACCESS_SHADER_WRITE_BIT
;
559 if (bind_flags
& WINED3D_BIND_INDIRECT_BUFFER
)
560 flags
|= VK_ACCESS_INDIRECT_COMMAND_READ_BIT
;
561 if (bind_flags
& WINED3D_BIND_RENDER_TARGET
)
562 flags
|= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
| VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
;
563 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
)
564 flags
|= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
| VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
;
565 if (bind_flags
& WINED3D_BIND_STREAM_OUTPUT
)
566 flags
|= VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT
;
571 VkPipelineStageFlags
vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags
)
573 VkPipelineStageFlags flags
= 0;
575 if (bind_flags
& (WINED3D_BIND_VERTEX_BUFFER
| WINED3D_BIND_INDEX_BUFFER
))
576 flags
|= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
;
577 if (bind_flags
& (WINED3D_BIND_CONSTANT_BUFFER
| WINED3D_BIND_SHADER_RESOURCE
| WINED3D_BIND_UNORDERED_ACCESS
))
578 flags
|= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
| VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
579 | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
| VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
580 | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
;
581 if (bind_flags
& WINED3D_BIND_INDIRECT_BUFFER
)
582 flags
|= VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
;
583 if (bind_flags
& WINED3D_BIND_RENDER_TARGET
)
584 flags
|= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
;
585 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
)
586 flags
|= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
;
587 if (bind_flags
& WINED3D_BIND_STREAM_OUTPUT
)
588 flags
|= VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT
;
593 void *resource_offset_map_pointer(struct wined3d_resource
*resource
, unsigned int sub_resource_idx
,
594 uint8_t *base_memory
, const struct wined3d_box
*box
)
596 const struct wined3d_format
*format
= resource
->format
;
597 unsigned int row_pitch
, slice_pitch
;
599 wined3d_resource_get_sub_resource_map_pitch(resource
, sub_resource_idx
, &row_pitch
, &slice_pitch
);
601 if ((resource
->format_flags
& (WINED3DFMT_FLAG_BLOCKS
| WINED3DFMT_FLAG_BROKEN_PITCH
)) == WINED3DFMT_FLAG_BLOCKS
)
603 /* Compressed textures are block based, so calculate the offset of
604 * the block that contains the top-left pixel of the mapped box. */
606 + (box
->front
* slice_pitch
)
607 + ((box
->top
/ format
->block_height
) * row_pitch
)
608 + ((box
->left
/ format
->block_width
) * format
->block_byte_count
);
613 + (box
->front
* slice_pitch
)
614 + (box
->top
* row_pitch
)
615 + (box
->left
* format
->byte_count
);