• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © Microsoft Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef NIR_TO_DXIL_H
25 #define NIR_TO_DXIL_H
26 
27 #include <stdbool.h>
28 
29 #include "nir.h"
30 #include "dxil_validator.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 struct blob;
37 
38 enum dxil_sysvalue_type {
39    DXIL_NO_SYSVALUE = 0,
40    DXIL_SYSVALUE,
41    DXIL_GENERATED_SYSVALUE
42 };
43 
44 enum dxil_sysvalue_type
45 nir_var_to_dxil_sysvalue_type(nir_variable *var, uint64_t other_stage_mask);
46 
47 /* Controls how resource decls/accesses are handled. Common to all:
48  *   Images, textures, and samplers map to D3D UAV, SRV, and sampler types
49  *   Shared is lowered to explicit I/O and then to a DXIL-specific intrinsic for 4-byte indices instead of byte addressing
50  *   Input/output are lowered to dedicated intrinsics
51  */
52 enum dxil_environment {
53    /* In the GL environment:
54     *   Samplers/textures are lowered, vars/intrinsics use binding to refer to them; dynamic array indexing not yet supported
55     *     The lowering done by mesa/st assigns bindings from 0 -> N
56     *   All other resource variables have driver_location set instead, assigned from 0 -> N
57     *   UBOs may or may not have interface variables, and are declared from ubo_binding_offset -> num_ubos; no dynamic indexing yet
58     *   SSBOs may or may not have interface variables, and are declared from from 0 -> num_ssbos; no dynamic indexing yet
59     *   Images are *not* lowered, so that dynamic indexing can deterministically get a base binding via the deref chain
60     *   No immediate constant buffer, or scratch
61     */
62    DXIL_ENVIRONMENT_GL,
63    /* In the CL environment:
64     *   Shader kind is always KERNEL
65     *   All resources use binding for identification
66     *   Samplers/textures/images are lowered; dynamic indexing not supported by spec
67     *   UBOs are arrays of uints in the NIR
68     *   SSBOs are implicitly declared via num_kernel_globals
69     *   Variables of shader_temp are used to declare an immediate constant buffer, with load_ptr_dxil intrinsics to access it
70     *   Scratch is supported and lowered to DXIL-specific intrinsics for scalar 32-bit access
71     */
72    DXIL_ENVIRONMENT_CL,
73    /* In the Vulkan environment:
74     *   All resources use binding / descriptor_set for identification
75     *   Samplers/textures/images are not lowered
76     *     Deref chains are walked to emit the DXIL handle to the resource; dynamic indexing supported
77     *   UBOs/SSBOs are struct variables in the NIR, accessed via vulkan_resource_index/load_vulkan_descriptor; dynamic indexing supported
78     *   Read-only SSBOs, as declared in the SPIR-V, are bound as raw buffer SRVs instead of UAVs
79     *   No immediate constant buffer or scratch
80     */
81    DXIL_ENVIRONMENT_VULKAN,
82 };
83 
84 enum dxil_shader_model {
85    SHADER_MODEL_6_0 = 0x60000,
86    SHADER_MODEL_6_1,
87    SHADER_MODEL_6_2,
88 };
89 
90 struct nir_to_dxil_options {
91    bool interpolate_at_vertex;
92    bool lower_int16;
93    bool disable_math_refactoring;
94    bool no_ubo0;
95    bool last_ubo_is_not_arrayed;
96    unsigned provoking_vertex;
97    unsigned num_kernel_globals;
98    unsigned input_clip_size;
99    enum dxil_environment environment;
100    uint32_t shader_model_max;
101    uint32_t validator_version_max;
102 };
103 
104 bool
105 nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
106             struct blob *blob);
107 
108 const nir_shader_compiler_options*
109 dxil_get_nir_compiler_options(void);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif
116