Skip to content

Commit 1b1aac7

Browse files
committed
all: support SDL3 v3.4.0
ci: add libxtst-dev ci: bump `setup-v` to v1.4 gpu: fix `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_STENCIL_UINT8` -> `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_STENCIL_NUMBER`
1 parent cd9c079 commit 1b1aac7

Some content is hidden

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

45 files changed

+3594
-348
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
timeout-minutes: 30
1515
env:
1616
VFLAGS: -cc tcc -no-retry-compilation
17-
SDL3_VERSION: 3.2.0
17+
SDL3_VERSION: 3.4.0
1818
steps:
1919
- name: Install dependencies
2020
run: |
2121
sudo apt-get update
2222
sudo apt-get install build-essential git make \
2323
pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev \
24-
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev \
24+
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev libxtst-dev \
2525
libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev \
2626
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
2727
libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev \
@@ -37,7 +37,7 @@ jobs:
3737
sudo cmake --install build
3838
3939
- name: Install V
40-
uses: vlang/setup-v@v1
40+
uses: vlang/setup-v@v1.4
4141
with:
4242
check-latest: true
4343

@@ -86,14 +86,14 @@ jobs:
8686
timeout-minutes: 30
8787
env:
8888
VFLAGS: -cc tcc -no-retry-compilation -no-skip-unused
89-
SDL3_VERSION: 3.2.0
89+
SDL3_VERSION: 3.4.0
9090
steps:
9191
- name: Install dependencies
9292
run: |
9393
sudo apt-get update
9494
sudo apt-get install build-essential git make \
9595
pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev \
96-
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev \
96+
libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev libxtst-dev \
9797
libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev \
9898
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
9999
libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev \
@@ -109,7 +109,7 @@ jobs:
109109
sudo cmake --install build
110110
111111
- name: Install V
112-
uses: vlang/setup-v@v1
112+
uses: vlang/setup-v@v1.4
113113
with:
114114
check-latest: true
115115

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ This will create a directory called "thirdparty" which will be used to download
172172
extract the required libraries. To successfully run a provided example or your own projects,
173173
the sdl dlls must be copied to the main application directory. e.g.:
174174
```bash
175-
copy thirdparty\SDL3-3.2.0\lib\x64\SDL3.dll examples\basic_window\
175+
copy thirdparty\SDL3-3.4.0\lib\x64\SDL3.dll examples\basic_window\
176176
cd ..
177177
v run sdl\examples\basic_window\main.v
178178
```

atomic.c.v

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,27 @@ pub fn get_atomic_u32(a &AtomicU32) u32 {
380380
return C.SDL_GetAtomicU32(a)
381381
}
382382

383+
// C.SDL_AddAtomicU32 [official documentation](https://wiki.libsdl.org/SDL3/SDL_AddAtomicU32)
384+
fn C.SDL_AddAtomicU32(a &AtomicU32, v int) u32
385+
386+
// add_atomic_u32 adds to an atomic variable.
387+
//
388+
// This function also acts as a full memory barrier.
389+
//
390+
// ***NOTE: If you don't know what this function is for, you shouldn't use
391+
// it!***
392+
//
393+
// `a` a a pointer to an SDL_AtomicU32 variable to be modified.
394+
// `v` v the desired value to add or subtract.
395+
// returns the previous value of the atomic variable.
396+
//
397+
// NOTE: (thread safety) It is safe to call this function from any thread.
398+
//
399+
// NOTE: This function is available since SDL 3.4.0.
400+
pub fn add_atomic_u32(a &AtomicU32, v int) u32 {
401+
return C.SDL_AddAtomicU32(a, v)
402+
}
403+
383404
// C.SDL_CompareAndSwapAtomicPointer [official documentation](https://wiki.libsdl.org/SDL3/SDL_CompareAndSwapAtomicPointer)
384405
fn C.SDL_CompareAndSwapAtomicPointer(a &voidptr, oldval voidptr, newval voidptr) bool
385406

audio.c.v

