Commit Graph

4303 Commits

Author SHA1 Message Date
Corentin Wallez d8c068fb4f Remove explicit usage transition from the API and validation
This removes the following for both Buffer and Texture:
 - The builder's SetInitialUsage
 - The object's FreezeUsage and TransitionUsage methods
 - The CommandBuffer Transition<Object>Usage methods

All samples and tests are simplified as a result. This also obsoletes
the UsageValidationTest which is removed.

Some validation was dependent on "current usage" and hasn't been
reintroduced for implicit transitions yet:
 - Buffers can be used while mapped
 - Swapchain textures can be used after they have been presented.

Validation for these will involve collecting all the resources used by a
command buffer and will be done in a follow-up patch.
2018-07-16 14:44:20 +02:00
Corentin Wallez d2312e8138 Fix D3D12 compute bindgroups 2018-07-16 14:44:20 +02:00
Corentin Wallez 27388434d6 D3D12: Fix SetDescriptorHeap when we only have a sampler heap 2018-07-13 13:31:14 +02:00
Corentin Wallez a430a9a0aa Make the D3D12 backend support implicit barriers
With this the backend ignores explicit usage transition hints from the
frontent and generates all the barriers automatically based on resource
usage.

The current implementation is very naive and encodes a barrier
immediately just before a resource is used in a new state.
2018-07-13 13:31:14 +02:00
Corentin Wallez 2beeae3ad3 CommandBufferD3D12: Iterate per pass 2018-07-13 13:31:14 +02:00
Corentin Wallez aa13be96e8 Make the Vulkan backend support implicit barriers.
With this commit the Vulkan backend completely ignores the explicit
barrier commands passed from the frontend, and generates its own
pipeline barriers.

Right now it encodes each barrier just before the resources are used,
which is quite bad but will be optimized later.

This commit also makes the frontend command buffer validation perform
the checks necessary for implicit barriers (although they are redundant
with checks for explicit barriers) because the tracking can pre-compute
pass usage information that's useful for the Vulkan backend.

Tests for usage validation inside passes will be added once the concept
of transition is removed from the API.
2018-07-11 17:17:21 +02:00
Corentin Wallez 117f2f0ad6 Make EnumClassBitmask operations constexpr
This allows declaring combinations of bits as constants in header.
kReadOnlyBufferUsages is added using this feature.

