39 Commits

Author SHA1 Message Date
Robin Voetter
979b410258
spirv: Do not generate the Alignment attribute on pointers for now
It seems that some implementations may have problems with these right now,
like Intel and Rusticl. In theory, these attributes should be superficial
on the pointer type, as alignment guarantees are also added via the
alignment option of the OpLoad and OpStore instructions. Therefore, get rid
of them for now.
2023-04-09 01:51:55 +02:00
Robin Voetter
fe0fb93fa0
spirv: deny global OpVariable in inline asm
This feature requires to be integrated with the mechanism that orders the
global variables, and that is not yet in place.
2023-04-09 01:51:54 +02:00
Robin Voetter
1de2d2ee1c
spirv: deny OpEntryPoint in asm
Kernels should be exported by marking the kernel using callconv(.Kernel) and
exporting it as a regular function.
2023-04-09 01:51:54 +02:00
Robin Voetter
3f2025f59e
spirv: emit interface variables for entry points
Also actually implement generating the OpEntryPoint instructions.
2023-04-09 01:51:54 +02:00
Robin Voetter
405f7298ac
spirv: add decl dependencies for functions also
Entry points need to be attributed with a complete list of
global variables that they use. To that end, the global dependencies
mechanism is extended to also allow functions - when flushing the
module, the list of dependencies is examined to generate this
list of global variable result-ids.
2023-04-09 01:51:53 +02:00
Robin Voetter
efe7fae6af
spirv: temporarily emit test kernels
SPIR-V cannot represent function pointers without extensions
that no vendor implements. For the time being, generate a test
kernel for each error, so that we can at least run SOME tests.

In the future we may be able to emulate function pointers in some
way, but that is not today.
2023-04-09 01:51:53 +02:00
Robin Voetter
8bbfbfc956
spirv: improve linking globals
SPIR-V globals must be emitted in order, so that any
declaration precedes usage. Zig, however, generates globals in
random order. To this end we keep for each global a list of
dependencies and perform a topological sort when flushing the
module.
2023-04-09 01:51:53 +02:00
Robin Voetter
80b8435569
spirv: overhaul constant lowering
Lowering constants is currently not really compatible with unions. In
this commit, constant lowering is drastically overhauled: instead of
playing nice and generating SPIR-V constant representations for everything
directly, we're just going to treat globals as an untyped bag of bytes (
or rather, SPIR-V 32-bit words), which we cast to the desired type at
usage. This is similar to how Rust generates constants in its LLVm backend.
2023-04-09 01:51:53 +02:00
Robin Voetter
3c7f93aa69
spirv: generic global pointers
Similar to function locals, taking the address of a global that does
not have an explicit address space assigned to it should result
in a generic pointer, not a global pointer. Also similar to function
locals, they cannot be generated into the generic storage class, and
so are generated into the global storage class and then cast to a
generic pointer, using OpSpecConstantOp. Note that using
OpSpecConstantOp results is only allowed by a hand full of other
OpSpecConstant instructions - which is why we generate constant
structs using OpSpecConstantComposite: These may use OpVariable
and OpSpecConstantOp results, while OpConstantComposite may not.
2023-04-09 01:51:52 +02:00
Robin Voetter
34b98ee372
spirv: start lowering non-function decls
Start to lower decls which are not functions. These generate
an OpVariable instruction by which they can be used later on.
2023-04-09 01:51:51 +02:00
Robin Voetter
2a8e784989
spirv: introduce type/value representations
There are two main ways in which a value can be stored: "Direct", as it
will be operated on as an immediate value, and "indirect", as it is stored
in memory. Some types need a different representation here: Bools, for
example, are opaque in SPIR-V, and so these need to have a different
representation in memory. The bool operations are not easily interchangable
with integer operations, though, so they need to be OpTypeBool as
immediate value.
2023-04-09 01:51:51 +02:00
Robin Voetter
8a00ec162c
spirv: more fixes and improvements
- Formatting.
- Improve `decorate` helper function to generate a decoration for a result-id.
- Reorder some functions in a more logical way
2023-04-09 01:51:51 +02:00
Robin Voetter
700dee34d5
spirv: make IdResultType and IdRef weak aliases of IdResult
Previously they were strong aliases, but as these types are used quite
intermittendly it resulted in a lot of toRef() calls. Removing them
improves readability a bit.
2023-04-09 01:51:51 +02:00
Robin Voetter
0c2526b18e
spirv: some fixes and improvements
- Adds the Int8. Int16, Int64 and GenericPointer capabilities.
  TODO: This should integrate with the feature system.
