Skip to content

Commit 04ca2f1

Browse files
committed
Implemeted AIO file writing (more like writing on different threads, actual AIO not yet implemented on linux)
* Reenabled shader pipeline on Linux after the current set of fixes. * Fixed bugs and issues in 'hscp_reader' tool. * Fixed params CLI11 not being able to handle same path values like Windows. (manually stripping quotes from values) * Fixed memory leak when creating resources from baked data.
1 parent 85171d0 commit 04ca2f1

File tree

15 files changed

+119
-39
lines changed

15 files changed

+119
-39
lines changed

source/asset_compiler.bff

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
.Name = 'Assets-Shaders-Mobile'
77
.Requires = { 'assets-mobile', 'Step-Bake-Shaders' }
88
.BuildOptions = {
9+
#if __WINDOWS__
910
'-c shader_tools.dll'
11+
#else // __LINUX__
12+
'-c libshader_tools.so'
13+
#endif
1014
'--param shader:target GLSL'
1115
}
1216
]
@@ -16,7 +20,11 @@
1620
.Name = 'Assets-Shaders-Web'
1721
.Requires = { 'assets-web', 'Step-Bake-Shaders' }
1822
.BuildOptions = {
23+
#if __WINDOWS__
1924
'-c shader_tools.dll'
25+
#else // __LINUX__
26+
'-c libshader_tools.so'
27+
#endif
2028
'--param shader:target WGSL'
2129
}
2230
]

source/code/core/utils/private/native_aio.cxx

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ namespace ice::native_aio
300300
internal.next = nullptr;
301301
internal.native_file_handle = file.native();
302302
internal.request_type = 1; // 1 = read, 2 = write
303-
internal.data_location = memory.location;
303+
internal.data_destination = memory.location;
304304
internal.data_offset = static_cast<ice::u32>(requested_read_offset.value);
305305
internal.data_size = static_cast<ice::u32>(requested_read_size.value);
306306
ice::linked_queue::push(request._port->_requests, ice::addressof(internal));
@@ -310,6 +310,40 @@ namespace ice::native_aio
310310
return ice::native_file::FileRequestStatus::Pending;
311311
}
312312

313+
auto aio_file_write_request(
314+
ice::native_aio::AIORequest& request,
315+
ice::native_file::File const& file,
316+
ice::usize requested_write_offset,
317+
ice::Data data
318+
) noexcept -> ice::native_file::FileRequestStatus
319+
{
320+
using ice::native_file::FileRequestStatus;
321+
322+
if (data.size == 0_B)
323+
{
324+
return FileRequestStatus::Completed;
325+
}
326+
327+
if (data.size.value > ice::u32_max)
328+
{
329+
// Too big of a write
330+
return FileRequestStatus::Error;
331+
}
332+
333+
AIORequestInternal& internal = reinterpret_cast<AIORequestInternal&>(request);
334+
internal.next = nullptr;
335+
internal.native_file_handle = file.native();
336+
internal.request_type = 2; // 1 = read, 2 = write
337+
internal.data_location = data.location;
338+
internal.data_size = ice::u32(data.size.value);
339+
internal.data_offset = ice::u32(requested_write_offset.value);
340+
ice::linked_queue::push(request._port->_requests, ice::addressof(internal));
341+
342+
// Increment the semaphore
343+
sem_post(&request._port->_semaphore);
344+
return ice::native_file::FileRequestStatus::Pending;
345+
}
346+
313347
bool aio_file_await_request(
314348
ice::native_aio::AIOPort port,
315349
ice::native_aio::AIOProcessLimits limits,
@@ -344,36 +378,48 @@ namespace ice::native_aio
344378
if (internal->request_type == 1)
345379
{
346380
// TODO: Handle sizes / offsets above 4gb
347-
ice::i32 const bytes_read = pread(
381+
ssize_t const bytes_read = pread(
348382
internal->native_file_handle,
349-
internal->data_location,
383+
internal->data_destination,
350384
internal->data_size,
351385
internal->data_offset
352386
);
353387

354388
ICE_ASSERT_CORE(bytes_read > 0); // 0 == eof, -1 == error
355389
ICE_ASSERT_CORE(bytes_read == internal->data_size);
356-
357390
out_size = { (ice::usize::base_type) bytes_read };
358391
}
359392
else
360393
{
361-
// TODO: Write requests
362-
ICE_ASSERT_CORE(false);
394+
ssize_t const bytes_written = pwrite(
395+
internal->native_file_handle,
396+
internal->data_location,
397+
internal->data_size,
398+
internal->data_offset
399+
);
400+
401+
ICE_ASSERT_CORE(bytes_written > 0);
402+
ICE_ASSERT_CORE(bytes_written == internal->data_size);
403+
out_size = { (ice::usize::base_type) bytes_written };
363404
}
364405
}
406+
else
407+
{
408+
// Repost the semaphore, because we missed a request.
409+
sem_post(&port->_semaphore);
410+
}
365411
return out_size > 0_B;
366412
}
367413