Also reformat the file.
2018-07-11 17:17:21 +02:00
Kai Ninomiya 23bec15f4c
ComputeCopyStorageBufferTests (#216)
These should hopefully subsume the ComputeBoids demo for testing purposes. Not all of these tests pass currently:

* ComputeCopyStorageBufferTests.StructTest/D3D12 fails due to "Reading structs from ByteAddressBuffer not yet supported."
* The disabled tests fail for various reasons on various backends.
2018-07-10 17:26:35 -07:00
Kai Ninomiya 0582bfdfda
Fix D3D12 descriptor renumbering (#218)
Previously, the renumbering loop would sometimes iterate in the wrong order. To fix this, instead use the binding info already correctly extracted by `ExtractSpirvInfo`.

Fixes ComputeCopyStorageBufferTests.BasicTest/D3D12.
2018-07-10 17:25:48 -07:00
Kai Ninomiya 21006bbe6f Assert HandleCommands succeeds 2018-07-10 14:00:52 -07:00
Corentin Wallez d5c1ecaf64 WireClient: MapReadCallback, unconditionnally consume the data
When a MapReadRequestCallback arrived late and hit one of the early out
of the handler (for example if the buffer was already unmapped), the
handler wouldn't consume the data payload of the command. This would
cause the command buffer pointer to not be advanced enough and point to
random data instead of the next command.
2018-07-10 14:00:52 -07:00
Kai Ninomiya 234becf175
Use a descriptor for BindGroupLayout (#211)
* Use a descriptor for BindGroupLayout
* Fix MatchesLambda
* Add WireTests.StructureOfStructureArrayArgument
* Add BindGroupValidationTests.BindGroupLayoutCache
2018-07-10 12:23:50 -07:00
Kai Ninomiya 7883e7e59c
Fix ComputeBoids (#214)
I know there was some churn on which version of this shader was correct - but right now, this goes from broken on all 4 backends to working on all 4 backends. So this seems better.

The old code (accidentally?) uses descriptor arrays (I think), which are not trivial to support on all backends, so we won't use them for now.
2018-07-10 11:01:28 -07:00
Kai Ninomiya 6c639c991e
Roll glslang to 1ea8f595 (#215)
Rolling this now to fix some memory leaks.
2018-07-10 10:55:46 -07:00
Corentin Wallez 976430c097 CommandBufferMTL: Iterate per-pass
This introduces a small amount of code duplication in the code that
handles push constants. On the plus side it removes the need for all the
asserts around which Metal encoder is active.
2018-07-10 10:59:44 +02:00
Corentin Wallez c9f0348bfe CommandBufferVk: Iterate per-pass 2018-07-10 10:59:44 +02:00
Corentin Wallez 47fe5c52b5 CommandBufferGL: Iterate per pass 2018-07-10 10:59:44 +02:00
Corentin Wallez b3bd35ed88 CommandBufferBuilder::Validate: Iterate per pass
This changes the validation to have one iteration loop for the main
buffer that calls to pass-specific iteration loops for compute passes
and render passes. This is done to simplify code a bit and will help
implement implicit transitions that are "precomputed" per pass in the
command buffer validation and re-used in the backends.

A number of code simplifications were made to CommandBufferStateTracker
since it doesn't need to know if we are in a pass anymore. Further
simplifications will happen when implicit barriers are implemented.
2018-07-10 10:59:44 +02:00
Corentin Wallez a884cb2479 Fix CubeReflection transitioning inside a pass 2018-07-10 10:59:44 +02:00
Corentin Wallez e909d4efe1 Move FreeCommands and SkipCommand to their own file 2018-07-10 10:59:44 +02:00
Stephen White bcd2e8559e
Remove extra copy of Queue in GL backend. (#213) 2018-07-06 15:39:11 -04:00
Kai Ninomiya 11fc210487 Move mDevice from PipelineLayoutVk to PipelineLayoutBase 2018-07-03 14:54:40 -07:00
Kai Ninomiya c5711ecd93 Rename GetBindGroupsLayoutMask -> GetBindGroupLayoutsMask 2018-07-03 14:54:40 -07:00
Kai Ninomiya 311e2a44b9 Allow bind group layouts to be sparse in pipeline layout
Instead of initializing all of the bind group layouts in the pipeline
layout to default values, let them be nullptr and allow this elsewhere.

Follow-up on some changes in #206
2018-07-03 14:54:40 -07:00
Corentin Wallez 804fc749a0 Fix CubeReflection's orientation 2018-07-03 22:23:52 +02:00
Corentin Wallez 30f85cb484 Remove samples that were only used as temporary tests
However keep the following samples:
 - CHelloTriangle that demonstrates the C API
 - CppHelloTriangle that demonstrates the C++ API
 - Animometer that matches the WebGL benchmark
 - HelloDepthStencil that does more than just a triangle, renamed
   to CubeReflection
 - ComputeBoids as a cool graphics and compute interop demo
 - glTFViewer that shows slightly more advanced usage of NXT
2018-07-03 22:23:52 +02:00
Kai Ninomiya 66c06f42f4
Manually retain/release mPendingCommands (#208)
Fixes a crash for me on macOS+Metal
2018-07-03 12:19:28 -07:00
Kai Ninomiya f53f98bf86
Use a descriptor for PipelineLayout (#206)
Adds support for structures inside descriptors.
2018-06-27 16:21:39 -07:00
Corentin Wallez a2f9277dac D3D12: Split D3D12Backend in Forward.h and DeviceD3D12 2018-06-19 13:51:26 -04:00
Corentin Wallez 1f51263672 Metal: Split off QueueMTL 2018-06-19 13:51:26 -04:00
Corentin Wallez 0f2e7b67c1 Metal: Split MetalBackend in Forward.h and DeviceMTL 2018-06-19 13:51:26 -04:00
Corentin Wallez a714f5b459 OpenGL: Split off QueueGL 2018-06-19 13:51:26 -04:00
Corentin Wallez 77d1f10493 OpenGL: Split OpenGLBackend in Forward.h and DeviceGL 2018-06-19 13:51:26 -04:00
Corentin Wallez 30f7ddbb6b Vulkan: Split VulkanBackend in Forward.h and DeviceVk 2018-06-19 13:51:26 -04:00
Corentin Wallez a4cb35cdbc Vulkan: Split off QueueVk 2018-06-19 13:51:26 -04:00
Corentin Wallez b703def640 Add Device::CreateQueue() instead of the builder
We are changing all object creation to use descriptors but there is no
creation argument to pass for queue, so instead Device::CreateQueue
takes no argument.
2018-06-18 13:33:40 -04:00
Corentin Wallez 40e72d79ca WireCmd: factor code to [de]serialize structs and methods
Methods, when their arguments are stored in a structure, are very
similar to structures (duh?) Take advantage of this to factor the
[de]serialization code between them and not just memcpy structures
around. This will allow structures to contain objects, and pointers to
other structures / array of objects etc.
2018-06-12 14:26:32 -04:00
Corentin Wallez 82565b340f Add NXT_UNUSED to silence unused warnings 2018-06-12 14:26:32 -04:00
Corentin Wallez 5ab96e0d40 Wire: Implement MapWriteAsync
The flow of commands is a bit more involved than for MapReadAsync and
goes like this:
 - C->S MapAsync isWrite = true
 - S: Call MapWriteAsync
 - S: MapWriteAsync callback fired
 - S->C: MapWriteAsyncCallback (no data compared to the read case)
 - C: Call the MapWriteAsync callback with a zeroed out buffer
 - C: Application calls unmap.
 - C->S: UpdateMappedData with the content of the mapped pointer
 - S: Copy the data in the mapped pointer
 - C->S: Regular unmap command
 - S: Call unmap

Makes nxt_end2end_tests -w pass all tests.

Also duplicates the MapRead wire tests for the write cases
2018-06-09 13:52:45 +02:00
Corentin Wallez 88fb8fa353 Wire: Move the logic of [de]serialization in WireCmd.
This will help with follow-up changes that add support for a more
complete grammer of types, including structures containing pointers
to objects or other structures.

Instead of having the wire::Client and wire::Server directly act on
buffer memory, a couple interfaces are introduced so that WireCmd can do
things like get the object<->id mapping and temporary allocations.

While the serialization and deserialization of most commands was moved
into WireCmd, the commands that don't directly correspond to NXT methods
have their logic moved inside Client and Server and will be made to
expose the new interface in a follow-up commit.
2018-06-08 13:58:55 +02:00
Corentin Wallez 419e9841a8 NXTTest: add -w to run the end2end tests through the wire
This will be useful to provide additional coverage of the wire in
addition to the very focused WireTests unittests. All tests pass except
the MapWriteAsync ones that aren't implemented in the wire yet. They can
be skipped with --gtest_filter=-*MapWrite*
2018-06-08 13:58:55 +02:00
Corentin Wallez 862f884a65 SampleUtils: Look at argv starting from 1 2018-06-08 13:58:55 +02:00
Corentin Wallez 79d9e16d3c Make Device::CreateSamplerImpl to return a ResultOrError
This will allow backends to do error-handling internally for things like
allocation failures though non of them take advantage of it yet.
2018-05-31 15:00:28 -04:00
Corentin Wallez 50e0986e0e Use Error in Sampler and autogenerated validation functions 2018-05-31 15:00:28 -04:00
Corentin Wallez 1fda980fa6 Add an Error and ResultOrError<T> type and tests
These types are meant to be used for computations that might but are not
expected to fail in backend/, such that the error case can be much
slower than the success case.

The NXT_TRY and NXT_TRY_RESULT macros are added to help write more
concise code that uses Error and ResultOrError.
2018-05-31 15:00:28 -04:00
Corentin Wallez 44b5ca4aa1 Add a functional-y Result<T, E> class and tests for it.
Implements two optimized versions of Result, one for Result<void, E*> as
a nullable pointer, and one for Result<T*, E*> as a tagged pointer.
2018-05-31 15:00:28 -04:00
Corentin Wallez 2141e960b7 Add NXT_(UN)?LIKELY macros to help with branch prediction 2018-05-31 15:00:28 -04:00
Corentin Wallez b1341db700 Add a NXT_NO_DISCARD that is C++17 [[nodiscard]] where available 2018-05-31 15:00:28 -04:00
Corentin Wallez b711b9b2c9 Add a GetDefaultSamplerDescriptor helper. 2018-05-23 14:03:51 -04:00
Corentin Wallez 5101d57972 WireTests: Add a test for sending structs of non-object values 2018-05-23 14:03:51 -04:00