- Default some struct fields of SPIR-V types so that we dont
  need to type them all the time.
- Store struct field name's in SPIR-V types, and generate the
  OpMemberName decoration if they are non-null.
- Also add the field names to the actual SPIR-V types.
- Generate OpName for functions.
2023-04-09 01:51:50 +02:00
Robin Voetter
e443b1bed7
spirv: switch_br lowering
Implements lowering switch statements in the SPIR-V backend.
2023-04-09 01:51:50 +02:00
Robin Voetter
6146abee1e
spirv: add_with_overflow
Implements lowering for the add_with_overflow AIR instructions. Also implements
a helper function, simpleStructType, to quickly generate a SPIR-V structure type
without having to do the whole allocation dance.
2023-04-09 01:51:49 +02:00
Robin Voetter
3f92eaceb6
spirv: array, structs, bitcast, call
Implements type lowering for arrays and structs, and implements instruction
lowering for bitcast and call. Bitcast currently naively maps to the OpBitcast
instruction - this is only valid for some primitive types, and should be
improved to work with composites.
2023-04-09 01:51:49 +02:00
Robin Voetter
dae8b4c11f
spirv: emit OpName for some primitive types
OpName instructions assign a debug name to a type. Some basic
types - bool, void, ints, and floats are given a debug name this way.
TODO is to extend this to the other types.
2023-04-09 01:51:49 +02:00
Robin Voetter
3eafe3033e
spirv: improve storage efficiency for integer and float types
In practice there are only a few variations of these types allowed, so it
kind-of makes sense to write them all out. Because the types are hashed this
does not actually save all that many bytes in the long run, though. Perhaps
some of these types should be pre-registered?
2023-04-09 01:51:48 +02:00
Robin Voetter
5826a8a064
spirv: make Type.Ref stronger
Making Type.Ref an unbounded enum rather than a simple integer
ensures that we don't accidently confuse this token for another type.
2023-04-09 01:51:48 +02:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Robin Voetter
074ba69ba6
spirv: assembler
spirv: introduce SpvModule.Fn to generate function code into

spirv: assembler error message setup

spirv: runtime spec info

spirv: inline assembly tokenizer

spirv: inline assembly lhs result/opcode parsing

spirv: forgot to fmt

spirv: tokenize opcodes and assigned result-ids

spirv: operand parsing setup

spirv: assembler string literals

spirv: assembler integer literals

spirv: assembler value enums

spirv: assembler bit masks

spirv: update assembler to new asm air format

spirv: target 1.5 for now

Current vulkan sdk version (1.3.204) ships spirv tools targetting 1.5,
and so these do not work with binaries targetting 1.6 yet. In the
future, this version number should be decided by the target.

spirv: store operands in flat arraylist.

Instead of having dedicated Operand variants for variadic operands,
just flatten them and store them in the normal inst.operands list.
This is a little simpler, but is not easily decodable in the operand
data representation.

spirv: parse variadic assembly operands

spirv: improve assembler result-id tokenization

spirv: begin instruction processing

spirv: only remove decl if it was actually allocated

spirv: work around weird miscompilation

Seems like there are problems with switch in anonymous struct literals.

spirv: begin resolving some types in assembler

spirv: improve instruction processing

spirv: rename some types + process OpTypeInt

spirv: process OpTypeVector

spirv: process OpTypeMatrix and OpTypeSampler

spirv: add opcode class to spec, remove @exclude'd instructions

spirv: process more type instructions

spirv: OpTypeFunction

