Commit Graph

1043 Commits

Author SHA1 Message Date
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
54b48a2f3a
Merge pull request #2133 from georgeouzou/main
GLSL: Support GL_KHR_shader_subgroup_arithmetic (WIP)
2023-05-10 11:32:00 +02:00
George Ouzounoudis
813cfdce4f GLSL: Address review comments
Fix a warning and some format issues
2023-05-01 14:24:33 +03:00
Laura Hermanns
16b5ce09d7 GLSL: Use actual field offset to validate vec4 boundary alignment. 2023-04-24 20:36:44 -04:00
georgeouzou
168e9f2cc9 GLSL: Support KHR_subgroup_arithmetic IMul/FMul
Support NV workarounds for IMul/FMul Reduce/InclusiveScan/ExclusiveScan
2023-04-03 19:13:30 +03:00
georgeouzou
ab3a6212b8 GLSL: Checking for inactive threads in non uniform arithmetic ops
The last argument of shuffle*NV functions does not return if the
current thread is inactive, but only if it is out of range.
2023-04-03 18:42:08 +03:00
georgeouzou
dbf6218883 GLSL: Support KHR_subgroup_arithmetic FAdd
Support NV workarounds for FAdd Reduce/InclusiveScan/ExclusiveScan
2023-04-02 10:45:25 +03:00
georgeouzou
b693d8faec GLSL: Support KHR_subgroup_arithmetic IAdd
Support NV workarounds for IAdd Reduce/InclusiveScan/ExclusiveScan
2023-04-02 01:25:15 +03:00
Hans-Kristian Arntzen
50623e13c8 GLSL: Fix expression reorder bug with legacy FMA fallback. 2023-03-30 17:24:11 +02:00
Try
cb45e4be6f cleanup 2023-03-21 21:11:07 +01:00
Try
4a5d21bf1c virtual emit_mesh_tasks 2023-03-21 21:08:59 +01:00
Try
dd8839c6f9 task shader initial 2023-03-18 17:20:16 +01:00
Laura Hermanns
83650af3fb GLSL: Don't create temporaries for sampled image types in GLSL.
This fixes a bug that was exposed when targeting GLSL with
Vulkan semantics while 'force_temporary' is enabled.
2023-02-27 11:51:49 -05:00
rdb
c356dd6220 GLSL: Fix missing precision qualifier in spvDeterminant return value
Follow-up to #2100
2023-01-27 21:44:47 +01:00
rdb
20981666cc GLSL: Legacy matrix inverse/determinant polyfills, outerProduct()
Also refactors polyfill mechanism in GLSL and fixes transpose() lowering precision.
2023-01-27 13:51:47 +01:00
Hans-Kristian Arntzen
86a985f28c
Merge pull request #2093 from rdb/emulate-unsupported-hyperbolic-funcs
GLSL/HLSL: Add emulated fallbacks for hyperbolic math functions
2023-01-27 12:15:28 +01:00
Hans-Kristian Arntzen
cd612e7dde
Merge pull request #2090 from rdb/glsl-legacy-math-funcs
GLSL: Add support for trunc, modf, isnan and isinf in legacy GLSL
2023-01-27 12:13:14 +01:00
rdb
f8cc03fd1e
GLSL: Drop invariant keyword in GLSL 110 2023-01-27 11:10:47 +01:00
rdb
53974b4fae GLSL/HLSL: Add emulated fallbacks for sinh/cosh/tanh/asinh/acosh/atanh
The inverse hyperbolic functions are not supported in HLSL, and none of them are supported in legacy GLSL.
2023-01-26 19:40:42 +01:00
rdb
d10044b23e GLSL: Add support for modf, isnan and isinf in legacy GLSL 2023-01-26 19:14:25 +01:00
Hans-Kristian Arntzen
9de5abaf78 GLSL: Minor fixes for shader clock implementation. 2023-01-26 15:41:51 +01:00
Hans-Kristian Arntzen
f575b89436
Merge pull request #2091 from LDeakin/shader-clock
GLSL: Support OpReadClockKHR
2023-01-26 15:41:40 +01:00
Hans-Kristian Arntzen
9da448c9ff
Merge pull request #2096 from rdb/glsl-extension-checks
GLSL: Add various missing extension checks
2023-01-26 15:41:15 +01:00
rdb
d70bfa5f34 GLSL: Allow sample inputs in desktop < 400 with GL_ARB_sample_shading
Neither legacy ES nor legacy desktop support these extensions
2023-01-23 14:51:26 +01:00
rdb
2202c2a701 GLSL: Add various additional extension checks. 2023-01-23 11:55:53 +01:00
rdb
dff276989b GLSL: Multiplying matrix with scalar shouldn't force transpose 2023-01-21 11:42:55 +01:00
libretroadmin
5029e30f0a (spirv_glsl.cpp) Fix error: no matching function for call to 'max(uint32_t&, unsigned int)' 2023-01-20 18:36:11 +01:00
Lachlan Deakin
3335835fad GLSL: Support OpReadClockKHR 2023-01-19 22:28:38 +11:00
Hans-Kristian Arntzen
4212eef67e
Merge pull request #2087 from rdb/patch-1
GLSL: Support GL_NV_shader_noperspective_interpolation in GLES
2023-01-17 12:02:22 +01:00
rdb
09dd11be96
GLSL: Support GL_NV_shader_noperspective_interpolation in GLES 2023-01-16 20:02:13 +01:00
rdb
4ba13e0c1a GLSL/HLSL: Add legacy handling for int vertex attributes 2023-01-14 18:57:24 +01:00
Hans-Kristian Arntzen
88c6b49959
Merge pull request #2085 from KhronosGroup/fix-2075
GLSL: Handle textureGatherOffsets properly.
2023-01-12 17:48:00 +01:00
Hans-Kristian Arntzen
1047c13d40 GLSL: Handle textureGatherOffsets properly.
We forgot to pass down the offset ID, clean up coffset vs offset jank
while we're at it.
2023-01-12 16:27:11 +01:00
Hans-Kristian Arntzen
f84527346d GLSL: Declare gl_in/gl_out as array more robustly.
If a builtin block was not already declared, we would miss some
scenarios.
2023-01-12 16:05:17 +01:00
Hans-Kristian Arntzen
bcbe33ad11 Also consider NonSemantic ExtInst in block_is_noop. 2023-01-12 12:41:53 +01:00
Hans-Kristian Arntzen
549cde7fae Fix GCC5 build. 2023-01-05 12:24:02 +01:00
Laura Hermanns
6371580f51 Fixed typo in CompilerGLSL::should_dereference() 2023-01-03 14:19:42 -05:00
Hans-Kristian Arntzen
03b1f66ef1 GLSL: Fix row-major workaround wrapper for ES.
By default, the matrix would be declared as mediump, causing precision
issues. Need to dispatch to two separate functions since GLSL does not
support overload based on precision.
2022-12-13 15:44:03 +01:00
Hans-Kristian Arntzen
c77b09b57c
Merge pull request #2063 from KhronosGroup/fix-2060
Merge #2061
2022-11-21 14:29:47 +01:00
Hans-Kristian Arntzen
df76a14056 MSL: Refactor member reference in terms of one boolean.
ptr_chain was really just masking the proper i == 0 check.
Be more explicit about what the check is actually doing and comment
this.
2022-11-21 13:40:27 +01:00
Dunfan Lu
e75c496ec6 Fix MSL Access Chain 2022-11-21 13:29:18 +01:00
Chip Davis
061cdd2052 MSL: Don't dereference forwarded copies of OpVariable pointers.
Fixes two more CTS tests under
`dEQP-VK.spirv_assembly.instruction.compute.empty_struct.copying`.
2022-11-20 02:08:37 -08:00
Chip Davis
5547b25afe Interleave undef values with constants and types.
Undef values may be of struct type and may be used in constants.
Therefore, they must be interleaved with constants and types.

