1 /*
2 * Copyright 2020 Google LLC
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "vkr_pipeline.h"
7
8 #include "vkr_pipeline_gen.h"
9
10 static void
vkr_dispatch_vkCreateShaderModule(struct vn_dispatch_context * dispatch,struct vn_command_vkCreateShaderModule * args)11 vkr_dispatch_vkCreateShaderModule(struct vn_dispatch_context *dispatch,
12 struct vn_command_vkCreateShaderModule *args)
13 {
14 vkr_shader_module_create_and_add(dispatch->data, args);
15 }
16
17 static void
vkr_dispatch_vkDestroyShaderModule(struct vn_dispatch_context * dispatch,struct vn_command_vkDestroyShaderModule * args)18 vkr_dispatch_vkDestroyShaderModule(struct vn_dispatch_context *dispatch,
19 struct vn_command_vkDestroyShaderModule *args)
20 {
21 vkr_shader_module_destroy_and_remove(dispatch->data, args);
22 }
23
24 static void
vkr_dispatch_vkCreatePipelineLayout(struct vn_dispatch_context * dispatch,struct vn_command_vkCreatePipelineLayout * args)25 vkr_dispatch_vkCreatePipelineLayout(struct vn_dispatch_context *dispatch,
26 struct vn_command_vkCreatePipelineLayout *args)
27 {
28 vkr_pipeline_layout_create_and_add(dispatch->data, args);
29 }
30
31 static void
vkr_dispatch_vkDestroyPipelineLayout(struct vn_dispatch_context * dispatch,struct vn_command_vkDestroyPipelineLayout * args)32 vkr_dispatch_vkDestroyPipelineLayout(struct vn_dispatch_context *dispatch,
33 struct vn_command_vkDestroyPipelineLayout *args)
34 {
35 vkr_pipeline_layout_destroy_and_remove(dispatch->data, args);
36 }
37
38 static void
vkr_dispatch_vkCreatePipelineCache(struct vn_dispatch_context * dispatch,struct vn_command_vkCreatePipelineCache * args)39 vkr_dispatch_vkCreatePipelineCache(struct vn_dispatch_context *dispatch,
40 struct vn_command_vkCreatePipelineCache *args)
41 {
42 vkr_pipeline_cache_create_and_add(dispatch->data, args);
43 }
44
45 static void
vkr_dispatch_vkDestroyPipelineCache(struct vn_dispatch_context * dispatch,struct vn_command_vkDestroyPipelineCache * args)46 vkr_dispatch_vkDestroyPipelineCache(struct vn_dispatch_context *dispatch,
47 struct vn_command_vkDestroyPipelineCache *args)
48 {
49 vkr_pipeline_cache_destroy_and_remove(dispatch->data, args);
50 }
51
52 static void
vkr_dispatch_vkGetPipelineCacheData(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkGetPipelineCacheData * args)53 vkr_dispatch_vkGetPipelineCacheData(UNUSED struct vn_dispatch_context *dispatch,
54 struct vn_command_vkGetPipelineCacheData *args)
55 {
56 struct vkr_device *dev = vkr_device_from_handle(args->device);
57 struct vn_device_proc_table *vk = &dev->proc_table;
58
59 vn_replace_vkGetPipelineCacheData_args_handle(args);
60 args->ret = vk->GetPipelineCacheData(args->device, args->pipelineCache,
61 args->pDataSize, args->pData);
62 }
63
64 static void
vkr_dispatch_vkMergePipelineCaches(UNUSED struct vn_dispatch_context * dispatch,struct vn_command_vkMergePipelineCaches * args)65 vkr_dispatch_vkMergePipelineCaches(UNUSED struct vn_dispatch_context *dispatch,
66 struct vn_command_vkMergePipelineCaches *args)
67 {
68 struct vkr_device *dev = vkr_device_from_handle(args->device);
69 struct vn_device_proc_table *vk = &dev->proc_table;
70
71 vn_replace_vkMergePipelineCaches_args_handle(args);
72 args->ret = vk->MergePipelineCaches(args->device, args->dstCache, args->srcCacheCount,
73 args->pSrcCaches);
74 }
75
76 static void
vkr_dispatch_vkCreateGraphicsPipelines(struct vn_dispatch_context * dispatch,struct vn_command_vkCreateGraphicsPipelines * args)77 vkr_dispatch_vkCreateGraphicsPipelines(struct vn_dispatch_context *dispatch,
78 struct vn_command_vkCreateGraphicsPipelines *args)
79 {
80 struct vkr_context *ctx = dispatch->data;
81 struct vkr_device *dev = vkr_device_from_handle(args->device);
82 struct object_array arr;
83
84 if (vkr_graphics_pipeline_create_array(ctx, args, &arr) < VK_SUCCESS)
85 return;
86
87 vkr_pipeline_add_array(ctx, dev, &arr, args->pPipelines);
88 }
89
90 static void
vkr_dispatch_vkCreateComputePipelines(struct vn_dispatch_context * dispatch,struct vn_command_vkCreateComputePipelines * args)91 vkr_dispatch_vkCreateComputePipelines(struct vn_dispatch_context *dispatch,
92 struct vn_command_vkCreateComputePipelines *args)
93 {
94 struct vkr_context *ctx = dispatch->data;
95 struct vkr_device *dev = vkr_device_from_handle(args->device);
96 struct object_array arr;
97
98 if (vkr_compute_pipeline_create_array(ctx, args, &arr) < VK_SUCCESS)
99 return;
100
101 vkr_pipeline_add_array(ctx, dev, &arr, args->pPipelines);
102 }
103
104 static void
vkr_dispatch_vkDestroyPipeline(struct vn_dispatch_context * dispatch,struct vn_command_vkDestroyPipeline * args)105 vkr_dispatch_vkDestroyPipeline(struct vn_dispatch_context *dispatch,
106 struct vn_command_vkDestroyPipeline *args)
107 {
108 vkr_pipeline_destroy_and_remove(dispatch->data, args);
109 }
110
111 void
vkr_context_init_shader_module_dispatch(struct vkr_context * ctx)112 vkr_context_init_shader_module_dispatch(struct vkr_context *ctx)
113 {
114 struct vn_dispatch_context *dispatch = &ctx->dispatch;
115
116 dispatch->dispatch_vkCreateShaderModule = vkr_dispatch_vkCreateShaderModule;
117 dispatch->dispatch_vkDestroyShaderModule = vkr_dispatch_vkDestroyShaderModule;
118 }
119
120 void
vkr_context_init_pipeline_layout_dispatch(struct vkr_context * ctx)121 vkr_context_init_pipeline_layout_dispatch(struct vkr_context *ctx)
122 {
123 struct vn_dispatch_context *dispatch = &ctx->dispatch;
124
125 dispatch->dispatch_vkCreatePipelineLayout = vkr_dispatch_vkCreatePipelineLayout;
126 dispatch->dispatch_vkDestroyPipelineLayout = vkr_dispatch_vkDestroyPipelineLayout;
127 }
128
129 void
vkr_context_init_pipeline_cache_dispatch(struct vkr_context * ctx)130 vkr_context_init_pipeline_cache_dispatch(struct vkr_context *ctx)
131 {
132 struct vn_dispatch_context *dispatch = &ctx->dispatch;
133
134 dispatch->dispatch_vkCreatePipelineCache = vkr_dispatch_vkCreatePipelineCache;
135 dispatch->dispatch_vkDestroyPipelineCache = vkr_dispatch_vkDestroyPipelineCache;
136 dispatch->dispatch_vkGetPipelineCacheData = vkr_dispatch_vkGetPipelineCacheData;
137 dispatch->dispatch_vkMergePipelineCaches = vkr_dispatch_vkMergePipelineCaches;
138 }
139
140 void
vkr_context_init_pipeline_dispatch(struct vkr_context * ctx)141 vkr_context_init_pipeline_dispatch(struct vkr_context *ctx)
142 {
143 struct vn_dispatch_context *dispatch = &ctx->dispatch;
144
145 dispatch->dispatch_vkCreateGraphicsPipelines = vkr_dispatch_vkCreateGraphicsPipelines;
146 dispatch->dispatch_vkCreateComputePipelines = vkr_dispatch_vkCreateComputePipelines;
147 dispatch->dispatch_vkDestroyPipeline = vkr_dispatch_vkDestroyPipeline;
148 }
149