Skip to content

Commit 8ee38ae

Browse files
authored
Initial update to create the new API for GPU programming (#640)
* Working ability to pull the physical devices * Working port of instance, surface, and physical device * Work in progress GPU wrapper port, not wokring * Broad major updates to many files * Fixing vk_render_pass errors * More wrapping of the gpu code * Moving buffer functions * On final home stretch, porting renderer.vk.go * Moving over the resize code * New GPU code implementation is now compiling (not running) * Fixing runtime errors with getting up to swap chain creation * Running up to creating the swap chain depth image * New working GPU abstraction * Fixing hard crash on close * Updating other platforms surface creation to new gpu code * Fixing surface creation error messaging * Fix missing return of nil * Updating preTransform and vkColorSpace * Fixing color space bug
1 parent 4b4211f commit 8ee38ae

File tree

93 files changed

+7276
-4535
lines changed

Some content is hidden

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

93 files changed

+7276
-4535
lines changed

src/editor/editor_stage_manager/data_binding_renderer/common_data_binding_renderer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func commonAttached(host *engine.Host, manager *editor_stage_manager.StageManage
6767
UVs: matrix.NewVec4(0, 0, 1, 1),
6868
}
6969
host.RunOnMainThread(func() {
70-
tex.DelayedCreate(host.Window.Renderer)
70+
tex.DelayedCreate(host.Window.GpuInstance.PrimaryDevice())
7171
draw := rendering.Drawing{
7272
Material: mat,
7373
Mesh: mesh,

src/editor/editor_stage_manager/data_binding_renderer/light_entity_data_renderer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (c *LightEntityDataRenderer) Attached(host *engine.Host, manager *editor_st
7373
return
7474
}
7575
lightType := rendering.LightType(data.FieldValueByName("Type").(int))
76-
l := rendering.NewLight(host.Window.Renderer.(*rendering.Vulkan),
76+
l := rendering.NewLight(host.Window.GpuInstance.PrimaryDevice(),
7777
host.AssetDatabase(), host.MaterialCache(), lightType)
7878
l.SetPosition(target.Transform.WorldPosition())
7979
l.SetDirection(target.Transform.Up().Negative())
@@ -144,7 +144,7 @@ func (c *LightEntityDataRenderer) Update(host *engine.Host, target *editor_stage
144144
l := c.Lights[target]
145145
lightType := rendering.LightType(data.FieldValueByName("Type").(int))
146146
if l.light.Type() != lightType {
147-
l.light.Light = rendering.NewLight(host.Window.Renderer.(*rendering.Vulkan),
147+
l.light.Light = rendering.NewLight(host.Window.GpuInstance.PrimaryDevice(),
148148
host.AssetDatabase(), host.MaterialCache(), lightType)
149149
}
150150
l.light.Light.SetPosition(l.light.Transform.WorldPosition())

src/editor/editor_stage_manager/editor_stage_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func (m *StageManager) spawnLoadedEntity(e *StageEntity, host *engine.Host, fs *
742742
m.AddBVH(e.StageData.Bvh, &e.Transform)
743743
host.RunOnMainThread(func() {
744744
for i := range texs {
745-
texs[i].DelayedCreate(host.Window.Renderer)
745+
texs[i].DelayedCreate(host.Window.GpuInstance.PrimaryDevice())
746746
}
747747
draw := rendering.Drawing{
748748
Material: mat,

src/editor/editor_workspace/stage_workspace/stage_spawner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (w *StageWorkspace) spawnTexture(cc *content_database.CachedContent, point
301301
}
302302
}
303303
w.Host.RunOnMainThread(func() {
304-
tex.DelayedCreate(w.Host.Window.Renderer)
304+
tex.DelayedCreate(w.Host.Window.GpuInstance.PrimaryDevice())
305305
draw := rendering.Drawing{
306306
Material: mat,
307307
Mesh: e.StageData.Mesh,

src/editor/project/project_database/content_previews/content_previewer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (p *ContentPreviewer) writePreviewFile(id string, data []byte) error {
153153

154154
func (p *ContentPreviewer) readRenderPass(host *engine.Host, sd rendering.DrawInstance, id string) {
155155
defer p.completeProc()
156-
pixels, err := p.mat.RenderPass().Texture(0).ReadAllPixels(host.Window.Renderer)
156+
pixels, err := p.mat.RenderPass().Texture(0).ReadAllPixels(&host.Window.GpuHost)
157157
sd.Destroy()
158158
if err != nil {
159159
slog.Error("failed to read the mesh preview image from GPU", "id", id, "error", err)

src/editor/project/project_database/content_previews/material_content_preview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (p *ContentPreviewer) renderMaterial(id string) {
4242
}
4343
host.Drawings.AddDrawing(draw)
4444
host.RunBeforeRender(func() {
45-
mat.Shader.DelayedCreate(host.Window.Renderer, host.AssetDatabase())
45+
mat.Shader.DelayedCreate(host.Window.GpuInstance.PrimaryDevice(), host.AssetDatabase())
4646
host.RunAfterFrames(1, func() {
4747
p.readRenderPass(host, sd, id)
4848
})
@@ -91,7 +91,7 @@ func readMaterial(id string, ed EditorInterface) (*rendering.Material, error) {
9191
materialData.RenderPass = "ed_thumb_preview_mesh.renderpass"
9292
materialData.ShaderPipeline = "ed_thumb_preview_mesh.shaderpipeline"
9393
host := ed.Host()
94-
mat, err := materialData.CompileExt(host.AssetDatabase(), host.Window.Renderer, true)
94+
mat, err := materialData.CompileExt(host.AssetDatabase(), host.Window.GpuInstance.PrimaryDevice(), true)
9595
if err != nil {
9696
return nil, err
9797
}

src/editor/project/project_database/content_previews/mesh_content_preview.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p *ContentPreviewer) renderMesh(id string) {
3434
}
3535
host.Drawings.AddDrawing(draw)
3636
host.RunBeforeRender(func() {
37-
mesh.DelayedCreate(host.Window.Renderer)
37+
mesh.DelayedCreate(host.Window.GpuInstance.PrimaryDevice())
3838
host.RunAfterFrames(1, func() {
3939
p.readRenderPass(host, sd, id)
4040
})

src/engine/host.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ func (host *Host) Initialize(width, height, x, y int, platformState any) error {
204204
host.uiThreads.Start()
205205
host.Cameras.Primary.Camera.ViewportChanged(float32(width), float32(height))
206206
host.Cameras.UI.Camera.ViewportChanged(float32(width), float32(height))
207-
host.shaderCache = rendering.NewShaderCache(host.Window.Renderer, host.assetDatabase)
208-
host.textureCache = rendering.NewTextureCache(host.Window.Renderer, host.assetDatabase)
209-
host.meshCache = rendering.NewMeshCache(host.Window.Renderer, host.assetDatabase)
210-
host.fontCache = rendering.NewFontCache(host.Window.Renderer, host.assetDatabase)
211-
host.materialCache = rendering.NewMaterialCache(host.Window.Renderer, host.assetDatabase)
207+
gpuDevice := host.Window.GpuInstance.PrimaryDevice()
208+
host.shaderCache = rendering.NewShaderCache(gpuDevice, host.assetDatabase)
209+
host.textureCache = rendering.NewTextureCache(gpuDevice, host.assetDatabase)
210+
host.meshCache = rendering.NewMeshCache(gpuDevice, host.assetDatabase)
211+
host.fontCache = rendering.NewFontCache(gpuDevice, host.assetDatabase)
212+
host.materialCache = rendering.NewMaterialCache(gpuDevice, host.assetDatabase)
212213
w := weak.Make(host)
213214
host.Window.OnResize.Add(func() { w.Value().resized() })
214215
return nil
@@ -224,11 +225,11 @@ func (host *Host) StartPhysics() {
224225

225226
func (host *Host) InitializeRenderer() error {
226227
w, h := int32(host.Window.Width()), int32(host.Window.Height())
227-
if err := host.Window.Renderer.Initialize(host, w, h); err != nil {
228+
if err := host.Window.GpuInstance.SetupCaches(host, w, h); err != nil {
228229
slog.Error("failed to initialize the renderer", "error", err)
229230
return err
230231
}
231-
if err := host.FontCache().Init(host.Window.Renderer, host.AssetDatabase(), host); err != nil {
232+
if err := host.FontCache().Init(host); err != nil {
232233
slog.Error("failed to initialize the font cache", "error", err)
233234
return err
234235
}
@@ -406,10 +407,11 @@ func (host *Host) Render() {
406407
lights.HasChanges = lights.Lights[i].ResetFrameDirty()
407408
}
408409
host.lighting.Update(host.PrimaryCamera().Position())
409-
if host.Window.Renderer.ReadyFrame(host.Window,
410+
gpuInstance := host.Window.GpuInstance
411+
if gpuInstance.PrimaryDevice().ReadyFrame(gpuInstance, host.Window,
410412
host.Cameras.Primary.Camera, host.Cameras.UI.Camera,
411413
lights, float32(host.Runtime())) {
412-
host.Drawings.Render(host.Window.Renderer, lights)
414+
host.Drawings.Render(gpuInstance.PrimaryDevice(), lights)
413415
}
414416
}
415417
host.Window.SwapBuffers()
@@ -482,14 +484,15 @@ func (host *Host) RunAfterTime(wait time.Duration, call func()) {
482484
// Teardown will destroy the host and all of its resources. This will also
483485
// execute the OnClose event. This will also signal the CloseSignal channel.
484486
func (host *Host) Teardown() {
485-
host.Window.Renderer.WaitForRender()
487+
gpuDevice := host.Window.GpuInstance.PrimaryDevice()
488+
gpuDevice.LogicalDevice.WaitForRender(gpuDevice)
486489
host.OnClose.Execute()
487490
host.processDestroyedEntities()
488491
host.UIUpdater.Destroy()
489492
host.UILateUpdater.Destroy()
490493
host.Updater.Destroy()
491494
host.LateUpdater.Destroy()
492-
host.Drawings.Destroy(host.Window.Renderer)
495+
host.Drawings.Destroy(gpuDevice)
493496
host.textureCache.Destroy()
494497
host.meshCache.Destroy()
495498
host.shaderCache.Destroy()

src/engine/stages/stage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func SetupEntityFromDescription(e *engine.Entity, host *engine.Host, se *EntityD
388388
mat = mat.CreateInstance(texs)
389389
sd := shader_data_registry.Create(mat.Shader.ShaderDataName())
390390
for i := range texs {
391-
texs[i].DelayedCreate(host.Window.Renderer)
391+
texs[i].DelayedCreate(host.Window.GpuInstance.PrimaryDevice())
392392
}
393393
draw := rendering.Drawing{
394394
Material: mat,

src/engine_entity_data/engine_entity_data_light/light_entity_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type LightModule struct {
8888
}
8989

9090
func (c LightEntityData) Init(e *engine.Entity, host *engine.Host) {
91-
light := rendering.NewLight(host.Window.Renderer.(*rendering.Vulkan),
91+
light := rendering.NewLight(host.Window.GpuInstance.PrimaryDevice(),
9292
host.AssetDatabase(), host.MaterialCache(),
9393
rendering.LightType(c.Type))
9494
light.SetPosition(e.Transform.WorldPosition())

0 commit comments

Comments
 (0)