Commit Graph

123 Commits

Author SHA1 Message Date
3256e054fa wip 2024-02-23 09:55:34 -05:00
ae934021e5 improve scanline timeout slightly i hope
finally touch this again after 2 months
2024-02-13 21:38:53 -05:00
ba4b4e2263 Merge remote-tracking branch 'upstream/master' into RDLines 2024-02-13 09:56:44 -05:00
8143f54956 Protect savestates while the threaded software renderer is running (#1864)
* First crack at ensuring the render thread doesn't touch GPU state while it's being serialized

* Get rid of the semaphore wait

* Add some extra fields into GPU3D's serialization

* Oops, TempVertexBuffer is already serialized

* Move vertex serialization into its own method

* Lock the GPU3D state when rendering on the render thread or serializing it

* Revert "Lock the GPU3D state when rendering on the render thread or serializing it"

This reverts commit 2f49a551c1.

* Add comments that describe the synchronization within GPU3D_Soft

- I need to understand it before I can solve my actual problem
- Now I do

* Revert "Revert "Lock the GPU3D state when rendering on the render thread or serializing it""

This reverts commit 1977566a6d.

* Let's try locking the GPU3D state throughout NDS::RunFrame

- Just to see what happens

* Slim down the lock's scope

* Narrow the lock's scope some more

* Remove the lock entirely

* Try protecting the GPU3D state with just a mutex

- I'll clean this up once I know it works

* Remove a duplicate method definition

* Add a missing `noexcept` specifier

* Remove an unused function

* Cut some non-hardware state from `GPU3D`'s savestate

* Assume that the next frame after loading a savestate won't be identical

* Actually, it _is_ worth it

* Don't serialize the clip matrix

- It's recalculated anyway

* Serialize `RenderPolygonRAM` as an array of indexes

* Clean up some comments

- I liked the dialogue style, but oh well

* Try restarting the render thread instead of using the lock

- Let's see what happens

* Put the lock back

* Fix some polygon and vertex indexes being saved incorrectly

- Taking the difference between two pointers results in the number of elements, not the number of bytes

* Remove `SoftRenderer::StateBusy` since it turns out we don't need it

- The real synchronization was the friends we made along the way
2024-01-07 23:39:43 +01:00
4cb2c23ad6 fine linux 2023-12-25 19:39:54 -05:00
bffc529c04 meh 2023-12-25 19:24:35 -05:00
4f3b99f5c4 fix another crash + bug w/ scanline delay 2023-12-25 15:26:48 -05:00
ee3e38aed3 fix bottom scanline bugging out
use a method of tracking progress through rendering that's less prone to me messing it up
2023-12-25 13:10:32 -05:00
f239d0cf0d fix a crash and scanlines being incorrectly partially read 2023-12-24 20:27:24 -05:00
fb5b2c299c new feature: crashes 2023-12-24 17:39:33 -05:00
c05c79321a it works again! 2023-12-23 22:24:09 -05:00
bf26b6817d partially rendering 2023-12-23 21:26:49 -05:00
78da2846e6 wip - rewrite 3 - scheduler edition 2023-12-23 00:38:39 -05:00
6cee0a7ad7 no idea how that one slipped in 2023-12-20 23:15:07 -05:00
8cc42490de fix build but also sw renderer crashes now 2023-12-20 21:54:03 -05:00
4c2e03af53 Merge branch 'master' of https://github.com/melonDS-emu/melonDS into RDLines 2023-12-20 20:55:35 -05:00
1054011c90 wip 2023-12-19 22:52:54 -05:00
c867a7f1c0 Make the initial 3D renderer configurable via NDSArgs (#1913)
* Allow 3D renderers to be created without passing `GPU` to the constructor

* Make the initial 3D renderer configurable via `NDSArgs`

* Fix a compiler error
2023-12-15 14:53:31 +01:00
2217a34d39 misc improvements 2023-12-14 23:00:12 -05:00
a46316d71f improved timings for the first 50 scanlines 2023-12-14 15:18:39 -05:00
9bfc9c08ff Sprinkle const around where appropriate (#1909)
* Sprinkle `const` around where appropriate

- This will make it easier to use `NDS` objects in `const` contexts (e.g. `const` parameters or methods)

* Remove the `const` qualifier on `DSi_DSP::DSPRead16`

- MMIO reads can be non-pure, so this may not be `const` in the future
2023-12-12 11:07:22 +01:00
24eecec50f implement first draft of improved timing structure 2023-12-12 00:01:26 -05:00
0d6a8e0fb9 ok this one actually works 2023-12-10 19:22:30 -05:00
2bf033e0bc optimize per pixel timing counting 2023-12-10 18:51:00 -05:00
785fab024f dont use templates
bigger code <<< slower code
2023-12-10 13:03:54 -05:00
63a39b130e refactor framebuffers to be more similar to hw
allows for emulation of niche scanline glitches
2023-12-10 12:18:46 -05:00
c45d3320d0 tentative timings for "empty" polys scanlines, fix swapped polys breaking 2023-12-09 15:56:36 -05:00
8e2c9cbff6 wip initial draft 2023-12-09 08:54:13 -05:00
7caddf9615 Clean up the 3D renderer for enhanced flexibility (#1895)
* Give `GPU2D::Unit` a virtual destructor

- Undefined behavior avoided!

* Add an `array2d` alias

* Move various parts of `GPU2D::SoftRenderer` to `constexpr`

- `SoftRenderer::MosaicTable` is now initialized at compile-time
- Most of the `SoftRenderer::Color*` functions are now `constexpr`
- The aforementioned functions are used with a constant value in at least one place, so they'll be at least partially computed at compile-time

* Generalize `GLRenderer::PrepareCaptureFrame`

- Declare it in the base `Renderer3D` class, but make it empty

* Remove unneeded `virtual` specifiers

* Store `Framebuffer`'s memory in `unique_ptr`s

- Reduce the risk of leaks this way

* Clean up how `GLCompositor` is initialized

- Return it as an `std::optional` instead of a `std::unique_ptr`
- Make `GLCompositor` movable
- Replace `GLCompositor`'s plain arrays with `std::array` to simplify moving

* Pass `GPU` to `GLCompositor`'s important functions instead of passing it to the constructor

* Move `GLCompositor` to be a field within `GLRenderer`

- Some methods were moved up and made `virtual`

* Fix some linker errors

* Set the renderer in the frontend

* Remove unneeded `virtual` specifiers

* Remove `RenderSettings` in favor of just exposing the relevant member variables

* Update the frontend to accommodate the core changes

* Add `constexpr` and `const` to places in the interpolator

* Qualify references to `size_t`

* Construct the `optional` directly instead of using `make_optional`

- It makes the Linux build choke
- I think it's because `GLCompositor`'s constructor is `private`
2023-11-29 15:23:11 +01:00
ad7b1a8c61 only fill edges when translucent if blending is enabled (#1882) 2023-11-25 18:40:07 +01:00
346dd4006e Move all core types into namespaces (#1886)
* Reorganize namespaces

- Most types are now moved into the `melonDS` namespace
- Only good chance to do this for a while, since a big refactor is next

* Fix the build
2023-11-25 18:32:09 +01:00
4558be0d8e Refactor the GPU to be object-oriented (#1873)
* Refactor GPU3D to be an object

- Who has two thumbs and is the sworn enemy of global state? This guy!

* Refactor GPU itself to be an object

- Wow, it's used in a lot of places
- Also introduce a new `Melon` namespace for a few classes
- I expect other classes will be moved into `Melon` over time

* Change signature of Renderer3D::SetRenderSettings

- Make it noexcept, and its argument const

* Remove some stray whitespace
2023-11-09 21:54:51 +01:00
ac38faef14 update copyright years 2023-11-04 00:21:46 +01:00
9d9ba83731 Clean up some rendering-related resources in DeInit (#1836)
- The unique_ptr destructors will take care of the cleanup
2023-09-24 18:33:14 +02:00
db963aa002 Make the NDS teardown more robust (#1798)
* Make cleanup a little more robust to mitigate undefined behavior

- Add some null checks before cleaning up the GPU3D renderer
- Make sure that all deleted objects are null
- Move cleanup logic out of an assert call
- Note that deleting a null pointer is a no-op, so there's no need to check for null beforehand
- Use RAII for GLCompositor instead of Init/DeInit methods

* Replace a DeInit call that I missed

* Make ARMJIT_Memory less likely to generate errors

- Set FastMem7/9Start to nullptr at the end
- Only close and unmap the file if it's initialized

* Make Renderer3D manage its resources with RAII

* Don't try to deallocate frontend resources that aren't loaded

* Make ARMJIT_Memory::DeInit more robust on the Switch

* Reset MemoryFile on Windows to INVALID_HANDLE_VALUE, not nullptr

- There is a difference

* Don't explicitly store a Valid state in GLCompositor or the 3D renderers

- Instead, create them with static methods while making the actual constructors private

* Make initialization of OpenGL resources fail if OpenGL isn't loaded

* assert that OpenGL is loaded instead of returning failure
2023-09-15 15:31:05 +02:00
2bd12669b2 Edge fill rules for swapped polygons + a few minor fixes to edge cases (#1815)
* fix edge fill rules for swapped polygons

also fixes translucent polygons not being always edge filled.

* fix right edge fill rule

* fix right edge fill rule for realsies

* fix a few more glitchy polygons

specifically quads similar to: (-67,40) (64, 160) (192, 160), (8, 111)

* fix one edge case pixel

i hate this so much

* fix "flat bottom" edge fill

* fix regression + apply changes to shadow masks

fix a regression with certain line polygons not rendering; there seems to be an exception made by the ds'  gpu in order for these polygons to render properly.
also apply these changes to shadow masks because i forgot to

* forgot to remove a line

---------

Co-authored-by: Arisotura <thetotalworm@gmail.com>
2023-08-27 13:32:31 +02:00
d69745b3a8 Fix Incorrect Polygon Swapping Behavior and Implement Correct Rules for Shifting Right Edges Left (#1816)
* fix polygons being swapped incorrectly

"borrowed" this from noods
needs verification that the >= and <= signs aren't actually supposed to be > and <

* proper rules for moving vertical right slopes left

* nvm most of that was actually pointless

that's on me for not checking
2023-08-27 13:29:12 +02:00
dc8efb62b8 Fix aa being upside down on swapped y-major slopes (#1803)
* fix aa being upside down on swapped y-major slopes

* further improvements to swapped aa

in addition to fixing swapped y-major slope aa, now fixes:
swapped x-major slope aa
swapped vertical slope aa

* use templates instead + style/comment tweaks

should force the compiler to precompile if statements like i want it to do, instead of just hoping it does so on its own
2023-08-27 13:28:44 +02:00
d7369857c3 Small Fix to Anti-Aliasing + Edge Marking Behavior (#1680)
* Anti-Alias All Edges

Changing a bunch of 0x3s to 0xF since I figure if they're checking the left and right edge they wanna be checking the top and bottom too now that they're gonna be aa'd. also copy that if statement over since otherwise there won't be anything to blend with.

* small optimization

its probably a tiny bit faster?
idk id need actual benchmarking tools.
doesn't break anything at least.
2023-08-27 13:28:26 +02:00
f454eba3c3 check lower pixel when top pixel ignores fog (#1808) 2023-08-13 05:38:26 +02:00
35cc79787d update copyright headers 2022-01-09 02:15:50 +01:00
19ddaee13b finally decouple Config from the core. baahhahahahah 2021-11-18 01:17:51 +01:00
883fceb6ce use std::swap 🔃 2021-08-21 01:54:45 +02:00
f900792dc0 addition to last commit 2021-08-04 14:35:54 +02:00
9181ab19c7 GPU3D soft: prevent out of bounds read 2021-05-24 19:41:24 +02:00
509107fb59 set instead of or stencil buffer for left edges 2021-05-08 00:12:48 +02:00
436b3c4c1d update copyright year and add missing GPL headers 2021-03-12 20:07:40 +01:00
bc63531e00 avoid leaking threads in NDSCart_SRAMManager
also atomics
2021-03-11 16:54:43 +01:00
295d60e4cb try to fix build when the compiler is stricter 2021-02-11 19:11:18 +01:00
f05bc50d40 use std::function in Thread_Create so we can revert back to using it 2021-02-11 16:00:36 +01:00