Commit Graph

403 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
04ddb9a809 Mark function call results as control dependent as necessary.
Inner function calls can contain flow-control sensitive code.
In this case, the function call itself must inherit the
control-dependence.

Rarely happens in practice since optimized code with SSA tends to
inline.
2024-05-10 14:52:24 +02:00
Hans-Kristian Arntzen
48bede6a2a Smaller cleanups on multi-function Private LUTs. 2024-03-18 11:25:38 +01: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
Hans-Kristian Arntzen
572c413176 Fix crash when traversing PtrAccessChain to OpTypeStruct. 2024-03-06 13:14:54 +01:00
Hans-Kristian Arntzen
5f7a6de552
Merge pull request #2282 from hypengw/main
GLSL: Fix atomic_uint being incorrectly generated as uint
2024-02-26 16:31:26 +01:00
penghaiyi
18cb2ce961 GLSL: Fix atomic_uint being incorrectly generated as uint 2024-02-23 09:33:08 +08:00
Bill Hollings
fa0d4b9057 OpCopyObject declare a temp var of base type, not pointer type.
Fixes MSL issue where temp variable was declared as pointer var, and
OpCopyObject attempted to copy a base type var into the pointer var.
2024-02-15 19:34:30 -05:00
Hans-Kristian Arntzen
32ac768c15 GLSL: Handle synthesized pointer-to-pointer. 2024-01-18 13:11:04 +01:00
Hans-Kristian Arntzen
871ac0e5b7 GLSL: Handle BDA to plain non-block struct.
The implementation assumed that BDA to struct would always result in a
Block-like type, but that is not necessarily the case. Treat non-Block
structs as POD types as well.
2024-01-18 12:40:47 +01:00
Hans-Kristian Arntzen
833c5936b0 Various nit fixes and improvements from review. 2023-12-07 14:31:36 +01:00
Hugo Devillers
55e08aff31 use 'op' as the ground truth in is_array and is_pointer 2023-12-04 18:49:46 +01:00
Hugo Devillers
738bfd49e3 msl: fix test regressions with samplemask 2023-12-04 12:47:15 +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
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