Commit Graph

391 Commits

Author SHA1 Message Date
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
Bill Hollings
16fbf8872a MSL: Workaround Metal 3.1 regression bug on recursive input structs.
Metal 3.1 introduced a Metal regression bug which causes an infinite recursion
crash during Metal's analysis of an entry point input structure that itself
contains internal recursion. This patch works around this by replacing the
recursive input declaration with a alternate variable of type void*, and
then casting to the correct type at the top of the entry point function.

- Add CompilerMSL::Options::replace_recursive_inputs to enable
  replacing recursive input.
- Add Compiler::type_contains_recursion() to determine if a struct
  contains internal recursion, and add custom Decorations to mark
  such structs, to short-cut future similar checks.
- Replace recursive input struct declarations with void*,
  and emit a recast to correct type at top of entry function.
- Add unit test.
- Compiler::type_is_top_level_block() remove hardcode reference to spirv_cross
  namespace, as it interferes with configurable namespaces (unrelated).
2023-10-14 14:46:47 -04:00
Hans-Kristian Arntzen
be944258be GLSL: Ignore bogus constant/undefs which use block types.
This is banned in more recent SPIR-V.
We cannot implement this in any reasonable way since block types don't
participate as normal types in GLSL.
2023-10-11 13:48:25 +02:00
Hitesh A. Bosamiya
df7fa1b92b [SC-2189] Compiler::get_shader_resources() does not return all uniforms 2023-08-26 11:35:16 +05:30
Hans-Kristian Arntzen
44966e5000 MSL: Fixup nits from review. 2023-08-17 12:01:26 +02:00
Try
844cb59cd6 MSL: runtime array over argument buffers 2023-08-17 11:37:29 +02:00
Hans-Kristian Arntzen
71fe651e43 Be more precise in usage of pointer/array mixing. 2023-05-11 11:42:32 +02:00
Hans-Kristian Arntzen
88790d3145 GLSL: Disambiguate pointer vs array properly in packed_size/alignment. 2023-05-10 12:35:47 +02:00
Hans-Kristian Arntzen
d46c10ebd3 Refactor PHI checks into block_is_noop instead. 2023-01-12 12:42:01 +01:00
Hans-Kristian Arntzen
bcbe33ad11 Also consider NonSemantic ExtInst in block_is_noop. 2023-01-12 12:41:53 +01:00
Loic Sharma
d69a2cafe5 Accept no ops 2023-01-09 18:14:37 -08:00
Hans-Kristian Arntzen
68a012a4f2 CFG: Handle implied access to opaque loaded values.
Similar concern as access chains. Objects that we cannot lower to
temporaries must implicitly access all expression dependencies when they
are themselves accessed.
2022-12-13 16:34:00 +01:00
Hans-Kristian Arntzen
e8a22a7cf6 Handle ShaderDebugInfo non-semantic extension. 2022-11-08 12:21:07 +01:00
Chip Davis
a171087180 MSL: Support "raw" buffer input in tessellation evaluation shaders.
Using vertex-style stage input is complex, and it doesn't support
nesting of structures or arrays. By using raw buffer input instead, we
get this support "for free," and everything becomes much simpler.
Arguably, this is the way I should've done this in the first place.

Eventually, I'd like to make this the default, and then remove the
option altogether. (And I still need to do that with
`multi_patch_workgroup`...)

Should help fix 66 tests in the Vulkan CTS, under the following trees:

 - `dEQP-VK.pipeline.*.interface_matching.*`
 - `dEQP-VK.tessellation.user_defined_io.*`
 - `dEQP-VK.clipping.user_defined.*`
2022-10-18 14:58:59 -07:00
Hans-Kristian Arntzen
f3b1375b13 Add reflection support for shader record buffers.
Reflect naming scheme in a context sensitive way that matches the
frontend.

GLSL -> use block name
HLSL (DXC) -> use instance name.
2022-10-03 12:20:08 +02:00
Hans-Kristian Arntzen
6d3518e238
Merge pull request #2018 from atyuwen/master
MSL: only fix up gl_FragCoord if really necessary.
2022-09-15 11:44:38 +02:00
Bill Hollings
5493b3030e MSL: Support OpPtrEqual, OpPtrNotEqual, and OpPtrDiff.
- Add CompilerMSL::emit_binary_ptr_op() and to_ptr_expression()
  to emit binary pointer op. Compare matrix addresses without automatic
  transpose() conversion, to avoid error taking address of temporary copy.
- Add Compiler::add_active_interface_variable() to also track active
  interface vars in the entry point for SPIR-V 1.4 and above.
- For OpPtrAccessChain that ends in array element, use Element
  as offset to existing index, otherwise it will access into
  array dimension that doesn't exist.
- Dereference pointer function call arguments. Ultimately, this
  dereferencing is actually backwards, and in future, we should aim
  to properly support passing pointer variables between functions,
  but such a refactoring was beyond the scope here.