Lines changed: 171 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,15 @@ fn C.SDL_GetAudioDeviceName(devid AudioDeviceID) &char
529529

530530
// get_audio_device_name gets the human-readable name of a specific audio device.
531531
//
532+
// **WARNING**: this function will work with SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
533+
// and SDL_AUDIO_DEVICE_DEFAULT_RECORDING, returning the current default
534+
// physical devices' names. However, as the default device may change at any
535+
// time, it is likely better to show a generic name to the user, like "System
536+
// default audio device" or perhaps "default [currently %s]". Do not store
537+
// this name to disk to reidentify the device in a later run of the program,
538+
// as the default might change in general, and the string will be the name of
539+
// a specific device and not the abstract system default.
540+
//
532541
// `devid` devid the instance ID of the device to query.
533542
// returns the name of the audio device, or NULL on failure; call
534543
// SDL_GetError() for more information.
@@ -1021,7 +1030,8 @@ fn C.SDL_GetAudioStreamDevice(stream &AudioStream) AudioDeviceID
10211030

10221031
// get_audio_stream_device querys an audio stream for its currently-bound device.
10231032
//
1024-
// This reports the audio device that an audio stream is currently bound to.
1033+
// This reports the logical audio device that an audio stream is currently
1034+
// bound to.
10251035
//
10261036
// If not bound, or invalid, this returns zero, which is not a valid device
10271037
// ID.
@@ -1069,6 +1079,17 @@ fn C.SDL_GetAudioStreamProperties(stream &AudioStream) PropertiesID
10691079

10701080
// get_audio_stream_properties gets the properties associated with an audio stream.
10711081
//
1082+
// The application can hang any data it wants here, but the following
1083+
// properties are understood by SDL:
1084+
//
1085+
// - `SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN`: if true (the default), the
1086+
// stream be automatically cleaned up when the audio subsystem quits. If set
1087+
// to false, the streams will persist beyond that. This property is ignored
1088+
// for streams created through SDL_OpenAudioDeviceStream(), and will always
1089+
// be cleaned up. Streams that are not cleaned up will still be unbound from
1090+
// devices when the audio subsystem quits. This property was added in SDL
1091+
// 3.4.0.
1092+
//
10721093
// `stream` stream the SDL_AudioStream to query.
10731094
// returns a valid property ID on success or 0 on failure; call
10741095
// SDL_GetError() for more information.
@@ -1080,6 +1101,8 @@ pub fn get_audio_stream_properties(stream &AudioStream) PropertiesID {
10801101
return C.SDL_GetAudioStreamProperties(stream)
10811102
}
10821103

1104+
pub const prop_audiostream_auto_cleanup_boolean = &char(C.SDL_PROP_AUDIOSTREAM_AUTO_CLEANUP_BOOLEAN) // 'SDL.audiostream.auto_cleanup'
1105+
10831106
// C.SDL_GetAudioStreamFormat [official documentation](https://wiki.libsdl.org/SDL3/SDL_GetAudioStreamFormat)
10841107
fn C.SDL_GetAudioStreamFormat(stream &AudioStream, src_spec &AudioSpec, dst_spec &AudioSpec) bool
10851108

