Commit Graph
997 Commits
Author SHA1 Message Date
Jim Blandy 9f7424c3af [spv-out]: Remove all #[allow(clippy::too_many_arguments)] attrs. 2021-07-01 01:06:18 -04:00
Jim Blandy 634632a382 [spv-out]: Introduce BlockContext.
This commit should should cause no visible change in behavior.

Many `back::spv::Writer` methods take long lists of arguments simply describing
the module and function we're generating code for, but these never change while
we generate a given function. This commit moves some of those values into a
`BlockContext` type, and turns those `Writer` methods into `BlockContext`
methods, so that code can access these values through `self`, rather than
threading them through everywhere as arguments.

Many uses of `self.foo` become `self.writer.foo`. Some of these can be
simplified, but to make this commit easier to review, most of those changes are
left to later commits.

This allows us to remove some `#[allow(clippy::too_many_arguments)]` attributes.
2021-07-01 01:06:18 -04:00
Jim Blandy e0b37667ca [spv-out] Move future BlockContext methods into their own impl block.
This commit should introduce no meaningful code changes. It's simply isolating
the `Writer` methods that should be `BlockContext` methods into their own impl
block, to make it easier to see the meaningful changes needed to introduce
`BlockContext`.
2021-07-01 01:06:18 -04:00
Jasper St. Pierre fbab3a3ba5 [glsl-in] Add support for texture function with LOD bias 2021-07-01 02:45:13 +01:00
Gordon-F 607206f9a5 [hlsl-out] Enable operators snapshot test 2021-06-29 09:49:00 -04:00
Gordon-F 6723c8f6ae [hlsl-out] Implement Derivative expression and enable standard snapshot test for HLSL 2021-06-29 09:49:00 -04:00
Dzmitry Malyshau 68a2efd3c5 glsl-out: make the cs adjustment to also flip Y 2021-06-29 02:18:56 -04:00
Dzmitry Malyshau ba066c83e7 glsl-out: proper continuing block 2021-06-29 01:44:54 -04:00
Dzmitry Malyshau e8b71b8dc5 [glsl-out] Support extended shadow sampling instructions, and the offset 2021-06-28 15:01:39 -04:00
Dzmitry Malyshau cfbe83e384 glsl-out: adjust coordinate space 2021-06-28 15:01:39 -04:00
Igor Shaposhnik 0cf5484bba [hlsl-out] Implement loop statement and composite constants 2021-06-27 18:36:28 -04:00
Jim Blandy 06cfbbde4e Flesh out the Naga module-level documentation. 2021-06-27 18:26:58 -04:00
Jasper St. Pierre dd791a26ae glsl: Replace todo!() with a NotImplemented error
So we can get a source location rather than a panic.
2021-06-27 21:54:21 +01:00
Jasper St. Pierre 8729391e53 [glsl-in] Fix function lookup
First look for exact matches before trying the implicit
lookup. Otherwise, finding two wrong matches first will
result in an ambiguous function error.

This logic could use with a bit of a cleanup, keeping
track of a closer score and doing more exact matching
on types, but this might be good enough for now.
2021-06-27 21:54:04 +01:00
Dzmitry Malyshau 57b3256020 [glsl-out] binding location mapping 2021-06-27 01:09:53 -04:00
Gordon-F 19de60f6e4 [hlsl-out] Implement more expressions 2021-06-26 13:15:44 -04:00
Gordon-F 24b2c548bd [hlsl-out] Add note about entry points in ReflectionInfo 2021-06-26 13:15:44 -04:00
Jim Blandy c156fa9ad3 [spv-out] Properly reset Writers between module writes.
A single `Writer` can be reused to convert any number of Naga IR modules to
SPIR-V. This lets us reuse the heap allocations, but makes us responsible for
resetting the state of the `Writer` fully between modules. The old code
neglected to clear several different fields: logical_layout (all fields),
lookup_type, and cached_constants.

This commit uses Rust struct literal expressions to construct the re-initialized
`Writer`, which makes the compiler check that each field has been handled.

It also introduces a policy limiting how much storage will be retained, so that
processing the occasional whale doesn't leave us with leviathan buffers
permanently.
2021-06-26 12:54:53 -04:00
Jim Blandy f0d41c3fd6 [spv-out] Track block termination statically.
Rather than giving `Block` an optional `terminator` field in addition to its
`body`, track block termination statically, with two types:

- `Block` is a block without a termination instruction. This is what most code
  generation functions operate on.

- `TerminatedBlock` is a block with a termination instruction. This is what
  `Function::blocks` holds.

The `Function::consume` method takes a `Block` by value, together with a
termination instruction, and turns it into a `TerminatedBlock`.

