Commit Graph

53 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
fe5a0aa72f
Merge pull request #1839 from KhronosGroup/spv1.6
Add sanity test for SPIR-V 1.6 modules.
2022-01-06 15:51:11 +01:00
Hans-Kristian Arntzen
7c12228359 Add sanity test for SPIR-V 1.6 modules.
Just verify that we don't blow up on these modules.
2022-01-06 14:16:28 +01:00
Hans-Kristian Arntzen
7c83fc22fa Add support for LocalSizeId.
WorkgroupSize builtin is deprecated in 1.6 and LocalSizeId is supported
in Vulkan starting with maintenance4.
2022-01-06 13:57:10 +01:00
Sebastián Aedo
6d8302ef14 MSL: Add 64 bit switch support
Add 64 bit switch support for MSL version 2.2.

* Also fixes a wrong endianness conversion.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-26 15:54:56 -03:00
Hans-Kristian Arntzen
37dfb3f45f
Merge pull request #1794 from etra0/master
Add 64 bit support for OpSwitch
2021-11-15 15:05:10 +01:00
Sebastián Aedo
5345051a85 Removed tracking of OpConstant and OpPhi.
We don't need to keep track of them because when the block.condition is
either a SPIRConstant or a SPIRVariable, we can get the type directly in
the get_case_list.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-13 14:13:30 -03:00
Sebastián Aedo
75e3752273 Added block.cases_32bit and reworked the cases fix
Now we added block.cases_32bit as requested and we only parse if the
remaining ops are a multiple of 2. None of them are mutable because we
return a reference of them depending of the op.condition width.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-12 12:50:39 -03:00
Sebastián Aedo
48046646ee Fixed wrong condition and formatting.
Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-08 15:21:19 -03:00
Hans-Kristian Arntzen
2714f5410c CFG: Handle degenerate selection constructs.
Apparently, it's legal to use a selection construct where both paths
branch to same location, but a different merge point is used.
This breaks many assumptions the variable scope analyzer makes.

The only logical way to generate code for this scenario is to treat the
selection construct as a trivial switch construct with only a default
case.
2021-11-07 13:32:29 +01:00
Sebastián Aedo
250a02967d Removed unnecessary tracking of types.
We don't need to keep track of the type itself, only its width since the
type check of the OpSwitch can be done at runtime. This also avoids
creating a dangling reference.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-03 16:12:14 -03:00
Sebastián Aedo
f099d714f3 Removing logic in the parser
Moving out the logic from the parser as requested because it's sensitive
to try to keep the parsing the most simple process as said.

For that, the load_types is now tracked in the ParsedIR, which can be
accessed in the Compiler struct. The switch cases are fixed in the CFG
stage since that's the point where the nullptr is deref.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-11-02 17:17:13 -03:00
Sebastián Aedo
3eb5532979 Add 64 bit support for OpSwitch
According to the spec, if the `condition` has a type wider than 32 bits,
the literals to be compared with will be of that size as well.

This caused some misalignments if the `condition` was bigger than 32,
causing a nullptr return without further explanation.

Currently neither GLSL nor MSL supports uint64 as the condition but the
SPIRV allows it anyway.

This also fixes #1768.

Signed-off-by: Sebastián Aedo <saedo@codeweavers.com>
2021-10-29 11:02:16 -03:00
Jon Leech
f2a65545b8 Finish adding SPDX tags and setup a reuse checked in Github Actions CI 2021-06-29 11:03:52 +02:00
Hans-Kristian Arntzen
bc4cb1b3c5 Throw if SPIR-V module has no entry points. 2021-03-08 10:40:19 +01:00
Hans-Kristian Arntzen
4704482bbc meta: Update copyright headers to 2021. 2021-01-14 16:07:49 +01:00
Hans-Kristian Arntzen
2097c30985 GLSL: Support both SPV_KHR_ray_tracing and NV_ray_tracing.
Fairly minor differences, so can keep them side by side without too much
effort. NV support is effectively deprecated now however.

