Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GH Action committed Jan 12, 2025
1 parent b6cd741 commit d787a72
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/sokol/c/sokol_fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
After the user callback returns, and all file data has been loaded
(response.finished flag is set) the request has reached its end-of-life
and will recycled.
and will be recycled.
Otherwise, if there's still data to load (because streaming was
requested by providing a non-zero request.chunk_size), the request
Expand Down Expand Up @@ -610,7 +610,7 @@
without downloading the entire file first (the Content-Length response
header only provides the compressed size). Furthermore, for HTTP
range-requests, the range is given on the compressed data, not the
uncompressed data. So if the web server decides to server the data
uncompressed data. So if the web server decides to serve the data
compressed, the content-length and range-request parameters don't
correspond to the uncompressed data that's arriving in the sokol-fetch
buffers, and there's no way from JS or WASM to either force uncompressed
Expand Down Expand Up @@ -671,7 +671,7 @@
When a request is sent to a channel via sfetch_send(), a "free lane" will
be picked and assigned to the request. The request will occupy this lane
for its entire life time (also while it is paused). If all lanes of a
channel are currently occupied, new requests will need to wait until a
channel are currently occupied, new requests will wait until a
lane becomes unoccupied.
Since the number of channels and lanes is known upfront, it is guaranteed
Expand Down Expand Up @@ -800,7 +800,7 @@
On platforms with threading support, each channel runs on its own
thread, but this is mainly an implementation detail to work around
the blocking traditional file IO functions, not for performance reasons.
the traditional blocking file IO functions, not for performance reasons.
MEMORY ALLOCATION OVERRIDE
Expand Down
2 changes: 1 addition & 1 deletion src/sokol/c/sokol_memtrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@ SOKOL_API_IMPL smemtrack_info_t smemtrack_info(void) {
return _smemtrack.state;
}