- Use [] to declare array of pointers, as array<T*> is not supported in MSL.
- Add unit test shaders.
2022-09-14 15:19:15 -04:00
Yuwen Wu
1b9296e1a5 MSL: only fix up gl_FragCoord if really necessary. 2022-09-13 18:50:57 +08: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
Hans-Kristian Arntzen
f7e98c39db Avoid detection of false loop variables.
If the loop variable candidate has a dominating block that lives in an
unrelated loop, we have to reject the loop variable candidate.
2022-07-22 14:08:21 +02:00
Hans-Kristian Arntzen
e08e0cf28d GLSL: Handle forced temporary OpConvertUToAccelerationStructureKHR.
Need to lower to temporary before casting to RTAS.
2022-06-17 13:38:45 +02:00
Hans-Kristian Arntzen
7eb5ced2a0 Refactor out query for operation type/result IDs. 2022-05-02 15:27:09 +02:00
Daniel Thornburgh
44c3333a1c Qualify std::move.
Clang added -Wunqualified-std-cast-call in
https://reviews.llvm.org/D119670, which warns on unqualified std::move
and std::forward calls. This change qualifies these calls to allow the
project to build on HEAD Clang -Werror.
2022-03-02 23:17:58 +00:00
Hans-Kristian Arntzen
29cc18988c Fix regression from adding 64-bit switch support.
Missed some cases where we did not handle the loaded type width
properly.
2022-02-16 11:49:24 +01:00
Hans-Kristian Arntzen
1d13a3e36a Rework how loop iteration counts are validated.
Introduces an idea of a recompilation making forward progress.

There are some extreme edge cases where we need more than 3 loops, but
only allow this in specific circumstances where we can reason about
forward progress being made.
2022-01-17 14:12:01 +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
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
Bill Hollings
fd252b21ff Separate (partially) the tracking of depth images from depth compare ops.
SPIR-V allows an image to be marked as a depth image, but with a non-depth
format. Such images should be read or sampled as vectors instead of scalars,
except when they are subject to compare operations.

Don't mark an OpSampledImage as using a compare operation just because the
image contains a depth marker. Instead, require that a compare operation
is actually used on that image.

Compiler::image_is_comparison() was really testing whether an image is a
depth image, since it incorporates the depth marker. Rename that function
to is_depth_image(), to clarify what it is really testing.

In Compiler::is_depth_image(), do not treat an image  as a depth image
if it has been explicitly marked with a color format, unless the image
is subject to compare operations.

In CompilerMSL::to_function_name(), test for compare operations
specifically, rather than assuming them from the depth-image marker.

CompilerGLSL and CompilerMSL still contain a number of internal tests that
use is_depth_image() both for testing for a depth image, and for testing
whether compare operations are being used. I've left these as they are
for now, but these should be cleaned up at some point.

Add unit tests for fetch/sample depth images with color formats and no compare ops.
2021-11-08 15:59:45 -05: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
f1b411c9e8 GLSL: Deal with buffer_reference_align.
This is somewhat awkward to support, but the best effort we can do here
is to analyze various Load/Store opcodes and deduce the ideal overall
alignment based on this. This is not a 100% perfect solution, but should
be correct for any reasonable use case.

Also fix various nitpicks with BDA support while I'm at it.
2021-11-07 17:11:46 +01:00
Hans-Kristian Arntzen
f1d4aff85e
Merge pull request #1805 from KhronosGroup/fix-1776
Handle Modf/Frexp in more cases.
2021-11-07 12:36:42 +01:00
Hans-Kristian Arntzen
4561ecddbd Handle Modf/Frexp in more cases.
Consider it a write to a variable, similar to OpStore.
2021-11-07 11:36:44 +01:00
Hans-Kristian Arntzen
05e8e5a953 Correctly reflect declared buffer size for out of order members.
Need to deduce size based on member with highest offset, not highest
index.
2021-11-07 10:08:17 +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
Hans-Kristian Arntzen
5b0cafb416 Track temporary access for OpArrayLength result.
The argument is a literal, but result is still a temporary.
2021-08-23 12:43:41 +02:00
Hans-Kristian Arntzen
cb613eb675 Handle value access in terminators.
Fixes case where value is created inside loop body and consumed by a
return outside it.
2021-07-29 15:27:52 +02:00
Hans-Kristian Arntzen
5b227cc57c GLSL: Implement GL_EXT_ray_query. 2021-07-19 14:01:21 +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
Hans-Kristian Arntzen
90c70e6605 MSL: Handle variable access in OpSelect.
CFG analysis needs to know if we need to take address of variable.
2021-04-20 13:20:49 +02:00
Hans-Kristian Arntzen
ae9ca7d73c MSL: Fix copy of arrays to/from stage IO variables.
Need to take into account effective storage classes and whether or not
we target stage IO blocks since native arrays are conditionally enabled.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
b4a380a04c Support reflecting builtins.
They were ignored in input/output variables.
2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
852f2da63c Check SPIR-V 1.4 rules when reflecting resources. 2021-04-19 12:10:49 +02:00
Hans-Kristian Arntzen
ea02a0c03a Check entry point variables in is_hidden_variables.
Need to be careful not to emit globals we're not supposed to.
2021-01-22 13:53:22 +01:00
Hans-Kristian Arntzen
9acb9ec31f
Merge pull request #1594 from KhronosGroup/fix-1591
Fix pathological complexity explosion for certain shaders.
2021-01-15 10:46:23 +01:00
Hans-Kristian Arntzen
4704482bbc meta: Update copyright headers to 2021. 2021-01-14 16:07:49 +01:00
Hans-Kristian Arntzen
4c866e4662 Fix pathological complexity explosion for certain shaders.
Certain shaders where functions have a *ton* of merging control flow
will end up with exponential time complexity to figure out parameter
preservation semantics.

The trivial fix to make it O(1) again is to terminate recursive traversal early if we've seen
the path before. Simple oversight :(
2021-01-14 16:00:10 +01:00