Fixes the rest of the Vulkan CTS test
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_spec_constant_composite`.

(Please excuse the churn in the reference output; it's an inevitable
result of this change.)
2022-11-20 02:08:37 -08:00
Chip Davis
06ef3de002 GLSL, MSL: Handle OpUndef as part of a constant composite.
Fixes the CTS test
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_constant_composite`
and helps with another,
`dEQP-VK.spirv_assembly.instruction.compute.opundef.undefined_spec_constant_composite`.
Unfortunately, fixing the latter requires another change.
2022-11-20 02:08:33 -08:00
Hans-Kristian Arntzen
e8a22a7cf6 Handle ShaderDebugInfo non-semantic extension. 2022-11-08 12:21:07 +01:00
Hans-Kristian Arntzen
ebf779dcfb HLSL: Do not support ClipCull size > 4 in mesh shaders.
The array mechanism breaks DXC which needs to observe that all
components have been written.

Uninitialized outputs will be undefined. Resort to simple vector
instead.
2022-11-02 13:34:11 +01:00
Hans-Kristian Arntzen
a4d5c0c4a5 HLSL: Fix-up some style issues from review. 2022-11-02 12:15:10 +01:00
Try
80146a20da HLSL: Implement VK_EXT_mesh_shader 2022-11-02 11:48:58 +01:00
Chip Davis
8cf99e7d44 MSL: Implement CompositeInsert OpSpecConstantOp.
This op creates a new composite constant with one element replaced. So,
we reconstruct the `SPIRConstant` for the composite constant, but with
one of the IDs replaced. Constant initializer lists are memoized for
when the result of a `CompositeInsert` is used in another
`CompositeInsert`.

