#Krypton - C++ Vulkan Engine

294 messages · Page 1 of 1 (latest)

void cedar
#

So basically, in September-October 2021 I wrote a purely ray traced Vulkan engine. By November, I decided to recycle a lot of the code but restart with what I had learned. So with that, Krypton was born. By March I had sold my RTX 2080 which meant I was a Mac user. I then decided to create a RHI to cover Metal and Vulkan, which turned out to be the biggest waste of time ever (Though I grew to very much like Metal, especially MSL). While it was very interesting to do, I never had much motivation because you'd essentially have to write two implementations next to your rendering code. This is why in mid-November 2022 I deleted the RHI and decided to start over again. As of writing this I now have a functioning render loop again, and we'll now see where the journey takes me.

#

and now I've created this thread so I can put some updates here, if anyone should care.

void cedar
#

brilliant; apart from a single validation error about my descriptor sets everything now runs and works. lovely to see

white fulcrum
#

Following along for the ride frogeheart

quiet stag
#

welcome back 🙂

void cedar
#

only one hazard sync error but I don't think its right

#

colours are fucked

#

but it's working

quiet stag
#

call it "night theme"

void cedar
#

combined length of 1100 loc, with some builder files that are like 450 loc

#

the RHI on the other hand was 10500 loc and could do the same

quiet stag
#

lol

void cedar
#

@quiet stag this looks right, no?

#

I removed the sRGB adjustment in the shader

#

ahh I know why

#

because I told ImGui with a flag that I support sRGB now

quiet stag
#

ah

#

yes that looks like the real deal

#

if you set classic color sceme you should get that ugly purple and washed out red

void cedar
#
ImGuiConfigFlags_IsSRGB                 = 1 << 20,  // Application is SRGB-aware.

hmm

quiet stag
#

yes

#

the one you have tehre is the new default one, "Dark" or what its called

#

just pick from the top there

#

dark, light and classic

void cedar
#

did it look like that at some point?

quiet stag
#

yep

#

for a VERY long time as well

#

ah i think that one here is even older

void cedar
#

so I don't have to decode them in the shader

#

(if I remember correctly that pow(col, 2.2) was decoding)

quiet stag
#

i have not touched proper colorspaceisms yet, at all

void cedar
#

I love my shader compiler tool that I made

#

compiles everything at compile time into these library files that I can then extract SPIR-V from at runtime

quiet stag
#

: )

#

reminds me to add hot reloadisms

void cedar
#

yeah I can do that too then

#

bit more complicated but should work

void cedar
#

ok what to do next

quiet stag
#

volume cluster renderer

void cedar
#

anyone have any font recommendations

#

I just tried Roboto but it looks weird and not very clean

#

do I have to change anything?

#

Perhaps I just have to slap some MSAA onto it?

quiet stag
#

hmm

#

i use .. hmm hang on

#

RobotoCondensed-Regular

void cedar
#

ok now it freezes

#

wtf

quiet stag
#

Kufam-Regular and Mali-Regular look neat too

void cedar
#

don't wanna configure msaa right now because I would have to restructure a bit of my ImGui renderer

#

also I'll have to figure out a good way to have a graph based pass thing going on soon

#

wanna have something like that

void cedar
#

and wtf is Mali

#

looks like that old Samsung font

quiet stag
#

heh

#

i think settled with RobotoCondensed

#

the other two look not bad either with large fontsize

void cedar
#

im just gonna go with Roboto now because its included with imgui

quiet stag
#

7800 deletions 🙂

void cedar
#

I think I will look into fiber task libs on thursday/friday so that I can load multiple assets at once and use multiple threads at will

#

and ill then go to graph based rendering

#

should be fun

quiet stag
#

are you looking at other engines while dinglefarting around?

void cedar
#

nope

#

never have actually

#

tbh I also think my biggest issue is that I don't know any good ways to structure large code

#

so I get lost quickly usually

#

I've never worked on a large code base and I taught all of this to myself using common sense and stackoverflow

quiet stag
#

: )

#

nothing wrong with that

void cedar
#

sure, but I still think it would help

quiet stag
#

im not happy with most engines i look at, from a structural point of view

#

probably due to my c# background and oopisms

#

many engines are also "just" modelviewers

void cedar
#

so I tested enkiTS out yesterday, and it’s quite simple and works right away

#