- Add OpConvertUToAccelerationStructureKHR
- Ignore/Terminate ray is now a terminator in KHR, but a call in NV.
- Fix some bugs with reportIntersection.
2021-01-08 14:59:04 +01:00
Hans-Kristian Arntzen
1a28a04333 GLSL: Update SPIR-V headers for modified ray tracing opcodes. 2021-01-06 11:38:27 +01:00
Hans-Kristian Arntzen
cf1e9e0643 Add MIT dual license for the SPIRV-Cross API. 2020-12-01 16:47:08 +01:00
Hans-Kristian Arntzen
1f018b0fb8 Parser: Don't assume OpTypePointer will always take a SPIRType.
Possible to receive a function prototype here. Don't try to do anything
smart here, just don't crash during parsing.
2020-11-03 10:53:37 +01:00
Hans-Kristian Arntzen
58dad82fcb Handle physical pointers in reflection API. 2020-05-25 13:45:49 +02:00
Hans-Kristian Arntzen
6b0e558169 Handle RayQueryKHR type.
Do not error out in parsing in shaders which use ray queries.
2020-04-21 14:25:18 +02:00
Hans-Kristian Arntzen
b8905bbd95 Add support for forcefully zero-initialized variables.
Useful to better support certain platforms which require all variables
to be initialized to something.
2020-03-26 13:38:27 +01:00
Hans-Kristian Arntzen
3ebc83da46 Remove old hack which forces NonWritable/NonReadable.
Somehow this has been lingering in the code base and effectively ignores
readonly/writeonly decoration declared by the shader.
2020-03-04 16:42:31 +01:00
Hans-Kristian Arntzen
92a4294c57 Reject SPIR-V modules with garbage ID bound.
SPIR-V spec has a limit of ~4 million, and Vulkan spec does not increase
this bound, so be a bit defensive and fail early.
2020-02-14 12:57:01 +01:00
Hans-Kristian Arntzen
f9818f0804 Update license headers to 2020. 2020-01-16 15:24:37 +01:00
Hans-Kristian Arntzen
02c34fe575 Update SPIR-V headers. 2019-09-19 10:26:04 +02:00
Hans-Kristian Arntzen
333980ae91 Refactor into stronger types in public API.
Some fallout where internal functions are using stronger types.
Overkill to move everything over to strong types right now, but perhaps
move over to it slowly over time.
2019-09-06 12:29:47 +02:00
lifpan
b11c20fc1d Remove unreasonable assertion for OpTypeImage Sampled parameter. 2019-07-11 19:39:44 +08:00
Hans-Kristian Arntzen
13378ad1ac Add simple test for extended debug operations. 2019-07-05 10:44:30 +02:00
Lifeng Pan
5ca8779044 Parse SPIR-V debug information extended instructions, as well as OpNoLine.
No impact on result shader string.
2019-07-04 16:21:44 +08:00
Hans-Kristian Arntzen
48a7da4f4d Fixup OpLine parsing comments. 2019-05-28 15:51:42 +02:00
Hans-Kristian Arntzen
65af09d2d1 Support emitting OpLine directive.
Facilitates easier mapping from source language to cross-compiled output
in tooling.
2019-05-28 13:44:24 +02:00
Hans-Kristian Arntzen
ab1fa9011f Accept SPIR-V 1.4 version. 2019-05-07 09:53:40 +02:00
Hans-Kristian Arntzen
2cc374a0c8 GLSL: Implement GL_EXT_buffer_reference.
Buffer objects can contain arbitrary pointers to blocks.
We can also implement ConvertPtrToU and ConvertUToPtr.
The latter can cast a uint64_t to any type as it pleases,
so we will need to generate fake buffer reference blocks to be able to
cast the type.
2019-04-26 11:43:51 +02:00
Hans-Kristian Arntzen
3fe57d3798 Do not use SmallVector as input type in public interfaces.
This is an API break, which we need to be careful with.
Handing out SmallVectors is easier since the interface is basically the
same.
2019-04-09 15:09:44 +02:00
Hans-Kristian Arntzen
a489ba7fd1 Reduce pressure on global allocation.
- Replace ostringstream with custom implementation.
  ~30% performance uplift on vector-shuffle-oom test.
  Allocations are measurably reduced in Valgrind.

- Replace std::vector with SmallVector.
  Classic malloc optimization, small vectors are backed by inline data.
  ~ 7-8% gain on vector-shuffle-oom on GCC 8 on Linux.

- Use an object pool for IVariant type.
  We generally allocate a lot of SPIR* objects. We can amortize these
  allocations neatly by pooling them.

