mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 13:11:00 +00:00
[qfcc] Emit extensions and extinst imports
The imports need their result id recorded somewhere (and the hard-coding in qc-parse.y removed), but that's a little bit of progress getting spir-v working.
This commit is contained in:
parent
e09f97685f
commit
2c445380b1
3 changed files with 54 additions and 4 deletions
|
@ -57,6 +57,8 @@ typedef struct module_s {
|
|||
} module_t;
|
||||
|
||||
void spirv_add_capability (module_t *module, SpvCapability capability);
|
||||
void spirv_add_extension (module_t *module, const char *extension);
|
||||
void spirv_add_extinst_import (module_t *module, const char *import);
|
||||
void spirv_set_addressing_model (module_t *module, SpvAddressingModel model);
|
||||
void spirv_set_memory_model (module_t *module, SpvMemoryModel model);
|
||||
bool spirv_write (struct pr_info_s *pr, const char *filename);
|
||||
|
|
|
@ -3096,6 +3096,9 @@ rua_init (void)
|
|||
pr.module = &module;
|
||||
|
||||
spirv_add_capability (pr.module, SpvCapabilityShader);
|
||||
//FIXME unhardcode
|
||||
spirv_add_extension (pr.module, "SPV_KHR_multiview");
|
||||
spirv_add_extinst_import (pr.module, "GLSL.std.450");
|
||||
//FIXME sufficient? phys 32/storage?
|
||||
spirv_set_addressing_model (pr.module, SpvAddressingModelLogical);
|
||||
//FIXME look into Vulkan, or even configurable
|
||||
|
|
|
@ -64,6 +64,18 @@ spirv_new_insn (int op, int size, defspace_t *space)
|
|||
return def;
|
||||
}
|
||||
|
||||
static def_t *
|
||||
spirv_str_insn (int op, int offs, int extra, const char *str, defspace_t *space)
|
||||
{
|
||||
int len = strlen (str) + 1;
|
||||
int str_size = RUP(len, 4) / 4;
|
||||
int size = offs + str_size + extra;
|
||||
auto def = spirv_new_insn (op, size, space);
|
||||
D_var_o(int, def, str_size - 1) = 0;
|
||||
memcpy (&D_var_o(int, def, offs), str, len);
|
||||
return def;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
spirv_id (spirvctx_t *ctx)
|
||||
{
|
||||
|
@ -77,6 +89,21 @@ spirv_Capability (SpvCapability capability, defspace_t *space)
|
|||
D_var_o(int, def, 1) = capability;
|
||||
}
|
||||
|
||||
static void
|
||||
spirv_Extension (const char *ext, defspace_t *space)
|
||||
{
|
||||
spirv_str_insn (SpvOpExtension, 1, 0, ext, space);
|
||||
}
|
||||
|
||||
static unsigned
|
||||
spirv_ExtInstImport (const char *imp, spirvctx_t *ctx)
|
||||
{
|
||||
auto def = spirv_str_insn (SpvOpExtInstImport, 2, 0, imp, ctx->space);
|
||||
int id = spirv_id (ctx);
|
||||
D_var_o(int, def, 1) = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
static void
|
||||
spirv_MemoryModel (SpvAddressingModel addressing, SpvMemoryModel memory,
|
||||
defspace_t *space)
|
||||
|
@ -89,11 +116,9 @@ spirv_MemoryModel (SpvAddressingModel addressing, SpvMemoryModel memory,
|
|||
static unsigned
|
||||
spirv_String (const char *name, spirvctx_t *ctx)
|
||||
{
|
||||
auto def = spirv_str_insn (SpvOpString, 2, 0, name, ctx->strings);
|
||||
int id = spirv_id (ctx);
|
||||
int len = strlen (name) + 1;
|
||||
auto def = spirv_new_insn (SpvOpString, 2 + RUP(len, 4) / 4, ctx->strings);
|
||||
D_var_o(int, def, 1) = id;
|
||||
memcpy (&D_var_o(int, def, 2), name, len);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -410,8 +435,14 @@ spirv_write (struct pr_info_s *pr, const char *filename)
|
|||
for (auto cap = pr->module->capabilities.head; cap; cap = cap->next) {
|
||||
spirv_Capability (expr_uint (cap->expr), ctx.space);
|
||||
}
|
||||
for (auto ext = pr->module->extensions.head; ext; ext = ext->next) {
|
||||
spirv_Extension (expr_string (ext->expr), ctx.space);
|
||||
}
|
||||
for (auto imp = pr->module->extinst_imports.head; imp; imp = imp->next) {
|
||||
//FIXME need to store id where it can be used for instructions
|
||||
spirv_ExtInstImport (expr_string (imp->expr), &ctx);
|
||||
}
|
||||
|
||||
//FIXME none of these should be hard-coded
|
||||
spirv_MemoryModel (expr_uint (pr->module->addressing_model),
|
||||
expr_uint (pr->module->memory_model), ctx.space);
|
||||
|
||||
|
@ -450,6 +481,20 @@ spirv_add_capability (module_t *module, SpvCapability capability)
|
|||
list_append (&module->capabilities, cap);
|
||||
}
|
||||
|
||||
void
|
||||
spirv_add_extension (module_t *module, const char *extension)
|
||||
{
|
||||
auto ext = new_string_expr (extension);
|
||||
list_append (&module->extensions, ext);
|
||||
}
|
||||
|
||||
void
|
||||
spirv_add_extinst_import (module_t *module, const char *import)
|
||||
{
|
||||
auto imp = new_string_expr (import);
|
||||
list_append (&module->extinst_imports, imp);
|
||||
}
|
||||
|
||||
void
|
||||
spirv_set_addressing_model (module_t *module, SpvAddressingModel model)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue