Commit Graph

226 Commits

Author SHA1 Message Date
Jan Sikorski
44a5f1fc3e MSL: Add support for overlapping bindings.
This adds support for bindings which share the same DescriptorSet/Binding pair.

The motivating example is vkd3d, which uses overlapping arrays of resources to
emulate D3D12 descriptor tables. The generated MSL argument buffer only
includes the first resource (in this example 't0'):

struct spvDescriptorSetBuffer2
{
    array<texture2d<float>, 499968> t0 [[id(0)]];
    // Overlapping binding: array<texture3d<float>, 499968> t2 [[id(0)]];
};

When t2 is referenced, we cast the instantiated member:

float4 r1 = spvDescriptorSet2.t0[_79].sample(...);
float4 r2 = (*(constant array<texture3d<float>, 499968>*)&spvDescriptorSet2.t0)[_97].sample(...);
2024-04-02 12:01:07 +02:00
Jan Sikorski
8465ec8109 Support cases of LUTs which are not function local.
Prevent cases where arrays that are globally defined constants are redeclared
on stack. On Intel macs, declaring a large, statically initialized
spvUnsafeArray on stack may cause an internal compiler error.
2024-03-15 17:19:49 +01:00
Frank McCoy
e07956776d
Fixed conflict with windows min and max
If windows.h is included before spirv_common.hpp without NOMINMAX being defined the windows min and max macros will conflict with the STL numeric limits functions.
2024-01-22 00:49:18 -08:00
Hans-Kristian Arntzen
e10bf53324 MSL: Support variable sized descriptor array in argument buffer. 2024-01-08 12:37:01 +01:00
Hans-Kristian Arntzen
833c5936b0 Various nit fixes and improvements from review. 2023-12-07 14:31:36 +01:00
Hugo Devillers
d019358ce0 fix unintialised struct in SPIRType 2023-12-06 17:54:34 +01:00
Hugo Devillers
950cad5913 Added an Op field to SPIRType
This field allows telling what the 'head' of the type is, without having to look at parent types.
2023-11-30 12:28:50 +01:00
chirsz-ever
20dd53b312
Allow to customize float literals in output 2023-11-22 22:17:24 +08:00
Try
68376504a0 track access to meshlet position.y, via SPIRExpression 2023-07-01 15:49:35 +02:00
Laura Hermanns
bcb6243798 HLSL: Add support to preserve (RW)StructuredBuffer resources. 2023-05-12 14:41:00 -04:00
Hans-Kristian Arntzen
bcbe33ad11 Also consider NonSemantic ExtInst in block_is_noop. 2023-01-12 12:41:53 +01:00
Hans-Kristian Arntzen
e8a22a7cf6 Handle ShaderDebugInfo non-semantic extension. 2022-11-08 12:21:07 +01:00
Hans-Kristian Arntzen
4de9d6c2b6 MSL: Handle implicit integer promotion rules.
MSL inherits the behavior of C where arithmetic on small types are
implicitly converted to int. SPIR-V does not have this behavior, so make
sure that arithmetic results are handled correctly.
2022-10-31 13:33:46 +01:00
Hans-Kristian Arntzen
4c345166dc GLSL: Implement task shaders.
Due to bugged glslang / spirv-tools w.r.t. terminator instructions,
add a hack to ignore invalid SPIR-V for the time being.
2022-09-05 12:31:22 +02:00
Hans-Kristian Arntzen
5762617729 GLSL: Implement GL_EXT_mesh_shader. 2022-09-05 11:25:04 +02:00
Chip Davis
fc4a12fd4f MSL: Use a wrapper type for matrices in workgroup storage.
The standard `matrix` type in MSL lacked a constructor in the
`threadgroup` AS. This means that it was impossible to declare a
`threadgroup` variable that contains a matrix. This appears to have been
an oversight that was corrected in macOS 13/Xcode 14 beta 4. This
workaround continues to be required, however, for older systems.

To avoid changing interfaces unnecessarily (which shouldn't be a problem
regardless because the old and new types take up the same amount of
storage), only do this for structs if the struct is positively
identified as being used for workgroup storage.

I'm entirely aware this is inconsistent with the way packed matrices are
handled. One of them should be changed to match the other. Not sure
which one.

Fixes 23 CTS tests under `dEQP-VK.memory_model.shared`.
2022-08-07 17:31:41 -07:00
Hans-Kristian Arntzen
7eb5ced2a0 Refactor out query for operation type/result IDs. 2022-05-02 15:27:09 +02:00
Hans-Kristian Arntzen
7a6c2da9aa GLSL: Handle more proper semantics for RelaxedPrecision.
GLSL and RelaxedPrecision are quite different in what they affect.
RelaxedPrecision affects operations, while this is merely implied in
GLSL based on inputs.

This leads to situations where we have to promote mediump inputs to
highp, and the simplest approach is to force highp temporaries for
inputs which are consumed in a highp context. For completeness, we also
demote RelaxedPrecision inputs to mediump variables.

PHI is handled by copying the PHI into a temporary.

We have to be very careful with hoisted temporaries, since the child
temporary will not be analyzed up-front. We inherit the hoisted-ness
state and emit the hoisted child temporary as necessary. When faking the
temporaries with OpCopyObject, we make sure to block any variable
hoisting.

Hoisting children of PHI variables is fine, since PHIs are not hoisted with
the same framework as other temporaries.
2022-05-02 15:11:24 +02:00
Hans-Kristian Arntzen
d2a4f9842b GLSL: Support GL_EXT_debug_printf. 2022-04-19 12:07:54 +02:00
Hans-Kristian Arntzen
476b6541fa Remove forwardable bit in SPIRVariable.
Was never really used for anything. It's always true.
2022-03-04 11:05:21 +01:00
Alex Brachet
0eda71c409 Qualify move as std::move
Seeing downstream errors:
"spirv_common.hpp:692:19: error: unqualified call to std::move"
2022-02-25 18:15:35 -05: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
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
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
Hans-Kristian Arntzen
97a438d214
Merge pull request #1757 from KhronosGroup/fix-1754
Improve handling of INT_MIN/INT64_MIN literals.
2021-09-30 17:04:30 +02:00
Hans-Kristian Arntzen
f72bb3c6f5 Improve handling of INT_MIN/INT64_MIN literals.
We cannot naively convert these to decimal literals. C/C++ (and thus
MSL) has extremely awkward literal promotion rules.
2021-09-30 16:29:30 +02:00
Hans-Kristian Arntzen
96d95fbb31 MSVC: Workaround crtdbg macroing free(). 2021-09-30 14:12:08 +02: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
Corentin Wallez
6a85c695cc Fix IVariant -Wdeprecated-copy-with-dtor
Since C++11 the generation of implicit copy constructor is deprecated if
the type has a user-defined constructor or destructor (even if defaulted).
Same thing for the implicit copy assignment operator.

Fix this by adding a defaulted copy-constructor for IVariant that remove
the implicit default constructor, so add it too.
2021-06-21 14:11:31 +02:00
Hans-Kristian Arntzen
2a2d57df13 MSL: Sketch out API to aid LTO-style optimization. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
4ca06c7278 Handle edge cases in OpCopyMemory.
Implement this by synthesizing an OpLoad/OpStore pair instead.
2021-03-08 14:15:27 +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
cf1e9e0643 Add MIT dual license for the SPIRV-Cross API. 2020-12-01 16:47:08 +01:00
Chip Davis
aca9b6879a MSL: Support pull-model interpolation on MSL 2.3+.
New in MSL 2.3 is a template that can be used in the place of a scalar
type in a stage-in struct. This template has methods which interpolate
the varying at the given points. Curiously, you can't set interpolation
attributes on such a varying; perspective-correctness is encoded in the
type, while interpolation must be done using one of the methods. This
makes using this somewhat awkward from SPIRV-Cross, requiring us to jump
through a bunch of hoops to make this all work.

Using varyings from functions in particular is a pain point, requiring
us to pass the stage-in struct itself around. An alternative is to pass
references to the interpolants; except this will fall over badly with
composite types, which naturally must be flattened.  As with
tessellation, dynamic indexing isn't supported with pull-model
interpolation. This is because of the need to reference the original
struct member in order to call one of the pull-model interpolation
methods on it. Also, this is done at the variable level; this means that
if one varying in a struct is used with the pull-model functions, then
the entire struct is emitted as pull-model interpolants.

For some reason, this was not documented in the MSL spec, though there
is a property on `MTLDevice`, `supportsPullModelInterpolation`,
indicating support for this, which *is* documented. This does not appear
to be implemented yet for AMD: it returns `NO` from
`supportsPullModelInterpolation`, and pipelines with shaders using the
templates fail to compile. It *is* implemeted for Intel. It's probably
also implemented for Apple GPUs: on Apple Silicon, OpenGL calls down to
Metal, and it wouldn't be possible to use the interpolation functions
without this implemented in Metal.

Based on my testing, where SPIR-V and GLSL have the offset relative to
the pixel center, in Metal it appears to be relative to the pixel's
upper-left corner, as in HLSL. Therefore, I've added an offset 0.4375,
i.e. one half minus one sixteenth, to all arguments to
`interpolate_at_offset()`.

This also fixes a long-standing bug: if a pull-model interpolation
function is used on a varying, make sure that varying is declared. We
were already doing this only for the AMD pull-model function,
`interpolateAtVertexAMD()`; for reasons which are completely beyond me,
we weren't doing this for the base interpolation functions. I also note
that there are no tests for the interpolation functions for GLSL or
HLSL.
2020-11-05 11:57:45 -06:00
atyuwen
871a023877 fixed compile error with -std=c++20 2020-10-30 17:30:46 +08:00
Hans-Kristian Arntzen
e0c9aad934 GLSL: Add support for transform_feedback3 geometry streams. 2020-09-30 13:01:35 +02:00
Chip Davis
688c5fcbda MSL: Add support for processing more than one patch per workgroup.
This should hopefully reduce underutilization of the GPU, especially on
GPUs where the thread execution width is greater than the number of
control points.

This also simplifies initialization by reading the buffer directly
instead of using Metal's vertex-attribute-in-compute support. It turns
out the only way in which shader stages are allowed to differ in their
interfaces is in the number of components per vector; the base type must
be the same. Since we are using the raw buffer instead of attributes, we
can now also emit arrays and matrices directly into the buffer, instead
of flattening them and then unpacking them. Structs are still flattened,
however; this is due to the need to handle vectors with fewer components
than were output, and I think handling this while also directly emitting
structs could get ugly.

Another advantage of this scheme is that the extra invocations needed to
read the attributes when there were more input than output points are
now no more. The number of threads per workgroup is now lcm(SIMD-size,
output control points). This should ensure we always process a whole
number of patches per workgroup.

To avoid complexity handling indices in the tessellation control shader,
I've also changed the way vertex shaders for tessellation are handled.
They are now compute kernels using Metal's support for vertex-style
stage input. This lets us always emit vertices into the buffer in order
of vertex shader execution. Now we no longer have to deal with indexing
in the tessellation control shader. This also fixes a long-standing
issue where if an index were greater than the number of vertices to
draw, the vertex shader would wind up writing outside the buffer, and
the vertex would be lost.

This is a breaking change, and I know SPIRV-Cross has other clients, so
I've hidden this behind an option for now. In the future, I want to
remove this option and make it the default.
2020-07-23 17:59:54 -05:00
Hans-Kristian Arntzen
36c999ae3f MSVC 2013: Fix silently broken builds.
Anonymous structs with initializers apparently fail to compile in MSVC
2013, so just name the structs.
2020-07-11 13:35:44 +02:00
Hans-Kristian Arntzen
2d43103a55 GLSL: Support multi-level struct flattening for I/O. 2020-07-03 14:38:51 +02:00
Hans-Kristian Arntzen
d573a95a9c Run format_all.sh. 2020-07-01 11:42:58 +02:00
Hans-Kristian Arntzen
3afbfdb090 Implement context-sensitive expression read tracking.
When inside a loop, treat any read of outer expressions to happen
multiple times, forcing a temporary of said outer expressions.
This avoids the problem where we can end up relying on loop-invariant code motion to happen in the
compiler when converting optimized shaders.
2020-06-29 12:20:35 +02:00
Hans-Kristian Arntzen
58dad82fcb Handle physical pointers in reflection API. 2020-05-25 13:45:49 +02:00
Hans-Kristian Arntzen
0ebb88cc39 MSL: Redirect member indices when buffer has been sorted by Offset.
If a buffer rewrites its Offsets, all member references to that struct
are invalidated, and must be redirected, do so in to_member_reference,
but there might be other places where this is needed. Fix as required.
SPIR-V code relying on this is somewhat questionable, but seems to be
in-spec.
2020-04-30 11:48:53 +02:00
Hans-Kristian Arntzen
137dbeb7f1
Merge pull request #1355 from Kangz/fix-microsoft-enum-value
Fix -Wmicrosoft-enum-value
2020-04-30 10:51:46 +02:00
Corentin Wallez
a3a590a82e Fix -Wmicrosoft-enum-value
This is triggered when building projects that depend on SPIRV-Cross with
clang-cl on Windows with `-pedantic`

../../third_party/spirv-cross/spirv_common.hpp(781,3): error: enumerator
value is not representable in the underlying type 'int'
[-Werror,-Wmicrosoft-enum-value]
                NoDominator = 0xffffffffu
2020-04-30 10:00:28 +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
Hanno
4560ee24fd Improve compatibility with clang-cl 2020-04-09 17:30:20 +02:00
Hans-Kristian Arntzen
30343f3e95 MSL: Reintroduce workaround for constant arrays being passed by value. 2020-02-24 13:22:52 +01:00