spirv: OpTypeOpaque

spirv: parse LiteralContextDependentNumber operands

spirv: emit assembly instruction into right section

spirv: parse OpPhi parameters

spirv: inline assembly inputs

spirv: also copy air types

spirv: inline assembly outputs

spirv: spir-v address spaces

spirv: basic vector constants/types and shuffle

spirv: assembler OpTypeImage

spirv: some stuff

spirv: remove spirv address spaces for now
2022-11-23 19:17:58 +01:00
Stevie Hryciw
04f3067a79 run zig fmt on everything checked by CI 2022-11-18 19:22:42 +00:00
Andrew Kelley
ecb4293afe stage2: disable unit tests when building with stage1
They trip LLVM assertions and spirv is not needed to bootstrap. Not
important for these tests to pass with stage1.
2022-07-04 16:20:33 -07:00
Isaac Freund
6f4343b61a std: replace usage of std.meta.bitCount() with @bitSizeOf() 2022-04-27 11:10:52 +02:00
Veikka Tuominen
cbd5d6c704 spirv spec: do not align packed struct fields 2022-02-24 19:48:34 +02:00
Andrew Kelley
39983d7ff5 stage2: update to new ArrayHashMap API 2022-01-31 21:12:37 -07:00
Robin Voetter
98ee39d1b0 spirv: spir-v dedicated type system 2022-01-28 14:45:23 +01:00
Robin Voetter
1b6ebce0da spirv: new module
This introduces a dedicated struct that handles module-wide information.
2022-01-28 14:38:58 +01:00
Robin Voetter
72e67aaf05 spirv: model spir-v section as separate type
The idea is that this type gains the relevant low-level instruction emitting
functions, and that higher-level checks and deduplications are performed
somewhere else.
2022-01-28 14:38:57 +01:00
Robin Voetter
94dd763936 spirv: regenerate spec
Regenerate the specification with the improvements previously made to the
spirv spec generator.
2022-01-28 14:38:57 +01:00
Andrew Kelley
e41e75a486 stage2: update for new usingnamespace semantics 2021-09-01 17:54:07 -07:00
Veikka Tuominen
e63ff4f1c1 add ast-check flag to zig fmt, fix found bugs 2021-06-14 00:16:40 +03:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
Robin Voetter
42f2ff6ec9 SPIR-V: Re-generate spec.zig 2021-05-14 19:49:32 +02:00
Andrew Kelley
bcfebb4b2b stage2: improvements aimed at std lib integration
* AstGen: emit decl lookup ZIR instructions rather than directly
   looking up decls in AstGen. This is necessary because we want to
   reuse the same immutable ZIR code for multiple generic instantiations
   (and comptime function calls).
 * AstGen: fix using members_len instead of fields_len for struct decls.
 * structs: the struct_decl ZIR instruction is now also a block. This is
   so that the type expressions, default field value expressions, and
   alignment expressions can be evaluated in a scope that contains the
   decls from the struct namespace itself.
 * Add "std" and "builtin" packages to the builtin package.
 * Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`.
 * builtin.zig is generated without `usingnamespace`.
 * builtin.zig takes advantage of `std.zig.fmtId` for CPU features.
 * A first pass at implementing `usingnamespace`. It's problematic and
   should either be deleted, or polished, before merging this branch.
 * Sema: allow explicitly specifying the namespace in which to look up
   Decls. This is used by `struct_decl` in order to put the decls from
   the struct namespace itself in scope when evaluating the type
   expressions, default value expressions, and alignment expressions.
 * Module: fix `analyzeNamespace` assuming that it is the top-level root
   declaration node.
 * Sema: implement comptime and runtime cmp operator.
 * Sema: implement peer type resolution for enums and enum literals.
 * Pull in the changes from master branch:
   262e09c482d98a78531c049a18b7f24146fe157f.
 * ZIR: complete out simple_ptr_type debug printing
2021-04-15 19:06:39 -07:00
Robin Voetter
9a6babf482 SPIR-V: Add generated specification 2021-01-19 15:28:17 +01:00