1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_RENDER_DEVICE_ISHADER_MANAGER_H
17 #define API_RENDER_DEVICE_ISHADER_MANAGER_H
18
19 #include <base/containers/string_view.h>
20 #include <base/containers/vector.h>
21 #include <core/json/json.h>
22 #include <core/namespace.h>
23 #include <render/device/intf_shader_pipeline_binder.h>
24 #include <render/device/pipeline_layout_desc.h>
25 #include <render/device/pipeline_state_desc.h>
26 #include <render/namespace.h>
27 #include <render/resource_handle.h>
28
RENDER_BEGIN_NAMESPACE()29 RENDER_BEGIN_NAMESPACE()
30
31 /** \addtogroup group_ishadermanager
32 * @{
33 */
34 /** Shader manager interface.
35 * Not internally synchronized.
36 *
37 * Shaders are automatically loaded from json files with LoadShaderFiles(prefix).
38 * One can explicitly (Re)LoadShaderFile(...) but LoadShaderFiles would be preferred method.
39 * Beware that shader manager is not internally synchronized. Create methods should only be called before
40 * calling RenderFrame (and not in render nodes).
41 *
42 * Loading shader data:
43 * By default shader data is loaded from default paths:
44 * Shaders "<prefix>shaders://"
45 * Shader states ""<prefix>shaderstates://";
46 * Vertex input declarations "<prefix>vertexinputdeclarations://"
47 * Pipeline layouts "<prefix>pipelinelayouts://"
48 *
49 * Naming of shader resources
50 * Shaders: .shader
51 * Shader states (graphics state): .shadergs
52 * Vertex input declaration: .shadervid
53 * Pipeline layout: .shaderpl
54 *
55 * Calling LoadShaderFiles effectively does the previous.
56 * In application one needs to load all plugin shader assets.
57 * This enables faster loading times when one can control if and when default shader files are needed.
58 *
59 * LoadShaderFile(uri)
60 * Loads a specified shader data file. Identifies the type and loads it's data.
61 *
62 * Shaders are created with default name which is the path.
63 *
64 * Methods that have a name as a parameter print error message if resource not found.
65 * Methods that have a handle as a parameter return invalid handles or default data if not found.
66 *
67 * Shader language is (vulkan):
68 * #version 460 core
69 * #extension GL_ARB_separate_shader_objects : enable
70 * #extension GL_ARB_shading_language_420pack : enable
71 *
72 * Default specilization that can be used (handled automatically):
73 * layout(constant_id = 0) const uint CORE_BACKEND_TYPE = 0;
74 * Vulkan: CORE_BACKEND_TYPE = 0
75 * GL and GLES: CORE_BACKEND_TYPE = 1
76 *
77 * NOTE: Do not set this automatically.
78 *
79 * Specialization constant ids need to be smaller than 256.
80 * Engine uses special low level specializations with ids 256+.
81 * Prefer using every id from zero onwards.
82
83 */
84 class IShaderManager {
85 public:
86 struct ShaderModulePath {
87 /* Shader module path */
88 BASE_NS::string_view path;
89 /* Shader stage flags */
90 ShaderStageFlags shaderStageFlags { 0u };
91 };
92 struct ComputeShaderCreateInfo {
93 /* Path, used as a name */
94 BASE_NS::string_view path;
95 /* Shader modules for this shader */
96 BASE_NS::array_view<const ShaderModulePath> shaderPaths;
97
98 /* Optional pipeline layout handle */
99 RenderHandle pipelineLayout;
100 /* Optional render slot mask */
101 uint32_t renderSlotId { ~0u };
102 };
103 struct ShaderCreateInfo {
104 /* Path, used as a name */
105 BASE_NS::string_view path;
106 /* Shader modules for this shader */
107 BASE_NS::array_view<const ShaderModulePath> shaderPaths;
108
109 /* Optional default graphics state handle for the shader */
110 RenderHandle graphicsState;
111 /* Optional pipeline layout handle */
112 RenderHandle pipelineLayout;
113 /* Optional vertex input declaration handle */
114 RenderHandle vertexInputDeclaration;
115 /* Optional render slot mask */
116 uint32_t renderSlotId { ~0u };
117 };
118
119 struct PipelineLayoutCreateInfo {
120 /* Path, used as a name */
121 BASE_NS::string_view path;
122 /* Reference to pipeline layout */
123 const PipelineLayout& pipelineLayout;
124 };
125 struct GraphicsStateCreateInfo {
126 /* Path, used as a name */
127 BASE_NS::string_view path;
128 /* Reference to graphics state */
129 const GraphicsState& graphicsState;
130 };
131 struct GraphicsStateVariantCreateInfo {
132 /* Render slot for the variant */
133 BASE_NS::string_view renderSlot;
134 /* Variant name for the graphics state */
135 BASE_NS::string_view variant;
136 /* Base graphics state name */
137 BASE_NS::string_view baseShaderState;
138 /* Base graphics state variant name */
139 BASE_NS::string_view baseVariant;
140 };
141 struct VertexInputDeclarationCreateInfo {
142 /* Path, used as a name */
143 BASE_NS::string_view path;
144 /* Reference to vertex input declaration view */
145 const VertexInputDeclarationView& vertexInputDeclarationView;
146 };
147 /* Id Description which can be fetched for handle */
148 struct IdDesc {
149 /* Unique path */
150 BASE_NS::string path;
151 /* Variant name */
152 BASE_NS::string variant;
153 /* Render slot id mask */
154 uint32_t renderSlotId { ~0u };
155 };
156 /* Render slot data. Used for default render slot data handles */
157 struct RenderSlotData {
158 /** Render slot ID */
159 uint32_t renderSlotId { ~0u };
160 /** Shader handle */
161 RENDER_NS::RenderHandleReference shader;
162 /** Graphics state handle */
163 RENDER_NS::RenderHandleReference graphicsState;
164 };
165
166 /* Shader files loading */
167 struct ShaderFilePathDesc {
168 /* Shaders path */
169 BASE_NS::string_view shaderPath;
170 /* Shader states path */
171 BASE_NS::string_view shaderStatePath;
172 /* Pipeline layouts path */
173 BASE_NS::string_view pipelineLayoutPath;
174 /* Vertex input declarations path */
175 BASE_NS::string_view vertexInputDeclarationPath;
176 };
177
178 /** Create a compute shader. Prefer loading shaders from json files.
179 * @param createInfo A create info with valid parameters.
180 * @return Returns compute shader gpu resource handle.
181 */
182 virtual RenderHandleReference CreateComputeShader(const ComputeShaderCreateInfo& createInfo) = 0;
183
184 /** Create a compute shader with a variant name. Prefer loading shaders from json files.
185 * @param createInfo A create info with valid parameters.
186 * @param baseShaderPath A base shader path/name to which the added variant is for.
187 * @param variantName A variant name.
188 * @return Returns compute shader gpu resource handle.
189 */
190 virtual RenderHandleReference CreateComputeShader(const ComputeShaderCreateInfo& createInfo,
191 const BASE_NS::string_view baseShaderPath, const BASE_NS::string_view variantName) = 0;
192
193 /** Create a shader. Prefer loading shaders from json files.
194 * @param createInfo A create info with valid parameters.
195 * @return Returns shader gpu resource handle.
196 */
197 virtual RenderHandleReference CreateShader(const ShaderCreateInfo& createInfo) = 0;
198
199 /** Create a shader. Prefer loading shaders from json files.
200 * @param createInfo A create info with valid parameters.
201 * @param baseShaderPath A base shader path/name to which the added variant is for.
202 * @param variantName A variant name.
203 * @return Returns shader gpu resource handle.
204 */
205 virtual RenderHandleReference CreateShader(const ShaderCreateInfo& createInfo,
206 const BASE_NS::string_view baseShaderPath, const BASE_NS::string_view variantName) = 0;
207
208 /** Create a pipeline layout. Prefer loading pipeline layouts from json files.
209 * @param createInfo A pipeline layout create info.
210 * @return Returns pipeline layout render handle.
211 */
212 virtual RenderHandleReference CreatePipelineLayout(const PipelineLayoutCreateInfo& createInfo) = 0;
213
214 /** Create a vertex input declaration. Prefer laoding vertex input declaration from json files.
215 * @param createInfo A vertex input declaration create info.
216 * @return Returns vertex input declaration handle.
217 */
218 virtual RenderHandleReference CreateVertexInputDeclaration(const VertexInputDeclarationCreateInfo& createInfo) = 0;
219
220 /** Create a graphics state. Prefer loading graphics states from json files.
221 * @param name Unique name of the graphics state. (Optional name, can be empty string view)
222 * @param createInfo A graphics state create info.
223 * @return Returns graphics state render handle.
224 */
225 virtual RenderHandleReference CreateGraphicsState(const GraphicsStateCreateInfo& createInfo) = 0;
226
227 /** Create a graphics state with additional variant info. Prefer loading graphics states from json files.
228 * @param createInfo A graphics state create info.
229 * @param variantCreateInfo A create info for shader graphics state variant.
230 * @return Returns graphics state render handle.
231 */
232 virtual RenderHandleReference CreateGraphicsState(
233 const GraphicsStateCreateInfo& createInfo, const GraphicsStateVariantCreateInfo& variantCreateInfo) = 0;
234
235 /** Create a render slot id for render slot name. If render slot already created for the name the slot id is
236 * returned.
237 * @param name Unique name of the render slot id.
238 * @return Returns render slot id for the name.
239 */
240 virtual uint32_t CreateRenderSlotId(const BASE_NS::string_view name) = 0;
241
242 /** Set render slot default data.
243 * @param renderSlotId Render slot id.
244 * @param shaderHandle Render slot default shader handle. (Does not replace if not valid)
245 * @param stateHandle Render slot default graphics state handle. (Does not replace if not valid)
246 */
247 virtual void SetRenderSlotData(const uint32_t renderSlotId, const RenderHandleReference& shaderHandle,
248 const RenderHandleReference& stateHandle) = 0;
249
250 /** Get shader handle.
251 * @param name Name of the shader.
252 * @return Returns shader handle.
253 */
254 virtual RenderHandleReference GetShaderHandle(const BASE_NS::string_view name) const = 0;
255
256 /** Get shader variant handle. One can fetch and explicit handle to variant.
257 * @param name Name of the base shader.
258 * @param variantName Name of variant.
259 * @return Returns shader gpu resource handle.
260 */
261 virtual RenderHandleReference GetShaderHandle(
262 const BASE_NS::string_view name, const BASE_NS::string_view variantName) const = 0;
263
264 /** Get shader handle. Tries to find a shader variant for provided render slot id.
265 * @param handle Shader handle.
266 * @param renderSlotId Render slot id.
267 * @return Returns shader handle for given render slot id.
268 */
269 virtual RenderHandleReference GetShaderHandle(
270 const RenderHandleReference& handle, const uint32_t renderSlotId) const = 0;
271
272 /** Get shaders
273 * @param renderSlotId Id of render slot
274 */
275 virtual BASE_NS::vector<RenderHandleReference> GetShaders(const uint32_t renderSlotId) const = 0;
276
277 /** Get graphics state based on path name
278 * @param name Unique name of the graphics state
279 */
280 virtual RenderHandleReference GetGraphicsStateHandle(const BASE_NS::string_view name) const = 0;
281
282 /** Get graphics state based on name and variant name
283 * @param name Unique name of the graphics state
284 * @param name Variant name of the graphics state
285 */
286 virtual RenderHandleReference GetGraphicsStateHandle(
287 const BASE_NS::string_view name, const BASE_NS::string_view variantName) const = 0;
288
289 /** Get graphics state handle. Tries to find a graphics state variant for provided render slot id.
290 * Returns the given handle if it's own slot matches.
291 * @param handle Graphics state handle.
292 * @param renderSlotId Render slot id.
293 * @return Returns shader handle for given render slot id.
294 */
295 virtual RenderHandleReference GetGraphicsStateHandle(
296 const RenderHandleReference& handle, const uint32_t renderSlotId) const = 0;
297
298 /** Get graphics state based on graphics state hash
299 * @param hash A hash created with HashGraphicsState()
300 */
301 virtual RenderHandleReference GetGraphicsStateHandleByHash(const uint64_t hash) const = 0;
302
303 /** Get graphics state handle based on shader handle. The default graphics in shader json.
304 * @param handle Valid shader handle.
305 */
306 virtual RenderHandleReference GetGraphicsStateHandleByShaderHandle(const RenderHandleReference& handle) const = 0;
307
308 /** Get graphics state
309 * @param handle Graphics state render handle
310 */
311 virtual GraphicsState GetGraphicsState(const RenderHandleReference& handle) const = 0;
312
313 /** Get render slot ID
314 * @param renderSlot Name of render slot
315 * @return render slot id if found (~0u invalid)
316 */
317 virtual uint32_t GetRenderSlotId(const BASE_NS::string_view renderSlot) const = 0;
318
319 /** Get render slot ID.
320 * @param handle Handle of shader or graphics state.
321 * @return render slot id if found (~0u invalid)
322 */
323 virtual uint32_t GetRenderSlotId(const RenderHandleReference& handle) const = 0;
324
325 /** Get render slot data. Get default data of render slot.
326 * @param renderSlotId Render slot id.
327 * @return render slot data.
328 */
329 virtual RenderSlotData GetRenderSlotData(const uint32_t renderSlotId) const = 0;
330
331 /** Get vertex input declaration handle by shader handle.
332 * @param handle A handle of the shader which vertex input declaration data handle will be returned.
333 * @return Returns a data handle for vertex input declaration.
334 */
335 virtual RenderHandleReference GetVertexInputDeclarationHandleByShaderHandle(
336 const RenderHandleReference& handle) const = 0;
337
338 /** Get vertex input declaration handle by vertex input declaration name.
339 * @param name A name of the vertex input declaration given in data.
340 * @return Returns a data handle for vertex input declaration.
341 */
342 virtual RenderHandleReference GetVertexInputDeclarationHandle(const BASE_NS::string_view name) const = 0;
343
344 /** Get vertex input declaration view by vertex input declaration data handle.
345 * The return value should not be hold into as it contains array_views to data which my change.
346 * @param handle A handle to the vertex input declaration data.
347 * @return Returns a view to vertex input declaration data.
348 */
349 virtual VertexInputDeclarationView GetVertexInputDeclarationView(const RenderHandleReference& handle) const = 0;
350
351 /** Get pipeline layout handle by shader handle.
352 * @param handle A handle of the shader which pipeline layout data handle will be returned.
353 * @return Returns a handle to pipeline layout.
354 */
355 virtual RenderHandleReference GetPipelineLayoutHandleByShaderHandle(const RenderHandleReference& handle) const = 0;
356
357 /** Get pipeline layout by shader or compute shader pipeline layout handle.
358 * @param handle A handle to pipeline layout.
359 * @return Returns a const reference to pipeline layout.
360 */
361 virtual PipelineLayout GetPipelineLayout(const RenderHandleReference& handle) const = 0;
362
363 /** Get pipeline layout handle by pipeline layout name.
364 * @param name A name of the pipeline layout.
365 * @return Returns a handle to pipeline layout.
366 */
367 virtual RenderHandleReference GetPipelineLayoutHandle(const BASE_NS::string_view name) const = 0;
368
369 /** Get pipeline layout handle for reflected shader data.
370 * @param handle A handle to a valid shader or compute shader.
371 * @return Returns a handle to pipeline layout.
372 */
373 virtual RenderHandleReference GetReflectionPipelineLayoutHandle(const RenderHandleReference& handle) const = 0;
374
375 /** Get pipeline layout reflected from the shader or compute shader pipeline layout handle.
376 * @param handle A handle to a valid shader or compute shader.
377 * @return Returns a const reference to pipeline layout.
378 */
379 virtual PipelineLayout GetReflectionPipelineLayout(const RenderHandleReference& handle) const = 0;
380
381 /** Get specialization reflected from the given shader.
382 * @param handle A handle to a valid shader or compute shader.
383 * @return Returns a view to shader specialization. The struct should not be holded unto.
384 */
385 virtual ShaderSpecilizationConstantView GetReflectionSpecialization(const RenderHandleReference& handle) const = 0;
386
387 /** Get vertex input declaration reflected from the shader. (Zero values if shader does not have one)
388 * @param handle A handle to a valid shader.
389 * @return Returns a view to vertex input declaration view. The struct should not be holded unto.
390 */
391 virtual VertexInputDeclarationView GetReflectionVertexInputDeclaration(
392 const RenderHandleReference& handle) const = 0;
393
394 /** Get thread group size of a given shader. (Zero values if shader does not have thread group)
395 * @param handle A handle to a valid compute shader.
396 * @return Returns a shader thread group size.
397 */
398 virtual ShaderThreadGroup GetReflectionThreadGroupSize(const RenderHandleReference& handle) const = 0;
399
400 /** Hash graphics state.
401 * @return Returns a hash for shader related graphics state.
402 */
403 virtual uint64_t HashGraphicsState(const GraphicsState& graphicsState) const = 0;
404
405 /** Checks if resource is a compute shader */
406 virtual bool IsComputeShader(const RenderHandleReference& handle) const = 0;
407 /** Checks if resource is a shader */
408 virtual bool IsShader(const RenderHandleReference& handle) const = 0;
409
410 /** Load shader files.
411 * Looks for json files under paths for shaders, shader states, vertex input declarations, and pipeline
412 * layouts. Creates resources based on loaded data.
413 * NOTE: does not re-create shader modules if the module with the same spv has already been done.
414 * @param desc Paths to shader files
415 */
416 virtual void LoadShaderFiles(const ShaderFilePathDesc& desc) = 0;
417
418 /** Load shader file and create resources.
419 * NOTE: beware that shader json files can refer to names (not uris) of other shader resources (like pipeline
420 * layout) and they need to be loaded before hand. Prefer using LoadShaderFiles() or automatic loading of shaders.
421 * @param uri A uri to a valid shader data json file.
422 */
423 virtual void LoadShaderFile(const BASE_NS::string_view uri) = 0;
424
425 /** Unload shader files.
426 * Looks for json files under paths for shaders, shader states, vertex input declarations, and pipeline
427 * layouts. Unloads/Destroys the shaders.
428 * @param desc Paths to shader files
429 */
430 virtual void UnloadShaderFiles(const ShaderFilePathDesc& desc) = 0;
431
432 /** Get material metadata for the shader.
433 * @param handle A handle to a valid shader.
434 * @return Returns available metadata as JSON.
435 */
436 virtual const CORE_NS::json::value* GetMaterialMetadata(const RenderHandleReference& handle) const = 0;
437
438 /** Destroy shader data handle (shaders, pipeline layouts, shader states, vertex input declarations).
439 * @param handle A handle to a valid shader (pl, state, vid).
440 */
441 virtual void Destroy(const RenderHandleReference& handle) = 0;
442
443 /** Get shaders based on render handle (pipeline layout, vertex input declaration, graphics state).
444 * Based on ShaderStageFlags searches for valid shaders.
445 * Not fast operation and should not be queried every frame.
446 * @param handle A handle to a valid render handle (pl, vid).
447 * @param shaderStateFlags Flags for specific shaders.
448 * @return Returns All shaders that use the specific handle.
449 */
450 virtual BASE_NS::vector<RenderHandleReference> GetShaders(
451 const RenderHandleReference& handle, const ShaderStageFlags shaderStageFlags) const = 0;
452
453 /** Get IdDesc for a RenderHandle.
454 * @param handle A handle to a valid render handle.
455 * @return Returns IdDesc for a given handle.
456 */
457 virtual IdDesc GetIdDesc(const RenderHandleReference& handle) const = 0;
458
459 /** Reload shader file and create resources.
460 * NOTE: Force re-creates shader modules from spv -files in shader json.
461 * NOTE: Do not call on perf-critical path.
462 * NOTE: beware that shader json files can refer to names (not uris) of other shader resources (like pipeline
463 * layout) and they need to be loaded before hand. Prefer using LoadShaderFiles() or automatic loading of shaders.
464 * @param uri A uri to a valid shader data json file.
465 */
466 virtual void ReloadShaderFile(const BASE_NS::string_view uri) = 0;
467
468 /** Create shader pipeline binder.
469 * @param handle Shader handle.
470 * @return Returns shader pipeline binder.
471 */
472 virtual IShaderPipelineBinder::Ptr CreateShaderPipelineBinder(const RenderHandleReference& handle) const = 0;
473
474 /** Compatibility flags */
475 enum CompatibilityFlagBits {
476 /** Is compatible */
477 COMPATIBLE_BIT = 0x00000001,
478 /** Exact match */
479 EXACT_BIT = 0x00000002,
480 };
481 /** Container for compatibility flag flag bits */
482 using CompatibilityFlags = uint32_t;
483
484 /** Check compatibility of render resources.
485 * @param lhs The base for compatibility check.
486 * @param rhs The one which will be compared against the base.
487 * @return Returns compatibility flags.
488 */
489 virtual CompatibilityFlags GetCompatibilityFlags(
490 const RenderHandleReference& lhs, const RenderHandleReference& rhs) const = 0;
491
492 protected:
493 IShaderManager() = default;
494 virtual ~IShaderManager() = default;
495
496 IShaderManager(const IShaderManager&) = delete;
497 IShaderManager& operator=(const IShaderManager&) = delete;
498 IShaderManager(IShaderManager&&) = delete;
499 IShaderManager& operator=(IShaderManager&&) = delete;
500 };
501
502 /** IRenderNodeShaderManager.
503 * Shader manager interface to be used inside render nodes.
504 *
505 * Some methods use faster path (no locking).
506 * Some methods are not available like creation methods
507 */
508 class IRenderNodeShaderManager {
509 public:
510 /** Get shader handle (any type).
511 * @param name Name of the shader.
512 * @return Returns shader handle.
513 */
514 virtual RenderHandle GetShaderHandle(const BASE_NS::string_view name) const = 0;
515
516 /** Get shader handle.
517 * @param name Name of the shader.
518 * @param variantName Name of the variant.
519 * @return Returns shader gpu resource handle.
520 */
521 virtual RenderHandle GetShaderHandle(
522 const BASE_NS::string_view name, const BASE_NS::string_view variantName) const = 0;
523
524 /** Get shader handle. Tries to find variant of shader with given render slot id.
525 * @param handle Shader handle.
526 * @param renderSlotId Render slot id.
527 * @return Returns shader gpu resource handle for given slot.
528 */
529 virtual RenderHandle GetShaderHandle(const RenderHandle& handle, const uint32_t renderSlotId) const = 0;
530
531 /** Get shaders
532 * @param renderSlotId Id of render slot
533 */
534 virtual BASE_NS::vector<RenderHandle> GetShaders(const uint32_t renderSlotId) const = 0;
535
536 /** Get graphics state based on name
537 * @param name Unique name of the graphics state
538 */
539 virtual RenderHandle GetGraphicsStateHandle(const BASE_NS::string_view name) const = 0;
540
541 /** Get graphics state based on name
542 * @param name Unique name of the graphics state
543 * @param variantName Variant name of the graphics state
544 */
545 virtual RenderHandle GetGraphicsStateHandle(
546 const BASE_NS::string_view name, const BASE_NS::string_view variantName) const = 0;
547
548 /** Get graphics state handle. Tries to find variant of graphics state with given render slot id.
549 * Returns the given handle if its render slot id matches.
550 * @param handle Graphics state handle.
551 * @param renderSlotId Render slot id.
552 * @return Returns shader graphics state handle for given slot.
553 */
554 virtual RenderHandle GetGraphicsStateHandle(const RenderHandle& handle, const uint32_t renderSlotId) const = 0;
555
556 /** Get graphics state based on graphics state hash
557 * @param hash A hash created with HashGraphicsState()
558 */
559 virtual RenderHandle GetGraphicsStateHandleByHash(const uint64_t hash) const = 0;
560
561 /** Get graphics state handle based on shader handle
562 * @param handle Valid shader handle.
563 */
564 virtual RenderHandle GetGraphicsStateHandleByShaderHandle(const RenderHandle& handle) const = 0;
565
566 /** Get graphics state
567 * @param handle Graphics state render handle
568 */
569 virtual const GraphicsState& GetGraphicsState(const RenderHandle& handle) const = 0;
570
571 /** Get render slot ID
572 * @param renderSlot Name of render slot
573 * @return render slot id if found (~0u invalid)
574 */
575 virtual uint32_t GetRenderSlotId(const BASE_NS::string_view renderSlot) const = 0;
576
577 /** Get render slot ID
578 * @param handle Handle to resource
579 * @return render slot mask if found (0 invalid)
580 */
581 virtual uint32_t GetRenderSlotId(const RenderHandle& handle) const = 0;
582
583 /** Get render slot data. Get default data of render slot.
584 * @param renderSlotId Render slot id.
585 * @return render slot data.
586 */
587 virtual IShaderManager::RenderSlotData GetRenderSlotData(const uint32_t renderSlotId) const = 0;
588
589 /** Get vertex input declaration handle by shader handle.
590 * @param handle A handle of the shader which vertex input declaration data handle will be returned.
591 * @return Returns a data handle for vertex input declaration.
592 */
593 virtual RenderHandle GetVertexInputDeclarationHandleByShaderHandle(const RenderHandle& handle) const = 0;
594
595 /** Get vertex input declaration handle by vertex input declaration name.
596 * @param name A name of the vertex input declaration given in data.
597 * @return Returns a data handle for vertex input declaration.
598 */
599 virtual RenderHandle GetVertexInputDeclarationHandle(const BASE_NS::string_view name) const = 0;
600
601 /** Get vertex input declaration view by vertex input declaration data handle.
602 * The return value should not be hold into as it contains array_views to data which my change.
603 * @param handle A handle to the vertex input declaration data.
604 * @return Returns a view to vertex input declaration data.
605 */
606 virtual VertexInputDeclarationView GetVertexInputDeclarationView(const RenderHandle& handle) const = 0;
607
608 /** Get pipeline layout handle by shader handle.
609 * @param handle A handle of the shader which pipeline layout data handle will be returned.
610 * @return Returns a handle to pipeline layout.
611 */
612 virtual RenderHandle GetPipelineLayoutHandleByShaderHandle(const RenderHandle& handle) const = 0;
613
614 /** Get pipeline layout by shader or compute shader pipeline layout handle.
615 * @param handle A handle to pipeline layout.
616 * @return Returns a const reference to pipeline layout.
617 */
618 virtual const PipelineLayout& GetPipelineLayout(const RenderHandle& handle) const = 0;
619
620 /** Get pipeline layout handle by pipeline layout name.
621 * @param name A name of the pipeline layout.
622 * @return Returns a handle to pipeline layout.
623 */
624 virtual RenderHandle GetPipelineLayoutHandle(const BASE_NS::string_view name) const = 0;
625
626 /** Get pipeline layout handle for the shader reflection pipeline layout.
627 * @param handle A handle to a valid shader or compute shader.
628 * @return Returns a render handle to pipeline layout.
629 */
630 virtual RenderHandle GetReflectionPipelineLayoutHandle(const RenderHandle& handle) const = 0;
631
632 /** Get pipeline layout reflected from the shader or compute shader pipeline layout handle.
633 * @param handle A handle to a valid shader or compute shader.
634 * @return Returns a const reference to pipeline layout.
635 */
636 virtual const PipelineLayout& GetReflectionPipelineLayout(const RenderHandle& handle) const = 0;
637
638 /** Get specialization reflected from the given shader.
639 * @param handle A handle to a valid shader or compute shader.
640 * @return Returns a view to shader specialization. The struct should not be holded unto.
641 */
642 virtual ShaderSpecilizationConstantView GetReflectionSpecialization(const RenderHandle& handle) const = 0;
643
644 /** Get vertex input declaration reflected from the shader. (Zero values if shader does not have one)
645 * @param handle A handle to a valid shader.
646 * @return Returns a view to vertex input declaration view. The struct should not be holded unto.
647 */
648 virtual VertexInputDeclarationView GetReflectionVertexInputDeclaration(const RenderHandle& handle) const = 0;
649
650 /** Get thread group size of a given shader. (Zero values if shader does not have thread group)
651 * @param handle A handle to a valid compute shader.
652 * @return Returns a shader thread group size.
653 */
654 virtual ShaderThreadGroup GetReflectionThreadGroupSize(const RenderHandle& handle) const = 0;
655
656 /** Hash graphics state.
657 * @return Returns a hash for shader related graphics state.
658 */
659 virtual uint64_t HashGraphicsState(const GraphicsState& graphicsState) const = 0;
660
661 /** Simple check if handle is valid or invalid */
662 virtual bool IsValid(const RenderHandle& handle) const = 0;
663 /** Checks if resource is a compute shader */
664 virtual bool IsComputeShader(const RenderHandle& handle) const = 0;
665 /** Checks if resource is a shader */
666 virtual bool IsShader(const RenderHandle& handle) const = 0;
667
668 /** Get shaders based on render handle (pipeline layout, vertex input declaration, graphics state).
669 * Not fast operation and should not be queried every frame.
670 * @param handle A handle to a valid render handle (pl, vid).
671 * @param shaderStateFlags Flags for specific shaders.
672 * @return Returns All shaders that use the specific handle.
673 */
674 virtual BASE_NS::vector<RenderHandle> GetShaders(
675 const RenderHandle& handle, const ShaderStageFlags shaderStageFlags) const = 0;
676
677 /** Check compatibility of render resources.
678 * @param lhs The base for compatibility check.
679 * @param rhs The one which will be compared against the base.
680 * @return Returns compatibility flags.
681 */
682 virtual IShaderManager::CompatibilityFlags GetCompatibilityFlags(
683 const RenderHandle& lhs, const RenderHandle& rhs) const = 0;
684
685 protected:
686 IRenderNodeShaderManager() = default;
687 virtual ~IRenderNodeShaderManager() = default;
688
689 IRenderNodeShaderManager(const IRenderNodeShaderManager&) = delete;
690 IRenderNodeShaderManager& operator=(const IRenderNodeShaderManager&) = delete;
691 IRenderNodeShaderManager(IRenderNodeShaderManager&&) = delete;
692 IRenderNodeShaderManager& operator=(IRenderNodeShaderManager&&) = delete;
693 };
694 /** @} */
695 RENDER_END_NAMESPACE()
696
697 #endif // API_RENDER_DEVICE_ISHADER_MANAGER_H
698