summaryrefslogtreecommitdiff
path: root/src/microsoft/compiler/nir_to_dxil.h
blob: c7b61423375d10daefc51b674bf89ef6f4d21482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright © Microsoft Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#ifndef NIR_TO_DXIL_H
#define NIR_TO_DXIL_H

#include <stdbool.h>

#include "nir.h"
#include "dxil_versions.h"

#ifdef __cplusplus
extern "C" {
#endif

struct blob;

/* Controls how resource decls/accesses are handled. Common to all:
 *   Images, textures, and samplers map to D3D UAV, SRV, and sampler types
 *   Shared is lowered to explicit I/O and then to a DXIL-specific intrinsic for 4-byte indices instead of byte addressing
 *   Input/output are lowered to dedicated intrinsics
 */
enum dxil_environment {
   /* In the GL environment:
    *   Samplers/textures are lowered, vars/intrinsics use binding to refer to them; dynamic array indexing supported with offset srcs
    *     The lowering done by mesa/st assigns bindings from 0 -> N
    *   All other resource variables have driver_location set instead, assigned from 0 -> N
    *   UBOs may or may not have interface variables, and are declared from ubo_binding_offset -> num_ubos
    *   SSBOs may or may not have interface variables, and are declared from from 0 -> num_ssbos
    *   Images are *not* lowered, so that dynamic indexing can deterministically get a base binding via the deref chain
    *     TODO: Maybe support lowering and use nir_intrinsic_range_base to get the base
    *   No immediate constant buffer, or scratch
    */
   DXIL_ENVIRONMENT_GL,
   /* In the CL environment:
    *   Shader kind is always KERNEL
    *   All resources use binding for identification
    *   Samplers/textures/images are lowered; dynamic indexing not supported by spec
    *   UBOs are arrays of uints in the NIR
    *   SSBOs are implicitly declared via num_kernel_globals
    *   Variables of shader_temp are used to declare an immediate constant buffer, with load_ptr_dxil intrinsics to access it
    *   Scratch is supported and lowered to DXIL-specific intrinsics for scalar 32-bit access
    */
   DXIL_ENVIRONMENT_CL,
   /* In the Vulkan environment:
    *   All resources use binding / descriptor_set for identification
    *   Samplers/textures/images support two modes:
    *     1. Derefs: deref chains are walked to emit the DXIL handle to the resource; dynamic indexing supported
    *     2. Bindless: the resource source is assumed as an index into a descriptor heap
    *   UBOs/SSBOs are struct variables in the NIR, accessed via vulkan_resource_index/load_vulkan_descriptor; dynamic indexing supported
    *     If load_vulkan_descriptor gets an index that didn't come from vulkan_resource_index, it is assumed to be an index into a descriptor heap
    *   Read-only SSBOs, as declared in the SPIR-V, are bound as raw buffer SRVs instead of UAVs, unless they're lowered to bindless
    *   No immediate constant buffer or scratch
    */
   DXIL_ENVIRONMENT_VULKAN,
};

struct nir_to_dxil_options {
   bool interpolate_at_vertex;
   bool lower_int16;
   bool disable_math_refactoring;
   bool no_ubo0;
   bool last_ubo_is_not_arrayed;
   unsigned provoking_vertex;
   unsigned num_kernel_globals;
   unsigned input_clip_size;
   enum dxil_environment environment;
   enum dxil_shader_model shader_model_max;
   enum dxil_validator_version validator_version_max;
};

typedef void (*dxil_msg_callback)(void *priv, const char *msg);

struct dxil_logger {
   void *priv;
   dxil_msg_callback log;
};

bool
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
            const struct dxil_logger *logger, struct blob *blob);

const nir_shader_compiler_options*
dxil_get_base_nir_compiler_options(void);

void
dxil_get_nir_compiler_options(nir_shader_compiler_options *options,
                              enum dxil_shader_model shader_model_max,
                              unsigned supported_int_sizes,
                              unsigned supported_float_sizes);

#ifdef __cplusplus
}
#endif

#endif