#endif /* SOKOL_MEMTRACK_IMPL */
#endif /* SOKOL_MEMTRACK_IMPL */
48 changes: 48 additions & 0 deletions src/sokol/fetch.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,38 @@ enum LogItem {
Clamping_num_channels_to_max_channels,
Request_pool_exhausted,
}
/// sfetch_logger_t
///
/// Used in sfetch_desc_t to provide a custom logging and error reporting
/// callback to sokol-fetch
extern(C)
struct Logger {
extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null;
void* user_data = null;
}
/// sfetch_range_t
///
/// A pointer-size pair struct to pass memory ranges into and out of sokol-fetch.
/// When initialized from a value type (array or struct) you can use the
/// SFETCH_RANGE() helper macro to build an sfetch_range_t struct
extern(C)
struct Range {
const(void)* ptr = null;
size_t size = 0;
}
/// sfetch_allocator_t
///
/// Used in sfetch_desc_t to provide custom memory-alloc and -free functions
/// to sokol_fetch.h. If memory management should be overridden, both the
/// alloc and free function must be provided (e.g. it's not valid to
/// override one function but not the other)
extern(C)
struct Allocator {
extern(C) void* function(size_t, void*) alloc_fn = null;
extern(C) void function(void*, void*) free_fn = null;
void* user_data = null;
}
/// configuration values for sfetch_setup()
extern(C)
struct Desc {
uint max_requests = 0;
Expand All @@ -42,10 +58,12 @@ struct Desc {
Allocator allocator;
Logger logger;
}
/// a request handle to identify an active fetch request, returned by sfetch_send()
extern(C)
struct Handle {
uint id = 0;
}
/// error codes
enum Error {
No_error,
File_not_found,
Expand All @@ -55,6 +73,7 @@ enum Error {
Invalid_http_status,
Cancelled,
}
/// the response struct passed to the response callback
extern(C)
struct Response {
Handle handle;
Expand All @@ -73,6 +92,7 @@ struct Response {
Range data;
Range buffer;
}
/// request parameters passed to sfetch_send()
extern(C)
struct Request {
uint channel = 0;
Expand All @@ -82,59 +102,87 @@ struct Request {
Range buffer;
Range user_data;
}
/// setup sokol-fetch (can be called on multiple threads)
extern(C) void sfetch_setup(const Desc *) @system @nogc nothrow;
/// setup sokol-fetch (can be called on multiple threads)
void setup(scope ref Desc desc) @trusted @nogc nothrow {
sfetch_setup(&desc);
}
/// discard a sokol-fetch context
extern(C) void sfetch_shutdown() @system @nogc nothrow;
/// discard a sokol-fetch context
void shutdown() @trusted @nogc nothrow {
sfetch_shutdown();
}
/// return true if sokol-fetch has been setup
extern(C) bool sfetch_valid() @system @nogc nothrow;
/// return true if sokol-fetch has been setup
bool valid() @trusted @nogc nothrow {
return sfetch_valid();
}
/// get the desc struct that was passed to sfetch_setup()
extern(C) Desc sfetch_desc() @system @nogc nothrow;
/// get the desc struct that was passed to sfetch_setup()
Desc desc() @trusted @nogc nothrow {
return sfetch_desc();
}
/// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t))
extern(C) int sfetch_max_userdata_bytes() @system @nogc nothrow;
/// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t))
int maxUserdataBytes() @trusted @nogc nothrow {
return sfetch_max_userdata_bytes();
}
/// return the value of the SFETCH_MAX_PATH implementation config value
extern(C) int sfetch_max_path() @system @nogc nothrow;
/// return the value of the SFETCH_MAX_PATH implementation config value
int maxPath() @trusted @nogc nothrow {
return sfetch_max_path();
}
/// send a fetch-request, get handle to request back
extern(C) Handle sfetch_send(const Request *) @system @nogc nothrow;
/// send a fetch-request, get handle to request back
Handle send(scope ref Request request) @trusted @nogc nothrow {
return sfetch_send(&request);
}
/// return true if a handle is valid *and* the request is alive
extern(C) bool sfetch_handle_valid(Handle) @system @nogc nothrow;
/// return true if a handle is valid *and* the request is alive
bool handleValid(Handle h) @trusted @nogc nothrow {
return sfetch_handle_valid(h);
}
/// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks
extern(C) void sfetch_dowork() @system @nogc nothrow;
/// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks
void dowork() @trusted @nogc nothrow {
sfetch_dowork();
}
/// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback
extern(C) void sfetch_bind_buffer(Handle, Range) @system @nogc nothrow;
/// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback
void bindBuffer(Handle h, Range buffer) @trusted @nogc nothrow {
sfetch_bind_buffer(h, buffer);
}
/// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback
extern(C) void* sfetch_unbind_buffer(Handle) @system @nogc nothrow;
/// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback
scope void* unbindBuffer(Handle h) @trusted @nogc nothrow {
return sfetch_unbind_buffer(h);
}
/// cancel a request that's in flight (will call response callback with .cancelled + .finished)
extern(C) void sfetch_cancel(Handle) @system @nogc nothrow;
/// cancel a request that's in flight (will call response callback with .cancelled + .finished)
void cancel(Handle h) @trusted @nogc nothrow {
sfetch_cancel(h);
}
/// pause a request (will call response callback each frame with .paused)
extern(C) void sfetch_pause(Handle) @system @nogc nothrow;
/// pause a request (will call response callback each frame with .paused)
void pause(Handle h) @trusted @nogc nothrow {
sfetch_pause(h);
}
/// continue a paused request
extern(C) void sfetch_continue(Handle) @system @nogc nothrow;
/// continue a paused request
void continueFetching(Handle h) @trusted @nogc nothrow {
sfetch_continue(h);
}
21 changes: 21 additions & 0 deletions src/sokol/memtrack.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// machine generated, do not edit

module sokol.memtrack;

extern(C)
struct Info {
int num_allocs = 0;
int num_bytes = 0;
}
extern(C) Info smemtrack_info() @system @nogc nothrow;
Info info() @trusted @nogc nothrow {
return smemtrack_info();
}
extern(C) void* smemtrack_alloc(size_t, void*) @system @nogc nothrow;
scope void* alloc(size_t size, scope void* user_data) @trusted @nogc nothrow {
return smemtrack_alloc(size, user_data);
}
extern(C) void smemtrack_free(void*, void*) @system @nogc nothrow;
void free(scope void* ptr, scope void* user_data) @trusted @nogc nothrow {
smemtrack_free(ptr, user_data);
}

0 comments on commit d787a72

Please sign in to comment.