Path: blob/21.2-virgl/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
4574 views
/*1* Copyright 2018 Collabora Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef SPIRV_BUILDER_H24#define SPIRV_BUILDER_H2526#include "compiler/spirv/spirv.h"27#include "compiler/spirv/GLSL.std.450.h"2829#include <stdbool.h>30#include <stdint.h>31#include <stdlib.h>3233struct hash_table;34struct set;3536struct spirv_buffer {37uint32_t *words;38size_t num_words, room;39};4041struct spirv_builder {42void *mem_ctx;4344struct set *caps;4546struct spirv_buffer extensions;47struct spirv_buffer imports;48struct spirv_buffer memory_model;49struct spirv_buffer entry_points;50struct spirv_buffer exec_modes;51struct spirv_buffer debug_names;52struct spirv_buffer decorations;5354struct spirv_buffer types_const_defs;55struct hash_table *types;56struct hash_table *consts;5758struct spirv_buffer instructions;59SpvId prev_id;60};6162static inline SpvId63spirv_builder_new_id(struct spirv_builder *b)64{65return ++b->prev_id;66}6768void69spirv_builder_emit_cap(struct spirv_builder *b, SpvCapability cap);7071void72spirv_builder_emit_extension(struct spirv_builder *b, const char *ext);7374void75spirv_builder_emit_source(struct spirv_builder *b, SpvSourceLanguage lang,76uint32_t version);7778void79spirv_builder_emit_mem_model(struct spirv_builder *b,80SpvAddressingModel addr_model,81SpvMemoryModel mem_model);8283void84spirv_builder_emit_name(struct spirv_builder *b, SpvId target,85const char *name);8687void88spirv_builder_emit_decoration(struct spirv_builder *b, SpvId target,89SpvDecoration decoration);9091void92spirv_builder_emit_specid(struct spirv_builder *b, SpvId target, uint32_t id);9394void95spirv_builder_emit_location(struct spirv_builder *b, SpvId target,96uint32_t location);9798void99spirv_builder_emit_component(struct spirv_builder *b, SpvId target,100uint32_t component);101102void103spirv_builder_emit_builtin(struct spirv_builder *b, SpvId target,104SpvBuiltIn builtin);105106void107spirv_builder_emit_index(struct spirv_builder *b, SpvId target, int index);108109void110spirv_builder_emit_stream(struct spirv_builder *b, SpvId target, int stream);111112void113spirv_builder_emit_descriptor_set(struct spirv_builder *b, SpvId target,114uint32_t descriptor_set);115116void117spirv_builder_emit_binding(struct spirv_builder *b, SpvId target,118uint32_t binding);119120void121spirv_builder_emit_array_stride(struct spirv_builder *b, SpvId target,122uint32_t stride);123124void125spirv_builder_emit_offset(struct spirv_builder *b, SpvId target,126uint32_t offset);127128void129spirv_builder_emit_xfb_buffer(struct spirv_builder *b, SpvId target,130uint32_t buffer);131132void133spirv_builder_emit_xfb_stride(struct spirv_builder *b, SpvId target,134uint32_t stride);135136void137spirv_builder_emit_member_offset(struct spirv_builder *b, SpvId target,138uint32_t member, uint32_t offset);139140void141spirv_builder_emit_entry_point(struct spirv_builder *b,142SpvExecutionModel exec_model, SpvId entry_point,143const char *name, const SpvId interfaces[],144size_t num_interfaces);145void146spirv_builder_emit_exec_mode_literal(struct spirv_builder *b, SpvId entry_point,147SpvExecutionMode exec_mode, uint32_t param);148void149spirv_builder_emit_exec_mode_literal3(struct spirv_builder *b, SpvId entry_point,150SpvExecutionMode exec_mode, uint32_t param[3]);151void152spirv_builder_emit_exec_mode(struct spirv_builder *b, SpvId entry_point,153SpvExecutionMode exec_mode);154155void156spirv_builder_function(struct spirv_builder *b, SpvId result,157SpvId return_type,158SpvFunctionControlMask function_control,159SpvId function_type);160161void162spirv_builder_function_end(struct spirv_builder *b);163164void165spirv_builder_label(struct spirv_builder *b, SpvId label);166167void168spirv_builder_return(struct spirv_builder *b);169170SpvId171spirv_builder_emit_undef(struct spirv_builder *b, SpvId result_type);172173SpvId174spirv_builder_emit_load(struct spirv_builder *b, SpvId result_type,175SpvId pointer);176177void178spirv_builder_emit_atomic_store(struct spirv_builder *b, SpvId pointer, SpvScope scope,179SpvMemorySemanticsMask semantics, SpvId object);180181void182spirv_builder_emit_store(struct spirv_builder *b, SpvId pointer, SpvId object);183184SpvId185spirv_builder_emit_access_chain(struct spirv_builder *b, SpvId result_type,186SpvId base, const SpvId indexes[],187size_t num_indexes);188189void190spirv_builder_emit_interlock(struct spirv_builder *b, bool end);191192SpvId193spirv_builder_emit_unop_const(struct spirv_builder *b, SpvOp op, SpvId result_type, uint64_t operand);194195SpvId196spirv_builder_emit_unop(struct spirv_builder *b, SpvOp op, SpvId result_type,197SpvId operand);198199SpvId200spirv_builder_emit_binop(struct spirv_builder *b, SpvOp op, SpvId result_type,201SpvId operand0, SpvId operand1);202203SpvId204spirv_builder_emit_triop(struct spirv_builder *b, SpvOp op, SpvId result_type,205SpvId operand0, SpvId operand1, SpvId operand2);206207SpvId208spirv_builder_emit_quadop(struct spirv_builder *b, SpvOp op, SpvId result_type,209SpvId operand0, SpvId operand1, SpvId operand2, SpvId operand3);210211SpvId212spirv_builder_emit_hexop(struct spirv_builder *b, SpvOp op, SpvId result_type,213SpvId operand0, SpvId operand1, SpvId operand2, SpvId operand3,214SpvId operand4, SpvId operand5);215216SpvId217spirv_builder_emit_composite_extract(struct spirv_builder *b, SpvId result_type,218SpvId composite, const uint32_t indexes[],219size_t num_indexes);220221SpvId222spirv_builder_emit_composite_construct(struct spirv_builder *b,223SpvId result_type,224const SpvId constituents[],225size_t num_constituents);226227SpvId228spirv_builder_emit_vector_shuffle(struct spirv_builder *b, SpvId result_type,229SpvId vector_1, SpvId vector_2,230const uint32_t components[],231size_t num_components);232SpvId233spirv_builder_emit_vector_extract(struct spirv_builder *b, SpvId result_type,234SpvId vector_1,235uint32_t component);236SpvId237spirv_builder_emit_vector_insert(struct spirv_builder *b, SpvId result_type,238SpvId vector_1,239SpvId component,240uint32_t index);241void242spirv_builder_emit_branch(struct spirv_builder *b, SpvId label);243244void245spirv_builder_emit_selection_merge(struct spirv_builder *b, SpvId merge_block,246SpvSelectionControlMask selection_control);247248void249spirv_builder_loop_merge(struct spirv_builder *b, SpvId merge_block,250SpvId cont_target, SpvLoopControlMask loop_control);251252void253spirv_builder_emit_branch_conditional(struct spirv_builder *b, SpvId condition,254SpvId true_label, SpvId false_label);255256SpvId257spirv_builder_emit_phi(struct spirv_builder *b, SpvId result_type,258size_t num_vars, size_t *position);259260void261spirv_builder_set_phi_operand(struct spirv_builder *b, size_t position,262size_t index, SpvId variable, SpvId parent);263264void265spirv_builder_emit_kill(struct spirv_builder *b);266267SpvId268spirv_builder_emit_vote(struct spirv_builder *b, SpvOp op, SpvId src);269270SpvId271spirv_builder_emit_image_sample(struct spirv_builder *b,272SpvId result_type,273SpvId sampled_image,274SpvId coordinate,275bool proj,276SpvId lod,277SpvId bias,278SpvId dref,279SpvId dx,280SpvId dy,281SpvId const_offset,282SpvId offset);283284SpvId285spirv_builder_emit_image(struct spirv_builder *b, SpvId result_type,286SpvId sampled_image);287288SpvId289spirv_builder_emit_image_texel_pointer(struct spirv_builder *b,290SpvId result_type,291SpvId image,292SpvId coordinate,293SpvId sample);294295SpvId296spirv_builder_emit_image_read(struct spirv_builder *b,297SpvId result_type,298SpvId image,299SpvId coordinate,300SpvId lod,301SpvId sample,302SpvId offset);303304void305spirv_builder_emit_image_write(struct spirv_builder *b,306SpvId image,307SpvId coordinate,308SpvId texel,309SpvId lod,310SpvId sample,311SpvId offset);312313SpvId314spirv_builder_emit_image_fetch(struct spirv_builder *b,315SpvId result_type,316SpvId image,317SpvId coordinate,318SpvId lod,319SpvId sample,320SpvId const_offset,321SpvId offset);322SpvId323spirv_builder_emit_image_gather(struct spirv_builder *b,324SpvId result_type,325SpvId image,326SpvId coordinate,327SpvId component,328SpvId lod,329SpvId sample,330SpvId const_offset,331SpvId offset,332SpvId dref);333334SpvId335spirv_builder_emit_image_query_size(struct spirv_builder *b,336SpvId result_type,337SpvId image,338SpvId lod);339340SpvId341spirv_builder_emit_image_query_levels(struct spirv_builder *b,342SpvId result_type,343SpvId image);344345SpvId346spirv_builder_emit_image_query_lod(struct spirv_builder *b,347SpvId result_type,348SpvId image,349SpvId coords);350351SpvId352spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,353SpvId set, uint32_t instruction,354const SpvId args[], size_t num_args);355356SpvId357spirv_builder_type_void(struct spirv_builder *b);358359SpvId360spirv_builder_type_bool(struct spirv_builder *b);361362SpvId363spirv_builder_type_int(struct spirv_builder *b, unsigned width);364365SpvId366spirv_builder_type_uint(struct spirv_builder *b, unsigned width);367368SpvId369spirv_builder_type_float(struct spirv_builder *b, unsigned width);370371SpvId372spirv_builder_type_image(struct spirv_builder *b, SpvId sampled_type,373SpvDim dim, bool depth, bool arrayed, bool ms,374unsigned sampled, SpvImageFormat image_format);375376SpvId377spirv_builder_type_sampled_image(struct spirv_builder *b, SpvId image_type);378379SpvId380spirv_builder_type_pointer(struct spirv_builder *b,381SpvStorageClass storage_class, SpvId type);382383SpvId384spirv_builder_type_vector(struct spirv_builder *b, SpvId component_type,385unsigned component_count);386387SpvId388spirv_builder_type_matrix(struct spirv_builder *b, SpvId component_type,389unsigned component_count);390391SpvId392spirv_builder_type_runtime_array(struct spirv_builder *b, SpvId component_type);393394SpvId395spirv_builder_type_array(struct spirv_builder *b, SpvId component_type,396SpvId length);397398SpvId399spirv_builder_type_struct(struct spirv_builder *b, const SpvId member_types[],400size_t num_member_types);401402SpvId403spirv_builder_type_function(struct spirv_builder *b, SpvId return_type,404const SpvId parameter_types[],405size_t num_parameter_types);406407SpvId408spirv_builder_const_bool(struct spirv_builder *b, bool val);409410SpvId411spirv_builder_const_int(struct spirv_builder *b, int width, int64_t val);412413SpvId414spirv_builder_const_uint(struct spirv_builder *b, int width, uint64_t val);415416SpvId417spirv_builder_spec_const_uint(struct spirv_builder *b, int width);418419SpvId420spirv_builder_const_float(struct spirv_builder *b, int width, double val);421422SpvId423spirv_builder_const_composite(struct spirv_builder *b, SpvId result_type,424const SpvId constituents[],425size_t num_constituents);426427SpvId428spirv_builder_spec_const_composite(struct spirv_builder *b, SpvId result_type,429const SpvId constituents[],430size_t num_constituents);431432SpvId433spirv_builder_emit_var(struct spirv_builder *b, SpvId type,434SpvStorageClass storage_class);435436void437spirv_builder_emit_memory_barrier(struct spirv_builder *b, SpvScope scope, SpvMemorySemanticsMask semantics);438439void440spirv_builder_emit_control_barrier(struct spirv_builder *b, SpvScope scope, SpvScope mem_scope, SpvMemorySemanticsMask semantics);441442SpvId443spirv_builder_import(struct spirv_builder *b, const char *name);444445size_t446spirv_builder_get_num_words(struct spirv_builder *b);447448size_t449spirv_builder_get_words(struct spirv_builder *b, uint32_t *words,450size_t num_words, uint32_t spirv_version);451452void453spirv_builder_emit_vertex(struct spirv_builder *b, uint32_t stream);454void455spirv_builder_end_primitive(struct spirv_builder *b, uint32_t stream);456#endif457458459