Skip to content

Commit 910fc7c

Browse files
committed
Work on more of the implementation
1 parent 689ed33 commit 910fc7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4678
-1778
lines changed

Silk.NET.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1313
LICENSE.md = LICENSE.md
1414
generator.json = generator.json
1515
Silk.NET.sln.DotSettings = Silk.NET.sln.DotSettings
16+
global.json = global.json
1617
EndProjectSection
1718
EndProject
1819
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{9DB0EA3E-7216-4F9C-98F5-8A7483E9F083}"

docs/for-contributors/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Welcome to the Silk.NET Contributors' Documentation
2+
3+
Silk.NET 3.0 development was approved on mandate of a documentation regime that included "for-contributors"
4+
documentation, with the goal of increasing the maintainability and ease of contribution to the library. You've landed in
5+
the home of that documentations!
6+
7+
The goal of this documentation area, like `tests`, is to mirror the directory structure of `sources` to allow easy
8+
navigation to the corresponding design notes for a given portion of the library.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# The Event Pump
2+
3+
The largest influence in the `ISurfaceApplication` design is the fact that for many platforms only the entry thread is
4+
allowed to interact with the window manager (e.g. for the purposes of events). This creates a problem because rendering
5+
is very much not single-threaded, nor are most use cases where the user has multiple windows. As such,
6+
`ISurfaceApplication` gives the implementation freedom to decide what the most appropriate thread is to call into the
7+
surface to raise events. This is further emphasised by the definition of `ISurfaceChildren` where the user can only
8+
`Spawn` a surface, and not have a blocking call they can send off to their own thread. This allows the child windows to
9+
use the same event thread and synchronization. This is likely inconvenient for rendering scenarios though
10+
(e.g. for OpenGL where it's one thread per context/window, but all surfaces use the same thread by default...), for
11+
which I expect that we'll add the ability to multithread for certain events in `SurfaceTimingOptions` or
12+
`SurfaceTickOptions`. This however has been excluded from the initial 3.0 proposal.
13+
14+
Note that `SDL_AppEvent` is only guaranteed to be called on the event thread for events raised by the window
15+
manager/operating system. As such, we always assume that those events are on the event thread when received and invoke
16+
the window directly. For other events, we should be wary of concurrency. Note that I have absolutely no idea what this
17+
means for things like our `Surface.Continue` method for `IsEventDriven` - right now this isn't implemented. Read more
18+
here: https://github.com/libsdl-org/SDL/issues/11387
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Silk.NET.Windowing
2+
3+
Silk.NET.Windowing is our cross-platform windowing abstraction. For more information about what it is, see the [proposal](../../proposals/Proposal%20-%20Windowing%203.0.md).
4+
5+
As per the proposal, Windowing is implemented in exactly one project/assembly containing the abstractions and one
6+
"reference implementation" given available target information (e.g. TFM). Today, this includes:
7+
- SDL3, used for every platform.
8+
9+
If the user doesn't want to use our reference implementation, it is expected that they use the trimmer to make its
10+
presence benign.
11+
12+
Note that for each "reference implementation" it is expected that there shall be a matching Silk.NET.Input "reference
13+
implementation" capable of receiving an `INativeWindow` from the Silk.NET.Windowing implementation in use. How you
14+
interpret this requirement is up to you, e.g. we could have a Silk.NET.Input Win32-specific implementation that uses
15+
`Win32PlatformInfo` for our SDL3 surface, likewise we could have a Silk.NET.Input SDL3 implementation that receives a
16+
`Win32PlatformInfo` from a Silk.NET.Windowing implementation and automatically creates a wrapping window - this is up to
17+
you (but try to keep it sane please, that last one sounded extremely cursed). Ultimately, the goal is the user being
18+
able to pull in `Silk.NET.Windowing` and `Silk.NET.Input`, create a surface, be able to do `surface.CreateInput()` and
19+
it all Just Work. Right now, this equates to a 1:1 match of Silk.NET.Windowing/Silk.NET.Input implementations, and is
20+
not expected to change.
21+
22+
Silk.NET.Input is completely independent from Silk.NET.Windowing this time around, unlike 1.X/2.X. This is because we
23+
believe the Input HLU can target wider applicability beyond just receiving input for a window, with VR being the
24+
principal use case in mind when making this decision. For more information, read the [Multi-Backend Input proposal](../../proposals/Proposal%20-%20Multi-Backend%20Input.md).
25+
26+
Most of the files within the top-level Windowing directory are exactly as proposed. The exception is the `Surface`
27+
class, which seeks to make as much common as humanly possible (this includes the Render/Update timing logic and some
28+
other auxiliary functions). Beyond that, this is functionally an interface. The actual entry-points into the Windowing
29+
API, `ISurfaceApplication.Run` and `IDetachedSurfaceLifecycle.TryCreate`, are defined `partial`ly with matching
30+
implementation parts in the `Implementations` subdirectories.
31+
32+
To find out more about the implementation details, see the `Implementations` directory.

eng/silktouch/sdl/SDL3/sdl-SDL.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
#define SDL_MAIN_USE_CALLBACKS
21
#include <SDL3/SDL.h>
2+
#include <SDL3/SDL_main.h>
3+
#include <SDL3/SDL_vulkan.h>

eng/silktouch/sdl/remap.rsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
--remap
22
SDL_fabsf=float.Abs
3+
VkSurfaceKHR=ulong
4+
VkInstance=void*
5+
VkPhysicalDevice=ulong
6+
VkAllocationCallbacks=void

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "9.0.100",
4+
"rollForward": "major"
5+
}
6+
}

sources/SDL/SDL/Extensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public static void ThrowError(this ISdl sdl)
2727
}
2828
}
2929

30-
public static void ThrowSdlError(this int ec)
30+
public static void ThrowSdlError(this bool ec)
3131
{
32-
if (ec != 0)
32+
if (!ec)
3333
{
3434
Sdl.ThrowError();
3535
}
3636
}
3737

38-
public static void ThrowSdlError(this int ec, ISdl sdl)
38+
public static void ThrowSdlError(this bool ec, ISdl sdl)
3939
{
40-
if (ec != 0)
40+
if (!ec)
4141
{
4242
sdl.ThrowError();
4343
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public readonly unsafe struct AppEventFunc : IDisposable
12+
{
13+
private readonly void* Pointer;
14+
public delegate* unmanaged<void*, Event*, AppResult> Handle =>
15+
(delegate* unmanaged<void*, Event*, AppResult>)Pointer;
16+
17+
public AppEventFunc(delegate* unmanaged<void*, Event*, AppResult> ptr) => Pointer = ptr;
18+
19+
public AppEventFunc(AppEventFuncDelegate proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
20+
21+
public void Dispose() => SilkMarshal.Free(Pointer);
22+
23+
public static implicit operator AppEventFunc(
24+
delegate* unmanaged<void*, Event*, AppResult> pfn
25+
) => new(pfn);
26+
27+
public static implicit operator delegate* unmanaged<void*, Event*, AppResult>(
28+
AppEventFunc pfn
29+
) => (delegate* unmanaged<void*, Event*, AppResult>)pfn.Pointer;
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public unsafe delegate AppResult AppEventFuncDelegate(void* arg0, Event* arg1);

0 commit comments

Comments
 (0)