368414
void aio_complete_request(
369415
ice::native_aio::AIORequest const* request,
370416
ice::native_aio::AIORequestResult result,
371-
ice::usize read_size
417+
ice::usize processed_bytes
372418
) noexcept
373419
{
374420
if (request != nullptr && request->_callback != nullptr)
375421
{
376-
request->_callback(result, read_size, request->_userdata);
422+
request->_callback(result, processed_bytes, request->_userdata);
377423
}
378424
}
379425
#else

source/code/core/utils/private/native_aio.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ namespace ice::native_aio
2424
AIORequestInternal* next;
2525
ice::i32 native_file_handle;
2626
ice::u32 request_type; // 1 == read, 2 == write
27-
void* data_location;
27+
union
28+
{
29+
void* data_destination;
30+
void const* data_location;
31+
};
2832
ice::u32 data_offset;
2933
ice::u32 data_size;
3034
};

source/code/core/utils/private/native_file.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,7 @@ namespace ice::native_file
683683
ice::Data data
684684
) noexcept -> ice::native_file::FileRequestStatus
685685
{
686-
ICE_ASSERT(false, "Missing implementation!");
687-
return FileRequestStatus::Error;
686+
return aio_file_write_request(request, native_file, write_offset, data);
688687
}
689688

690689
auto append_file(
@@ -860,7 +859,14 @@ namespace ice::native_file
860859
ice::String string
861860
) noexcept
862861
{
863-
ice::path::join(path, string);
862+
if (ice::string::any(path))
863+
{
864+
ice::path::join(path, string);
865+
}
866+
else if (ice::string::any(string))
867+
{
868+
path = string;
869+
}
864870
}
865871

866872
#else

source/code/core/utils/private/params.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,39 @@ namespace ice
227227
}
228228
}
229229

230+
#if ISP_LINUX
231+
static auto f = [](std::string p) noexcept -> std::string
232+
{
233+
size_t const start_quote = p.find_first_of('"');
234+
size_t const end_quote = p.find_last_of('"');
235+
if (start_quote != std::string::npos && end_quote != std::string::npos && start_quote < end_quote)
236+
{
237+
return p.substr(start_quote + 1, (end_quote - start_quote) - 1);
238+
}
239+
return p;
240+
};
241+
#endif
242+
230243
// Built-In Validators
231244
if (ice::has_all(definition.flags, PF::ValidatePath))
232245
{
246+
#if ISP_LINUX
247+
opt->transform(f);
248+
#endif
233249
opt->check(CLI::ExistingPath);
234250
}
235251
else if (ice::has_all(definition.flags, PF::ValidateFile))
236252
{
253+
#if ISP_LINUX
254+
opt->transform(f);
255+
#endif
237256
opt->check(CLI::ExistingFile);
238257
}
239258
else if (ice::has_all(definition.flags, PF::ValidateDirectory))
240259
{
260+
#if ISP_LINUX
261+
opt->transform(f);
262+
#endif
241263
opt->check(CLI::ExistingDirectory);
242264
}
243265
return opt;