(I wanted to add a test case for GLSL as well, but for two things:
1. `glslang` in Vulkan mode chokes on the first constant array,
   insisting that its initializer needs to be a constant. [Bug in
   glslang?]
2. The declarations for the buffers used by the shader aren't emitted,
   regardless of whether Vulkan mode is enabled.)

Fixes five tests under
`dEQP-VK.spirv_assembly.instruction.*.opspecconstantop.vector_related`.
2022-11-01 18:11:39 -07: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
Aaron Siegel
7b4c470f16 GLSL: Account for ES sampler1D to sampler2D promotion in textureSize. 2022-09-15 11:33:09 -07: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
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
Yuwen Wu
f40dba4919 GLSL: added an option to disable row-major-load workaround. 2022-08-24 11:07:12 +08:00
Yuwen Wu
9afa82e7b8 GLSL: disable row major load around on GLES. 2022-08-23 19:27:01 +08:00
Hans-Kristian Arntzen
05bbcc2d09 Do not optimize OpCompositeInsert for hoisted temporaries.
We cannot track uses that happens in subsequent loop iterations, so have
to be very careful.

Fixes regression introduced after this was added.
2022-08-09 12:44:57 +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
4dfac510ed Handle multiple breaks out of switches.
Use a switch stack instead.
2022-07-22 15:31:40 +02:00
Hans-Kristian Arntzen
963fdfdf68 Handle PHI in collapsed switch constructs.
Collapsed switch constructs only branch directly to the merge block.
2022-07-04 13:55:00 +02:00
Hans-Kristian Arntzen
f46745095d
Merge pull request #1965 from billhollings/msl-physical_storage_buffer
MSL: Add support for SPV_KHR_physical_storage_buffer extension.
2022-07-04 12:59:42 +02:00
Bill Hollings
4185acc70d MSL: Fixes from review for SPV_KHR_physical_storage_buffer extension.
- Assign ulongn physical type to buffer pointers in short arrays
  when array stride is larger than pointer size.
- Support GL_EXT_buffer_reference_uvec2 casting
  buffer reference pointers to and from uvec2 values.
