@@ -102,6 +102,18 @@ pub struct VulkanImage {
102
102
reserved : [ * mut :: std:: os:: raw:: c_void ; 4usize ] ,
103
103
}
104
104
105
+ #[ repr( u32 ) ]
106
+ #[ derive( Copy , Clone ) ]
107
+ pub enum VulkanSwapchainMode {
108
+ Default = UnityVulkanSwapchainMode_kUnityVulkanSwapchainMode_Default ,
109
+ Offscreen = UnityVulkanSwapchainMode_kUnityVulkanSwapchainMode_Offscreen ,
110
+ }
111
+
112
+ #[ repr( C ) ]
113
+ pub struct VulkanSwapchainConfiguration {
114
+ pub mode : VulkanSwapchainMode ,
115
+ }
116
+
105
117
impl UnityGraphicsVulkan {
106
118
pub unsafe fn intercept_initialization (
107
119
& self ,
@@ -162,23 +174,163 @@ impl UnityGraphicsVulkan {
162
174
pub unsafe fn access_texture (
163
175
& self ,
164
176
native_texture : * mut :: std:: os:: raw:: c_void ,
165
- sub_resource : Option :: < & ash:: vk:: ImageSubresource > ,
177
+ sub_resource : Option < & ash:: vk:: ImageSubresource > ,
166
178
layout : ash:: vk:: ImageLayout ,
167
179
pipeline_stage_flags : ash:: vk:: PipelineStageFlags ,
168
180
access_flags : ash:: vk:: AccessFlags ,
169
- access_mode : VulkanResourceAccessMode ) -> Option :: < VulkanImage > {
181
+ access_mode : VulkanResourceAccessMode ,
182
+ ) -> Option < VulkanImage > {
170
183
let mut ret = std:: mem:: zeroed :: < VulkanImage > ( ) ;
171
184
if self . interface ( ) . AccessTexture . expect ( "AccessTexture" ) (
172
185
native_texture,
173
186
match sub_resource {
174
187
Some ( t) => std:: mem:: transmute ( t) ,
175
- None => std:: ptr:: null ( )
188
+ None => std:: ptr:: null ( ) ,
189
+ } ,
190
+ std:: mem:: transmute ( layout) ,
191
+ std:: mem:: transmute ( pipeline_stage_flags) ,
192
+ std:: mem:: transmute ( access_flags) ,
193
+ access_mode as UnityVulkanResourceAccessMode ,
194
+ std:: mem:: transmute ( & mut ret) ,
195
+ ) {
196
+ Some ( ret)
197
+ } else {
198
+ None
199
+ }
200
+ }
201
+
202
+ pub unsafe fn access_render_buffer_texture (
203
+ & self ,
204
+ native_render_buffer : unity_native_plugin:: graphics:: RenderBuffer ,
205
+ sub_resource : Option < & ash:: vk:: ImageSubresource > ,
206
+ layout : ash:: vk:: ImageLayout ,
207
+ pipeline_stage_flags : ash:: vk:: PipelineStageFlags ,
208
+ access_flags : ash:: vk:: AccessFlags ,
209
+ access_mode : VulkanResourceAccessMode ,
210
+ ) -> Option < VulkanImage > {
211
+ let mut ret = std:: mem:: zeroed :: < VulkanImage > ( ) ;
212
+ if self
213
+ . interface ( )
214
+ . AccessRenderBufferTexture
215
+ . expect ( "AccessRenderBufferTexture" ) (
216
+ native_render_buffer,
217
+ match sub_resource {
218
+ Some ( t) => std:: mem:: transmute ( t) ,
219
+ None => std:: ptr:: null ( ) ,
220
+ } ,
221
+ std:: mem:: transmute ( layout) ,
222
+ std:: mem:: transmute ( pipeline_stage_flags) ,
223
+ std:: mem:: transmute ( access_flags) ,
224
+ access_mode as UnityVulkanResourceAccessMode ,
225
+ std:: mem:: transmute ( & mut ret) ,
226
+ ) {
227
+ Some ( ret)
228
+ } else {
229
+ None
230
+ }
231
+ }
232
+
233
+ pub unsafe fn access_render_buffer_resolve_texture (
234
+ & self ,
235
+ native_render_buffer : unity_native_plugin:: graphics:: RenderBuffer ,
236
+ sub_resource : Option < & ash:: vk:: ImageSubresource > ,
237
+ layout : ash:: vk:: ImageLayout ,
238
+ pipeline_stage_flags : ash:: vk:: PipelineStageFlags ,
239
+ access_flags : ash:: vk:: AccessFlags ,
240
+ access_mode : VulkanResourceAccessMode ,
241
+ ) -> Option < VulkanImage > {
242
+ let mut ret = std:: mem:: zeroed :: < VulkanImage > ( ) ;
243
+ if self
244
+ . interface ( )
245
+ . AccessRenderBufferResolveTexture
246
+ . expect ( "AccessRenderBufferResolveTexture" ) (
247
+ native_render_buffer,
248
+ match sub_resource {
249
+ Some ( t) => std:: mem:: transmute ( t) ,
250
+ None => std:: ptr:: null ( ) ,
251
+ } ,
252
+ std:: mem:: transmute ( layout) ,
253
+ std:: mem:: transmute ( pipeline_stage_flags) ,
254
+ std:: mem:: transmute ( access_flags) ,
255
+ access_mode as UnityVulkanResourceAccessMode ,
256
+ std:: mem:: transmute ( & mut ret) ,
257
+ ) {
258
+ Some ( ret)
259
+ } else {
260
+ None
261
+ }
262
+ }
263
+
264
+ pub unsafe fn access_buffer (
265
+ & self ,
266
+ native_buffer : * mut :: std:: os:: raw:: c_void ,
267
+ pipeline_stage_flags : ash:: vk:: PipelineStageFlags ,
268
+ access_flags : ash:: vk:: AccessFlags ,
269
+ access_mode : VulkanResourceAccessMode ,
270
+ ) -> Option < VulkanImage > {
271
+ let mut ret = std:: mem:: zeroed :: < VulkanImage > ( ) ;
272
+ if self . interface ( ) . AccessBuffer . expect ( "AccessTexture" ) (
273
+ native_buffer,
274
+ std:: mem:: transmute ( pipeline_stage_flags) ,
275
+ std:: mem:: transmute ( access_flags) ,
276
+ access_mode as UnityVulkanResourceAccessMode ,
277
+ std:: mem:: transmute ( & mut ret) ,
278
+ ) {
279
+ Some ( ret)
280
+ } else {
281
+ None
282
+ }
283
+ }
284
+
285
+ pub fn ensure_outside_render_pass ( & self ) {
286
+ unsafe {
287
+ self . interface ( )
288
+ . EnsureOutsideRenderPass
289
+ . expect ( "EnsureOutsideRenderPass" ) ( )
290
+ }
291
+ }
292
+
293
+ pub fn ensure_inside_render_pass ( & self ) {
294
+ unsafe {
295
+ self . interface ( )
296
+ . EnsureInsideRenderPass
297
+ . expect ( "EnsureInsideRenderPass" ) ( )
298
+ }
299
+ }
300
+
301
+ //pub fn access_queue
302
+
303
+ pub fn config_swapchain ( & self , swapchain_config : & VulkanSwapchainConfiguration ) -> bool {
304
+ unsafe {
305
+ self . interface ( )
306
+ . ConfigureSwapchain
307
+ . expect ( "ConfigureSwapchain" ) (
308
+ std:: mem:: transmute ( swapchain_config) ,
309
+ )
310
+ }
311
+ }
312
+
313
+ pub unsafe fn access_texture_by_id (
314
+ & self ,
315
+ texture_id : unity_native_plugin:: graphics:: TextureID ,
316
+ sub_resource : Option < & ash:: vk:: ImageSubresource > ,
317
+ layout : ash:: vk:: ImageLayout ,
318
+ pipeline_stage_flags : ash:: vk:: PipelineStageFlags ,
319
+ access_flags : ash:: vk:: AccessFlags ,
320
+ access_mode : VulkanResourceAccessMode ,
321
+ ) -> Option < VulkanImage > {
322
+ let mut ret = std:: mem:: zeroed :: < VulkanImage > ( ) ;
323
+ if self . interface ( ) . AccessTextureByID . expect ( "AccessTextureByID" ) (
324
+ texture_id,
325
+ match sub_resource {
326
+ Some ( t) => std:: mem:: transmute ( t) ,
327
+ None => std:: ptr:: null ( ) ,
176
328
} ,
177
329
std:: mem:: transmute ( layout) ,
178
330
std:: mem:: transmute ( pipeline_stage_flags) ,
179
331
std:: mem:: transmute ( access_flags) ,
180
332
access_mode as UnityVulkanResourceAccessMode ,
181
- std:: mem:: transmute ( & ret)
333
+ std:: mem:: transmute ( & mut ret) ,
182
334
) {
183
335
Some ( ret)
184
336
} else {
@@ -213,5 +365,9 @@ mod test {
213
365
:: std:: mem:: size_of:: <VulkanImage >( ) ,
214
366
:: std:: mem:: size_of:: <unity_native_plugin_sys:: UnityVulkanImage >( )
215
367
) ;
368
+ assert_eq ! (
369
+ :: std:: mem:: size_of:: <VulkanSwapchainConfiguration >( ) ,
370
+ :: std:: mem:: size_of:: <unity_native_plugin_sys:: UnityVulkanSwapchainConfiguration >( )
371
+ ) ;
216
372
}
217
373
}
0 commit comments