This lets us remove some unwraps and awkward conditions.

As part of this change, `Writer::write_block` no longer hits an `unimplemented!`
for Naga statements following `Break`, `Return`, and so on. Instead, it simply
doesn't emit code for them, which is a correct translation. If we want to forbid
these, we should handle that in validation instead.
2021-06-26 12:45:47 -04:00
Gordon-F e28344edbb [hlsl-out] Return entry points name to users 2021-06-24 10:47:17 -04:00
Gordon-F 391983459a [hlsl-out] Add enum with supported shader models 2021-06-24 10:47:17 -04:00
Gordon-F c9a782f8d6 [hlsl-out] Fix panic with shader with multiple entry points without argument 2021-06-24 10:47:17 -04:00
Gordon-F 64b9e45015 [msl-out] Add type for backend result 2021-06-23 11:16:45 -04:00
Jonathan Behrens 42f1f37741 [glsl-in] Deduplicate constants so array types match 2021-06-23 11:13:40 -04:00
Gordon-F 0a957f9427 [wgsl-out] Reduce global import usage 2021-06-23 11:10:12 -04:00
Gordon-F 1d4f2305b0 [msl-out] Reduce global import usage 2021-06-23 11:10:12 -04:00
Gordon-F 9e245d1fde [hlsl-out] Reduce global import usage 2021-06-23 11:10:12 -04:00
Gordon-F 7eeab393b2 [glsl-out] Reduce global import usage 2021-06-23 11:10:12 -04:00
Igor Shaposhnik a5874eb0cf [wgsl-out] Fix Pointer writing 2021-06-22 12:29:14 -04:00
Gordon-F 0292a2897a Move FunctionCtx into back module 2021-06-22 10:23:27 -04:00
Gordon-F ec6b18a782 [glsl-out] Refactor FunctionCtx 2021-06-22 10:23:27 -04:00
Dzmitry Malyshau 064263272c Refactor control flow validation, allow break in switches 2021-06-22 00:24:50 -04:00
Gordon-F 9b823c1b60 [hlsl-out] Implement Access and Unary expressions 2021-06-21 16:41:00 -04:00
João Capucho d3fe1c978b [glsl-in] Add support for precision qualifiers 2021-06-21 21:37:08 +01:00
João Capucho 898c2e7c68 [glsl-in] Use macro for qualifier match 2021-06-21 21:37:08 +01:00
João Capucho 93436047f3 [glsl-in] Fix builtin types 2021-06-21 21:37:08 +01:00
Igor Shaposhnik 3a4d6fa295 Reduce code duplication between backends 2021-06-21 15:33:56 -04:00
Jim Blandy 548cde4701 Clear Validator::valid_expression_list before validating each function.
If validation fails, `Validator` may be left with entries in
`valid_expression_list` and `valid_expression_set`. The validator does clear the
set before examining a function's body, but not the list, which means a
long-lived `Validator` could accumulate an unbounded amount of garbage in the
list.

(Minor cleanup: use structural update syntax where appropriate.)
2021-06-21 14:53:20 -04:00
João Capucho cae71a788a [glsl-in] Support for vector scalar operations 2021-06-21 10:44:26 -04:00
João Capucho ffe67139cd [glsl-in] Add support for mix with bool selectors 2021-06-20 23:11:16 -04:00
João Capucho c152205c87 [glsl-in] arguments of opaque types are constant 2021-06-20 23:11:16 -04:00
João Capucho 01036e8f42 [glsl-in] Use crate::BOOL_WIDTH for booleans width 2021-06-20 23:11:16 -04:00
João Capucho e7d712e608 [glsl-in] Apply constant binary ops to composites 2021-06-20 23:11:16 -04:00
João Capucho 60644504d8 [glsl-in] Implicit cast stores with ValuePointer 2021-06-20 23:11:16 -04:00
João Capucho 68609cdff8 [glsl-in] Implement textureSize 2021-06-20 23:11:16 -04:00
João Capucho fd042e6f31 [glsl-in] Implement default for options 2021-06-20 23:11:16 -04:00
João Capucho 16d7c0e428 [glsl-in] Implement texelFetch 2021-06-20 23:11:16 -04:00
Jim Blandy 696ca340e0 Improve docs for TypeInner, valid::TypeFlags, and some internal types. 2021-06-20 12:18:50 -04:00
Jim Blandy 70016ce6e3 Address warnings about links from cargo doc --package naga. 2021-06-20 12:18:50 -04:00
Dzmitry Malyshau 70071228a3 [spv-out] don't OpConvert the same width 2021-06-20 01:27:58 -04:00