# HG changeset patch # User sam # Date 1712399388 -25200 # Node ID b9401944ba0ac91f0733d299b5d14f0b68df31d1 # Parent 450b8a5042cd0d853bc26221db63aeb7946e8d60 do: try to increase compatability with older hardware... diff -r 450b8a5042cd -r b9401944ba0a semicongine/core/gpu_types.nim --- a/semicongine/core/gpu_types.nim Sat Apr 06 16:41:26 2024 +0700 +++ b/semicongine/core/gpu_types.nim Sat Apr 06 17:29:48 2024 +0700 @@ -378,8 +378,14 @@ func glslUniforms*(group: openArray[ShaderAttribute], blockName = "Uniforms", binding: int): seq[string] = if group.len == 0: return @[] + for uniform in group: + if uniform.arrayCount > 0: + assert uniform.theType.size mod 16 == 0, &"Uniform '{uniform.name}': Array elements in a uniform block must align to 16 but current size is {uniform.theType.size} (until we can two different shaders)" + # TODO: read the lines below, having at least std430 would be nice... # currently only a single uniform block supported, therefore binding = 0 - result.add(&"layout(std430, binding = {binding}) uniform T{blockName} {{") + # Also, we might need to figure out how we can ship std430 on newer hardware and normal on older? + # result.add(&"layout(std430, binding = {binding}) uniform T{blockName} {{") + result.add(&"layout(binding = {binding}) uniform T{blockName} {{") var last_size = high(uint64) for attribute in group: assert attribute.size <= last_size, &"The attribute '{attribute.name}' is bigger than the attribute before, which is not allowed" # using smaller uniform-types first will lead to problems (I think due to alignment, there is also some stuff on the internet about this ;) diff -r 450b8a5042cd -r b9401944ba0a semicongine/vulkan/device.nim --- a/semicongine/vulkan/device.nim Sat Apr 06 16:41:26 2024 +0700 +++ b/semicongine/vulkan/device.nim Sat Apr 06 17:29:48 2024 +0700 @@ -32,7 +32,11 @@ assert queueFamilies.len > 0 result.physicalDevice = physicalDevice - let hasUniformBufferStandardLayout = "VK_KHR_uniform_buffer_standard_layout" in physicalDevice.getExtensions() + # TODO: allowing support for physical devices without hasUniformBufferStandardLayout + # would require us to ship different shaders, so we don't support standard layout + # if that will be added, check the function vulkan/shaders.nim:glslUniforms and update accordingly + # let hasUniformBufferStandardLayout = "VK_KHR_uniform_buffer_standard_layout" in physicalDevice.getExtensions() + let hasUniformBufferStandardLayout = false var allExtensions = enabledExtensions & @["VK_KHR_swapchain"] if hasUniformBufferStandardLayout: diff -r 450b8a5042cd -r b9401944ba0a tests/test_materials.nim --- a/tests/test_materials.nim Sat Apr 06 16:41:26 2024 +0700 +++ b/tests/test_materials.nim Sat Apr 06 17:29:48 2024 +0700 @@ -35,7 +35,7 @@ var flag = rect() flag.material = material var scene = Scene(name: "main", meshes: @[flag]) - scene.addShaderGlobalArray("test2", @[0'f32, 0'f32]) + scene.addShaderGlobalArray("test2", @[newVec4f(), newVec4f()]) var engine = initEngine("Test materials") @@ -48,17 +48,17 @@ intermediates = [ attr[Vec2f]("uvout"), ], - uniforms = [attr[float32]("test2", arrayCount = 2)], + uniforms = [attr[Vec4f]("test2", arrayCount = 2)], samplers = @[ attr[Texture]("tex1"), attr[Texture]("tex2"), ], outputs = [attr[Vec4f]("color")], vertexCode = """ - gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1]) / Uniforms.test2[1] * 0.5, position.z, 1.0); + gl_Position = vec4(position.x, position.y + sin(Uniforms.test2[1].x) / Uniforms.test2[1].x * 0.5, position.z, 1.0); uvout = uv;""", fragmentCode = """ - float d = sin(Uniforms.test2[0]) * 0.5 + 0.5; + float d = sin(Uniforms.test2[0].x) * 0.5 + 0.5; color = texture(tex1, uvout) * (1 - d) + texture(tex2, uvout) * d; """, ) @@ -69,7 +69,7 @@ var t = cpuTime() while engine.updateInputs() == Running and not engine.keyIsDown(Escape): var d = float32(cpuTime() - t) - setShaderGlobalArray(scene, "test2", @[d, d * 2]) + setShaderGlobalArray(scene, "test2", @[newVec4f(d), newVec4f(d * 2)]) engine.renderScene(scene) engine.destroy()