- ~15% overall uplift on ./test_shaders.py --iterations 10000 shaders/.
2019-04-09 15:09:44 +02:00
lifpan
876627df3b Add OpUndef instruction to block's instruction list for completeness. 2019-04-08 19:45:31 +08:00
Hans-Kristian Arntzen
9b92e68d71 Add an option to override the namespace used for spirv_cross.
This is a pragmatic trick to avoid symbol collision where a project
links against SPIRV-Cross statically, while linking to other projects
which also use SPIRV-Cross statically. We can end up with very awkward
symbol collisions which can resolve themselves silently because
SPIRV-Cross is pulled in as necessary. To fix this, we must use
different symbols and embed two copies of SPIRV-Cross in this scenario,
now with different namespaces, which in turn leads to different symbols.
2019-03-29 10:29:44 +01:00
Hans-Kristian Arntzen
df3e21a762 Parser: Fix OpCompositeConstruct with OpUndef.
Just treat any undefined argument as 0. It is risky to use the undefined
variable as it might not lower to a true constant.
2019-03-27 10:51:23 +01:00
Patrick Mours
b2651d01e5 Merge branch master into SPV_NV_ray_tracing 2019-03-25 14:09:15 +01:00
Hans-Kristian Arntzen
45baf24a17 Move check for structured OpSwitch to CompilerGLSL.
Can still parse correctly.
2019-03-20 10:42:38 +01:00
Patrick Mours
da39a7b02f Add support for SPV_NV_ray_tracing 2019-02-26 15:43:03 +01:00
Hans-Kristian Arntzen
2ed171e525 GLSL/MSL: Implement 8-bit part of VK_KHR_shader_float16_int8.
Storage was in place already, so mostly just dealing with bitcasts and
constants.

Simplies some of the bitcasting logic, and this exposed some bugs in the
implementation. Refactor to use correct width integers with explicit bitcast opcodes.
2019-01-30 15:45:24 +01:00
Hans-Kristian Arntzen
b629878f45 Make meta a hashmap.
A flat array was consuming way too much memory and was far too slow to
initialize properly with a very large ID bound (8 million IDs, showed up as #1 hotspot in perf).

Meta struct does not have to be in-order as we never iterate over it in
a meaningful way, so using a hashmap here is reasonable. Very few IDs
should need decorations or meta-data, so this should also be a quite
decent memory save.

For the pathological case, a 6x uplift was observed.
2019-01-10 14:04:01 +01:00
Chip Davis
3bfb2f94d4 MSL: Support SPV_KHR_variable_pointers.
This allows shaders to declare and use pointer-type variables. Pointers
may be loaded and stored, be the result of an `OpSelect`, be passed to
and returned from functions, and even be passed as inputs to the `OpPhi`
instruction. All types of pointers may be used as variable pointers.
Variable pointers to storage buffers and workgroup memory may even be
loaded from and stored to, as though they were ordinary variables. In
addition, this enables using an interior pointer to an array as though
it were an array pointer itself using the `OpPtrAccessChain`
instruction.

This is a rather large and involved change, mostly because this is
somewhat complicated with a lot of moving parts. It's a wonder
SPIRV-Cross's output is largely unchanged. Indeed, many of these changes
are to accomplish exactly that! Perhaps the largest source of changes
was the violation of the assumption that, when emitting types, the
pointer type didn't matter.

One of the test cases added by the change doesn't optimize very well;
the output of `spirv-opt` here is invalid SPIR-V. I need to file a bug
with SPIRV-Tools about this.

I wanted to test that variable pointers to images worked too, but I
couldn't figure out how to propagate the access qualifier properly--in
MSL, it's part of the type, so getting this right is important. I've
punted on that for now.
2019-01-07 11:19:10 -06:00
Hans-Kristian Arntzen
318c17cbb2 Nonfunctional: Update copyright headers for 2019. 2019-01-04 12:38:35 +01:00
lifpan
b21525bcce Fix build warning. 2018-11-28 14:20:24 +08:00
Hans-Kristian Arntzen
d0b937206f Keep track of pointer-to-pointer depth in parser.
Defer failure of pointer-to-pointer to compilation time, so we can still
reflect VK_KHR_variable_pointer shaders.
2018-11-26 12:23:28 +01:00
Hans-Kristian Arntzen
fa42ed37ba Parser: Handle group decorations. 2018-11-15 10:51:52 +01:00
lifpan
00a765eccf Handle opcode OpSourceContinued. 2018-11-15 09:04:36 +08:00