mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 19:50:11 +01:00
microsoft/compiler: Add dxil_logger type and parameter to nir_to_dxil
v2 (jenatali): Add a default logger which aborts via unreachable, and use NULL from GL/Vulkan to use the default logger. Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12510>
This commit is contained in:
parent
58bf84044b
commit
55b3980e78
9 changed files with 54 additions and 9 deletions
|
|
@ -154,7 +154,7 @@ compile_nir(struct d3d12_context *ctx, struct d3d12_shader_selector *sel,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct blob tmp;
|
struct blob tmp;
|
||||||
if (!nir_to_dxil(nir, &opts, &tmp)) {
|
if (!nir_to_dxil(nir, &opts, NULL, &tmp)) {
|
||||||
debug_printf("D3D12: nir_to_dxil failed\n");
|
debug_printf("D3D12: nir_to_dxil failed\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1143,8 +1143,11 @@ clc_spirv_to_dxil(struct clc_libclc *lib,
|
||||||
goto err_free_dxil;
|
goto err_free_dxil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dxil_logger dxil_logger = {.priv = logger->priv,
|
||||||
|
.log = logger->error};
|
||||||
|
|
||||||
struct blob tmp;
|
struct blob tmp;
|
||||||
if (!nir_to_dxil(nir, &opts, &tmp)) {
|
if (!nir_to_dxil(nir, &opts, &dxil_logger, &tmp)) {
|
||||||
debug_printf("D3D12: nir_to_dxil failed\n");
|
debug_printf("D3D12: nir_to_dxil failed\n");
|
||||||
goto err_free_dxil;
|
goto err_free_dxil;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,15 @@ DEBUG_GET_ONCE_FLAGS_OPTION(debug_dxil, "DXIL_DEBUG", dxil_debug_options, 0)
|
||||||
fprintf(stderr, "\n"); \
|
fprintf(stderr, "\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
static void
|
||||||
|
default_logger_func(void *priv, const char *msg)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s", msg);
|
||||||
|
unreachable("Unhandled error");
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct dxil_logger default_logger = { .priv = NULL, .log = default_logger_func };
|
||||||
|
|
||||||
#define TRACE_CONVERSION(instr) \
|
#define TRACE_CONVERSION(instr) \
|
||||||
if (debug_dxil & DXIL_DEBUG_TRACE) \
|
if (debug_dxil & DXIL_DEBUG_TRACE) \
|
||||||
do { \
|
do { \
|
||||||
|
|
@ -487,6 +496,8 @@ struct ntd_context {
|
||||||
struct dxil_func_def *main_func_def;
|
struct dxil_func_def *main_func_def;
|
||||||
struct dxil_func_def *tess_ctrl_patch_constant_func_def;
|
struct dxil_func_def *tess_ctrl_patch_constant_func_def;
|
||||||
unsigned unnamed_ubo_count;
|
unsigned unnamed_ubo_count;
|
||||||
|
|
||||||
|
const struct dxil_logger *logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char*
|
static const char*
|
||||||
|
|
@ -5797,7 +5808,7 @@ static const unsigned dxil_validator_max_capable_version = DXIL_VALIDATOR_1_7;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
||||||
struct blob *blob)
|
const struct dxil_logger *logger, struct blob *blob)
|
||||||
{
|
{
|
||||||
assert(opts);
|
assert(opts);
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
|
|
@ -5831,6 +5842,7 @@ nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
||||||
|
|
||||||
ctx->opts = opts;
|
ctx->opts = opts;
|
||||||
ctx->shader = s;
|
ctx->shader = s;
|
||||||
|
ctx->logger = logger ? logger : &default_logger;
|
||||||
|
|
||||||
ctx->ralloc_ctx = ralloc_context(NULL);
|
ctx->ralloc_ctx = ralloc_context(NULL);
|
||||||
if (!ctx->ralloc_ctx) {
|
if (!ctx->ralloc_ctx) {
|
||||||
|
|
|
||||||
|
|
@ -101,9 +101,16 @@ struct nir_to_dxil_options {
|
||||||
uint32_t validator_version_max;
|
uint32_t validator_version_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*dxil_msg_callback)(void *priv, const char *msg);
|
||||||
|
|
||||||
|
struct dxil_logger {
|
||||||
|
void *priv;
|
||||||
|
dxil_msg_callback log;
|
||||||
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
nir_to_dxil(struct nir_shader *s, const struct nir_to_dxil_options *opts,
|
||||||
struct blob *blob);
|
const struct dxil_logger *logger, struct blob *blob);
|
||||||
|
|
||||||
const nir_shader_compiler_options*
|
const nir_shader_compiler_options*
|
||||||
dxil_get_nir_compiler_options(void);
|
dxil_get_nir_compiler_options(void);
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,12 @@ stage_to_enum(char *stage)
|
||||||
return MESA_SHADER_NONE;
|
return MESA_SHADER_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
log_spirv_to_dxil_error(void *priv, const char *msg)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "spirv_to_dxil error: %s", msg);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -142,12 +148,16 @@ main(int argc, char **argv)
|
||||||
struct dxil_spirv_debug_options dbg_opts = {
|
struct dxil_spirv_debug_options dbg_opts = {
|
||||||
.dump_nir = debug,
|
.dump_nir = debug,
|
||||||
};
|
};
|
||||||
|
const struct dxil_spirv_logger logger = {
|
||||||
|
.priv = NULL,
|
||||||
|
.log = log_spirv_to_dxil_error
|
||||||
|
};
|
||||||
|
|
||||||
struct dxil_spirv_object obj;
|
struct dxil_spirv_object obj;
|
||||||
memset(&obj, 0, sizeof(obj));
|
memset(&obj, 0, sizeof(obj));
|
||||||
if (spirv_to_dxil((uint32_t *)file_contents, word_count, NULL, 0,
|
if (spirv_to_dxil((uint32_t *)file_contents, word_count, NULL, 0,
|
||||||
(dxil_spirv_shader_stage)shader_stage, entry_point,
|
(dxil_spirv_shader_stage)shader_stage, entry_point,
|
||||||
&dbg_opts, &conf, &obj)) {
|
&dbg_opts, &conf, &logger, &obj)) {
|
||||||
|
|
||||||
if (validate && !validate_dxil(&obj)) {
|
if (validate && !validate_dxil(&obj)) {
|
||||||
fprintf(stderr, "Failed to validate DXIL\n");
|
fprintf(stderr, "Failed to validate DXIL\n");
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
#include "dxil_spirv_nir.h"
|
#include "dxil_spirv_nir.h"
|
||||||
#include "spirv_to_dxil.h"
|
#include "spirv_to_dxil.h"
|
||||||
#include "nir_to_dxil.h"
|
|
||||||
#include "dxil_nir.h"
|
#include "dxil_nir.h"
|
||||||
|
#include "nir_to_dxil.h"
|
||||||
#include "shader_enums.h"
|
#include "shader_enums.h"
|
||||||
#include "spirv/nir_spirv.h"
|
#include "spirv/nir_spirv.h"
|
||||||
#include "util/blob.h"
|
#include "util/blob.h"
|
||||||
|
|
@ -96,6 +96,7 @@ spirv_to_dxil(const uint32_t *words, size_t word_count,
|
||||||
const char *entry_point_name,
|
const char *entry_point_name,
|
||||||
const struct dxil_spirv_debug_options *dgb_opts,
|
const struct dxil_spirv_debug_options *dgb_opts,
|
||||||
const struct dxil_spirv_runtime_conf *conf,
|
const struct dxil_spirv_runtime_conf *conf,
|
||||||
|
const struct dxil_spirv_logger *logger,
|
||||||
struct dxil_spirv_object *out_dxil)
|
struct dxil_spirv_object *out_dxil)
|
||||||
{
|
{
|
||||||
if (stage == DXIL_SPIRV_SHADER_NONE || stage == DXIL_SPIRV_SHADER_KERNEL)
|
if (stage == DXIL_SPIRV_SHADER_NONE || stage == DXIL_SPIRV_SHADER_KERNEL)
|
||||||
|
|
@ -148,8 +149,12 @@ spirv_to_dxil(const uint32_t *words, size_t word_count,
|
||||||
.shader_model_max = SHADER_MODEL_6_2,
|
.shader_model_max = SHADER_MODEL_6_2,
|
||||||
.validator_version_max = DXIL_VALIDATOR_1_4,
|
.validator_version_max = DXIL_VALIDATOR_1_4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct dxil_logger logger_inner = {.priv = logger->priv,
|
||||||
|
.log = logger->log};
|
||||||
|
|
||||||
struct blob dxil_blob;
|
struct blob dxil_blob;
|
||||||
if (!nir_to_dxil(nir, &opts, &dxil_blob)) {
|
if (!nir_to_dxil(nir, &opts, &logger_inner, &dxil_blob)) {
|
||||||
if (dxil_blob.allocated)
|
if (dxil_blob.allocated)
|
||||||
blob_finish(&dxil_blob);
|
blob_finish(&dxil_blob);
|
||||||
ralloc_free(nir);
|
ralloc_free(nir);
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,13 @@ struct dxil_spirv_debug_options {
|
||||||
bool dump_nir;
|
bool dump_nir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*dxil_spirv_msg_callback)(void *priv, const char *msg);
|
||||||
|
|
||||||
|
struct dxil_spirv_logger {
|
||||||
|
void *priv;
|
||||||
|
dxil_spirv_msg_callback log;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile a SPIR-V module into DXIL.
|
* Compile a SPIR-V module into DXIL.
|
||||||
* \param words SPIR-V module to compile
|
* \param words SPIR-V module to compile
|
||||||
|
|
@ -182,6 +189,7 @@ spirv_to_dxil(const uint32_t *words, size_t word_count,
|
||||||
const char *entry_point_name,
|
const char *entry_point_name,
|
||||||
const struct dxil_spirv_debug_options *debug_options,
|
const struct dxil_spirv_debug_options *debug_options,
|
||||||
const struct dxil_spirv_runtime_conf *conf,
|
const struct dxil_spirv_runtime_conf *conf,
|
||||||
|
const struct dxil_spirv_logger *logger,
|
||||||
struct dxil_spirv_object *out_dxil);
|
struct dxil_spirv_object *out_dxil);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ dzn_meta_compile_shader(struct dzn_device *device, nir_shader *nir,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct blob dxil_blob;
|
struct blob dxil_blob;
|
||||||
ASSERTED bool ret = nir_to_dxil(nir, &opts, &dxil_blob);
|
ASSERTED bool ret = nir_to_dxil(nir, &opts, NULL, &dxil_blob);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ dzn_pipeline_compile_shader(struct dzn_device *device,
|
||||||
if (instance->debug_flags & DZN_DEBUG_NIR)
|
if (instance->debug_flags & DZN_DEBUG_NIR)
|
||||||
nir_print_shader(nir, stderr);
|
nir_print_shader(nir, stderr);
|
||||||
|
|
||||||
if (nir_to_dxil(nir, &opts, &dxil_blob)) {
|
if (nir_to_dxil(nir, &opts, NULL, &dxil_blob)) {
|
||||||
blob_finish_get_buffer(&dxil_blob, (void **)&slot->pShaderBytecode,
|
blob_finish_get_buffer(&dxil_blob, (void **)&slot->pShaderBytecode,
|
||||||
(size_t *)&slot->BytecodeLength);
|
(size_t *)&slot->BytecodeLength);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue