S
Silk.NET•3y ago
Perksey

what is the actual asm

what is the actual asm?
57 Replies
Perksey
PerkseyOP•3y ago
damn that's ugly
TechPizza
TechPizza•3y ago
i don't even understand why the static method does 3 calls
Perksey
PerkseyOP•3y ago
what are the implications of using Unsafe.As instead of our as thing
TechPizza
TechPizza•3y ago
1. speed 2. nothing else as long as the IVTable is always the correct type which it seems to be
Perksey
PerkseyOP•3y ago
but if it's not how does it blow up right now we just get a NullReferenceException
TechPizza
TechPizza•3y ago
i think you get a runtime exception unrecoverable would possibly be safer to store the, in this case, _B type inside Vk directly instead of accessing base.CurrentTable
Kai
Kai•3y ago
It can't Unsafe.As just isn't available
TechPizza
TechPizza•3y ago
strongly typed field in Vk it is
Kai
Kai•3y ago
You should really look at the disasm using disasmo or similar, it will show you much of that is the GC transitions I would, but I can't cause backwards compat
TechPizza
TechPizza•3y ago
oh? how would this affect compat 👀
Kai
Kai•3y ago
Well, there is an interface, or there used to be. You can or could change the underlying caching strategy We can't just remove it cause breaking
TechPizza
TechPizza•3y ago
how could you possibly change the vtable if every call expects a strong type anyways 🤔
Kai
Kai•3y ago
You really can't anymore, iirc I couldn't convince @Perksey at the time
TechPizza
TechPizza•3y ago
well yeah, it will just nullrefexc now
Perksey
PerkseyOP•3y ago
we can have a strong typed protected field so long as assignment in CurrentVTable is checked and then Unsafe.As at call site i'm happy with that
TechPizza
TechPizza•3y ago
you can't replace the _B type though
Perksey
PerkseyOP•3y ago
i know, but back compat
Kai
Kai•3y ago
See https://discord.com/channels/521092042781229087/587346162802229298/749748329612836965 for the original asm after I optimized it the last time
TechPizza
TechPizza•3y ago
interesting angryturtle
Kai
Kai•3y ago
The logic is that we'd rather have someone report they are getting nullrefs everywhere instead of it just failing to load and we have to figure it out I could probably invest some time in this, but I'd rather build the direct call stuff that will ship in 3.0
Perksey
PerkseyOP•3y ago
yeah i would leave this opt as community-only
Kai
Kai•3y ago
Cause given the new abstractions + partitioning we can get the preload asm I linked above, which is still a good amount better then the other one
TechPizza
TechPizza•3y ago
pfft i would rather have 3.0 magic
Kai
Kai•3y ago
And for some (especially Vulkan) functions we might even be able to skip transitions, which would result in the literal best asm possible
Perksey
PerkseyOP•3y ago
still in design!
Kai
Kai•3y ago
We should make a notebook somewhere with ideas
Perksey
PerkseyOP•3y ago
just put a note on the 3.0 tracker 😛
Kai
Kai•3y ago
Not detailed enough
Perksey
PerkseyOP•3y ago
you can have big notes now
Kai
Kai•3y ago
Might start a wiki folder or something Markdown??
Perksey
PerkseyOP•3y ago
No description
Perksey
PerkseyOP•3y ago
yep
Kai
Kai•3y ago
Oh that is cool Time to write
Perksey
PerkseyOP•3y ago
so yeah i think i'd be happy with
class Vk
{
private _B _b;
protected override IVTable GetVTable() => _b;
protected override void SetVTable(IVTable vt) => _b = vt as _B ?? throw new("idk");
}

class NativeApiContainer
{
protected virtual IVTable GetVTable() { /* throw whatever exception we throw elsewhere in this file for corrupt impls */ }
protected virtual void SetVTable(IVTable vt) { /* throw whatever exception we throw elsewhere in this file for corrupt impls */ }
public IVTable CurrentVTable { get => GetVTable(); set => SetVTable(value); }
}
class Vk
{
private _B _b;
protected override IVTable GetVTable() => _b;
protected override void SetVTable(IVTable vt) => _b = vt as _B ?? throw new("idk");
}

class NativeApiContainer
{
protected virtual IVTable GetVTable() { /* throw whatever exception we throw elsewhere in this file for corrupt impls */ }
protected virtual void SetVTable(IVTable vt) { /* throw whatever exception we throw elsewhere in this file for corrupt impls */ }
public IVTable CurrentVTable { get => GetVTable(); set => SetVTable(value); }
}
and then using _b in codegen or at least that's the only way i can think of in a non-api breaking way (can't just make the property abstract because that's a break)
TechPizza
TechPizza•3y ago
yeah looks fine, shouldn't break it more than it already is
Kai
Kai•3y ago
This is wrong cause we still allow swapping the vtable to a new one with the same type using CreateVTable (this was a feature that was very important to you, I still don't know why, but hey it exists for a reason I guess)
TechPizza
TechPizza•3y ago
the _B type is private though
Kai
Kai•3y ago
But CreateVTable sort of exposes its constructor
TechPizza
TechPizza•3y ago
then it could still sort of be a strong type _B field in Vk 🙃 /S
Perksey
PerkseyOP•3y ago
that will continue to work, the public API will continue to work as is but just blow up at assignment time rather than call time if you pass an invalid vtable mainly for Vulkan and OpenXR for swapping out device and instance vtables. see CurrentInstance and CurrentDevice for more. if you wanted to implement this i'd be happy to accept a PR for this change
Kai
Kai•3y ago
Ngl good luck you'll need it Maybe I can have a look later 😅
TechPizza
TechPizza•3y ago
sounds like joy, especially on a 8GB laptop 🙃
Perksey
PerkseyOP•3y ago
just do nuke sln --projects silk.net.vulkan and it'll create a solution with only the projects you need, which by my count is just 4 projects (nuke sln --projects vulkan would load all of vulkan + extensions, so probably don't want that!)
TechPizza
TechPizza•3y ago
do extensions not need fixing? when do they all use the same source generator
TechPizza
TechPizza•3y ago
so how would i go about debugging the source generator? 👀 CreateDefaultContext is missing 🔥
Perksey
PerkseyOP•3y ago
so there's a commented out WriteAllText line in NativeApiGenerator, you can use that to get outputs
CreateDefaultContext is missing 🔥
that's a source generated method, so it's probably a silly IDE warning
TechPizza
TechPizza•3y ago
ok i got a "launch debugger" prompt out of nowhere
Perksey
PerkseyOP•3y ago
that's.. odd... unless you put one there
TechPizza
TechPizza•3y ago
was here in VTableGeneration
No description
Perksey
PerkseyOP•3y ago
........................................ that was me fuck well there you go that's how you debug the source generator lmfao feel free to move that to here (the start of source generation) https://github.com/dotnet/Silk.NET/blob/main/src/Core/Silk.NET.SilkTouch/NativeApiGenerator.cs#L32 (but really it should be commented out when not needed)
TechPizza
TechPizza•3y ago
i usually add a DebugAnalyzer configuration to my projects and #if DEBUGANALYZER
Perksey
PerkseyOP•3y ago
that sounds like a much better solution the silktouch.lock thing is so we don't get spammed with debug prompts as we have a lot of targets and tfms etc
TechPizza
TechPizza•3y ago
i could make two PRs when
Perksey
PerkseyOP•3y ago
hah, however you want to do it. we've (kai's) seen it all
TechPizza
TechPizza•3y ago
maybe a lock file that deletes itself after program exit 👀 too bad the compiler is a long-running process does nuke read configurations from the Silk.NET.sln? yes it did, great

Did you find this page helpful?