- When packing structs, include structs inside physical buffers.
- Update mechanism for traversing pointer arrays when calculating type sizes.
- Added unit test shaders.
2022-07-01 16:10:41 -04:00
Frédéric Wang
9c44a97faa address more review comments 2022-06-23 11:40:02 +02:00
Frédéric Wang
1310f5ba4d Keep using sprintf on windows. 2022-06-23 11:34:51 +02:00
Frédéric Wang
99f8613847 Fix compilation errors with deprecated sprintf function
This commit modifies sprintf calls to fix the following compilation
errors using XCode 14.0 beta on MacOS:

> 'sprintf' is deprecated: This function is provided for compatibility
> reasons only.  Due to security concerns inherent in the design of
> sprintf(3), it is highly recommended that you use snprintf(3) instead.
2022-06-21 16:28:16 +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
df21a99d1a GLSL: Add more extension ladder fallbacks for unusual integer sizes. 2022-06-07 18:30:10 +02:00
Hans-Kristian Arntzen
e45d01c41f Emit KHR barycentrics if source enables the KHR extension.
For roundtrip purposes, need to match KHR or NV extension.
2022-05-27 13:28:25 +02:00
Hans-Kristian Arntzen
af223101c6
Merge pull request #1952 from KhronosGroup/fix-1944
GLSL: Add basic support for GL_EXT_shader_atomic_float.
2022-05-27 13:17:22 +02:00
Hans-Kristian Arntzen
88e583d062 GLSL: Add basic support for GL_EXT_shader_atomic_float. 2022-05-27 12:13:40 +02:00
Hans-Kristian Arntzen
1c88730e12 GLSL: Implement 1D texture emulation for ES.
ES does not support 1D images at all. Fake it by promoting 1D images to
2D.
2022-05-27 11:51:34 +02:00
Hans-Kristian Arntzen
b3ff97d0fe
Merge pull request #1946 from KhronosGroup/fix-1943
Promote Unreachable cases into break to avoid fallthrough.
2022-05-18 19:22:45 +02:00
Hans-Kristian Arntzen
d08ce828f4 Promote Unreachable cases into break to avoid fallthrough.
HLSL is very fussy about fallthrough in switch blocks, so promote
Unreachable blocks to breaks if they are inside a switch construct.

Some false positives are possible in weird multi-break scenarios, but
this is benign.
2022-05-18 18:36:32 +02:00
Hans-Kristian Arntzen
23662668dd Attempt more optimal codegen for OpCompositeInsert.
Speculate that we can modify the SSA value in-place. As long as it is
not used after the modify, this is fine.

Also need to make sure we don't attempt to RMW something that is
impossible to modify.
2022-05-18 16:37:33 +02:00
Hans-Kristian Arntzen
a3c4177324 GLSL: Don't apply Grad LOD workarounds for fetch. 2022-05-13 15:47:38 +02:00
Hans-Kristian Arntzen
92164d38d1 GLSL: Do not analyze precision for Undef variables.
Undefs won't have a chance to emit aliases, and any expression depending
on Undef will be garbage either way.
2022-05-13 12:18:10 +02: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
d28136cc7a GLSL: Clean up some ways of querying decoration flags. 2022-04-29 13:47:49 +02:00
Hans-Kristian Arntzen
40b3053b4c Handle early reads from loop variables with initializers.
Need to consider that static_expression can be 0. Fallback as necessary.
Also need to clear the static expression.
2022-04-28 14:36:53 +02:00
Hans-Kristian Arntzen
d2a4f9842b GLSL: Support GL_EXT_debug_printf. 2022-04-19 12:07:54 +02:00
Bill Hollings
85f98eb0c5 Allow volatile vars that are not builtins to be forwarded.
This fixes a regression introduced by 93b0dc7, where all volatile variables
were not allowed to be forwarded. This doesn't work well for volatile memory
object variables like images or buffer blocks, because it forces local variables
to be defined, which is unnecessary, and sometimes results in wrong types.