source/code/systems/resource_system/private/resource_filesystem_baked.cxx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ namespace ice
8888
ice::Allocator& alloc,
8989
ice::ResourceFormatHeader const& header,
9090
ice::HeapString<> origin,
91-
ice::HeapString<> name,
92-
ice::Memory metadata
91+
ice::HeapString<> name
9392
) noexcept
9493
: _allocator{ alloc }
9594
, _header{ header }
@@ -213,20 +212,13 @@ namespace ice
213212
ICE_ASSERT_CORE(read >= 0_B);
214213
ice::string::push_back(utf8_uri, { temp, header.name_size });
215214

216-
ice::Memory metadata = alloc.allocate(ice::usize{ header.meta_size });
217-
read = ice::native_file::read_file(
218-
file, {header.meta_offset}, {header.meta_size}, metadata
219-
);
220-
ICE_ASSERT_CORE(read >= 0_B);
221-
222215
return ice::create_resource_object<BakedFileResource>(
223216
alloc,
224217
provider,
225218
alloc,
226219
header,
227220
ice::move(utf8_file_path),
228-
ice::move(utf8_uri),
229-
metadata
221+
ice::move(utf8_uri)
230222
);
231223
}
232224

source/code/systems/resource_system/private/resource_filesystem_baked.hxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ namespace ice
2323
ice::Allocator& alloc,
2424
ice::ResourceFormatHeader const& header,
2525
ice::HeapString<> origin,
26-
ice::HeapString<> name,
27-
ice::Memory metadata
26+
ice::HeapString<> name
2827
) noexcept;
2928

3029
~BakedFileResource() noexcept override;

source/code/systems/resource_system/private/resource_provider_filesystem.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ namespace ice
206206
ice::HeapString<> uri_base{ _named_allocator };
207207
ice::string::push_format(uri_base, "file://{}/", _virtual_hostname);
208208

209-
create_resource_from_baked_file(_named_allocator, *this, uri_base, filepath);
209+
return create_resource_from_baked_file(_named_allocator, *this, uri_base, filepath);
210210
}
211211
else
212212
{

source/code/tools/hsc_packer/private/hsc_packer_aiostream.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct HailstormAIOWriter
4242
ice::Span<ice::ResourceHandle> _resources;
4343

4444
std::atomic_uint32_t _started_writes;
45+
std::atomic_uint32_t _finished_loads;
4546
std::atomic_uint32_t _finished_writes;
4647

4748
~HailstormAIOWriter() noexcept = default;
@@ -289,6 +290,7 @@ inline auto HailstormAIOWriter::async_write_resource(ice::u32 idx, ice::usize of
289290
{
290291
_started_writes.fetch_add(1, std::memory_order_relaxed);
291292
ice::ResourceResult const load_result = co_await _resource_tracker.load_resource(_resources[idx]);
293+
_finished_loads.fetch_add(1, std::memory_order_relaxed);
292294
if (load_result.resource_status == ice::ResourceStatus::Loaded)
293295
{
294296
bool const success = co_await async_write(offset, data_to_hsdata(load_result.data));

source/code/tools/hsc_reader/private/hsc_reader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class HailStormReaderApp final : public ice::tool::ToolApp<HailStormReaderApp>
4747
// Open the pack file
4848
if (packfile_validate() == false)
4949
{
50-
ICE_LOG(ice::LogSeverity::Retail, LogTag_Main, "Provide input file is not a valid Hailstorm pack.");
50+
ICE_LOG(ice::LogSeverity::Retail, LogTag_Main, "Provided input file is not a valid Hailstorm pack.");
5151
return 1;
5252
}
5353

0 commit comments

Comments
 (0)