2019-09-04 10:51:29 +01:00
|
|
|
|
/*
|
|
|
|
|
* 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"
|
2022-10-24 14:17:38 +01:00
|
|
|
|
#include "dxil_versions.h"
|
2019-09-04 10:51:29 +01:00
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct blob;
|
|
|
|
|
|
2021-12-28 21:13:03 +00:00
|
|
|
|
/* 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:
|
2023-02-27 21:57:35 +00:00
|
|
|
|
* Samplers/textures are lowered, vars/intrinsics use binding to refer to them; dynamic array indexing supported with offset srcs
|
2021-12-28 21:13:03 +00:00
|
|
|
|
* The lowering done by mesa/st assigns bindings from 0 -> N
|
|
|
|
|
* All other resource variables have driver_location set instead, assigned from 0 -> N
|
2023-02-27 21:57:35 +00:00
|
|
|
|
* 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
|
2021-12-31 01:51:41 +00:00
|
|
|
|
* Images are *not* lowered, so that dynamic indexing can deterministically get a base binding via the deref chain
|
2023-02-27 21:57:35 +00:00
|
|
|
|
* TODO: Maybe support lowering and use nir_intrinsic_range_base to get the base
|
2021-12-31 01:51:41 +00:00
|
|
|
|
* No immediate constant buffer, or scratch
|
2021-12-28 21:13:03 +00:00
|
|
|
|
*/
|
|
|
|
|
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
|
2023-02-27 21:57:35 +00:00
|
|
|
|
* 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
|
2021-12-28 21:13:03 +00:00
|
|
|
|
* UBOs/SSBOs are struct variables in the NIR, accessed via vulkan_resource_index/load_vulkan_descriptor; dynamic indexing supported
|
2023-02-27 21:57:35 +00:00
|
|
|
|
* 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
|
2021-12-28 21:13:03 +00:00
|
|
|
|
* No immediate constant buffer or scratch
|
|
|
|
|
*/
|
|
|
|
|
DXIL_ENVIRONMENT_VULKAN,
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-04 10:51:29 +01:00
|
|
|
|
struct nir_to_dxil_options {
|
|
|
|
|
bool interpolate_at_vertex;
|
|
|
|
|
bool lower_int16;
|
|
|
|
|
bool disable_math_refactoring;
|
2022-01-17 15:31:53 +00:00
|
|
|
|
bool no_ubo0;
|
|
|
|
|
bool last_ubo_is_not_arrayed;
|
2019-09-04 10:51:29 +01:00
|
|
|
|
unsigned provoking_vertex;
|
2020-11-06 16:09:30 +00:00
|
|
|
|
unsigned num_kernel_globals;
|
2022-01-06 15:40:24 +00:00
|
|
|
|
unsigned input_clip_size;
|
2021-12-28 21:13:03 +00:00
|
|
|
|
enum dxil_environment environment;
|
2022-10-24 14:17:38 +01:00
|
|
|
|
enum dxil_shader_model shader_model_max;
|
|
|
|
|
enum dxil_validator_version validator_version_max;
|
2019-09-04 10:51:29 +01:00
|
|
|
|
};
|
|
|
|
|
|
2021-10-08 23:23:35 +01:00
|
|
|
|
typedef void (*dxil_msg_callback)(void *priv, const char *msg);
|
|
|
|
|
|
|
|
|
|
struct dxil_logger {
|
|
|
|
|
void *priv;
|
|
|
|
|
dxil_msg_callback log;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-04 10:51:29 +01:00
|
|
|
|
bool
|
|
|
|
|
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
2021-10-08 23:23:35 +01:00
|
|
|
|
const struct dxil_logger *logger, struct blob *blob);
|
2019-09-04 10:51:29 +01:00
|
|
|
|
|
|
|
|
|
const nir_shader_compiler_options*
|
|
|
|
|
dxil_get_nir_compiler_options(void);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|