This patch restricts volatile builtin variables (eg. HelperInvocation) from
being forwarded, but allows other volatile variables to be forwarded, as before.
2022-03-23 14:48:22 -04:00
Hans-Kristian Arntzen
7b9eaf0b5e MSL: Handle awkward mix and match of Offset / ArrayStride in constants.
In normal buffer blocks, every member must be declared, but for
constants, you can technically mix and match, causing much pain and
suffering ...
2022-03-22 12:25:09 +01:00
Hans-Kristian Arntzen
4ab5bbb4e5 Fixup names of anonymous inner structs.
Just like we try to fixup struct names for block types, inner structs
can be "anonymous" structs. HLSL codegen from DXC tends to emit this,
and emitting dummy struct names tends to break GL linkage on some
drivers.
2022-03-10 15:45:38 +01:00
Hans-Kristian Arntzen
93b0dc7718 Consider Volatile in should_forward().
Never forward these variables.
2022-03-04 11:08:55 +01: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
Hans-Kristian Arntzen
005c14ad6a HLSL: Implement HelperInvocationEXT.
It is volatile by nature and must not be forwarded.
2022-03-04 10:54:31 +01:00
Hans-Kristian Arntzen
31be74a853 Add relax_nan_checks options.
Makes codegen from typical D3D emulation SPIR-V more readable.
Also makes cross compilation with NotEqual more sensible.
It's very rare to actually need the strict NaN-checks in practice.

Also, glslang now emits UnordNotEqual by default it seems, so give up
trying to assume OrdNotEqual. Harmonize for UnordNotEqual as the sane
default.
2022-03-03 14:50:56 +01: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
188dc8b13c
Merge pull request #1862 from flokart-world/feature/flatten-ubo-for-hlsl
HLSL: Make --flatten-ubo work correctly
2022-02-16 16:39:45 +01:00
Shintaro Sakahara
ed4ded040e HLSL: Make --flatten-ubo work correctly 2022-02-16 21:53:24 +09:00
Hans-Kristian Arntzen
a56b22bf4e Add more scenarios where we can guarantee forward progress.
The patterns where we force temporary due to invalid/overused expression -> recompile
should be seen as making forward progress, and there are very rare scenarios where
these recompiles can cascade into many loops.

Refactor this style of logic into a new function which is equivalent to handle_invalid_expression().
2022-02-16 12:12:58 +01:00
Hans-Kristian Arntzen
c716a9a5dd Add debug option to modify maximum number of compile iterations.
Should be seen as a hack, but it's pragmatic in some scenarios.
2022-02-16 12:12:27 +01:00
Hans-Kristian Arntzen
339e61a0e0 Do not emit hoisted access chain temporaries unless backend supports it.
This can happen for access chains into buffer objects which were marked
as potentially hoisted, but it's benign in almost all cases.
2022-02-16 11:36:38 +01:00
Hans-Kristian Arntzen
5d9a95370f GLSL: Ensure correct signed integer type for more texture functions. 2022-02-16 11:14:07 +01:00
Hans-Kristian Arntzen
48b5a9069f Handle aliased names in spec constants.
Need to register resource name.
2022-01-18 12:31:28 +01:00
Hans-Kristian Arntzen
9b25581d49 MSL: Handle constant construct of block-like array types.
Need this to be context sensitive, since array of block-like struct is
template, but struct of block-like array is C-style.

Also, test a mix and match, so we have constant array of block-like
struct with array inside. :v
2022-01-17 18:28:25 +01:00
Hans-Kristian Arntzen
7dd974b9db
Merge pull request #1847 from KhronosGroup/fix-1775
Rework how loop iteration counts are validated.
2022-01-17 14:55:56 +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
ef6bde6580 Do not forward expressions which carry a huge amount of dependencies.
Need to force temporaries eventually, or compilers have a tendency to
explode.
2022-01-17 13:45:12 +01:00