2 * Copyright 2018 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
21 #include "wined3d_private.h"
23 #include "wine/vulkan_driver.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
27 static const struct wined3d_state_entry_template misc_state_template_vk
[] =
29 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX
), state_nop
}},
30 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL
), state_nop
}},
31 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN
), state_nop
}},
32 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY
), state_nop
}},
33 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL
), state_nop
}},
34 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE
), {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE
), state_nop
}},
35 {STATE_GRAPHICS_SHADER_RESOURCE_BINDING
, {STATE_GRAPHICS_SHADER_RESOURCE_BINDING
, state_nop
}},
36 {STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING
, {STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING
, state_nop
}},
37 {STATE_COMPUTE_SHADER_RESOURCE_BINDING
, {STATE_COMPUTE_SHADER_RESOURCE_BINDING
, state_nop
}},
38 {STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING
, {STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING
, state_nop
}},
39 {STATE_STREAM_OUTPUT
, {STATE_STREAM_OUTPUT
, state_nop
}},
40 {STATE_BLEND
, {STATE_BLEND
, state_nop
}},
41 {STATE_BLEND_FACTOR
, {STATE_BLEND_FACTOR
, state_nop
}},
42 {STATE_SAMPLE_MASK
, {STATE_SAMPLE_MASK
, state_nop
}},
43 {STATE_STREAMSRC
, {STATE_STREAMSRC
, state_nop
}},
44 {STATE_VDECL
, {STATE_VDECL
, state_nop
}},
45 {STATE_DEPTH_STENCIL
, {STATE_DEPTH_STENCIL
, state_nop
}},
46 {STATE_STENCIL_REF
, {STATE_STENCIL_REF
, state_nop
}},
47 {STATE_RASTERIZER
, {STATE_RASTERIZER
, state_nop
}},
48 {STATE_SCISSORRECT
, {STATE_SCISSORRECT
, state_nop
}},
49 {STATE_POINTSPRITECOORDORIGIN
, {STATE_POINTSPRITECOORDORIGIN
, state_nop
}},
51 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
52 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00
)}},
53 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00
)}},
54 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00
)}},
55 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
56 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00
)}},
57 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00
)}},
58 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00
)}},
59 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
60 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00
)}},
61 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00
)}},
62 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00
)}},
63 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
64 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00
)}},
65 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00
)}},
66 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00
)}},
67 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
68 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00
)}},
69 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00
)}},
70 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00
)}},
71 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
72 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00
)}},
73 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00
)}},
74 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00
)}},
75 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
76 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00
)}},
77 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00
)}},
78 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00
)}},
79 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00
), state_nop
}},
80 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00
)}},
81 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00
)}},
82 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00
)}},
83 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
84 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE
)}},
85 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
86 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE
)}},
87 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
88 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE
)}},
89 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
90 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE
)}},
91 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
92 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE
)}},
93 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
94 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE
)}},
95 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
96 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE
)}},
97 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE
), state_nop
}},
98 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET
), {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE
)}},
100 {STATE_VIEWPORT
, {STATE_VIEWPORT
, state_nop
}},
101 {STATE_INDEXBUFFER
, {STATE_INDEXBUFFER
, state_nop
}},
102 {STATE_RENDER(WINED3D_RS_ANTIALIAS
), {STATE_RENDER(WINED3D_RS_ANTIALIAS
), state_nop
}},
103 {STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE
), {STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE
), state_nop
}},
104 {STATE_RENDER(WINED3D_RS_WRAPU
), {STATE_RENDER(WINED3D_RS_WRAPU
), state_nop
}},
105 {STATE_RENDER(WINED3D_RS_WRAPV
), {STATE_RENDER(WINED3D_RS_WRAPV
), state_nop
}},
106 {STATE_RENDER(WINED3D_RS_LINEPATTERN
), {STATE_RENDER(WINED3D_RS_LINEPATTERN
), state_nop
}},
107 {STATE_RENDER(WINED3D_RS_MONOENABLE
), {STATE_RENDER(WINED3D_RS_MONOENABLE
), state_nop
}},
108 {STATE_RENDER(WINED3D_RS_ROP2
), {STATE_RENDER(WINED3D_RS_ROP2
), state_nop
}},
109 {STATE_RENDER(WINED3D_RS_PLANEMASK
), {STATE_RENDER(WINED3D_RS_PLANEMASK
), state_nop
}},
110 {STATE_RENDER(WINED3D_RS_LASTPIXEL
), {STATE_RENDER(WINED3D_RS_LASTPIXEL
), state_nop
}},
111 {STATE_RENDER(WINED3D_RS_DITHERENABLE
), {STATE_RENDER(WINED3D_RS_DITHERENABLE
), state_nop
}},
112 {STATE_RENDER(WINED3D_RS_SUBPIXEL
), {STATE_RENDER(WINED3D_RS_SUBPIXEL
), state_nop
}},
113 {STATE_RENDER(WINED3D_RS_SUBPIXELX
), {STATE_RENDER(WINED3D_RS_SUBPIXELX
), state_nop
}},
114 {STATE_RENDER(WINED3D_RS_STIPPLEDALPHA
), {STATE_RENDER(WINED3D_RS_STIPPLEDALPHA
), state_nop
}},
115 {STATE_RENDER(WINED3D_RS_STIPPLEENABLE
), {STATE_RENDER(WINED3D_RS_STIPPLEENABLE
), state_nop
}},
116 {STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS
), {STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS
), state_nop
}},
117 {STATE_RENDER(WINED3D_RS_ANISOTROPY
), {STATE_RENDER(WINED3D_RS_ANISOTROPY
), state_nop
}},
118 {STATE_RENDER(WINED3D_RS_FLUSHBATCH
), {STATE_RENDER(WINED3D_RS_FLUSHBATCH
), state_nop
}},
119 {STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
), {STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
), state_nop
}},
120 {STATE_RENDER(WINED3D_RS_WRAP0
), {STATE_RENDER(WINED3D_RS_WRAP0
), state_nop
}},
121 {STATE_RENDER(WINED3D_RS_WRAP1
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
122 {STATE_RENDER(WINED3D_RS_WRAP2
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
123 {STATE_RENDER(WINED3D_RS_WRAP3
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
124 {STATE_RENDER(WINED3D_RS_WRAP4
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
125 {STATE_RENDER(WINED3D_RS_WRAP5
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
126 {STATE_RENDER(WINED3D_RS_WRAP6
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
127 {STATE_RENDER(WINED3D_RS_WRAP7
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
128 {STATE_RENDER(WINED3D_RS_WRAP8
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
129 {STATE_RENDER(WINED3D_RS_WRAP9
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
130 {STATE_RENDER(WINED3D_RS_WRAP10
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
131 {STATE_RENDER(WINED3D_RS_WRAP11
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
132 {STATE_RENDER(WINED3D_RS_WRAP12
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
133 {STATE_RENDER(WINED3D_RS_WRAP13
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
134 {STATE_RENDER(WINED3D_RS_WRAP14
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
135 {STATE_RENDER(WINED3D_RS_WRAP15
), {STATE_RENDER(WINED3D_RS_WRAP0
)}},
136 {STATE_RENDER(WINED3D_RS_EXTENTS
), {STATE_RENDER(WINED3D_RS_EXTENTS
), state_nop
}},
137 {STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE
), {STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE
), state_nop
}},
138 {STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING
), {STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING
), state_nop
}},
139 {STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE
), {STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE
), state_nop
}},
140 {STATE_RENDER(WINED3D_RS_PATCHSEGMENTS
), {STATE_RENDER(WINED3D_RS_PATCHSEGMENTS
), state_nop
}},
141 {STATE_RENDER(WINED3D_RS_POSITIONDEGREE
), {STATE_RENDER(WINED3D_RS_POSITIONDEGREE
), state_nop
}},
142 {STATE_RENDER(WINED3D_RS_NORMALDEGREE
), {STATE_RENDER(WINED3D_RS_NORMALDEGREE
), state_nop
}},
143 {STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
144 {STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
145 {STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
146 {STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
147 {STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
148 {STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
)}},
149 {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
), {STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION
), state_nop
}},
150 {STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS
), {STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS
), state_nop
}},
151 {STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN
), {STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN
), state_nop
}},
152 {STATE_RENDER(WINED3D_RS_ZVISIBLE
), {STATE_RENDER(WINED3D_RS_ZVISIBLE
), state_nop
}},
154 {STATE_SAMPLER(0), {STATE_SAMPLER(0), state_nop
}},
155 {STATE_SAMPLER(1), {STATE_SAMPLER(1), state_nop
}},
156 {STATE_SAMPLER(2), {STATE_SAMPLER(2), state_nop
}},
157 {STATE_SAMPLER(3), {STATE_SAMPLER(3), state_nop
}},
158 {STATE_SAMPLER(4), {STATE_SAMPLER(4), state_nop
}},
159 {STATE_SAMPLER(5), {STATE_SAMPLER(5), state_nop
}},
160 {STATE_SAMPLER(6), {STATE_SAMPLER(6), state_nop
}},
161 {STATE_SAMPLER(7), {STATE_SAMPLER(7), state_nop
}},
162 {STATE_SAMPLER(8), {STATE_SAMPLER(8), state_nop
}},
163 {STATE_SAMPLER(9), {STATE_SAMPLER(9), state_nop
}},
164 {STATE_SAMPLER(10), {STATE_SAMPLER(10), state_nop
}},
165 {STATE_SAMPLER(11), {STATE_SAMPLER(11), state_nop
}},
166 {STATE_SAMPLER(12), {STATE_SAMPLER(12), state_nop
}},
167 {STATE_SAMPLER(13), {STATE_SAMPLER(13), state_nop
}},
168 {STATE_SAMPLER(14), {STATE_SAMPLER(14), state_nop
}},
169 {STATE_SAMPLER(15), {STATE_SAMPLER(15), state_nop
}},
170 {STATE_SAMPLER(16), /* Vertex sampler 0 */ {STATE_SAMPLER(16), state_nop
}},
171 {STATE_SAMPLER(17), /* Vertex sampler 1 */ {STATE_SAMPLER(17), state_nop
}},
172 {STATE_SAMPLER(18), /* Vertex sampler 2 */ {STATE_SAMPLER(18), state_nop
}},
173 {STATE_SAMPLER(19), /* Vertex sampler 3 */ {STATE_SAMPLER(19), state_nop
}},
174 {STATE_BASEVERTEXINDEX
, {STATE_STREAMSRC
}},
175 {STATE_FRAMEBUFFER
, {STATE_FRAMEBUFFER
, state_nop
}},
176 {STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL
), {STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL
), state_nop
}},
177 {STATE_SHADER(WINED3D_SHADER_TYPE_HULL
), {STATE_SHADER(WINED3D_SHADER_TYPE_HULL
), state_nop
}},
178 {STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN
), {STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN
), state_nop
}},
179 {STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY
), {STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY
), state_nop
}},
180 {STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE
), {STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE
), state_nop
}},
184 static inline const struct wined3d_adapter_vk
*wined3d_adapter_vk_const(const struct wined3d_adapter
*adapter
)
186 return CONTAINING_RECORD(adapter
, struct wined3d_adapter_vk
, a
);
189 static const char *debug_vk_version(uint32_t version
)
191 return wine_dbg_sprintf("%u.%u.%u",
192 VK_VERSION_MAJOR(version
), VK_VERSION_MINOR(version
), VK_VERSION_PATCH(version
));
195 static HRESULT
hresult_from_vk_result(VkResult vr
)
201 case VK_ERROR_OUT_OF_HOST_MEMORY
:
202 WARN("Out of host memory.\n");
203 return E_OUTOFMEMORY
;
204 case VK_ERROR_OUT_OF_DEVICE_MEMORY
:
205 WARN("Out of device memory.\n");
206 return E_OUTOFMEMORY
;
207 case VK_ERROR_DEVICE_LOST
:
208 WARN("Device lost.\n");
210 case VK_ERROR_EXTENSION_NOT_PRESENT
:
211 WARN("Extension not present.\n");
214 FIXME("Unhandled VkResult %d.\n", vr
);
219 #ifdef USE_WIN32_VULKAN
220 static BOOL
wined3d_load_vulkan(struct wined3d_vk_info
*vk_info
)
222 struct vulkan_ops
*vk_ops
= &vk_info
->vk_ops
;
224 if (!(vk_info
->vulkan_lib
= LoadLibraryA("vulkan-1.dll")))
226 WARN("Failed to load vulkan-1.dll.\n");
230 vk_ops
->vkGetInstanceProcAddr
= (void *)GetProcAddress(vk_info
->vulkan_lib
, "vkGetInstanceProcAddr");
231 if (!vk_ops
->vkGetInstanceProcAddr
)
233 FreeLibrary(vk_info
->vulkan_lib
);
240 static void wined3d_unload_vulkan(struct wined3d_vk_info
*vk_info
)
242 if (vk_info
->vulkan_lib
)
244 FreeLibrary(vk_info
->vulkan_lib
);
245 vk_info
->vulkan_lib
= NULL
;
249 static BOOL
wined3d_load_vulkan(struct wined3d_vk_info
*vk_info
)
251 struct vulkan_ops
*vk_ops
= &vk_info
->vk_ops
;
252 const struct vulkan_funcs
*vk_funcs
;
256 vk_funcs
= __wine_get_vulkan_driver(dc
, WINE_VULKAN_DRIVER_VERSION
);
262 vk_ops
->vkGetInstanceProcAddr
= (void *)vk_funcs
->p_vkGetInstanceProcAddr
;
266 static void wined3d_unload_vulkan(struct wined3d_vk_info
*vk_info
) {}
269 static void adapter_vk_destroy(struct wined3d_adapter
*adapter
)
271 struct wined3d_adapter_vk
*adapter_vk
= wined3d_adapter_vk(adapter
);
272 struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
274 VK_CALL(vkDestroyInstance(vk_info
->instance
, NULL
));
275 wined3d_unload_vulkan(vk_info
);
276 wined3d_adapter_cleanup(&adapter_vk
->a
);
277 heap_free(adapter_vk
->device_extensions
);
278 heap_free(adapter_vk
);
281 static HRESULT
wined3d_select_vulkan_queue_family(const struct wined3d_adapter_vk
*adapter_vk
,
282 uint32_t *queue_family_index
, uint32_t *timestamp_bits
)
284 VkPhysicalDevice physical_device
= adapter_vk
->physical_device
;
285 const struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
286 VkQueueFamilyProperties
*queue_properties
;
289 VK_CALL(vkGetPhysicalDeviceQueueFamilyProperties(physical_device
, &count
, NULL
));
291 if (!(queue_properties
= heap_calloc(count
, sizeof(*queue_properties
))))
292 return E_OUTOFMEMORY
;
294 VK_CALL(vkGetPhysicalDeviceQueueFamilyProperties(physical_device
, &count
, queue_properties
));
296 for (i
= 0; i
< count
; ++i
)
298 if (queue_properties
[i
].queueFlags
& VK_QUEUE_GRAPHICS_BIT
)
300 *queue_family_index
= i
;
301 *timestamp_bits
= queue_properties
[i
].timestampValidBits
;
302 heap_free(queue_properties
);
306 heap_free(queue_properties
);
308 WARN("Failed to find graphics queue.\n");
312 struct wined3d_physical_device_info
314 VkPhysicalDeviceTransformFeedbackFeaturesEXT xfb_features
;
315 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT vertex_divisor_features
;
317 VkPhysicalDeviceFeatures2 features2
;
320 static void wined3d_disable_vulkan_features(struct wined3d_physical_device_info
*info
)
322 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*vertex_divisor_features
= &info
->vertex_divisor_features
;
323 VkPhysicalDeviceFeatures
*features
= &info
->features2
.features
;
325 vertex_divisor_features
->vertexAttributeInstanceRateZeroDivisor
= VK_FALSE
;
327 features
->depthBounds
= VK_FALSE
;
328 features
->alphaToOne
= VK_FALSE
;
329 features
->textureCompressionETC2
= VK_FALSE
;
330 features
->textureCompressionASTC_LDR
= VK_FALSE
;
331 features
->shaderStorageImageMultisample
= VK_FALSE
;
332 features
->shaderUniformBufferArrayDynamicIndexing
= VK_FALSE
;
333 features
->shaderSampledImageArrayDynamicIndexing
= VK_FALSE
;
334 features
->shaderStorageBufferArrayDynamicIndexing
= VK_FALSE
;
335 features
->shaderStorageImageArrayDynamicIndexing
= VK_FALSE
;
336 features
->shaderInt16
= VK_FALSE
;
337 features
->shaderResourceResidency
= VK_FALSE
;
338 features
->shaderResourceMinLod
= VK_FALSE
;
339 features
->sparseBinding
= VK_FALSE
;
340 features
->sparseResidencyBuffer
= VK_FALSE
;
341 features
->sparseResidencyImage2D
= VK_FALSE
;
342 features
->sparseResidencyImage3D
= VK_FALSE
;
343 features
->sparseResidency2Samples
= VK_FALSE
;
344 features
->sparseResidency4Samples
= VK_FALSE
;
345 features
->sparseResidency8Samples
= VK_FALSE
;
346 features
->sparseResidency16Samples
= VK_FALSE
;
347 features
->sparseResidencyAliased
= VK_FALSE
;
348 features
->inheritedQueries
= VK_FALSE
;
351 static struct wined3d_allocator_chunk
*wined3d_allocator_vk_create_chunk(struct wined3d_allocator
*allocator
,
352 struct wined3d_context
*context
, unsigned int memory_type
, size_t chunk_size
)
354 struct wined3d_context_vk
*context_vk
= wined3d_context_vk(context
);
355 struct wined3d_allocator_chunk_vk
*chunk_vk
;
357 if (!(chunk_vk
= heap_alloc(sizeof(*chunk_vk
))))
360 if (!wined3d_allocator_chunk_init(&chunk_vk
->c
, allocator
))
366 if (!(chunk_vk
->vk_memory
= wined3d_context_vk_allocate_vram_chunk_memory(context_vk
, memory_type
, chunk_size
)))
368 wined3d_allocator_chunk_cleanup(&chunk_vk
->c
);
372 list_add_head(&allocator
->pools
[memory_type
].chunks
, &chunk_vk
->c
.entry
);
377 static void wined3d_allocator_vk_destroy_chunk(struct wined3d_allocator_chunk
*chunk
)
379 struct wined3d_allocator_chunk_vk
*chunk_vk
= wined3d_allocator_chunk_vk(chunk
);
380 const struct wined3d_vk_info
*vk_info
;
381 struct wined3d_device_vk
*device_vk
;
383 TRACE("chunk %p.\n", chunk
);
385 device_vk
= CONTAINING_RECORD(chunk_vk
->c
.allocator
, struct wined3d_device_vk
, allocator
);
386 vk_info
= &device_vk
->vk_info
;
388 if (chunk_vk
->c
.map_ptr
)
389 VK_CALL(vkUnmapMemory(device_vk
->vk_device
, chunk_vk
->vk_memory
));
390 VK_CALL(vkFreeMemory(device_vk
->vk_device
, chunk_vk
->vk_memory
, NULL
));
391 TRACE("Freed memory 0x%s.\n", wine_dbgstr_longlong(chunk_vk
->vk_memory
));
392 wined3d_allocator_chunk_cleanup(&chunk_vk
->c
);
396 static const struct wined3d_allocator_ops wined3d_allocator_vk_ops
=
398 .allocator_create_chunk
= wined3d_allocator_vk_create_chunk
,
399 .allocator_destroy_chunk
= wined3d_allocator_vk_destroy_chunk
,
402 static HRESULT
adapter_vk_create_device(struct wined3d
*wined3d
, const struct wined3d_adapter
*adapter
,
403 enum wined3d_device_type device_type
, HWND focus_window
, unsigned int flags
, BYTE surface_alignment
,
404 const enum wined3d_feature_level
*levels
, unsigned int level_count
,
405 struct wined3d_device_parent
*device_parent
, struct wined3d_device
**device
)
407 const struct wined3d_adapter_vk
*adapter_vk
= wined3d_adapter_vk_const(adapter
);
408 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*vertex_divisor_features
;
409 const struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
410 VkPhysicalDeviceTransformFeedbackFeaturesEXT
*xfb_features
;
411 struct wined3d_physical_device_info physical_device_info
;
412 static const float priorities
[] = {1.0f
};
413 VkPhysicalDeviceFeatures2
*features2
;
414 struct wined3d_device_vk
*device_vk
;
415 VkDevice vk_device
= VK_NULL_HANDLE
;
416 VkDeviceQueueCreateInfo queue_info
;
417 VkPhysicalDevice physical_device
;
418 VkDeviceCreateInfo device_info
;
419 uint32_t queue_family_index
;
420 uint32_t timestamp_bits
;
424 if (!(device_vk
= heap_alloc_zero(sizeof(*device_vk
))))
425 return E_OUTOFMEMORY
;
427 if (FAILED(hr
= wined3d_select_vulkan_queue_family(adapter_vk
, &queue_family_index
, ×tamp_bits
)))
430 physical_device
= adapter_vk
->physical_device
;
432 memset(&physical_device_info
, 0, sizeof(physical_device_info
));
434 xfb_features
= &physical_device_info
.xfb_features
;
435 xfb_features
->sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT
;
437 vertex_divisor_features
= &physical_device_info
.vertex_divisor_features
;
438 vertex_divisor_features
->sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
;
439 vertex_divisor_features
->pNext
= xfb_features
;
441 features2
= &physical_device_info
.features2
;
442 features2
->sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2
;
443 features2
->pNext
= vertex_divisor_features
;
445 if (vk_info
->vk_ops
.vkGetPhysicalDeviceFeatures2
)
446 VK_CALL(vkGetPhysicalDeviceFeatures2(physical_device
, features2
));
448 VK_CALL(vkGetPhysicalDeviceFeatures(physical_device
, &features2
->features
));
450 if (!vertex_divisor_features
->vertexAttributeInstanceRateDivisor
)
452 WARN("Vertex attribute divisors not supported.\n");
457 wined3d_disable_vulkan_features(&physical_device_info
);
459 queue_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
;
460 queue_info
.pNext
= NULL
;
461 queue_info
.flags
= 0;
462 queue_info
.queueFamilyIndex
= queue_family_index
;
463 queue_info
.queueCount
= ARRAY_SIZE(priorities
);
464 queue_info
.pQueuePriorities
= priorities
;
466 device_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
;
467 device_info
.pNext
= features2
->pNext
;
468 device_info
.flags
= 0;
469 device_info
.queueCreateInfoCount
= 1;
470 device_info
.pQueueCreateInfos
= &queue_info
;
471 device_info
.enabledLayerCount
= 0;
472 device_info
.ppEnabledLayerNames
= NULL
;
473 device_info
.enabledExtensionCount
= adapter_vk
->device_extension_count
;
474 device_info
.ppEnabledExtensionNames
= adapter_vk
->device_extensions
;
475 device_info
.pEnabledFeatures
= &features2
->features
;
477 if ((vr
= VK_CALL(vkCreateDevice(physical_device
, &device_info
, NULL
, &vk_device
))) < 0)
479 WARN("Failed to create Vulkan device, vr %s.\n", wined3d_debug_vkresult(vr
));
480 vk_device
= VK_NULL_HANDLE
;
481 hr
= hresult_from_vk_result(vr
);
485 device_vk
->vk_device
= vk_device
;
486 VK_CALL(vkGetDeviceQueue(vk_device
, queue_family_index
, 0, &device_vk
->vk_queue
));
487 device_vk
->vk_queue_family_index
= queue_family_index
;
488 device_vk
->timestamp_bits
= timestamp_bits
;
490 device_vk
->vk_info
= *vk_info
;
491 #define VK_DEVICE_PFN(name) \
492 if (!(device_vk->vk_info.vk_ops.name = (void *)VK_CALL(vkGetDeviceProcAddr(vk_device, #name)))) \
494 WARN("Could not get device proc addr for '" #name "'.\n"); \
498 #define VK_DEVICE_EXT_PFN(name) \
499 device_vk->vk_info.vk_ops.name = (void *)VK_CALL(vkGetDeviceProcAddr(vk_device, #name));
501 #undef VK_DEVICE_EXT_PFN
504 if (!wined3d_allocator_init(&device_vk
->allocator
,
505 adapter_vk
->memory_properties
.memoryTypeCount
, &wined3d_allocator_vk_ops
))
507 WARN("Failed to initialise allocator.\n");
512 if (FAILED(hr
= wined3d_device_init(&device_vk
->d
, wined3d
, adapter
->ordinal
, device_type
, focus_window
,
513 flags
, surface_alignment
, levels
, level_count
, vk_info
->supported
, device_parent
)))
515 WARN("Failed to initialize device, hr %#x.\n", hr
);
516 wined3d_allocator_cleanup(&device_vk
->allocator
);
520 *device
= &device_vk
->d
;
525 VK_CALL(vkDestroyDevice(vk_device
, NULL
));
526 heap_free(device_vk
);
530 static void adapter_vk_destroy_device(struct wined3d_device
*device
)
532 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(device
);
533 const struct wined3d_vk_info
*vk_info
= &device_vk
->vk_info
;
535 wined3d_device_cleanup(&device_vk
->d
);
536 wined3d_allocator_cleanup(&device_vk
->allocator
);
537 VK_CALL(vkDestroyDevice(device_vk
->vk_device
, NULL
));
538 heap_free(device_vk
);
541 struct wined3d_context
*adapter_vk_acquire_context(struct wined3d_device
*device
,
542 struct wined3d_texture
*texture
, unsigned int sub_resource_idx
)
544 TRACE("device %p, texture %p, sub_resource_idx %u.\n", device
, texture
, sub_resource_idx
);
546 wined3d_from_cs(device
->cs
);
548 if (!device
->context_count
)
551 return &wined3d_device_vk(device
)->context_vk
.c
;
554 void adapter_vk_release_context(struct wined3d_context
*context
)
556 TRACE("context %p.\n", context
);
559 static void adapter_vk_get_wined3d_caps(const struct wined3d_adapter
*adapter
, struct wined3d_caps
*caps
)
561 const struct wined3d_adapter_vk
*adapter_vk
= wined3d_adapter_vk_const(adapter
);
562 const VkPhysicalDeviceLimits
*limits
= &adapter_vk
->device_limits
;
563 bool sampler_anisotropy
= limits
->maxSamplerAnisotropy
> 1.0f
;
564 const struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
566 caps
->ddraw_caps
.dds_caps
|= WINEDDSCAPS_BACKBUFFER
567 | WINEDDSCAPS_COMPLEX
568 | WINEDDSCAPS_FRONTBUFFER
569 | WINEDDSCAPS_3DDEVICE
570 | WINEDDSCAPS_VIDEOMEMORY
572 | WINEDDSCAPS_LOCALVIDMEM
573 | WINEDDSCAPS_NONLOCALVIDMEM
;
574 caps
->ddraw_caps
.caps
|= WINEDDCAPS_3D
;
576 caps
->Caps2
|= WINED3DCAPS2_CANGENMIPMAP
;
578 caps
->PrimitiveMiscCaps
|= WINED3DPMISCCAPS_BLENDOP
579 | WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS
580 | WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
581 | WINED3DPMISCCAPS_POSTBLENDSRGBCONVERT
582 | WINED3DPMISCCAPS_SEPARATEALPHABLEND
;
584 caps
->RasterCaps
|= WINED3DPRASTERCAPS_MIPMAPLODBIAS
;
586 if (sampler_anisotropy
)
588 caps
->RasterCaps
|= WINED3DPRASTERCAPS_ANISOTROPY
;
590 caps
->TextureFilterCaps
|= WINED3DPTFILTERCAPS_MAGFANISOTROPIC
591 | WINED3DPTFILTERCAPS_MINFANISOTROPIC
;
593 caps
->MaxAnisotropy
= limits
->maxSamplerAnisotropy
;
596 caps
->SrcBlendCaps
|= WINED3DPBLENDCAPS_BLENDFACTOR
;
597 caps
->DestBlendCaps
|= WINED3DPBLENDCAPS_BLENDFACTOR
598 | WINED3DPBLENDCAPS_SRCALPHASAT
;
600 caps
->TextureCaps
|= WINED3DPTEXTURECAPS_VOLUMEMAP
601 | WINED3DPTEXTURECAPS_MIPVOLUMEMAP
602 | WINED3DPTEXTURECAPS_VOLUMEMAP_POW2
;
603 caps
->VolumeTextureFilterCaps
|= WINED3DPTFILTERCAPS_MAGFLINEAR
604 | WINED3DPTFILTERCAPS_MAGFPOINT
605 | WINED3DPTFILTERCAPS_MINFLINEAR
606 | WINED3DPTFILTERCAPS_MINFPOINT
607 | WINED3DPTFILTERCAPS_MIPFLINEAR
608 | WINED3DPTFILTERCAPS_MIPFPOINT
609 | WINED3DPTFILTERCAPS_LINEAR
610 | WINED3DPTFILTERCAPS_LINEARMIPLINEAR
611 | WINED3DPTFILTERCAPS_LINEARMIPNEAREST
612 | WINED3DPTFILTERCAPS_MIPLINEAR
613 | WINED3DPTFILTERCAPS_MIPNEAREST
614 | WINED3DPTFILTERCAPS_NEAREST
;
615 caps
->VolumeTextureAddressCaps
|= WINED3DPTADDRESSCAPS_INDEPENDENTUV
616 | WINED3DPTADDRESSCAPS_CLAMP
617 | WINED3DPTADDRESSCAPS_WRAP
;
618 caps
->VolumeTextureAddressCaps
|= WINED3DPTADDRESSCAPS_BORDER
619 | WINED3DPTADDRESSCAPS_MIRROR
;
620 if (vk_info
->supported
[WINED3D_VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE
])
621 caps
->VolumeTextureAddressCaps
|= WINED3DPTADDRESSCAPS_MIRRORONCE
;
623 caps
->MaxVolumeExtent
= limits
->maxImageDimension3D
;
625 caps
->TextureCaps
|= WINED3DPTEXTURECAPS_CUBEMAP
626 | WINED3DPTEXTURECAPS_MIPCUBEMAP
627 | WINED3DPTEXTURECAPS_CUBEMAP_POW2
;
628 caps
->CubeTextureFilterCaps
|= WINED3DPTFILTERCAPS_MAGFLINEAR
629 | WINED3DPTFILTERCAPS_MAGFPOINT
630 | WINED3DPTFILTERCAPS_MINFLINEAR
631 | WINED3DPTFILTERCAPS_MINFPOINT
632 | WINED3DPTFILTERCAPS_MIPFLINEAR
633 | WINED3DPTFILTERCAPS_MIPFPOINT
634 | WINED3DPTFILTERCAPS_LINEAR
635 | WINED3DPTFILTERCAPS_LINEARMIPLINEAR
636 | WINED3DPTFILTERCAPS_LINEARMIPNEAREST
637 | WINED3DPTFILTERCAPS_MIPLINEAR
638 | WINED3DPTFILTERCAPS_MIPNEAREST
639 | WINED3DPTFILTERCAPS_NEAREST
;
641 if (sampler_anisotropy
)
643 caps
->CubeTextureFilterCaps
|= WINED3DPTFILTERCAPS_MAGFANISOTROPIC
644 | WINED3DPTFILTERCAPS_MINFANISOTROPIC
;
647 caps
->TextureAddressCaps
|= WINED3DPTADDRESSCAPS_BORDER
648 | WINED3DPTADDRESSCAPS_MIRROR
;
649 if (vk_info
->supported
[WINED3D_VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE
])
650 caps
->TextureAddressCaps
|= WINED3DPTADDRESSCAPS_MIRRORONCE
;
652 caps
->StencilCaps
|= WINED3DSTENCILCAPS_DECR
653 | WINED3DSTENCILCAPS_INCR
654 | WINED3DSTENCILCAPS_TWOSIDED
;
656 caps
->DeclTypes
|= WINED3DDTCAPS_FLOAT16_2
| WINED3DDTCAPS_FLOAT16_4
;
658 caps
->MaxPixelShader30InstructionSlots
= WINED3DMAX30SHADERINSTRUCTIONS
;
659 caps
->MaxVertexShader30InstructionSlots
= WINED3DMAX30SHADERINSTRUCTIONS
;
660 caps
->PS20Caps
.temp_count
= WINED3DPS20_MAX_NUMTEMPS
;
661 caps
->VS20Caps
.temp_count
= WINED3DVS20_MAX_NUMTEMPS
;
664 static BOOL
adapter_vk_check_format(const struct wined3d_adapter
*adapter
,
665 const struct wined3d_format
*adapter_format
, const struct wined3d_format
*rt_format
,
666 const struct wined3d_format
*ds_format
)
671 static HRESULT
adapter_vk_init_3d(struct wined3d_device
*device
)
673 struct wined3d_context_vk
*context_vk
;
674 struct wined3d_device_vk
*device_vk
;
677 TRACE("device %p.\n", device
);
679 device_vk
= wined3d_device_vk(device
);
680 context_vk
= &device_vk
->context_vk
;
681 if (FAILED(hr
= wined3d_context_vk_init(context_vk
, device
->swapchains
[0])))
683 WARN("Failed to initialise context.\n");
687 if (FAILED(hr
= device
->shader_backend
->shader_alloc_private(device
,
688 device
->adapter
->vertex_pipe
, device
->adapter
->fragment_pipe
)))
690 ERR("Failed to allocate shader private data, hr %#x.\n", hr
);
691 wined3d_context_vk_cleanup(context_vk
);
695 if (!device_context_add(device
, &context_vk
->c
))
697 ERR("Failed to add the newly created context to the context list.\n");
698 device
->shader_backend
->shader_free_private(device
, NULL
);
699 wined3d_context_vk_cleanup(context_vk
);
703 TRACE("Initialised context %p.\n", context_vk
);
705 if (!(device_vk
->d
.blitter
= wined3d_cpu_blitter_create()))
707 ERR("Failed to create CPU blitter.\n");
708 device_context_remove(device
, &context_vk
->c
);
709 device
->shader_backend
->shader_free_private(device
, NULL
);
710 wined3d_context_vk_cleanup(context_vk
);
713 wined3d_vk_blitter_create(&device_vk
->d
.blitter
);
715 wined3d_device_create_default_samplers(device
, &context_vk
->c
);
716 wined3d_device_vk_create_null_resources(device_vk
, context_vk
);
717 wined3d_device_vk_create_null_views(device_vk
, context_vk
);
722 static void adapter_vk_uninit_3d_cs(void *object
)
724 struct wined3d_device_vk
*device_vk
= object
;
725 struct wined3d_context_vk
*context_vk
;
726 struct wined3d_device
*device
;
727 struct wined3d_shader
*shader
;
729 TRACE("device_vk %p.\n", device_vk
);
731 context_vk
= &device_vk
->context_vk
;
732 device
= &device_vk
->d
;
734 LIST_FOR_EACH_ENTRY(shader
, &device
->shaders
, struct wined3d_shader
, shader_list_entry
)
736 device
->shader_backend
->shader_destroy(shader
);
739 device
->blitter
->ops
->blitter_destroy(device
->blitter
, NULL
);
740 device
->shader_backend
->shader_free_private(device
, &context_vk
->c
);
741 wined3d_device_vk_destroy_null_views(device_vk
, context_vk
);
742 wined3d_device_vk_destroy_null_resources(device_vk
, context_vk
);
743 wined3d_device_destroy_default_samplers(device
, &context_vk
->c
);
746 static void adapter_vk_uninit_3d(struct wined3d_device
*device
)
748 struct wined3d_context_vk
*context_vk
;
749 struct wined3d_device_vk
*device_vk
;
751 TRACE("device %p.\n", device
);
753 device_vk
= wined3d_device_vk(device
);
754 context_vk
= &device_vk
->context_vk
;
756 wined3d_cs_destroy_object(device
->cs
, adapter_vk_uninit_3d_cs
, device_vk
);
757 wined3d_cs_finish(device
->cs
, WINED3D_CS_QUEUE_DEFAULT
);
759 device_context_remove(device
, &context_vk
->c
);
760 wined3d_context_vk_cleanup(context_vk
);
763 static void *wined3d_bo_vk_map(struct wined3d_bo_vk
*bo
, struct wined3d_context_vk
*context_vk
)
765 const struct wined3d_vk_info
*vk_info
;
766 struct wined3d_device_vk
*device_vk
;
767 struct wined3d_bo_slab_vk
*slab
;
773 vk_info
= context_vk
->vk_info
;
774 device_vk
= wined3d_device_vk(context_vk
->c
.device
);
776 if ((slab
= bo
->slab
))
778 if (!(bo
->map_ptr
= wined3d_bo_slab_vk_map(slab
, context_vk
)))
780 ERR("Failed to map slab.\n");
786 struct wined3d_allocator_chunk_vk
*chunk_vk
= wined3d_allocator_chunk_vk(bo
->memory
->chunk
);
788 if (!(bo
->map_ptr
= wined3d_allocator_chunk_vk_map(chunk_vk
, context_vk
)))
790 ERR("Failed to map chunk.\n");
794 else if ((vr
= VK_CALL(vkMapMemory(device_vk
->vk_device
, bo
->vk_memory
, 0, VK_WHOLE_SIZE
, 0, &bo
->map_ptr
))) < 0)
796 ERR("Failed to map memory, vr %s.\n", wined3d_debug_vkresult(vr
));
803 static void wined3d_bo_vk_unmap(struct wined3d_bo_vk
*bo
, struct wined3d_context_vk
*context_vk
)
805 const struct wined3d_vk_info
*vk_info
;
806 struct wined3d_device_vk
*device_vk
;
807 struct wined3d_bo_slab_vk
*slab
;
809 if (wined3d_map_persistent())
814 if ((slab
= bo
->slab
))
816 wined3d_bo_slab_vk_unmap(slab
, context_vk
);
822 wined3d_allocator_chunk_vk_unmap(wined3d_allocator_chunk_vk(bo
->memory
->chunk
), context_vk
);
826 vk_info
= context_vk
->vk_info
;
827 device_vk
= wined3d_device_vk(context_vk
->c
.device
);
828 VK_CALL(vkUnmapMemory(device_vk
->vk_device
, bo
->vk_memory
));
831 void *wined3d_bo_slab_vk_map(struct wined3d_bo_slab_vk
*slab_vk
, struct wined3d_context_vk
*context_vk
)
833 TRACE("slab_vk %p, context_vk %p.\n", slab_vk
, context_vk
);
835 if (!slab_vk
->map_ptr
&& !(slab_vk
->map_ptr
= wined3d_bo_vk_map(&slab_vk
->bo
, context_vk
)))
837 ERR("Failed to map slab.\n");
841 ++slab_vk
->map_count
;
843 return slab_vk
->map_ptr
;
846 void wined3d_bo_slab_vk_unmap(struct wined3d_bo_slab_vk
*slab_vk
, struct wined3d_context_vk
*context_vk
)
848 if (--slab_vk
->map_count
)
851 wined3d_bo_vk_unmap(&slab_vk
->bo
, context_vk
);
852 slab_vk
->map_ptr
= NULL
;
855 static VkAccessFlags
vk_access_mask_from_buffer_usage(VkBufferUsageFlags usage
)
857 VkAccessFlags flags
= 0;
859 if (usage
& VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
)
860 flags
|= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
;
861 if (usage
& VK_BUFFER_USAGE_INDEX_BUFFER_BIT
)
862 flags
|= VK_ACCESS_INDEX_READ_BIT
;
863 if (usage
& VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
)
864 flags
|= VK_ACCESS_UNIFORM_READ_BIT
;
865 if (usage
& VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT
)
866 flags
|= VK_ACCESS_SHADER_READ_BIT
;
867 if (usage
& VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT
)
868 flags
|= VK_ACCESS_SHADER_READ_BIT
| VK_ACCESS_SHADER_WRITE_BIT
;
869 if (usage
& VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
)
870 flags
|= VK_ACCESS_INDIRECT_COMMAND_READ_BIT
;
871 if (usage
& VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT
)
872 flags
|= VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT
;
873 if (usage
& VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT
)
874 flags
|= VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT
875 | VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT
;
880 static void *adapter_vk_map_bo_address(struct wined3d_context
*context
,
881 const struct wined3d_bo_address
*data
, size_t size
, uint32_t map_flags
)
883 struct wined3d_context_vk
*context_vk
= wined3d_context_vk(context
);
884 const struct wined3d_vk_info
*vk_info
;
885 struct wined3d_device_vk
*device_vk
;
886 VkCommandBuffer vk_command_buffer
;
887 VkBufferMemoryBarrier vk_barrier
;
888 struct wined3d_bo_user
*bo_user
;
889 struct wined3d_bo_vk
*bo
, tmp
;
890 VkMappedMemoryRange range
;
893 if (!(bo
= (struct wined3d_bo_vk
*)data
->buffer_object
))
896 vk_info
= context_vk
->vk_info
;
897 device_vk
= wined3d_device_vk(context
->device
);
899 if (map_flags
& WINED3D_MAP_NOOVERWRITE
)
902 if ((map_flags
& WINED3D_MAP_DISCARD
) && bo
->command_buffer_id
> context_vk
->completed_command_buffer_id
)
904 if (wined3d_context_vk_create_bo(context_vk
, bo
->size
, bo
->usage
, bo
->memory_type
, &tmp
))
906 list_move_head(&tmp
.users
, &bo
->users
);
907 wined3d_context_vk_destroy_bo(context_vk
, bo
);
909 list_init(&bo
->users
);
910 list_move_head(&bo
->users
, &tmp
.users
);
911 LIST_FOR_EACH_ENTRY(bo_user
, &bo
->users
, struct wined3d_bo_user
, entry
)
913 bo_user
->valid
= false;
919 ERR("Failed to create new buffer object.\n");
922 if (map_flags
& WINED3D_MAP_READ
)
924 if (!(vk_command_buffer
= wined3d_context_vk_get_command_buffer(context_vk
)))
926 ERR("Failed to get command buffer.\n");
930 wined3d_context_vk_end_current_render_pass(context_vk
);
932 vk_barrier
.sType
= VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
;
933 vk_barrier
.pNext
= NULL
;
934 vk_barrier
.srcAccessMask
= vk_access_mask_from_buffer_usage(bo
->usage
);
935 vk_barrier
.dstAccessMask
= VK_ACCESS_HOST_READ_BIT
;
936 vk_barrier
.srcQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
937 vk_barrier
.dstQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
938 vk_barrier
.buffer
= bo
->vk_buffer
;
939 vk_barrier
.offset
= bo
->buffer_offset
+ (uintptr_t)data
->addr
;
940 vk_barrier
.size
= size
;
941 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer
, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
,
942 VK_PIPELINE_STAGE_HOST_BIT
, 0, 0, NULL
, 1, &vk_barrier
, 0, NULL
));
944 if (!(bo
->memory_type
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
946 range
.sType
= VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE
;
948 range
.memory
= bo
->vk_memory
;
949 range
.offset
= bo
->memory_offset
+ (uintptr_t)data
->addr
;
951 VK_CALL(vkInvalidateMappedMemoryRanges(device_vk
->vk_device
, 1, &range
));
954 wined3d_context_vk_reference_bo(context_vk
, bo
);
957 if (bo
->command_buffer_id
== context_vk
->current_command_buffer
.id
)
958 wined3d_context_vk_submit_command_buffer(context_vk
, 0, NULL
, NULL
, 0, NULL
);
959 wined3d_context_vk_wait_command_buffer(context_vk
, bo
->command_buffer_id
);
962 if (!(map_ptr
= wined3d_bo_vk_map(bo
, context_vk
)))
964 ERR("Failed to map bo.\n");
968 return (uint8_t *)map_ptr
+ bo
->memory_offset
+ (uintptr_t)data
->addr
;
971 static void adapter_vk_unmap_bo_address(struct wined3d_context
*context
,
972 const struct wined3d_bo_address
*data
, unsigned int range_count
, const struct wined3d_range
*ranges
)
974 struct wined3d_context_vk
*context_vk
= wined3d_context_vk(context
);
975 const struct wined3d_vk_info
*vk_info
;
976 struct wined3d_device_vk
*device_vk
;
977 VkMappedMemoryRange range
;
978 struct wined3d_bo_vk
*bo
;
981 if (!(bo
= (struct wined3d_bo_vk
*)data
->buffer_object
))
984 vk_info
= context_vk
->vk_info
;
985 device_vk
= wined3d_device_vk(context
->device
);
987 if (!(bo
->memory_type
& VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
))
989 range
.sType
= VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE
;
991 range
.memory
= bo
->vk_memory
;
993 for (i
= 0; i
< range_count
; ++i
)
995 range
.offset
= bo
->memory_offset
+ ranges
[i
].offset
;
996 range
.size
= ranges
[i
].size
;
997 VK_CALL(vkFlushMappedMemoryRanges(device_vk
->vk_device
, 1, &range
));
1001 wined3d_bo_vk_unmap(bo
, context_vk
);
1004 static void adapter_vk_copy_bo_address(struct wined3d_context
*context
,
1005 const struct wined3d_bo_address
*dst
, const struct wined3d_bo_address
*src
, size_t size
)
1007 struct wined3d_context_vk
*context_vk
= wined3d_context_vk(context
);
1008 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1009 struct wined3d_bo_vk staging_bo
, *src_bo
, *dst_bo
;
1010 VkAccessFlags src_access_mask
, dst_access_mask
;
1011 VkBufferMemoryBarrier vk_barrier
[2];
1012 struct wined3d_bo_address staging
;
1013 VkCommandBuffer vk_command_buffer
;
1014 struct wined3d_range range
;
1015 void *dst_ptr
, *src_ptr
;
1016 VkBufferCopy region
;
1018 src_bo
= (struct wined3d_bo_vk
*)src
->buffer_object
;
1019 dst_bo
= (struct wined3d_bo_vk
*)dst
->buffer_object
;
1021 if (src_bo
&& dst_bo
)
1023 if (!(vk_command_buffer
= wined3d_context_vk_get_command_buffer(context_vk
)))
1025 ERR("Failed to get command buffer.\n");
1029 wined3d_context_vk_end_current_render_pass(context_vk
);
1031 src_access_mask
= vk_access_mask_from_buffer_usage(src_bo
->usage
);
1032 dst_access_mask
= vk_access_mask_from_buffer_usage(dst_bo
->usage
);
1034 region
.srcOffset
= src_bo
->buffer_offset
+ (uintptr_t)src
->addr
;
1035 region
.dstOffset
= dst_bo
->buffer_offset
+ (uintptr_t)dst
->addr
;
1038 vk_barrier
[0].sType
= VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
;
1039 vk_barrier
[0].pNext
= NULL
;
1040 vk_barrier
[0].srcAccessMask
= src_access_mask
;
1041 vk_barrier
[0].dstAccessMask
= VK_ACCESS_TRANSFER_READ_BIT
;
1042 vk_barrier
[0].srcQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
1043 vk_barrier
[0].dstQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
1044 vk_barrier
[0].buffer
= src_bo
->vk_buffer
;
1045 vk_barrier
[0].offset
= region
.srcOffset
;
1046 vk_barrier
[0].size
= region
.size
;
1048 vk_barrier
[1].sType
= VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
;
1049 vk_barrier
[1].pNext
= NULL
;
1050 vk_barrier
[1].srcAccessMask
= dst_access_mask
;
1051 vk_barrier
[1].dstAccessMask
= VK_ACCESS_TRANSFER_WRITE_BIT
;
1052 vk_barrier
[1].srcQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
1053 vk_barrier
[1].dstQueueFamilyIndex
= VK_QUEUE_FAMILY_IGNORED
;
1054 vk_barrier
[1].buffer
= dst_bo
->vk_buffer
;
1055 vk_barrier
[1].offset
= region
.dstOffset
;
1056 vk_barrier
[1].size
= region
.size
;
1058 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer
, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
,
1059 VK_PIPELINE_STAGE_TRANSFER_BIT
, 0, 0, NULL
, 2, vk_barrier
, 0, NULL
));
1061 VK_CALL(vkCmdCopyBuffer(vk_command_buffer
, src_bo
->vk_buffer
, dst_bo
->vk_buffer
, 1, ®ion
));
1063 vk_barrier
[0].srcAccessMask
= VK_ACCESS_TRANSFER_READ_BIT
;
1064 vk_barrier
[0].dstAccessMask
= src_access_mask
;
1066 vk_barrier
[1].srcAccessMask
= VK_ACCESS_TRANSFER_WRITE_BIT
;
1067 vk_barrier
[1].dstAccessMask
= dst_access_mask
;
1069 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer
, VK_PIPELINE_STAGE_TRANSFER_BIT
,
1070 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
, 0, 0, NULL
, 2, vk_barrier
, 0, NULL
));
1072 wined3d_context_vk_reference_bo(context_vk
, src_bo
);
1073 wined3d_context_vk_reference_bo(context_vk
, dst_bo
);
1078 if (src_bo
&& !(src_bo
->memory_type
& VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
))
1080 if (!(wined3d_context_vk_create_bo(context_vk
, size
, VK_BUFFER_USAGE_TRANSFER_DST_BIT
,
1081 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
, &staging_bo
)))
1083 ERR("Failed to create staging bo.\n");
1087 staging
.buffer_object
= (uintptr_t)&staging_bo
;
1088 staging
.addr
= NULL
;
1089 adapter_vk_copy_bo_address(context
, &staging
, src
, size
);
1090 adapter_vk_copy_bo_address(context
, dst
, &staging
, size
);
1092 wined3d_context_vk_destroy_bo(context_vk
, &staging_bo
);
1097 if (dst_bo
&& (dst_bo
->command_buffer_id
> context_vk
->completed_command_buffer_id
1098 || !(dst_bo
->memory_type
& VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
)))
1100 if (!(wined3d_context_vk_create_bo(context_vk
, size
, VK_BUFFER_USAGE_TRANSFER_SRC_BIT
,
1101 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
, &staging_bo
)))
1103 ERR("Failed to create staging bo.\n");
1107 staging
.buffer_object
= (uintptr_t)&staging_bo
;
1108 staging
.addr
= NULL
;
1109 adapter_vk_copy_bo_address(context
, &staging
, src
, size
);
1110 adapter_vk_copy_bo_address(context
, dst
, &staging
, size
);
1112 wined3d_context_vk_destroy_bo(context_vk
, &staging_bo
);
1117 src_ptr
= adapter_vk_map_bo_address(context
, src
, size
, WINED3D_MAP_READ
);
1118 dst_ptr
= adapter_vk_map_bo_address(context
, dst
, size
, WINED3D_MAP_WRITE
);
1120 memcpy(dst_ptr
, src_ptr
, size
);
1124 adapter_vk_unmap_bo_address(context
, dst
, 1, &range
);
1125 adapter_vk_unmap_bo_address(context
, src
, 0, NULL
);
1128 static HRESULT
adapter_vk_create_swapchain(struct wined3d_device
*device
,
1129 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain_state_parent
*state_parent
,
1130 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_swapchain
**swapchain
)
1132 struct wined3d_swapchain_vk
*swapchain_vk
;
1135 TRACE("device %p, desc %p, state_parent %p, parent %p, parent_ops %p, swapchain %p.\n",
1136 device
, desc
, state_parent
, parent
, parent_ops
, swapchain
);
1138 if (!(swapchain_vk
= heap_alloc_zero(sizeof(*swapchain_vk
))))
1139 return E_OUTOFMEMORY
;
1141 if (FAILED(hr
= wined3d_swapchain_vk_init(swapchain_vk
, device
, desc
, state_parent
, parent
,
1144 WARN("Failed to initialise swapchain, hr %#x.\n", hr
);
1145 heap_free(swapchain_vk
);
1149 TRACE("Created swapchain %p.\n", swapchain_vk
);
1150 *swapchain
= &swapchain_vk
->s
;
1155 static void adapter_vk_destroy_swapchain(struct wined3d_swapchain
*swapchain
)
1157 struct wined3d_swapchain_vk
*swapchain_vk
= wined3d_swapchain_vk(swapchain
);
1159 wined3d_swapchain_vk_cleanup(swapchain_vk
);
1160 heap_free(swapchain_vk
);
1163 unsigned int wined3d_adapter_vk_get_memory_type_index(const struct wined3d_adapter_vk
*adapter_vk
,
1164 uint32_t memory_type_mask
, VkMemoryPropertyFlags flags
)
1166 const VkPhysicalDeviceMemoryProperties
*memory_info
= &adapter_vk
->memory_properties
;
1169 for (i
= 0; i
< memory_info
->memoryTypeCount
; ++i
)
1171 if (!(memory_type_mask
& (1u << i
)))
1173 if ((memory_info
->memoryTypes
[i
].propertyFlags
& flags
) == flags
)
1180 static HRESULT
adapter_vk_create_buffer(struct wined3d_device
*device
,
1181 const struct wined3d_buffer_desc
*desc
, const struct wined3d_sub_resource_data
*data
,
1182 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_buffer
**buffer
)
1184 struct wined3d_buffer_vk
*buffer_vk
;
1187 TRACE("device %p, desc %p, data %p, parent %p, parent_ops %p, buffer %p.\n",
1188 device
, desc
, data
, parent
, parent_ops
, buffer
);
1190 if (!(buffer_vk
= heap_alloc_zero(sizeof(*buffer_vk
))))
1191 return E_OUTOFMEMORY
;
1193 if (FAILED(hr
= wined3d_buffer_vk_init(buffer_vk
, device
, desc
, data
, parent
, parent_ops
)))
1195 WARN("Failed to initialise buffer, hr %#x.\n", hr
);
1196 heap_free(buffer_vk
);
1200 TRACE("Created buffer %p.\n", buffer_vk
);
1201 *buffer
= &buffer_vk
->b
;
1206 static void adapter_vk_destroy_buffer(struct wined3d_buffer
*buffer
)
1208 struct wined3d_buffer_vk
*buffer_vk
= wined3d_buffer_vk(buffer
);
1209 struct wined3d_device
*device
= buffer_vk
->b
.resource
.device
;
1210 unsigned int swapchain_count
= device
->swapchain_count
;
1212 TRACE("buffer_vk %p.\n", buffer_vk
);
1214 /* Take a reference to the device, in case releasing the buffer would
1215 * cause the device to be destroyed. However, swapchain resources don't
1216 * take a reference to the device, and we wouldn't want to increment the
1217 * refcount on a device that's in the process of being destroyed. */
1218 if (swapchain_count
)
1219 wined3d_device_incref(device
);
1220 wined3d_buffer_cleanup(&buffer_vk
->b
);
1221 wined3d_cs_destroy_object(device
->cs
, heap_free
, buffer_vk
);
1222 if (swapchain_count
)
1223 wined3d_device_decref(device
);
1226 static HRESULT
adapter_vk_create_texture(struct wined3d_device
*device
,
1227 const struct wined3d_resource_desc
*desc
, unsigned int layer_count
, unsigned int level_count
,
1228 uint32_t flags
, void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_texture
**texture
)
1230 struct wined3d_texture_vk
*texture_vk
;
1233 TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, parent %p, parent_ops %p, texture %p.\n",
1234 device
, desc
, layer_count
, level_count
, flags
, parent
, parent_ops
, texture
);
1236 if (!(texture_vk
= wined3d_texture_allocate_object_memory(sizeof(*texture_vk
), level_count
, layer_count
)))
1237 return E_OUTOFMEMORY
;
1239 if (FAILED(hr
= wined3d_texture_vk_init(texture_vk
, device
, desc
,
1240 layer_count
, level_count
, flags
, parent
, parent_ops
)))
1242 WARN("Failed to initialise texture, hr %#x.\n", hr
);
1243 heap_free(texture_vk
);
1247 TRACE("Created texture %p.\n", texture_vk
);
1248 *texture
= &texture_vk
->t
;
1253 static void adapter_vk_destroy_texture(struct wined3d_texture
*texture
)
1255 struct wined3d_texture_vk
*texture_vk
= wined3d_texture_vk(texture
);
1256 struct wined3d_device
*device
= texture_vk
->t
.resource
.device
;
1257 unsigned int swapchain_count
= device
->swapchain_count
;
1259 TRACE("texture_vk %p.\n", texture_vk
);
1261 /* Take a reference to the device, in case releasing the texture would
1262 * cause the device to be destroyed. However, swapchain resources don't
1263 * take a reference to the device, and we wouldn't want to increment the
1264 * refcount on a device that's in the process of being destroyed. */
1265 if (swapchain_count
)
1266 wined3d_device_incref(device
);
1268 wined3d_texture_sub_resources_destroyed(texture
);
1269 texture
->resource
.parent_ops
->wined3d_object_destroyed(texture
->resource
.parent
);
1271 wined3d_texture_cleanup(&texture_vk
->t
);
1272 wined3d_cs_destroy_object(device
->cs
, heap_free
, texture_vk
);
1274 if (swapchain_count
)
1275 wined3d_device_decref(device
);
1278 static HRESULT
adapter_vk_create_rendertarget_view(const struct wined3d_view_desc
*desc
,
1279 struct wined3d_resource
*resource
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1280 struct wined3d_rendertarget_view
**view
)
1282 struct wined3d_rendertarget_view_vk
*view_vk
;
1285 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
1286 wined3d_debug_view_desc(desc
, resource
), resource
, parent
, parent_ops
, view
);
1288 if (!(view_vk
= heap_alloc_zero(sizeof(*view_vk
))))
1289 return E_OUTOFMEMORY
;
1291 if (FAILED(hr
= wined3d_rendertarget_view_vk_init(view_vk
, desc
, resource
, parent
, parent_ops
)))
1293 WARN("Failed to initialise view, hr %#x.\n", hr
);
1298 TRACE("Created render target view %p.\n", view_vk
);
1299 *view
= &view_vk
->v
;
1304 struct wined3d_view_vk_destroy_ctx
1306 struct wined3d_device_vk
*device_vk
;
1307 VkBufferView
*vk_buffer_view
;
1308 VkImageView
*vk_image_view
;
1309 struct wined3d_bo_vk
*vk_counter_bo
;
1310 VkBufferView
*vk_counter_view
;
1311 uint64_t *command_buffer_id
;
1313 struct wined3d_view_vk_destroy_ctx
*free
;
1316 static void wined3d_view_vk_destroy_object(void *object
)
1318 struct wined3d_view_vk_destroy_ctx
*ctx
= object
;
1319 const struct wined3d_vk_info
*vk_info
;
1320 struct wined3d_device_vk
*device_vk
;
1321 struct wined3d_context
*context
;
1323 TRACE("ctx %p.\n", ctx
);
1325 device_vk
= ctx
->device_vk
;
1326 vk_info
= &wined3d_adapter_vk(device_vk
->d
.adapter
)->vk_info
;
1327 context
= context_acquire(&device_vk
->d
, NULL
, 0);
1329 if (ctx
->vk_buffer_view
)
1333 wined3d_context_vk_destroy_buffer_view(wined3d_context_vk(context
),
1334 *ctx
->vk_buffer_view
, *ctx
->command_buffer_id
);
1338 VK_CALL(vkDestroyBufferView(device_vk
->vk_device
, *ctx
->vk_buffer_view
, NULL
));
1339 TRACE("Destroyed buffer view 0x%s.\n", wine_dbgstr_longlong(*ctx
->vk_buffer_view
));
1342 if (ctx
->vk_image_view
)
1346 wined3d_context_vk_destroy_image_view(wined3d_context_vk(context
),
1347 *ctx
->vk_image_view
, *ctx
->command_buffer_id
);
1351 VK_CALL(vkDestroyImageView(device_vk
->vk_device
, *ctx
->vk_image_view
, NULL
));
1352 TRACE("Destroyed image view 0x%s.\n", wine_dbgstr_longlong(*ctx
->vk_image_view
));
1355 if (ctx
->vk_counter_bo
&& ctx
->vk_counter_bo
->vk_buffer
)
1356 wined3d_context_vk_destroy_bo(wined3d_context_vk(context
), ctx
->vk_counter_bo
);
1357 if (ctx
->vk_counter_view
)
1361 wined3d_context_vk_destroy_buffer_view(wined3d_context_vk(context
),
1362 *ctx
->vk_counter_view
, *ctx
->command_buffer_id
);
1366 VK_CALL(vkDestroyBufferView(device_vk
->vk_device
, *ctx
->vk_counter_view
, NULL
));
1367 TRACE("Destroyed counter buffer view 0x%s.\n", wine_dbgstr_longlong(*ctx
->vk_counter_view
));
1372 context_release(context
);
1374 heap_free(ctx
->object
);
1375 heap_free(ctx
->free
);
1378 static void wined3d_view_vk_destroy(struct wined3d_device
*device
, VkBufferView
*vk_buffer_view
,
1379 VkImageView
*vk_image_view
, struct wined3d_bo_vk
*vk_counter_bo
,
1380 VkBufferView
*vk_counter_view
, uint64_t *command_buffer_id
, void *view_vk
)
1382 struct wined3d_view_vk_destroy_ctx
*ctx
, c
;
1384 if (!(ctx
= heap_alloc(sizeof(*ctx
))))
1386 ctx
->device_vk
= wined3d_device_vk(device
);
1387 ctx
->vk_buffer_view
= vk_buffer_view
;
1388 ctx
->vk_image_view
= vk_image_view
;
1389 ctx
->vk_counter_bo
= vk_counter_bo
;
1390 ctx
->vk_counter_view
= vk_counter_view
;
1391 ctx
->command_buffer_id
= command_buffer_id
;
1392 ctx
->object
= view_vk
;
1393 ctx
->free
= ctx
!= &c
? ctx
: NULL
;
1395 wined3d_cs_destroy_object(device
->cs
, wined3d_view_vk_destroy_object
, ctx
);
1397 wined3d_cs_finish(device
->cs
, WINED3D_CS_QUEUE_DEFAULT
);
1400 static void adapter_vk_destroy_rendertarget_view(struct wined3d_rendertarget_view
*view
)
1402 struct wined3d_rendertarget_view_vk
*view_vk
= wined3d_rendertarget_view_vk(view
);
1403 struct wined3d_device
*device
= view_vk
->v
.resource
->device
;
1404 unsigned int swapchain_count
= device
->swapchain_count
;
1406 TRACE("view_vk %p.\n", view_vk
);
1408 /* Take a reference to the device, in case releasing the view's resource
1409 * would cause the device to be destroyed. However, swapchain resources
1410 * don't take a reference to the device, and we wouldn't want to increment
1411 * the refcount on a device that's in the process of being destroyed. */
1412 if (swapchain_count
)
1413 wined3d_device_incref(device
);
1414 wined3d_rendertarget_view_cleanup(&view_vk
->v
);
1415 wined3d_view_vk_destroy(device
, NULL
, &view_vk
->vk_image_view
,
1416 NULL
, NULL
, &view_vk
->command_buffer_id
, view_vk
);
1417 if (swapchain_count
)
1418 wined3d_device_decref(device
);
1421 static HRESULT
adapter_vk_create_shader_resource_view(const struct wined3d_view_desc
*desc
,
1422 struct wined3d_resource
*resource
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1423 struct wined3d_shader_resource_view
**view
)
1425 struct wined3d_shader_resource_view_vk
*view_vk
;
1428 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
1429 wined3d_debug_view_desc(desc
, resource
), resource
, parent
, parent_ops
, view
);
1431 if (!(view_vk
= heap_alloc_zero(sizeof(*view_vk
))))
1432 return E_OUTOFMEMORY
;
1434 if (FAILED(hr
= wined3d_shader_resource_view_vk_init(view_vk
, desc
, resource
, parent
, parent_ops
)))
1436 WARN("Failed to initialise view, hr %#x.\n", hr
);
1441 TRACE("Created shader resource view %p.\n", view_vk
);
1442 *view
= &view_vk
->v
;
1447 static void adapter_vk_destroy_shader_resource_view(struct wined3d_shader_resource_view
*view
)
1449 struct wined3d_shader_resource_view_vk
*srv_vk
= wined3d_shader_resource_view_vk(view
);
1450 struct wined3d_device
*device
= srv_vk
->v
.resource
->device
;
1451 unsigned int swapchain_count
= device
->swapchain_count
;
1452 struct wined3d_view_vk
*view_vk
= &srv_vk
->view_vk
;
1453 VkBufferView
*vk_buffer_view
= NULL
;
1454 VkImageView
*vk_image_view
= NULL
;
1456 TRACE("srv_vk %p.\n", srv_vk
);
1458 /* Take a reference to the device, in case releasing the view's resource
1459 * would cause the device to be destroyed. However, swapchain resources
1460 * don't take a reference to the device, and we wouldn't want to increment
1461 * the refcount on a device that's in the process of being destroyed. */
1462 if (swapchain_count
)
1463 wined3d_device_incref(device
);
1464 if (srv_vk
->v
.resource
->type
== WINED3D_RTYPE_BUFFER
)
1465 vk_buffer_view
= &view_vk
->u
.vk_buffer_view
;
1467 vk_image_view
= &view_vk
->u
.vk_image_info
.imageView
;
1468 list_remove(&view_vk
->bo_user
.entry
);
1469 wined3d_shader_resource_view_cleanup(&srv_vk
->v
);
1470 wined3d_view_vk_destroy(device
, vk_buffer_view
, vk_image_view
,
1471 NULL
, NULL
, &view_vk
->command_buffer_id
, srv_vk
);
1472 if (swapchain_count
)
1473 wined3d_device_decref(device
);
1476 static HRESULT
adapter_vk_create_unordered_access_view(const struct wined3d_view_desc
*desc
,
1477 struct wined3d_resource
*resource
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1478 struct wined3d_unordered_access_view
**view
)
1480 struct wined3d_unordered_access_view_vk
*view_vk
;
1483 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
1484 wined3d_debug_view_desc(desc
, resource
), resource
, parent
, parent_ops
, view
);
1486 if (!(view_vk
= heap_alloc_zero(sizeof(*view_vk
))))
1487 return E_OUTOFMEMORY
;
1489 if (FAILED(hr
= wined3d_unordered_access_view_vk_init(view_vk
, desc
, resource
, parent
, parent_ops
)))
1491 WARN("Failed to initialise view, hr %#x.\n", hr
);
1496 TRACE("Created unordered access view %p.\n", view_vk
);
1497 *view
= &view_vk
->v
;
1502 static void adapter_vk_destroy_unordered_access_view(struct wined3d_unordered_access_view
*view
)
1504 struct wined3d_unordered_access_view_vk
*uav_vk
= wined3d_unordered_access_view_vk(view
);
1505 struct wined3d_device
*device
= uav_vk
->v
.resource
->device
;
1506 unsigned int swapchain_count
= device
->swapchain_count
;
1507 struct wined3d_view_vk
*view_vk
= &uav_vk
->view_vk
;
1508 VkBufferView
*vk_buffer_view
= NULL
;
1509 VkImageView
*vk_image_view
= NULL
;
1511 TRACE("uav_vk %p.\n", uav_vk
);
1513 /* Take a reference to the device, in case releasing the view's resource
1514 * would cause the device to be destroyed. However, swapchain resources
1515 * don't take a reference to the device, and we wouldn't want to increment
1516 * the refcount on a device that's in the process of being destroyed. */
1517 if (swapchain_count
)
1518 wined3d_device_incref(device
);
1519 if (uav_vk
->v
.resource
->type
== WINED3D_RTYPE_BUFFER
)
1520 vk_buffer_view
= &view_vk
->u
.vk_buffer_view
;
1522 vk_image_view
= &view_vk
->u
.vk_image_info
.imageView
;
1523 list_remove(&view_vk
->bo_user
.entry
);
1524 wined3d_unordered_access_view_cleanup(&uav_vk
->v
);
1525 wined3d_view_vk_destroy(device
, vk_buffer_view
, vk_image_view
, &uav_vk
->counter_bo
,
1526 &uav_vk
->vk_counter_view
, &view_vk
->command_buffer_id
, uav_vk
);
1527 if (swapchain_count
)
1528 wined3d_device_decref(device
);
1531 static HRESULT
adapter_vk_create_sampler(struct wined3d_device
*device
, const struct wined3d_sampler_desc
*desc
,
1532 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_sampler
**sampler
)
1534 struct wined3d_sampler_vk
*sampler_vk
;
1536 TRACE("device %p, desc %p, parent %p, parent_ops %p, sampler %p.\n",
1537 device
, desc
, parent
, parent_ops
, sampler
);
1539 if (!(sampler_vk
= heap_alloc_zero(sizeof(*sampler_vk
))))
1540 return E_OUTOFMEMORY
;
1542 wined3d_sampler_vk_init(sampler_vk
, device
, desc
, parent
, parent_ops
);
1544 TRACE("Created sampler %p.\n", sampler_vk
);
1545 *sampler
= &sampler_vk
->s
;
1550 static void wined3d_sampler_vk_destroy_object(void *object
)
1552 struct wined3d_sampler_vk
*sampler_vk
= object
;
1553 struct wined3d_context_vk
*context_vk
;
1555 TRACE("sampler_vk %p.\n", sampler_vk
);
1557 context_vk
= wined3d_context_vk(context_acquire(sampler_vk
->s
.device
, NULL
, 0));
1559 wined3d_context_vk_destroy_sampler(context_vk
, sampler_vk
->vk_image_info
.sampler
, sampler_vk
->command_buffer_id
);
1560 heap_free(sampler_vk
);
1562 context_release(&context_vk
->c
);
1565 static void adapter_vk_destroy_sampler(struct wined3d_sampler
*sampler
)
1567 struct wined3d_sampler_vk
*sampler_vk
= wined3d_sampler_vk(sampler
);
1569 TRACE("sampler_vk %p.\n", sampler_vk
);
1571 wined3d_cs_destroy_object(sampler
->device
->cs
, wined3d_sampler_vk_destroy_object
, sampler_vk
);
1574 static HRESULT
adapter_vk_create_query(struct wined3d_device
*device
, enum wined3d_query_type type
,
1575 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_query
**query
)
1577 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1578 device
, type
, parent
, parent_ops
, query
);
1580 return wined3d_query_vk_create(device
, type
, parent
, parent_ops
, query
);
1583 static void wined3d_query_vk_destroy_object(void *object
)
1585 struct wined3d_query_vk
*query_vk
= object
;
1587 TRACE("query_vk %p.\n", query_vk
);
1589 query_vk
->q
.query_ops
->query_destroy(&query_vk
->q
);
1592 static void adapter_vk_destroy_query(struct wined3d_query
*query
)
1594 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1596 TRACE("query_vk %p.\n", query_vk
);
1598 wined3d_cs_destroy_object(query
->device
->cs
, wined3d_query_vk_destroy_object
, query_vk
);
1601 static void adapter_vk_flush_context(struct wined3d_context
*context
)
1603 struct wined3d_context_vk
*context_vk
= wined3d_context_vk(context
);
1605 TRACE("context_vk %p.\n", context_vk
);
1607 wined3d_context_vk_submit_command_buffer(context_vk
, 0, NULL
, NULL
, 0, NULL
);
1610 static void adapter_vk_draw_primitive(struct wined3d_device
*device
,
1611 const struct wined3d_state
*state
, const struct wined3d_draw_parameters
*parameters
)
1613 struct wined3d_buffer_vk
*indirect_vk
= NULL
;
1614 const struct wined3d_vk_info
*vk_info
;
1615 struct wined3d_context_vk
*context_vk
;
1616 VkCommandBuffer vk_command_buffer
;
1617 uint32_t instance_count
;
1620 TRACE("device %p, state %p, parameters %p.\n", device
, state
, parameters
);
1622 context_vk
= wined3d_context_vk(context_acquire(device
, NULL
, 0));
1623 vk_info
= context_vk
->vk_info
;
1625 if (parameters
->indirect
)
1626 indirect_vk
= wined3d_buffer_vk(parameters
->u
.indirect
.buffer
);
1628 if (!(vk_command_buffer
= wined3d_context_vk_apply_draw_state(context_vk
,
1629 state
, indirect_vk
, parameters
->indexed
)))
1631 ERR("Failed to apply draw state.\n");
1632 context_release(&context_vk
->c
);
1636 if (context_vk
->c
.transform_feedback_active
)
1638 if (!context_vk
->vk_so_counter_bo
.vk_buffer
)
1640 struct wined3d_bo_vk
*bo
= &context_vk
->vk_so_counter_bo
;
1642 if (!wined3d_context_vk_create_bo(context_vk
, ARRAY_SIZE(context_vk
->vk_so_counters
) * sizeof(uint32_t) * 2,
1643 VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT
, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
, bo
))
1644 ERR("Failed to create counter BO.\n");
1645 for (i
= 0; i
< ARRAY_SIZE(context_vk
->vk_so_counters
); ++i
)
1647 context_vk
->vk_so_counters
[i
] = bo
->vk_buffer
;
1648 context_vk
->vk_so_offsets
[i
] = bo
->buffer_offset
+ i
* sizeof(uint32_t) * 2;
1652 wined3d_context_vk_reference_bo(context_vk
, &context_vk
->vk_so_counter_bo
);
1653 if (context_vk
->c
.transform_feedback_paused
)
1654 VK_CALL(vkCmdBeginTransformFeedbackEXT(vk_command_buffer
, 0, ARRAY_SIZE(context_vk
->vk_so_counters
),
1655 context_vk
->vk_so_counters
, context_vk
->vk_so_offsets
));
1657 VK_CALL(vkCmdBeginTransformFeedbackEXT(vk_command_buffer
, 0, 0, NULL
, NULL
));
1660 if (parameters
->indirect
)
1662 struct wined3d_bo_vk
*bo
= &indirect_vk
->bo
;
1663 uint32_t stride
, size
;
1665 wined3d_context_vk_reference_bo(context_vk
, bo
);
1666 size
= indirect_vk
->b
.resource
.size
- parameters
->u
.indirect
.offset
;
1668 if (parameters
->indexed
)
1670 stride
= sizeof(VkDrawIndexedIndirectCommand
);
1671 VK_CALL(vkCmdDrawIndexedIndirect(vk_command_buffer
, bo
->vk_buffer
,
1672 bo
->buffer_offset
+ parameters
->u
.indirect
.offset
, size
/ stride
, stride
));
1676 stride
= sizeof(VkDrawIndirectCommand
);
1677 VK_CALL(vkCmdDrawIndirect(vk_command_buffer
, bo
->vk_buffer
,
1678 bo
->buffer_offset
+ parameters
->u
.indirect
.offset
, size
/ stride
, stride
));
1683 instance_count
= parameters
->u
.direct
.instance_count
;
1684 if (context_vk
->c
.instance_count
)
1685 instance_count
= context_vk
->c
.instance_count
;
1686 if (!instance_count
)
1689 if (parameters
->indexed
)
1690 VK_CALL(vkCmdDrawIndexed(vk_command_buffer
, parameters
->u
.direct
.index_count
,
1691 instance_count
, parameters
->u
.direct
.start_idx
, parameters
->u
.direct
.base_vertex_idx
,
1692 parameters
->u
.direct
.start_instance
));
1694 VK_CALL(vkCmdDraw(vk_command_buffer
, parameters
->u
.direct
.index_count
, instance_count
,
1695 parameters
->u
.direct
.start_idx
, parameters
->u
.direct
.start_instance
));
1698 if (context_vk
->c
.transform_feedback_active
)
1700 VK_CALL(vkCmdEndTransformFeedbackEXT(vk_command_buffer
, 0, ARRAY_SIZE(context_vk
->vk_so_counters
),
1701 context_vk
->vk_so_counters
, context_vk
->vk_so_offsets
));
1702 context_vk
->c
.transform_feedback_paused
= 1;
1703 context_vk
->c
.transform_feedback_active
= 0;
1706 context_release(&context_vk
->c
);
1709 static void adapter_vk_dispatch_compute(struct wined3d_device
*device
,
1710 const struct wined3d_state
*state
, const struct wined3d_dispatch_parameters
*parameters
)
1712 struct wined3d_buffer_vk
*indirect_vk
= NULL
;
1713 const struct wined3d_vk_info
*vk_info
;
1714 struct wined3d_context_vk
*context_vk
;
1715 VkCommandBuffer vk_command_buffer
;
1717 TRACE("device %p, state %p, parameters %p.\n", device
, state
, parameters
);
1719 context_vk
= wined3d_context_vk(context_acquire(device
, NULL
, 0));
1720 vk_info
= context_vk
->vk_info
;
1722 if (parameters
->indirect
)
1723 indirect_vk
= wined3d_buffer_vk(parameters
->u
.indirect
.buffer
);
1725 if (!(vk_command_buffer
= wined3d_context_vk_apply_compute_state(context_vk
, state
, indirect_vk
)))
1727 ERR("Failed to apply compute state.\n");
1728 context_release(&context_vk
->c
);
1732 if (parameters
->indirect
)
1734 struct wined3d_bo_vk
*bo
= &indirect_vk
->bo
;
1736 wined3d_context_vk_reference_bo(context_vk
, bo
);
1737 VK_CALL(vkCmdDispatchIndirect(vk_command_buffer
, bo
->vk_buffer
,
1738 bo
->buffer_offset
+ parameters
->u
.indirect
.offset
));
1742 const struct wined3d_direct_dispatch_parameters
*direct
= ¶meters
->u
.direct
;
1744 VK_CALL(vkCmdDispatch(vk_command_buffer
, direct
->group_count_x
, direct
->group_count_y
, direct
->group_count_z
));
1747 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer
, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
,
1748 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT
, 0, 0, NULL
, 0, NULL
, 0, NULL
));
1750 context_release(&context_vk
->c
);
1753 static void adapter_vk_clear_uav(struct wined3d_context
*context
,
1754 struct wined3d_unordered_access_view
*view
, const struct wined3d_uvec4
*clear_value
)
1756 TRACE("context %p, view %p, clear_value %s.\n", context
, view
, debug_uvec4(clear_value
));
1758 wined3d_unordered_access_view_vk_clear_uint(wined3d_unordered_access_view_vk(view
),
1759 clear_value
, wined3d_context_vk(context
));
1762 static const struct wined3d_adapter_ops wined3d_adapter_vk_ops
=
1764 .adapter_destroy
= adapter_vk_destroy
,
1765 .adapter_create_device
= adapter_vk_create_device
,
1766 .adapter_destroy_device
= adapter_vk_destroy_device
,
1767 .adapter_acquire_context
= adapter_vk_acquire_context
,
1768 .adapter_release_context
= adapter_vk_release_context
,
1769 .adapter_get_wined3d_caps
= adapter_vk_get_wined3d_caps
,
1770 .adapter_check_format
= adapter_vk_check_format
,
1771 .adapter_init_3d
= adapter_vk_init_3d
,
1772 .adapter_uninit_3d
= adapter_vk_uninit_3d
,
1773 .adapter_map_bo_address
= adapter_vk_map_bo_address
,
1774 .adapter_unmap_bo_address
= adapter_vk_unmap_bo_address
,
1775 .adapter_copy_bo_address
= adapter_vk_copy_bo_address
,
1776 .adapter_create_swapchain
= adapter_vk_create_swapchain
,
1777 .adapter_destroy_swapchain
= adapter_vk_destroy_swapchain
,
1778 .adapter_create_buffer
= adapter_vk_create_buffer
,
1779 .adapter_destroy_buffer
= adapter_vk_destroy_buffer
,
1780 .adapter_create_texture
= adapter_vk_create_texture
,
1781 .adapter_destroy_texture
= adapter_vk_destroy_texture
,
1782 .adapter_create_rendertarget_view
= adapter_vk_create_rendertarget_view
,
1783 .adapter_destroy_rendertarget_view
= adapter_vk_destroy_rendertarget_view
,
1784 .adapter_create_shader_resource_view
= adapter_vk_create_shader_resource_view
,
1785 .adapter_destroy_shader_resource_view
= adapter_vk_destroy_shader_resource_view
,
1786 .adapter_create_unordered_access_view
= adapter_vk_create_unordered_access_view
,
1787 .adapter_destroy_unordered_access_view
= adapter_vk_destroy_unordered_access_view
,
1788 .adapter_create_sampler
= adapter_vk_create_sampler
,
1789 .adapter_destroy_sampler
= adapter_vk_destroy_sampler
,
1790 .adapter_create_query
= adapter_vk_create_query
,
1791 .adapter_destroy_query
= adapter_vk_destroy_query
,
1792 .adapter_flush_context
= adapter_vk_flush_context
,
1793 .adapter_draw_primitive
= adapter_vk_draw_primitive
,
1794 .adapter_dispatch_compute
= adapter_vk_dispatch_compute
,
1795 .adapter_clear_uav
= adapter_vk_clear_uav
,
1798 static unsigned int wined3d_get_wine_vk_version(void)
1800 const char *ptr
= PACKAGE_VERSION
;
1805 while (isdigit(*ptr
))
1812 return VK_MAKE_VERSION(major
, minor
, 0);
1818 unsigned int core_since_version
;
1821 vulkan_instance_extensions
[] =
1823 {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
, VK_API_VERSION_1_1
, FALSE
},
1824 {VK_KHR_SURFACE_EXTENSION_NAME
, ~0u, TRUE
},
1825 {VK_KHR_WIN32_SURFACE_EXTENSION_NAME
, ~0u, TRUE
},
1828 static BOOL
enable_vulkan_instance_extensions(uint32_t *extension_count
,
1829 const char *enabled_extensions
[], const struct wined3d_vk_info
*vk_info
)
1831 PFN_vkEnumerateInstanceExtensionProperties pfn_vkEnumerateInstanceExtensionProperties
;
1832 VkExtensionProperties
*extensions
= NULL
;
1833 BOOL success
= FALSE
, found
;
1834 unsigned int i
, j
, count
;
1837 *extension_count
= 0;
1839 if (!(pfn_vkEnumerateInstanceExtensionProperties
1840 = (void *)VK_CALL(vkGetInstanceProcAddr(NULL
, "vkEnumerateInstanceExtensionProperties"))))
1842 WARN("Failed to get 'vkEnumerateInstanceExtensionProperties'.\n");
1846 if ((vr
= pfn_vkEnumerateInstanceExtensionProperties(NULL
, &count
, NULL
)) < 0)
1848 WARN("Failed to count instance extensions, vr %s.\n", wined3d_debug_vkresult(vr
));
1851 if (!(extensions
= heap_calloc(count
, sizeof(*extensions
))))
1853 WARN("Out of memory.\n");
1856 if ((vr
= pfn_vkEnumerateInstanceExtensionProperties(NULL
, &count
, extensions
)) < 0)
1858 WARN("Failed to enumerate extensions, vr %s.\n", wined3d_debug_vkresult(vr
));
1862 TRACE("Vulkan instance extensions reported:\n");
1863 for (i
= 0; i
< count
; ++i
)
1865 TRACE(" - %s.\n", debugstr_a(extensions
[i
].extensionName
));
1868 for (i
= 0; i
< ARRAY_SIZE(vulkan_instance_extensions
); ++i
)
1870 if (vulkan_instance_extensions
[i
].core_since_version
<= vk_info
->api_version
)
1873 for (j
= 0, found
= FALSE
; j
< count
; ++j
)
1875 if (!strcmp(extensions
[j
].extensionName
, vulkan_instance_extensions
[i
].name
))
1883 TRACE("Enabling instance extension '%s'.\n", vulkan_instance_extensions
[i
].name
);
1884 enabled_extensions
[(*extension_count
)++] = vulkan_instance_extensions
[i
].name
;
1886 else if (!found
&& vulkan_instance_extensions
[i
].required
)
1888 WARN("Required extension '%s' is not available.\n", vulkan_instance_extensions
[i
].name
);
1895 heap_free(extensions
);
1899 static BOOL
wined3d_init_vulkan(struct wined3d_vk_info
*vk_info
)
1901 const char *enabled_instance_extensions
[ARRAY_SIZE(vulkan_instance_extensions
)];
1902 PFN_vkEnumerateInstanceVersion pfn_vkEnumerateInstanceVersion
;
1903 struct vulkan_ops
*vk_ops
= &vk_info
->vk_ops
;
1904 VkInstance instance
= VK_NULL_HANDLE
;
1905 VkInstanceCreateInfo instance_info
;
1906 VkApplicationInfo app_info
;
1907 uint32_t api_version
= 0;
1908 char app_name
[MAX_PATH
];
1911 if (!wined3d_load_vulkan(vk_info
))
1914 if (!(vk_ops
->vkCreateInstance
= (void *)VK_CALL(vkGetInstanceProcAddr(NULL
, "vkCreateInstance"))))
1916 ERR("Failed to get 'vkCreateInstance'.\n");
1920 vk_info
->api_version
= VK_API_VERSION_1_0
;
1921 if ((pfn_vkEnumerateInstanceVersion
= (void *)VK_CALL(vkGetInstanceProcAddr(NULL
, "vkEnumerateInstanceVersion")))
1922 && pfn_vkEnumerateInstanceVersion(&api_version
) == VK_SUCCESS
)
1924 TRACE("Vulkan instance API version %s.\n", debug_vk_version(api_version
));
1926 if (api_version
>= VK_API_VERSION_1_1
)
1927 vk_info
->api_version
= VK_API_VERSION_1_1
;
1930 memset(&app_info
, 0, sizeof(app_info
));
1931 app_info
.sType
= VK_STRUCTURE_TYPE_APPLICATION_INFO
;
1932 if (wined3d_get_app_name(app_name
, ARRAY_SIZE(app_name
)))
1933 app_info
.pApplicationName
= app_name
;
1934 app_info
.pEngineName
= "Damavand";
1935 app_info
.engineVersion
= wined3d_get_wine_vk_version();
1936 app_info
.apiVersion
= vk_info
->api_version
;
1938 memset(&instance_info
, 0, sizeof(instance_info
));
1939 instance_info
.sType
= VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
;
1940 instance_info
.pApplicationInfo
= &app_info
;
1941 instance_info
.ppEnabledExtensionNames
= enabled_instance_extensions
;
1942 if (!enable_vulkan_instance_extensions(&instance_info
.enabledExtensionCount
, enabled_instance_extensions
, vk_info
))
1945 memset(vk_info
->supported
, 0, sizeof(vk_info
->supported
));
1946 vk_info
->supported
[WINED3D_VK_EXT_NONE
] = TRUE
;
1948 if ((vr
= VK_CALL(vkCreateInstance(&instance_info
, NULL
, &instance
))) < 0)
1950 WARN("Failed to create Vulkan instance, vr %s.\n", wined3d_debug_vkresult(vr
));
1954 TRACE("Created Vulkan instance %p.\n", instance
);
1956 #define LOAD_INSTANCE_PFN(name) \
1957 if (!(vk_ops->name = (void *)VK_CALL(vkGetInstanceProcAddr(instance, #name)))) \
1959 WARN("Could not get instance proc addr for '" #name "'.\n"); \
1962 #define LOAD_INSTANCE_OPT_PFN(name) \
1963 vk_ops->name = (void *)VK_CALL(vkGetInstanceProcAddr(instance, #name));
1964 #define VK_INSTANCE_PFN LOAD_INSTANCE_PFN
1965 #define VK_INSTANCE_EXT_PFN LOAD_INSTANCE_OPT_PFN
1966 #define VK_DEVICE_PFN LOAD_INSTANCE_PFN
1967 #define VK_DEVICE_EXT_PFN LOAD_INSTANCE_OPT_PFN
1970 #undef VK_INSTANCE_PFN
1971 #undef VK_INSTANCE_EXT_PFN
1972 #undef VK_DEVICE_PFN
1973 #undef VK_DEVICE_EXT_PFN
1975 #define MAP_INSTANCE_FUNCTION(core_pfn, ext_pfn) \
1976 if (!vk_ops->core_pfn) \
1977 vk_ops->core_pfn = (void *)VK_CALL(vkGetInstanceProcAddr(instance, #ext_pfn));
1978 MAP_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties2
, vkGetPhysicalDeviceProperties2KHR
)
1979 MAP_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures2
, vkGetPhysicalDeviceFeatures2KHR
)
1980 #undef MAP_INSTANCE_FUNCTION
1982 vk_info
->instance
= instance
;
1987 if (vk_ops
->vkDestroyInstance
)
1988 VK_CALL(vkDestroyInstance(instance
, NULL
));
1989 wined3d_unload_vulkan(vk_info
);
1993 static VkPhysicalDevice
get_vulkan_physical_device(struct wined3d_vk_info
*vk_info
)
1995 VkPhysicalDevice physical_devices
[1];
1999 if ((vr
= VK_CALL(vkEnumeratePhysicalDevices(vk_info
->instance
, &count
, NULL
))) < 0)
2001 WARN("Failed to enumerate physical devices, vr %s.\n", wined3d_debug_vkresult(vr
));
2002 return VK_NULL_HANDLE
;
2006 WARN("No physical device.\n");
2007 return VK_NULL_HANDLE
;
2011 /* TODO: Create wined3d_adapter for each device. */
2012 FIXME("Multiple physical devices available.\n");
2016 if ((vr
= VK_CALL(vkEnumeratePhysicalDevices(vk_info
->instance
, &count
, physical_devices
))) < 0)
2018 WARN("Failed to get physical devices, vr %s.\n", wined3d_debug_vkresult(vr
));
2019 return VK_NULL_HANDLE
;
2022 return physical_devices
[0];
2025 static enum wined3d_display_driver
guess_display_driver(enum wined3d_pci_vendor vendor
)
2029 case HW_VENDOR_AMD
: return DRIVER_AMD_RX
;
2030 case HW_VENDOR_INTEL
: return DRIVER_INTEL_HD4000
;
2031 case HW_VENDOR_NVIDIA
: return DRIVER_NVIDIA_GEFORCE8
;
2032 default: return DRIVER_WINE
;
2036 static bool adapter_vk_init_driver_info(struct wined3d_adapter_vk
*adapter_vk
,
2037 const VkPhysicalDeviceProperties
*properties
)
2039 const VkPhysicalDeviceMemoryProperties
*memory_properties
= &adapter_vk
->memory_properties
;
2040 const struct wined3d_gpu_description
*gpu_description
;
2041 struct wined3d_gpu_description description
;
2042 UINT64 vram_bytes
, sysmem_bytes
;
2043 const VkMemoryType
*type
;
2044 const VkMemoryHeap
*heap
;
2047 TRACE("Device name: %s.\n", debugstr_a(properties
->deviceName
));
2048 TRACE("Vendor ID: 0x%04x, Device ID: 0x%04x.\n", properties
->vendorID
, properties
->deviceID
);
2049 TRACE("Driver version: %#x.\n", properties
->driverVersion
);
2050 TRACE("API version: %s.\n", debug_vk_version(properties
->apiVersion
));
2052 for (i
= 0, vram_bytes
= 0, sysmem_bytes
= 0; i
< memory_properties
->memoryHeapCount
; ++i
)
2054 heap
= &memory_properties
->memoryHeaps
[i
];
2055 TRACE("Memory heap [%u]: flags %#x, size 0x%s.\n",
2056 i
, heap
->flags
, wine_dbgstr_longlong(heap
->size
));
2057 if (heap
->flags
& VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
)
2058 vram_bytes
+= heap
->size
;
2060 sysmem_bytes
+= heap
->size
;
2062 TRACE("Total device memory: 0x%s.\n", wine_dbgstr_longlong(vram_bytes
));
2063 TRACE("Total shared system memory: 0x%s.\n", wine_dbgstr_longlong(sysmem_bytes
));
2065 for (i
= 0; i
< memory_properties
->memoryTypeCount
; ++i
)
2067 type
= &memory_properties
->memoryTypes
[i
];
2068 TRACE("Memory type [%u]: flags %#x, heap %u.\n", i
, type
->propertyFlags
, type
->heapIndex
);
2071 if (!(gpu_description
= wined3d_get_user_override_gpu_description(properties
->vendorID
, properties
->deviceID
)))
2072 gpu_description
= wined3d_get_gpu_description(properties
->vendorID
, properties
->deviceID
);
2074 if (!gpu_description
)
2076 FIXME("Failed to retrieve GPU description for device %s %04x:%04x.\n",
2077 debugstr_a(properties
->deviceName
), properties
->vendorID
, properties
->deviceID
);
2079 description
.vendor
= properties
->vendorID
;
2080 description
.device
= properties
->deviceID
;
2081 description
.description
= properties
->deviceName
;
2082 description
.driver
= guess_display_driver(properties
->vendorID
);
2083 description
.vidmem
= vram_bytes
;
2085 gpu_description
= &description
;
2088 return wined3d_driver_info_init(&adapter_vk
->a
.driver_info
, gpu_description
,
2089 adapter_vk
->a
.d3d_info
.feature_level
, vram_bytes
, sysmem_bytes
);
2092 static enum wined3d_feature_level
feature_level_from_caps(const struct shader_caps
*shader_caps
)
2094 unsigned int shader_model
;
2096 shader_model
= min(shader_caps
->vs_version
, shader_caps
->ps_version
);
2097 shader_model
= min(shader_model
, max(shader_caps
->gs_version
, 3));
2098 shader_model
= min(shader_model
, max(shader_caps
->hs_version
, 4));
2099 shader_model
= min(shader_model
, max(shader_caps
->ds_version
, 4));
2101 if (shader_model
>= 5)
2102 return WINED3D_FEATURE_LEVEL_11_1
;
2104 if (shader_model
>= 4)
2105 return WINED3D_FEATURE_LEVEL_10_1
;
2107 return WINED3D_FEATURE_LEVEL_NONE
;
2110 static void wined3d_adapter_vk_init_d3d_info(struct wined3d_adapter_vk
*adapter_vk
, uint32_t wined3d_creation_flags
)
2112 struct wined3d_d3d_info
*d3d_info
= &adapter_vk
->a
.d3d_info
;
2113 struct wined3d_vertex_caps vertex_caps
;
2114 struct fragment_caps fragment_caps
;
2115 struct shader_caps shader_caps
;
2117 adapter_vk
->a
.shader_backend
->shader_get_caps(&adapter_vk
->a
, &shader_caps
);
2118 adapter_vk
->a
.vertex_pipe
->vp_get_caps(&adapter_vk
->a
, &vertex_caps
);
2119 adapter_vk
->a
.fragment_pipe
->get_caps(&adapter_vk
->a
, &fragment_caps
);
2121 d3d_info
->limits
.vs_version
= shader_caps
.vs_version
;
2122 d3d_info
->limits
.hs_version
= shader_caps
.hs_version
;
2123 d3d_info
->limits
.ds_version
= shader_caps
.ds_version
;
2124 d3d_info
->limits
.gs_version
= shader_caps
.gs_version
;
2125 d3d_info
->limits
.ps_version
= shader_caps
.ps_version
;
2126 d3d_info
->limits
.cs_version
= shader_caps
.cs_version
;
2127 d3d_info
->limits
.vs_uniform_count
= shader_caps
.vs_uniform_count
;
2128 d3d_info
->limits
.ps_uniform_count
= shader_caps
.ps_uniform_count
;
2129 d3d_info
->limits
.varying_count
= shader_caps
.varying_count
;
2130 d3d_info
->limits
.ffp_textures
= fragment_caps
.MaxSimultaneousTextures
;
2131 d3d_info
->limits
.ffp_blend_stages
= fragment_caps
.MaxTextureBlendStages
;
2132 d3d_info
->limits
.ffp_vertex_blend_matrices
= vertex_caps
.max_vertex_blend_matrices
;
2133 d3d_info
->limits
.active_light_count
= vertex_caps
.max_active_lights
;
2135 d3d_info
->limits
.max_rt_count
= WINED3D_MAX_RENDER_TARGETS
;
2136 d3d_info
->limits
.max_clip_distances
= WINED3D_MAX_CLIP_DISTANCES
;
2137 d3d_info
->limits
.texture_size
= adapter_vk
->device_limits
.maxImageDimension2D
;
2138 d3d_info
->limits
.pointsize_max
= adapter_vk
->device_limits
.pointSizeRange
[1];
2140 d3d_info
->wined3d_creation_flags
= wined3d_creation_flags
;
2142 d3d_info
->xyzrhw
= vertex_caps
.xyzrhw
;
2143 d3d_info
->emulated_flatshading
= vertex_caps
.emulated_flatshading
;
2144 d3d_info
->ffp_generic_attributes
= vertex_caps
.ffp_generic_attributes
;
2145 d3d_info
->ffp_alpha_test
= false;
2146 d3d_info
->vs_clipping
= !!(shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_VS_CLIPPING
);
2147 d3d_info
->shader_color_key
= !!(fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_COLOR_KEY
);
2148 d3d_info
->shader_double_precision
= !!(shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_DOUBLE_PRECISION
);
2149 d3d_info
->shader_output_interpolation
= !!(shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION
);
2150 d3d_info
->viewport_array_index_any_shader
= false; /* VK_EXT_shader_viewport_index_layer */
2151 d3d_info
->texture_npot
= true;
2152 d3d_info
->texture_npot_conditional
= true;
2153 d3d_info
->draw_base_vertex_offset
= true;
2154 d3d_info
->vertex_bgra
= true;
2155 d3d_info
->texture_swizzle
= true;
2156 d3d_info
->srgb_read_control
= false;
2157 d3d_info
->srgb_write_control
= false;
2158 d3d_info
->clip_control
= true;
2159 d3d_info
->full_ffp_varyings
= !!(shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_FULL_FFP_VARYINGS
);
2160 d3d_info
->scaled_resolve
= false;
2161 d3d_info
->feature_level
= feature_level_from_caps(&shader_caps
);
2163 d3d_info
->multisample_draw_location
= WINED3D_LOCATION_TEXTURE_RGB
;
2166 static bool wined3d_adapter_vk_init_device_extensions(struct wined3d_adapter_vk
*adapter_vk
)
2168 VkPhysicalDevice physical_device
= adapter_vk
->physical_device
;
2169 struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
2170 unsigned int count
, enable_count
, i
, j
;
2171 const char **enabled_extensions
= NULL
;
2172 VkExtensionProperties
*extensions
;
2173 bool found
, success
= false;
2174 SIZE_T enable_size
= 0;
2180 unsigned int core_since_version
;
2185 {VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME
, ~0u},
2186 {VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME
, ~0u, true},
2187 {VK_KHR_MAINTENANCE1_EXTENSION_NAME
, VK_API_VERSION_1_1
, true},
2188 {VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,VK_API_VERSION_1_2
},
2189 {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
, VK_API_VERSION_1_1
, true},
2190 {VK_KHR_SWAPCHAIN_EXTENSION_NAME
, ~0u, true},
2196 enum wined3d_vk_extension extension
;
2200 {VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME
, WINED3D_VK_EXT_TRANSFORM_FEEDBACK
},
2201 {VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
, WINED3D_VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE
},
2204 if ((vr
= VK_CALL(vkEnumerateDeviceExtensionProperties(physical_device
, NULL
, &count
, NULL
))) < 0)
2206 ERR("Failed to enumerate device extensions, vr %s.\n", wined3d_debug_vkresult(vr
));
2210 if (!(extensions
= heap_calloc(count
, sizeof(*extensions
))))
2212 ERR("Failed to allocate extension properties array.\n");
2216 if ((vr
= VK_CALL(vkEnumerateDeviceExtensionProperties(physical_device
, NULL
, &count
, extensions
))) < 0)
2218 ERR("Failed to enumerate device extensions, vr %s.\n", wined3d_debug_vkresult(vr
));
2222 TRACE("Vulkan device extensions reported:\n");
2223 for (i
= 0; i
< count
; ++i
)
2225 TRACE(" - %s.\n", debugstr_a(extensions
[i
].extensionName
));
2228 for (i
= 0, enable_count
= 0; i
< ARRAY_SIZE(info
); ++i
)
2230 if (info
[i
].core_since_version
<= vk_info
->api_version
)
2233 for (j
= 0, found
= false; j
< count
; ++j
)
2235 if (!strcmp(extensions
[j
].extensionName
, info
[i
].name
))
2244 if (!info
[i
].required
)
2246 WARN("Required extension '%s' is not available.\n", info
[i
].name
);
2250 TRACE("Enabling device extension '%s'.\n", info
[i
].name
);
2251 if (!wined3d_array_reserve((void **)&enabled_extensions
, &enable_size
,
2252 enable_count
+ 1, sizeof(*enabled_extensions
)))
2254 ERR("Failed to allocate enabled extensions array.\n");
2257 enabled_extensions
[enable_count
++] = info
[i
].name
;
2261 for (i
= 0; i
< ARRAY_SIZE(map
); ++i
)
2263 for (j
= 0; j
< enable_count
; ++j
)
2265 if (!strcmp(enabled_extensions
[j
], map
[i
].name
))
2267 vk_info
->supported
[map
[i
].extension
] = TRUE
;
2276 adapter_vk
->device_extension_count
= enable_count
;
2277 adapter_vk
->device_extensions
= enabled_extensions
;
2281 heap_free(enabled_extensions
);
2283 heap_free(extensions
);
2287 static BOOL
wined3d_adapter_vk_init(struct wined3d_adapter_vk
*adapter_vk
,
2288 unsigned int ordinal
, unsigned int wined3d_creation_flags
)
2290 struct wined3d_vk_info
*vk_info
= &adapter_vk
->vk_info
;
2291 struct wined3d_adapter
*adapter
= &adapter_vk
->a
;
2292 VkPhysicalDeviceIDProperties id_properties
;
2293 VkPhysicalDeviceProperties2 properties2
;
2294 LUID primary_luid
, *luid
= NULL
;
2296 TRACE("adapter_vk %p, ordinal %u, wined3d_creation_flags %#x.\n",
2297 adapter_vk
, ordinal
, wined3d_creation_flags
);
2299 if (!wined3d_init_vulkan(vk_info
))
2301 WARN("Failed to initialize Vulkan.\n");
2305 if (!(adapter_vk
->physical_device
= get_vulkan_physical_device(vk_info
)))
2308 if (!wined3d_adapter_vk_init_device_extensions(adapter_vk
))
2311 memset(&id_properties
, 0, sizeof(id_properties
));
2312 id_properties
.sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
;
2313 properties2
.sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2
;
2314 properties2
.pNext
= &id_properties
;
2316 if (vk_info
->vk_ops
.vkGetPhysicalDeviceProperties2
)
2317 VK_CALL(vkGetPhysicalDeviceProperties2(adapter_vk
->physical_device
, &properties2
));
2319 VK_CALL(vkGetPhysicalDeviceProperties(adapter_vk
->physical_device
, &properties2
.properties
));
2320 adapter_vk
->device_limits
= properties2
.properties
.limits
;
2322 VK_CALL(vkGetPhysicalDeviceMemoryProperties(adapter_vk
->physical_device
, &adapter_vk
->memory_properties
));
2324 if (id_properties
.deviceLUIDValid
)
2325 luid
= (LUID
*)id_properties
.deviceLUID
;
2326 else if (ordinal
== 0 && wined3d_get_primary_adapter_luid(&primary_luid
))
2327 luid
= &primary_luid
;
2329 if (!wined3d_adapter_init(adapter
, ordinal
, luid
, &wined3d_adapter_vk_ops
))
2331 heap_free(adapter_vk
->device_extensions
);
2335 adapter
->vertex_pipe
= wined3d_spirv_vertex_pipe_init_vk();
2336 adapter
->fragment_pipe
= wined3d_spirv_fragment_pipe_init_vk();
2337 adapter
->misc_state_template
= misc_state_template_vk
;
2338 adapter
->shader_backend
= wined3d_spirv_shader_backend_init_vk();
2340 wined3d_adapter_vk_init_d3d_info(adapter_vk
, wined3d_creation_flags
);
2342 if (!adapter_vk_init_driver_info(adapter_vk
, &properties2
.properties
))
2344 TRACE("Reporting (fake) driver version 0x%08x-0x%08x.\n",
2345 adapter_vk
->a
.driver_info
.version_high
, adapter_vk
->a
.driver_info
.version_low
);
2346 adapter
->vram_bytes_used
= 0;
2347 TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter
->driver_info
.vram_bytes
));
2349 memcpy(&adapter
->driver_uuid
, id_properties
.driverUUID
, sizeof(adapter
->driver_uuid
));
2350 memcpy(&adapter
->device_uuid
, id_properties
.deviceUUID
, sizeof(adapter
->device_uuid
));
2352 if (!wined3d_adapter_vk_init_format_info(adapter_vk
, vk_info
))
2358 wined3d_adapter_cleanup(adapter
);
2359 heap_free(adapter_vk
->device_extensions
);
2361 VK_CALL(vkDestroyInstance(vk_info
->instance
, NULL
));
2362 wined3d_unload_vulkan(vk_info
);
2366 struct wined3d_adapter
*wined3d_adapter_vk_create(unsigned int ordinal
,
2367 unsigned int wined3d_creation_flags
)
2369 struct wined3d_adapter_vk
*adapter_vk
;
2371 if (!(adapter_vk
= heap_alloc_zero(sizeof(*adapter_vk
))))
2374 if (!wined3d_adapter_vk_init(adapter_vk
, ordinal
, wined3d_creation_flags
))
2376 heap_free(adapter_vk
);
2380 TRACE("Created adapter %p.\n", adapter_vk
);
2382 return &adapter_vk
->a
;