# HG changeset patch # User Sam # Date 1683112499 -25200 # Node ID bfbadd0758c63a1ef4f6af99c633250a6e6177d1 # Parent 315c809c8e60e15f511344cea92402caba6d9e6c did: fix whole bunch of bugs (threading + amd vulkan driver) diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/audio.nim --- a/src/semicongine/audio.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/audio.nim Wed May 03 18:14:59 2023 +0700 @@ -1,7 +1,8 @@ import std/tables import std/locks +import std/logging except Level -when defined(windows): # used for setting audio thread priority on windows +when defined(windows): # used for setting audio thread priority import winim when defined(linux): import std/posix @@ -179,19 +180,21 @@ # Threaded implementation, usually used for audio -var mixer* = createShared(Mixer) +var + mixer* = createShared(Mixer) + audiothread: Thread[void] proc audioWorker() {.thread.} = - when defined(linux): - discard nice(-20) + mixer[].setupDevice() onThreadDestruction(proc() = mixer[].lock.withLock(mixer[].destroy()); freeShared(mixer)) - mixer[].setupDevice() while true: mixer[].updateSoundBuffer() proc startMixerThread*() = mixer[] = initMixer() - var audiothread: Thread[void] audiothread.createThread(audioWorker) + debug "Created audio thread" when defined(window): SetThreadPriority(audiothread.handle(), THREAD_PRIORITY_TIME_CRITICAL) + when defined(linux): + discard pthread_setschedprio(Pthread(audiothread.handle()), cint(-20)) diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/platform/linux/audio.nim --- a/src/semicongine/platform/linux/audio.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/platform/linux/audio.nim Wed May 03 18:14:59 2023 +0700 @@ -15,7 +15,7 @@ snd_pcm_hw_params_p* = ptr object snd_pcm_uframes_t* = culong snd_pcm_sframes_t* = clong -{.pragma: alsafunc, importc, cdecl, dynlib: "libasound.so" .} +{.pragma: alsafunc, importc, cdecl, dynlib: "libasound.so.2" .} proc snd_pcm_open*(pcm_ref: ptr snd_pcm_p, name: cstring, streamMode: StreamMode, openmode: OpenMode): cint {.alsafunc.} proc snd_pcm_close*(pcm: snd_pcm_p): cint {.alsafunc.} proc snd_pcm_hw_params_malloc*(hw_params_ptr: ptr snd_pcm_hw_params_p): cint {.alsafunc.} diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/platform/linux/window.nim --- a/src/semicongine/platform/linux/window.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/platform/linux/window.nim Wed May 03 18:14:59 2023 +0700 @@ -1,15 +1,16 @@ import std/options import std/tables import std/strformat -import std/logging import x11/xlib, x11/xutil, x11/keysym, - x11/xatom + x11/x11pragma import x11/x +echo x11pragma.libX11 + import ../../events import ../../math/vector @@ -97,7 +98,8 @@ var wm_state = window.display.XInternAtom("_NET_WM_STATE", 1) - wm_state_operation = window.display.XInternAtom(if enable: "_NET_WM_STATE_ADD" else: "_NET_WM_STATE_REMOVE", 1) + op = (if enable: "_NET_WM_STATE_ADD" else: "_NET_WM_STATE_REMOVE") + wm_state_operation = window.display.XInternAtom(cstring(op), 1) wm_fullscreen = window.display.XInternAtom("_NET_WM_STATE_FULLSCREEN", 1) xev = XEvent( theType: ClientMessage, diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/vulkan/descriptor.nim --- a/src/semicongine/vulkan/descriptor.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/vulkan/descriptor.nim Wed May 03 18:14:59 2023 +0700 @@ -89,6 +89,7 @@ assert layout.device.vk.valid assert layout.vk.valid + var layouts: seq[VkDescriptorSetLayout] var descriptorSets = newSeq[VkDescriptorSet](nframes) for i in 0 ..< nframes: diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/vulkan/instance.nim --- a/src/semicongine/vulkan/instance.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/vulkan/instance.nim Wed May 03 18:14:59 2023 +0700 @@ -53,12 +53,14 @@ ): Instance = let requiredExtensions = REQUIRED_PLATFORM_EXTENSIONS & @["VK_KHR_surface"] & instanceExtensions - for i in layers: - assert i in getLayers(), $i for i in requiredExtensions: assert i in getInstanceExtensions(), $i + var availableLayers: seq[string] + for i in layers: + if i in getLayers(): + availableLayers.add i var - layersC = allocCStringArray(layers) + layersC = allocCStringArray(availableLayers) instanceExtensionsC = allocCStringArray(requiredExtensions) appinfo = VkApplicationInfo( sType: VK_STRUCTURE_TYPE_APPLICATION_INFO, @@ -69,7 +71,7 @@ createinfo = VkInstanceCreateInfo( sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, pApplicationInfo: addr(appinfo), - enabledLayerCount: layers.len.uint32, + enabledLayerCount: availableLayers.len.uint32, ppEnabledLayerNames: layersC, enabledExtensionCount: requiredExtensions.len.uint32, ppEnabledExtensionNames: instanceExtensionsC diff -r 315c809c8e60 -r bfbadd0758c6 src/semicongine/vulkan/pipeline.nim --- a/src/semicongine/vulkan/pipeline.nim Wed May 03 00:43:44 2023 +0700 +++ b/src/semicongine/vulkan/pipeline.nim Wed May 03 18:14:59 2023 +0700 @@ -183,7 +183,7 @@ nil, addr(result.vk) ) - result.descriptorPool = result.device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1'u32)]) + result.descriptorPool = result.device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32(inFlightFrames))]) result.descriptorSets = result.descriptorPool.allocateDescriptorSet(result.descriptorSetLayout, inFlightFrames) discard result.uniforms # just for assertion result.setupUniforms(inFlightFrames=inFlightFrames)