@@ -1167,14 +1190,14 @@ fn C.SDL_SetAudioStreamFrequencyRatio(stream &AudioStream, ratio f32) bool
11671190
//
11681191
// The frequency ratio is used to adjust the rate at which input data is
11691192
// consumed. Changing this effectively modifies the speed and pitch of the
1170-
// audio. A value greater than 1.0 will play the audio faster, and at a higher
1171-
// pitch. A value less than 1.0 will play the audio slower, and at a lower
1172-
// pitch.
1193+
// audio. A value greater than 1.0f will play the audio faster, and at a
1194+
// higher pitch. A value less than 1.0f will play the audio slower, and at a
1195+
// lower pitch. 1.0f means play at normal speed.
11731196
//
11741197
// This is applied during SDL_GetAudioStreamData, and can be continuously
11751198
// changed to create various effects.
11761199
//
1177-
// `stream` stream the stream the frequency ratio is being changed.
1200+
// `stream` stream the stream on which the frequency ratio is being changed.
11781201
// `ratio` ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01
11791202
// and 100.
11801203
// returns true on success or false on failure; call SDL_GetError() for more
@@ -1351,7 +1374,7 @@ fn C.SDL_SetAudioStreamInputChannelMap(stream &AudioStream, const_chmap &int, co
13511374
// NOTE: (thread safety) It is safe to call this function from any thread, as it holds
13521375
// a stream-specific mutex while running. Don't change the
13531376
// stream's format to have a different number of channels from a
1354-
// a different thread at the same time, though!
1377+
// different thread at the same time, though!
13551378
//
13561379
// NOTE: This function is available since SDL 3.2.0.
13571380
//
@@ -1368,7 +1391,7 @@ fn C.SDL_SetAudioStreamOutputChannelMap(stream &AudioStream, const_chmap &int, c
13681391
// Channel maps are optional; most things do not need them, instead passing
13691392
// data in the [order that SDL expects](CategoryAudio#channel-layouts).
13701393
//
1371-
// The output channel map reorders data that leaving a stream via
1394+
// The output channel map reorders data that is leaving a stream via
13721395
// SDL_GetAudioStreamData.
13731396
//
13741397
// Each item in the array represents an input channel, and its value is the
@@ -1454,6 +1477,143 @@ pub fn put_audio_stream_data(stream &AudioStream, const_buf voidptr, len int) bo
14541477
return C.SDL_PutAudioStreamData(stream, const_buf, len)
14551478
}
14561479

1480+
// AudioStreamDataCompleteCallback as callback that fires for completed SDL_PutAudioStreamDataNoCopy() data.
1481+
//
1482+
// When using SDL_PutAudioStreamDataNoCopy() to provide data to an
1483+
// SDL_AudioStream, it's not safe to dispose of the data until the stream has
1484+
// completely consumed it. Often times it's difficult to know exactly when
1485+
// this has happened.
1486+
//
1487+
// This callback fires once when the stream no longer needs the buffer,
1488+
// allowing the app to easily free or reuse it.
1489+
//
1490+
// `userdata` userdata an opaque pointer provided by the app for their personal
1491+
// use.
1492+
// `buf` buf the pointer provided to SDL_PutAudioStreamDataNoCopy().
1493+
// `buflen` buflen the size of buffer, in bytes, provided to
1494+
// SDL_PutAudioStreamDataNoCopy().
1495+
//
1496+
// NOTE: (thread safety) This callbacks may run from any thread, so if you need to
1497+
// protect shared data, you should use SDL_LockAudioStream to
1498+
// serialize access; this lock will be held before your callback
1499+
// is called, so your callback does not need to manage the lock
1500+
// explicitly.
1501+
//
1502+
// NOTE: This datatype is available since SDL 3.4.0.
1503+
//
1504+
// See also: set_audio_stream_get_callback (SDL_SetAudioStreamGetCallback)
1505+
// See also: set_audio_stream_put_callback (SDL_SetAudioStreamPutCallback)
1506+
//
1507+
// [Official documentation](https://wiki.libsdl.org/SDL3/SDL_AudioStreamDataCompleteCallback)
1508+
pub type AudioStreamDataCompleteCallback = fn (userdata voidptr, const_buf voidptr, buflen int)
1509+
1510+
// C.SDL_PutAudioStreamDataNoCopy [official documentation](https://wiki.libsdl.org/SDL3/SDL_PutAudioStreamDataNoCopy)
1511+
fn C.SDL_PutAudioStreamDataNoCopy(stream &AudioStream, const_buf voidptr, len int, callback AudioStreamDataCompleteCallback, userdata voidptr) bool
1512+
1513+
// put_audio_stream_data_no_copy adds external data to an audio stream without copying it.
1514+
//
1515+
// Unlike SDL_PutAudioStreamData(), this function does not make a copy of the
1516+
// provided data, instead storing the provided pointer. This means that the
1517+
// put operation does not need to allocate and copy the data, but the original
1518+
// data must remain available until the stream is done with it, either by
1519+
// being read from the stream in its entirety, or a call to
1520+
// SDL_ClearAudioStream() or SDL_DestroyAudioStream().
1521+
//
1522+
// The data must match the format/channels/samplerate specified in the latest
1523+
// call to SDL_SetAudioStreamFormat, or the format specified when creating the
1524+
// stream if it hasn't been changed.
1525+
//
1526+
// An optional callback may be provided, which is called when the stream no
1527+
// longer needs the data. Once this callback fires, the stream will not access
1528+
// the data again. This callback will fire for any reason the data is no
1529+
// longer needed, including clearing or destroying the stream.
1530+
//
1531+
// Note that there is still an allocation to store tracking information, so
1532+
// this function is more efficient for larger blocks of data. If you're
1533+
// planning to put a few samples at a time, it will be more efficient to use
1534+
// SDL_PutAudioStreamData(), which allocates and buffers in blocks.
1535+
//
1536+
// `stream` stream the stream the audio data is being added to.
1537+
// `buf` buf a pointer to the audio data to add.
1538+
// `len` len the number of bytes to add to the stream.
1539+
// `callback` callback the callback function to call when the data is no longer
1540+
// needed by the stream. May be NULL.
1541+
// `userdata` userdata an opaque pointer provided to the callback for its own
1542+
// personal use.
1543+
// returns true on success or false on failure; call SDL_GetError() for more
1544+
// information.
1545+
//
1546+
// NOTE: (thread safety) It is safe to call this function from any thread, but if the
1547+
// stream has a callback set, the caller might need to manage
1548+
// extra locking.
1549+
//
1550+
// NOTE: This function is available since SDL 3.4.0.
1551+
//
1552+
// See also: clear_audio_stream (SDL_ClearAudioStream)
1553+
// See also: flush_audio_stream (SDL_FlushAudioStream)
1554+
// See also: get_audio_stream_data (SDL_GetAudioStreamData)
1555+
// See also: get_audio_stream_queued (SDL_GetAudioStreamQueued)
1556+
pub fn put_audio_stream_data_no_copy(stream &AudioStream, const_buf voidptr, len int, callback AudioStreamDataCompleteCallback, userdata voidptr) bool {
1557+
return C.SDL_PutAudioStreamDataNoCopy(stream, const_buf, len, callback, userdata)
1558+
}
1559+
1560+
// C.SDL_PutAudioStreamPlanarData [official documentation](https://wiki.libsdl.org/SDL3/SDL_PutAudioStreamPlanarData)
1561+
fn C.SDL_PutAudioStreamPlanarData(stream &AudioStream, const_channel_buffers voidptr, num_channels int, num_samples int) bool
1562+
1563+
// put_audio_stream_planar_data adds data to the stream with each channel in a separate array.
1564+
//
1565+
// This data must match the format/channels/samplerate specified in the latest
1566+
// call to SDL_SetAudioStreamFormat, or the format specified when creating the
1567+
// stream if it hasn't been changed.
1568+
//
1569+
// The data will be interleaved and queued. Note that SDL_AudioStream only
1570+
// operates on interleaved data, so this is simply a convenience function for
1571+
// easily queueing data from sources that provide separate arrays. There is no
1572+
// equivalent function to retrieve planar data.
1573+
//
1574+
// The arrays in `channel_buffers` are ordered as they are to be interleaved;
1575+
// the first array will be the first sample in the interleaved data. Any
1576+
// individual array may be NULL; in this case, silence will be interleaved for
1577+
// that channel.
1578+
//
1579+
// `num_channels` specifies how many arrays are in `channel_buffers`. This can
1580+
// be used as a safety to prevent overflow, in case the stream format has
1581+
// changed elsewhere. If more channels are specified than the current input
1582+
// spec, they are ignored. If less channels are specified, the missing arrays
1583+
// are treated as if they are NULL (silence is written to those channels). If
1584+
// the count is -1, SDL will assume the array count matches the current input
1585+
// spec.
1586+
//
1587+
// Note that `num_samples` is the number of _samples per array_. This can also
1588+
// be thought of as the number of _sample frames_ to be queued. A value of 1
1589+
// with stereo arrays will queue two samples to the stream. This is different
1590+
// than SDL_PutAudioStreamData, which wants the size of a single array in
1591+
// bytes.
1592+
//
1593+
// `stream` stream the stream the audio data is being added to.
1594+
// `channel_buffers` channel_buffers a pointer to an array of arrays, one array per
1595+
// channel.
1596+
// `num_channels` num_channels the number of arrays in `channel_buffers` or -1.
1597+
// `num_samples` num_samples the number of _samples_ per array to write to the
1598+
// stream.
1599+
// returns true on success or false on failure; call SDL_GetError() for more
1600+
// information.
1601+
//
1602+
// NOTE: (thread safety) It is safe to call this function from any thread, but if the
1603+
// stream has a callback set, the caller might need to manage
1604+
// extra locking.
1605+
//
1606+
// NOTE: This function is available since SDL 3.4.0.
1607+
//
1608+
// See also: clear_audio_stream (SDL_ClearAudioStream)
1609+
// See also: flush_audio_stream (SDL_FlushAudioStream)
1610+
// See also: get_audio_stream_data (SDL_GetAudioStreamData)
1611+
// See also: get_audio_stream_queued (SDL_GetAudioStreamQueued)
1612+
pub fn put_audio_stream_planar_data(stream &AudioStream, const_channel_buffers voidptr, num_channels int, num_samples int) bool {
1613+
return C.SDL_PutAudioStreamPlanarData(stream, const_channel_buffers, num_channels,
1614+
num_samples)
1615+
}
1616+
14571617
// C.SDL_GetAudioStreamData [official documentation](https://wiki.libsdl.org/SDL3/SDL_GetAudioStreamData)
14581618
fn C.SDL_GetAudioStreamData(stream &AudioStream, buf voidptr, len int) int
14591619

@@ -1641,6 +1801,9 @@ fn C.SDL_ResumeAudioStreamDevice(stream &AudioStream) bool
16411801
// previously been paused. Once unpaused, any bound audio streams will begin
16421802
// to progress again, and audio can be generated.
16431803
//
1804+
// SDL_OpenAudioDeviceStream opens audio devices in a paused state, so this
1805+
// function call is required for audio playback to begin on such devices.
1806+
//
16441807
// `stream` stream the audio stream associated with the audio device to resume.
16451808
// returns true on success or false on failure; call SDL_GetError() for more
16461809
// information.
@@ -1913,7 +2076,7 @@ fn C.SDL_OpenAudioDeviceStream(devid AudioDeviceID, const_spec &AudioSpec, callb
19132076
// Also unlike other functions, the audio device begins paused. This is to map
19142077
// more closely to SDL2-style behavior, since there is no extra step here to
19152078
// bind a stream to begin audio flowing. The audio device should be resumed
1916-
// with `SDL_ResumeAudioStreamDevice(stream);`
2079+
// with SDL_ResumeAudioStreamDevice().
19172080
//
19182081
// This function works with both playback and recording devices.
19192082
//

c/sdl.c.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ $if !windows {
2121
}
2222

2323
$if x64 {
24-
#flag windows -L @VMODROOT/thirdparty/SDL3-3.2.0/lib/x64
24+
#flag windows -L @VMODROOT/thirdparty/SDL3-3.4.0/lib/x64
2525
} $else {
26-
#flag windows -L @VMODROOT/thirdparty/SDL3-3.2.0/lib/x86
26+
#flag windows -L @VMODROOT/thirdparty/SDL3-3.4.0/lib/x86
2727
}
2828

29-
#flag windows -I @VMODROOT/thirdparty/SDL3-3.2.0/include
29+
#flag windows -I @VMODROOT/thirdparty/SDL3-3.4.0/include
3030
#flag windows -lSDL3
3131

3232
// NOTE::

0 commit comments

Comments
 (0)