Commit Graph
100 Commits
Author SHA1 Message Date
WunkandGitHub 5284109fd4 Implement shader-interpreter relative MOVA addressing (#471)
* Add shader uniform-read unit test

* Add unit test f24 vector formatter

* Add Address Register Offset shader unit test

* Implement float-uniform out-of-bound return value

In the case that the resulting float-uniform index is greater than the 96 slots that it has, a result of `{1,1,1,1}` is to be returned.

* Implement shader relative addressing

Fails on the negative unit tests at the moment but passes all of the
others.

* Fix `MOVA` source register indexing
2024-03-22 18:48:03 +02:00
Wunkolo 40e2774b7f Implement arm64 LG2/EX2 2024-03-19 21:26:13 -07:00
Wunkolo dcd64802a3 Refactor ShaderJITTest into a specialization of ShaderInterpreterTest 2024-03-19 11:17:05 -07:00
Wunkolo 2b34ef4a89 Implement PICA200 compliant arm64 MUL
Adds `emitSafeMUL` to implement a PICA200 compliant multiplication that
handles the special `0 * inf = 0` case.
2024-03-14 12:30:42 -07:00
WunkandGitHub c89fe05b8a Fix shader-interpreter non-IEEE outputs (#459)
* Re-enable non-IEEE shader test

* Fix shader-interpreter RCP/RSQ output

Handle the `-0.0` special-case

* Fix shader-interpreter MIN/MAX output

Takes advantage of min/max's properties regarding non-finites to return
NaN depending on its input position:
```
max(NaN, 2.f) -> NaN
max(2.f, NaN) -> 2
min(NaN, 2.f) -> NaN
min(2.f, NaN) -> 2
```

* Fix shader-interpreter FLR indexing bug

`3 - 1` should be `3 - i`
2024-03-12 08:34:02 +02:00
WunkandGitHub fe9939689d Add shader-jit unit-tests (#458)
* Rename `dynapica` TU to `shader`

These unit-tests in particular only actually test
the shader-interpreter and not any of the JITs.

* Conditionally test the shader-jit

In the case that the host supports the shader-jit, the interpreter and the shader-jit will both be tested with the same unit-tests. Allowing for even more coverage.

* Remove weird git submodule
2024-03-12 02:29:58 +02:00
WunkandGitHub 18df066463 Add shader unit-testing (#457)
* Initialize catch-2 based unit tests

* Add nihstro submodule

Enabled only during testing to help with assembling shaders in-code.

* Implement `ADD` instruction unit-test

* Add arithmetic/logical instruction unit tests

* Add embedded catch2 submodule

Will use the host catch2 if available.
2024-03-12 00:53:49 +02:00
929019e76b Refactor build targets into AlberCore (#455)
* Ignore `.cache` folder

* Add `AlberCore` build-target

Separate the AlberCore from its frontends. Allowing two front-ends to interface
with the same core implementation.  This also allows for the core to interface
better with unit-testing.

* Modularize SDL/Qt frontend

Separates all QT/SDL build files and options into the frontend-build-target

* Fix optional OpenGL enablement

Software renderer requires OpenGL, so AlberCore requries OpenGL.

The QT frontend currently requires OpenGL due to `ScreenWidget`

* Fix Android build

* Fix LTO linking

* Fix windows build

`LoadLibrary` is a preprocessor that will use either `LoadLibraryW` or
`LoadLibraryA` depending on if `UNICODE` is defined or not.
In this case we are using an ASCII string literal and and can explicitly
specify the usage of `LoadLibraryA` with an ASCII literal.

* Bonk

* Bonk

---------

Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com>
2024-03-11 19:51:17 +02:00
Wunkolo 1b1dbeb105 vulkan: Add shader debugging information
Utilize the `GPU_DEBUG_INFO` flag to conditionally compile spirv files
with debugging information.
2023-08-31 13:13:16 -07:00
Wunkolo c77740acf0 Fix render-texture size
Use the width/height provided and not the current `fbSize`.
Fixes a division exception.
2023-08-26 22:44:57 -07:00
Wunkolo 2f96c1d24d Fix Depth/Stencil render-target aspects
Views must have a singular aspect set, while pipeline barriers need both aspects.

Fixes more validation messages
2023-08-26 22:25:18 -07:00
Wunkolo 225d2095b9 Remove redundant semaphore wait
Don't need this anymore now that we sync on the host anyways
2023-08-26 22:11:44 -07:00
Wunkolo 085d7d5568 Add clear-buffer support for Depth/Stencil 2023-08-26 22:06:46 -07:00
Wunkolo 1540c941d0 Write and flush top/bottom-screen descriptors
A descriptor is consumed immediately when bound to a command buffer and
cannot be updated after unless we mark the descriptors with
`UPDATE_AFTER_BIND` flags and such.

For now, just flush the writes immediately before binding the
descriptors.

Fixes all of the validation messages regarding invalid command buffers
due to updated/deleted descriptor-sets.
2023-08-26 22:06:46 -07:00
Wunkolo 57ee0a3db9 Fix display drawing
Disable depth-testing, the display vertex-shader, and the
viewport/scissor positioning of the bottom screen.

We have visual!
2023-08-24 11:31:55 -07:00
Wunkolo e4195d4d4d Implement color-buffer clears 2023-08-24 11:27:49 -07:00
Wunkolo d781802eb0 Fix render-texture cache lookups
`[32bit loc | 32bit attributes]`
Use `std::map::lower_bound(loc << 32)` to find the first address that matches the key in O(logn) time, finer grained searchs can happen after the fact in O(n) time.

Fixes render-texture cache lookups
2023-08-24 10:40:02 -07:00
Wunkolo be5ebeefed Default all texture layouts to eShaderReadOnlyOptimal
By default, a texture sitting somewhere and ignored should be in a shader-read-only state, and transitioned into other layouts in exception to this passive state.

This allows all shaders to be ready to be interpreted by shaders by default.
2023-08-24 09:47:11 -07:00
Wunkolo 84e0d58d9e Add initial render-target layout transition, depth-stencil aspect fix
Fixes a lot of the render-target validation error messages.
We "might" change the default layout for render-targets to shader-read-only and only use attachment-optimal layouts when they are armed for a render-pass. Render-Textures more often need to be ready for shaders than they need to be ready for render-passes.
2023-08-21 22:52:51 -07:00
Wunkolo d35c803ad6 Fix RenderTexture usage/image-aspect
All color textures need to be sampled due to how we are transposing the image when writing to the render-texture.

Depth-Stencil render-textures need to designate if it wants _either_ depth or stencil when creating an image-view.
2023-08-21 22:40:40 -07:00
Wunkolo cfd02f936e Fix swapchain/screenTexture layout synchronization issues
Been deving with a headless machine for too long.
Fixes some presentation issues.
2023-08-21 22:34:31 -07:00
Wunkolo b3812548fe Fix bottom screen detection 2023-08-20 23:42:34 -07:00
Wunkolo 0258640da9 Add cached sampler creation
Using the sampler cache we can maintain a pool of reusable samplers. The
`sampler2D` utility function can help make some trivial samplers.
2023-08-20 23:40:51 -07:00
Wunkolo 7a86595a1b Add vulkan sampler cache 2023-08-20 23:35:52 -07:00
Wunkolo 14b1d7d8a8 Add display-shader presentation
Uses the graphics pipeline to both blit and transpose the 3ds-formatted
textures. Does not read from the actual texture just yet since we dont
write to the descriptor just yet. Some other patterns need to line up
before then.
2023-08-20 23:01:43 -07:00
Wunkolo 4b7bd9df3d Add Vulkan Descriptor-Update batching
Allows multiple descriptor operations to be batched up and dispatched in
one API call rather than scattered through out the code base.
2023-08-20 23:01:43 -07:00
Wunkolo 72c77e41b4 Draft Vulkan DescriptorHeap
A utility class from a personal project for managing a heap of
descriptors of a particular layout.

Allows the display graphics pipeline to be successfully created,
satisfying its descriptor layout issues.
2023-08-20 23:01:43 -07:00
Wunkolo 6ebbd80286 Add Display-pipeline as member variables 2023-08-20 23:01:43 -07:00
Wunkolo 89f3eb3a87 Add simple graphics pipeline creation
This will eventually need to move into a cache, but this is introducing
some foundational patterns so that we know how to properly design a
pipeline cache. Currently does not provide a `DescriptorSetLayout`
argument. Causing validation errors. This will be a general-case cache
right from the get-go.
2023-08-20 23:01:43 -07:00
Wunkolo 13e52ac047 Add shader-module loading
Loads spirv files from the embedded virtual file system and loads them
into vulkan shader-modules.
2023-08-20 23:01:43 -07:00
Wunkolo 4b193c8d6b Add general purpose vulkan render cache
Takes in a general `vk::Format` rather than PICA-types
2023-08-20 23:01:43 -07:00
Wunkolo d4b75deaf8 Remove separate presentation/graphics command buffers
Now there is just one primary command buffer where all work is enqueued
into. At the end of the frame, the next frame's CPU-side fence is waited
on before resetting and beginning its command buffer again for
recording. This command buffer must always be in the RECORDING state.
2023-08-20 23:01:43 -07:00
Wunkolo 6052abe551 Fix swapchain synchronization issues
While we wait on the CPU-side fence for these command buffers, we must
also wait on the GPU-side semaphore to be compliant to validation
layers synchronization. We still get an error on the very first frame
since it will wait for a semaphore that has nothing signaling it.
2023-08-20 23:01:43 -07:00
Wunkolo 52ddaae221 Add getCurrentCommandBuffer for all frame workloads
Rather than allocating new command buffers for each small task, schedule
all work onto the frame's main command buffer to be dispatched at
display-time. Fixes all layout transition and synchronization issues.
2023-08-20 23:01:43 -07:00
Wunkolo cb8c53e0b8 Map RGB8 to RGBA8
RGB8 is not supported by drivers like RADV. Instead, we map it to RGBA8.
RGBA8 is mandated to be supported by the vulkan spec.
2023-08-20 23:01:43 -07:00
Wunkolo 9e2781e874 Refactor render-texture cache
Implement `displayTransfer` in parity with the OpenGL renderer. Allow
arguments to `get{Color,Depth}RenderTexture`.
2023-08-20 23:01:43 -07:00
Wunkolo 97b6b7f122 Add Vulkan Host-Shader compilation
Compiles Vulkan Host shaders into spirv binary files and embeds them
into the application's virtual file-system.
2023-08-20 23:01:43 -07:00
Wunkolo f62f1bf9b2 Fix ambiguous extension name conversion 2023-08-20 23:01:43 -07:00
Wunkolo cb64c52d2f Use inline rotl/ror
Fixes apple-clang builds, which do not implement a lot of the `bit`
header.
2023-08-20 23:01:43 -07:00
Wunkolo c778c34433 Separate present/graphics workloads
Separate the "Display" texture from the cache of framebuffer textures,
move present/graphics into separate command buffers.
2023-08-20 23:01:43 -07:00
Wunkolo 50029e1333 Avoid usage of D24-S8 format
This support is not supported on `radv`. Vulkan mandates D16 only and a
combination of Depth and Depth-Stencil types only.
2023-08-20 23:01:43 -07:00
Wunkolo 27268f86d3 Fix instance-extension iteration
Add the extensions when they are available rather than statically
including them.
2023-08-20 23:01:43 -07:00
Wunkolo 6dcd09af3e Implement basic color/depth render-texture cache 2023-08-20 23:01:43 -07:00
Wunkolo a36ee0025f Disable present queue when present unavailable. 2023-08-20 23:01:43 -07:00
Wunkolo bf3917f074 Add subpass dependencies, optional depth attachment 2023-08-20 23:01:43 -07:00
Wunkolo 37902cd9d6 Implement a renderpass cache.
Technically we can generate every possible render-pass up-front based on
the possible combinations of ColorFmt and DepthFmt, but we should only
allocate what the game asks for. Save that pattern for pipelines.
2023-08-20 23:01:43 -07:00
Wunkolo bf8bb5d459 Add vk_pica translation unit
Intended for conversions and utils between PICA definitions and Vulkan.
2023-08-20 23:01:43 -07:00
Wunkolo d19b8cf364 Separate frame-work from presentation 2023-08-20 23:01:43 -07:00
Wunkolo 4976671ef0 Rename vulkan_api.hpp to vk_api.hpp
Consistant with other vulkan header patterns.
This header in particular is to configure our Vulkan API usage.
2023-08-20 23:01:43 -07:00
Wunkolo ac1f7bc521 Remove dependency on C++20 ranges
AppleClang does not support this unfortunately
2023-08-20 23:01:43 -07:00
Wunkolo e87db99a97 Remove ownership of SDL's vulkan-surface
This surface is managed by SDL itself, so there is no need to keep it in
a Unique handle for us to delete.  Fixes the bug where vulkan crashes
during shutdown.
2023-08-20 23:01:43 -07:00
Wunkolo e3699fe8f8 Allocate and present separate top/bottom screen framebuffer images
Instead of operating directly on the swapchain images, we have our own
top/bottom framebuffer images that will be rendered to independent of
having an available swapchain. The images are blitted into the swapchain
images, allowing for resizing too!
2023-08-20 23:01:43 -07:00
Wunkolo d0832ca558 Fix support for headless vulkan context 2023-08-20 23:01:43 -07:00
Wunkolo 17101e9bb9 Fix graphics queue assignment
Copy-paste error
2023-08-20 23:01:43 -07:00
Wunkolo e2e49b7291 Add in-place swapchain recreation
Lots of todos, this should probably just be its own self-contained
object to allow the emulator to render "headlessly" regardless of a
swapchain existing or not.
2023-07-23 21:44:39 -07:00
Wunkolo c49fd71722 Use numeric_limits rather than ~0ULL 2023-07-22 19:44:09 -07:00
Wunkolo af4163de19 Implement simple swapchain image clearing
Creates a swapchain, and per-swapchain image data for safe parallelism and synchronization.
2023-07-22 19:41:41 -07:00
Wunkolo 90a4c9cf8d Initialize command buffer allocationFix SDL_Vulkan_GetDrawableSize call 2023-07-22 17:13:13 -07:00
Wunkolo fa804ae4c7 Implement swapchain draw loop
Verified on Windows and MacOS(M2)
2023-07-22 16:44:54 -07:00
Wunkolo 26c97eb716 Implement initial swapchain creation 2023-07-22 15:24:41 -07:00
Wunkolo 197e2a4bbd Allocate present/graphics/compute/transfer queue families 2023-07-22 14:23:37 -07:00
Wunkolo da6f880128 Disable timeline semaphore features
This is an optional feature that can be supported conditionally later
2023-07-22 13:34:10 -07:00
Wunkolo 8ace959d72 Fix RendererSW initGraphicsContext prototype 2023-07-22 13:20:57 -07:00
Wunkolo f715cb9478 Install VulkanSDK into CI environment 2023-07-22 13:16:23 -07:00
Wunkolo 428a9d1f1a Fix SDL_Window forward declaration
Should be struct, not class.
2023-07-22 13:16:23 -07:00
Wunkolo 165134ca40 Consider surface-support in device partitions
Use a stable_partitioning of the list of devices the driver gave us with
the addition of checking of the physical device supports the
display-surface that SDL gave us as well.
2023-07-22 13:16:23 -07:00
Wunkolo 0ada1f4e38 Include additional vulkan-extensions that SDL requests
Required for proper surface creation. This gets the surface-creation
call to pass now.
2023-07-22 13:16:23 -07:00
Wunkolo c7a93c4f52 Warn on failed surface creation for vulkan
Vulkan can technically work just fine without presenting to the user, so
consider these failed window procedures as "warnings" during iteration.
2023-07-22 13:16:23 -07:00
Wunkolo 444d50eaf5 Fix instance extensions on MacOS
These preprocessors were combining into a singular string rather than
the name of two individual extensions. Whoops.
2023-07-22 13:16:23 -07:00
Wunkolo eff62d3de7 Disable asserts on Vulkan result codes 2023-07-22 13:16:23 -07:00
Wunkolo d9afb12daf Fix MacOS build 2023-07-22 13:16:23 -07:00
Wunkolo b048d4dd6e Add SDL_Window to initGraphicsContext prototype
This value is needed for vulkan to properly allocate a surface, and would benefit OpenGL to move more of its initialization code into here rather than in `emulator.cpp`.
2023-07-22 13:16:23 -07:00
Wunkolo 870b6a21bf Add initial vulkan instance creation
Headlessly creates a new vulkan instance, with conditional MacOS
support, and enables the `VK_EXT_debug_utils` instance-extension with a
debug-messenger to hook onto validation layer messages.
2023-07-22 13:16:23 -07:00
Wunkolo d2241a25bc Stub Vulkan backend support
A lot of the architecture of the emulator here does not allow for vulkan
to initialize easily since it involves a bit of data to be exchanged
between SDL and Vulkan. This commit just adds the foundational linkage
and library code for vulkan support.
2023-07-22 13:16:23 -07:00
Wunkolo 19a77c2a85 Add missing algorithm header 2023-07-18 10:24:06 -07:00
Wunkolo 0b60cf6901 Migrate RenderType string functions to static Renderer functions
Also fix some IWYU build errors
2023-07-18 10:02:07 -07:00
Wunkolo 528ed510c2 Add string-based renderer backend configuration
Rather than using integer-indices, just use plaintext case-insensitive
names and leave the actual enum indexes as an implementation detail.
2023-07-17 18:02:01 -07:00
Wunkolo 2c57936c50 Fix EmulatorConfig initialization order
`config` was being consumed much too early before it has a chance to
call `load`. This caused GPU to read weird uninitialized data, and then
`load` called, and then further initialization to occur based on default
data and the data inside of `config.toml`. `EmulatorConfig` needs to be
loaded in first before any sort of initialization happens, by adding a
new constructor so that it can be initialized sooner.
2023-07-17 10:23:19 -07:00
Wunkolo ceff20f57f Add configurable Renderer backend
There are still some initialization errors to work through, such as
config not being initialized properly by the time GPU tries to utilize
it too. Also some life-time issues. But manually forcing it to use the
Null backnd successfully works and allows games to be "played"
headlessly.
2023-07-17 10:13:34 -07:00
Wunkolo 1becbef811 Add Null rendering backend
Doesn't implement any functions, currently not selectable or
configurable
2023-07-17 09:34:10 -07:00
Wunkolo b10e69de0e Add virtual deconstructor override
Virtual classes need to override the base-type deconstructor so that they are proper called when referred to by their base-type.
2023-07-17 09:30:12 -07:00
Wunkolo 413a03c8a3 Use https protocol for cmrc submodule 2023-07-15 19:21:26 -07:00
Wunkolo a9bb11e4b3 Migrate OpenGL string-literals to embedded files
Rather than declaring a big C++ literal for these strings, they are now
proper `.vert` and `.frag` files that will become embedded into the
application at build-time. It also allows for clang-format to format the
glsl files the same as our C++ code. CMake will also automatically track
and re-embed the file if it detects that the glsl source files have
changed since the last build. Ex, making a change to
`opengl_display.frag` and compiling will automatically recompile and
link the resource-target that it is associated with.
2023-07-15 19:12:07 -07:00
Wunkolo c294786846 Add cmrc submodule 2023-07-15 19:00:48 -07:00
Wunkolo 2f45714240 Add override-specifier to renderer implementation 2023-07-11 11:28:06 -07:00
Wunkolo 666fd96e7f Move color/depth format and size to Renderer interface
The state of these values are not specific to any rendering backend and
can be moved to be part of the interface itself
2023-07-11 11:28:06 -07:00
Wunkolo 5b7fa5be7e Remove redundant Renderer::screenshot definition 2023-07-11 11:28:06 -07:00
Wunkolo 0f3d77768d Fix array declarations to use block-formatting 2023-07-11 11:28:06 -07:00
Wunkolo 0a605339a3 Conditionally compile and link glad
Only include this library in the case that the OpenGL backend is
enabled.
2023-07-11 11:28:06 -07:00
Wunkolo 4864c51125 Migrate OpenGL specific headers to renderer_gl 2023-07-11 11:28:06 -07:00
Wunkolo a636a0d1da Replace ENABLE_OPENGL with PANDA3DS_ENABLE_OPENGL 2023-07-11 11:28:06 -07:00
Wunkolo c53080b444 Fix HTTPServer gpu-renderer interfacing
Fixing some compilation issues that occur when enabling the HTTP server
2023-07-11 11:28:06 -07:00
Wunkolo 9e32b6d4bf Remove OpenGL-specific vector-types
Removes dependency on the OpenGL header and rendering backen for its
`OpenGL::Vector` type in favor of a more standard array.
2023-07-11 11:27:35 -07:00
Wunkolo 2a1683ba62 Introduce "Renderer" abstraction layer
Adds a `renderer` class for which a rendering backend must implement and
will conditionally use OpenGL in the case that `ENABLE_GL` is enabled.
2023-07-11 11:27:35 -07:00
Wunkolo d664d5caf0 Emulator: Conditional OpenGL compilation 2023-07-11 11:27:04 -07:00
Wunkolo 0009b0817d Add ENABLE_OPENGL build option
Allows the OpenGL backend to be fully disabled, continuing a modular
pattern of having multiple possible rendering backends. Also defines the
`ENABLE_OPENGL` preprocessor in the case of conditional source-file
changes depending on the rendering backend.
2023-07-11 11:27:04 -07:00
WunkandGitHub 7382e29fa7 Merge pull request #105 from Wunkolo/tunit-stb_image_write
Move `stb_image_write` into its own translation unit
2023-07-11 11:03:08 -07:00
Wunkolo e4e8e7ce26 Move stb_image_write into its own translation unit
Rather than having the entire implementation within `emulator.cpp`,
causing incremental builds to be much slower, give it its own
translation unit `stb_image_write.c`.
2023-07-11 10:43:20 -07:00
WunkandGitHub 72252fc702 Merge pull request #102 from Wunkolo/sdl-test-disable
Disable compilation of SDL tests
2023-07-10 13:02:23 -07:00
Wunkolo d96289cc05 Address remaining C4244 warnings
Remaining warnings regarding an implicit cast from `double` to `float`.
2023-07-10 12:33:37 -07:00