found a funny thing though: running the task that creates a command pool, records a command buffer to copy the staging buffer of a texture to the actual texture, submit that buffer, and then wait on that to complete is all faster than vkGetPhysicalDeviceSurfaceCapabilitiesKHR. And that function isn’t even the slowest of all the swapchain creation stuff

#

… however I had a good look at entt yesterday. So when my exams end I’ll try and use entt and implement a basic scene graph, after which I will add a threaded model loading queue to fill that scene graph

#

hope that works out

void cedar
#

hmm I wonder if making some sort of custom thread scheduler is actually worth it

#

so my nvidia gpu has 2 dedicated transfer queues, so the naive solution would be to use 2 CPU threads to submit any work onto those queues

#

however, I am allowed to submit commands from any CPU thread, as long as the submit call is synchronized with a mutex or similar

#

which probably also means that I can have n CPU threads that all just submit, as long as I have that mutex in place

#

so no custom thread scheduler is not worth it, ok

#

though I am still interested to see how one would manage all the command pools for all the threads that might submit something.

#

like should I have a globally accessible struct that contains all the VkQueue handles and their mutexes, together with a array of VkCommandPools so that one pool is always available to a threadß

#

ok well then

solemn flare
#

the worm in the brain never stops eating

dapper owl
void cedar
solemn flare
void cedar
void cedar
#

i love and hate multithreading in c++

dapper owl
#

running with scissors

void cedar
#

the camera quality of that gif is so shit

quiet stag
#

unfortunately

void cedar
#

you could redo it

dapper owl
#

2023: deep learning magic to improve all discord gifs to high quality

void cedar
#

yay my first issue with ECS

#
            entt::entity root;
            {
                auto lock = std::scoped_lock(editor->registryMutex);
                root = registry.create();
                auto& rootRelationship = registry.emplace<NodeRelationship>(root);

I do create a NodeRelationship component for my root entity

#

ah fuck

#

I can't read

#

nvm

#

I was reading the wrong entity

quiet stag
#

sweet

#

font is ugly af tho :>

#

i have like 300loc just to display some things with imgui in my thing

#

super annoying

void cedar
#

yeah it’s getting longer for me too

#

i’m somewhat considering a header that includes RAII imgui stuff and more stuff for stdlib or my stuff

quiet stag
#

ye im also considering to wrap that shit somehow behind some Window/Control isms

void cedar
#

well first im gonna cook this lasagna

#

then i’ll continue with adding a file menu to select gltf files to add

quiet stag
#

: D

#

bon appetit

void cedar
#

because currently i just click a button and it’ll always load mcsponza.gltf

void cedar
#

might kindly steal your theme later on

#

and then look into fonts again someday

quiet stag
#

its someone's

#

oi, 31 stars Oo

#

there are a few more

#

its kinda scattered across various ocornut/imgui issues and single imgui styles in various github repos

#

if you find other cool ones, please send a PR to this repo, in the same style if possible

void cedar
#

where is yours in here

#

haha

#

dougbinks (the last one) doesn't even compile

#

and its ancient

quiet stag
#

ye some might need a little massage

#

mine is not in thre, but you can grab mine from deccer/EngineKit/src/UIRenderer/UIRenderer.cs

void cedar
#

daaaaamn

quiet stag
#

ye there are like 6 or 7 of those issues

#

"..PART1.." "..PART2..." etc

quiet stag
void cedar
#

fucking imgui popup and aligning to the right took way too fucking long

void cedar
void cedar
#

looks good tho

quiet stag
#

noice

#

i need something like that too 😄

void cedar
#

fuck yeah

quiet stag
#

do you hide something behind the collapsed primitive nodes?

void cedar
#

wdym?

quiet stag
#

Circle.022_11 for example

#

it suggests theres more nodes underneath

void cedar
#

just an object

quiet stag
#

ah

void cedar
#

now to some cleanups

#

and then I can render stuff

#

though I already really like the look of this

quiet stag
#

rotation loks misplaced

#

but i understand why it looks like that

void cedar
#

yeah it's a quat

quiet stag
#

ye

void cedar
#

dunno how to change that

quiet stag
#

maybe for display reasons it makes sense to go to euler angles

void cedar
#

but that's definitely something I could change

#

yeah

#

whaaaat

#

clion actually displays it as a quaternion

#

how funny is that

quiet stag
#

yeah

#

i suspect it ships some viz' packs for commonly used libs

void cedar
#

I think I might just butcher this thread briefly to just dump stuff about my MoltenVK PR right now

#

so MoltenVK doesn't properly report that some formats that the M1 and M2 do support with Metal

#

and so, for example, it says M1 and M2 on macOS don't support ASTC and they don't support 4-bit and packed formats like e.g. R4G4B4A4

#

though if you run that M1 on an iOS/iPadOS device it suddenly does support those, but doesn't support BC

#

this is just because the current madness that MoltenVK has here differentiates between iOS and macOS and just assumes that some requirement is always a thing on some platform

#

so it hardcodes that ASTC and those 4-bit formats are not available on macOS

#

and hardcodes that BC isn't supported on iOS

#

but that should depend entirely on the GPU that it's running on, not the OS

#

especially since Metal 3, as the drivers are nearly exactly the same now and the same GPUs are available on both platforms

#

so I have this massive urge to just Ctrl+A, Del this whole thing

#

because it's also just littered with macros everywhere, when you could instead use some virtual class to handle every format generically

#

this is just hard to read

#

however, as I have to put my PR in before Friday, I might just hack this together quickly

#

like, this whole thing should just connect the Vulkan format with the Metal format, give it some basic information , and then put a requirement on that format based on a lambda, or a generic one that checks the MTLFeatureSet or MTLGPUFamily

#

according to the docs all formats are introduced by GPU Family

#

so say I want to check for the M1, I would get every format that is supported by Apple7 and Mac2 (and before, support has never been removed, yet)

#

so that format would just go and do [device supportsFamily:MTLGPUFamilyApple7] and then advertise the according Vulkan format as supported

#

also funny bug, VulkanCapsViewer and vkconfig error out saying "no ICD found", but the vulkaninfo in vkconfig still reports the device and all the features properly

#

the GPU capabilities are directly tied to the platform, which is a plain wrong assumption

void cedar
#

oh no

addFormatCustom(MTLPixelFormatA8Unorm, MVKMTLViewClass::Color8, [](MVKMTLFormatDesc desc, id<MTLDevice> device) { return ([device supportsFamily:MTLGPUFamilyApple6]) ? kMVKMTLFmtCapsRF : kMVKMTLFmtCapsRF; });
void cedar
#

would it be a good idea to 'streamline' all vertex formats because I use glTF anyway?

#

like say I will convert everything to some specific format

#

like if you don't use float3 for your position idk what else I'm supposed to use

quiet stag
#

at least for the geometry pass(es)

#

you might want some debug pass which just has PositionColor and imgui has PositionUv and Color as uint iirc

#

and one for FSTs PositionUv

void cedar
#

not sure what you mean?

quiet stag
#

ignore what i said

#

i dont even know what your engine is doing/capable of 🙂

void cedar
#

though I essentially want to make an editor for a 2D game I want to make

#

something like stardew valley

#

but for now I might want to load glTF models for fun

#

also because I kinda want to write some PBR shaders and whatnot

quiet stag
#

gltf kinda describes your vertexformat already indeed

#

what i meant is, when you render debug cubes or shapes for whatever ... visualize light fixtures or other objects

#

you might want to use a different vertexformat

#

or just disable unused attributes from the thing you used for your gltfisms ?

void cedar
#

uhh

quiet stag
#

still no idea what i mean?

void cedar
#

no not really

quiet stag
void cedar
#

I've done a minor restructuring to how this all works and have something new going

#

essentially, I'm just gonna try and make a simple game now which I'll try and build on as much as I can

#

my current concept has this ECS for every entity and gives that some properties here and there

#

though I now want to allow scripting through Lua so I can change the behaviour and tweak everything while the game is running

#

still not quite sure how to efficiently have multiple Lua scripts, but what I'm aiming at is, for example, the InputSystem and that will iterate over the View with some Input component which will then contain some reference to some Lua function which will then be executed

quiet stag
#

: )

#

what kind of game?

void cedar
#

like a 2d dungeon type of game

#

while you're here do you have any resources on how to design the systems for ECSes? Using entt::dispatcher for example? Or how should I handle these events

quiet stag
#

noice

#

i am not familiar with entt really

#

but dispatcher just sounds like an event emitter, which others can subscribe to

#

like, when you step on a trapdoor tile of sorts

#

other tiles in the room could disintegrate or dispensers in various corners could shoot arrows at you

#

or some music is played

#

rather than having a 100k line long if else block in your OnPlayerMove function

quiet stag
#

a messagebus/eventdispatcher and evensubscribers

void cedar
#

how do the subscribers look like though

quiet stag
#

like i said, i have no clue in the context of entt

#

but a subscriber could be anything

#

let me try to create a little shrimple

#
class Bus
{
    Dictionary<TEvent, List<Callback>> _subscriptions;

    void PublishEvent(TEvent event)
    {
        if (_subscriptions.TryGet(event, out var callbacks))
        {
            foreach (var callback in callbacks)
            {
                callback(event);
            }
        }
    }

    int Subscribe<TEvent>(Callback callback)
    {
        if (_subscriptions.TryGet(event, out var callbacks))
        {
            _subscriptions.Add(TEvent, callback);
        }
        else
        {
            _subscriuptions.Add(Event, new List<Callback> { callback });
        }
    }
};

class Producer
{
    ctor(Bus bus)

    void OnFoo()
    {
        bus.PublishEvent(new FooEvent{ payload });
    }
}

class Consumer
{
    ctor(Bus bus)
    {
        us.Subscribe<FooEvent>(handleFoo);
    }
    
    void handleFoo(FooEvent fooEvent)
    {
         //... use fooEvent payload to pay yo mama
    }
}
void cedar
#

I think for the first part I'm just gonna have my GLFW callbacks act as the "systems"

#

so the key callback will do everything related to updating the player position

#

or text input (in the future)

#

will also have to look and see how I will do text rendering and UI

#

also should I make every tile an actual entity? Or just the entities that have some behaviour connected to them?

quiet stag
#

there is a very neat talk about that

#

let me try to find it

#

from a well known person whos name i cant remember atm, let me find it

#

bob nystrom

#

this yt channel has a lot of cool shit in it, not just this one

#

hehe seeing this again makes me want to resurrect my other 2004384 dungeon crawler trial and errors XD

void cedar
#

thanks for that video, gonna watxh it tomorrow

void cedar
void cedar
#

ok I think my problem is not knowing how the game loop of a game works

#

in the sense that if my player attacks, does it instantly take away HP of the enemy? or how does that work?

#

I can imagine that becoming recursive or being really expensive

#

so... how does that work?

quiet stag
#

you would have a HealthSystem for instance

#

or a Fight/AttackSystem

#

the fight system takes care of hit and block, when hit, you could create a damagecomponent, which the healthsystem/damagesystem picks up and reduces your health by the value in damagecomponent and then you remove the damagecomponent again

void cedar
#

say I would use GLFW callbacks for my systems

#

couldn't I have some weird desyncs?

#

where if the mouse input comes before the movement input, it could be attacking from the old position in that frame

#

and there would not be any guarantee about the order of the input

#

or would that even matter at all?

#

because otherwise I would just do what most other people in the examples with SDL did, where they just essentially do glfwGetKey in an UpdateMovement function

#

and the order would always be the same

#

Another thing, is it an antipattern if I store a entt::entity handle in my Game class that would represent the player or the camera? Because then I wouldn't have the system that just updates all entities with certain components, but would always assume there's only one player and only one camera.

void cedar
#

... writing an AI in Python to play 2048 trial 1

#

Over 1000 runs the highest score was 2704, with an average score of 695

void cedar
#

so ive decided to write a simple 2d game and get it as far as I can (i have a rather good idea)

#

but then when I have it in a pretty good state I will try and factor out a few things that I will then call my „engine“ that I will try and reuse across revisions of my game(s)

#

because I have in fact never written a game

#

so I was going in quite blind

#

I think that should help significantly

#

still not quite sure how I wanna go about scripting

#

because in the end I want to have a simple level editor I can use to efficiently design my map

#

and optimally I would want to use a simple scripting framework I could use so I can quickly write scripts to get custom behaviour quickly

#

I was thinking about Lua but it seems quite limited to me

#

not sure how one would actually have a large scale Lua codebasw

#

don’t think I want to do my own language, thats something for much later

quiet stag
#

ss13 clone? 😄

void cedar
#

something in that direction yes

#

i can find their gh org

#

but wheres the repo

quiet stag
#

whose?

#

i am only aware of ss14, a ss13 remake/clone... with repo etc, all made with c#