swift: Linux Support

This commit is contained in:
2025-06-16 07:14:26 +10:00
parent fbce9754d7
commit 340448cf4c
12 changed files with 53 additions and 43 deletions

View File

@@ -119,7 +119,7 @@ struct Lesson10: AppDelegate
var samplers = [OpaquePointer?](repeating: nil, count: 3)
var texture: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
var blending = false
var filter = 0

View File

@@ -34,7 +34,7 @@ struct Lesson2: AppDelegate
var pso: OpaquePointer? = nil
var vtxBuffer: OpaquePointer? = nil
var idxBuffer: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
mutating func `init`(ctx: inout NeHeContext) throws(NeHeError)
{

View File

@@ -45,7 +45,7 @@ struct Lesson3: AppDelegate
var pso: OpaquePointer? = nil
var vtxBuffer: OpaquePointer? = nil
var idxBuffer: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
mutating func `init`(ctx: inout NeHeContext) throws(NeHeError)
{

View File

@@ -45,7 +45,7 @@ struct Lesson4: AppDelegate
var pso: OpaquePointer? = nil
var vtxBuffer: OpaquePointer? = nil
var idxBuffer: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
var rotTri: Float = 0.0, rotQuad: Float = 0.0

View File

@@ -75,7 +75,7 @@ struct Lesson5: AppDelegate
var pso: OpaquePointer? = nil
var vtxBuffer: OpaquePointer? = nil
var idxBuffer: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
var rotTri: Float = 0.0, rotQuad: Float = 0.0

View File

@@ -70,7 +70,7 @@ struct Lesson6: AppDelegate
var idxBuffer: OpaquePointer? = nil
var sampler: OpaquePointer? = nil
var texture: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
var rot: SIMD3<Float> = .init(repeating: 0.0)
@@ -217,7 +217,7 @@ struct Lesson6: AppDelegate
// Push shader uniforms
var modelViewProj = self.projection * model
SDL_PushGPUVertexUniformData(cmd, 0, &modelViewProj, UInt32(MemoryLayout<matrix_float4x4>.size))
SDL_PushGPUVertexUniformData(cmd, 0, &modelViewProj, UInt32(MemoryLayout<simd_float4x4>.size))
// Draw textured cube
SDL_DrawGPUIndexedPrimitives(pass, UInt32(Self.indices.count), 1, 0, 0, 0)

View File

@@ -72,7 +72,7 @@ struct Lesson7: AppDelegate
var idxBuffer: OpaquePointer? = nil
var samplers = [OpaquePointer?](repeating: nil, count: 3)
var texture: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
struct Light { let ambient: SIMD4<Float>, diffuse: SIMD4<Float>, position: SIMD4<Float> }

View File

@@ -72,7 +72,7 @@ struct Lesson8: AppDelegate
var idxBuffer: OpaquePointer? = nil
var samplers = [OpaquePointer?](repeating: nil, count: 3)
var texture: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
struct Light { let ambient: SIMD4<Float>, diffuse: SIMD4<Float>, position: SIMD4<Float> }

View File

@@ -52,7 +52,7 @@ struct Lesson9: AppDelegate
struct Instance
{
let model: matrix_float4x4
let model: simd_float4x4
let color: SIMD4<Float>
}
@@ -85,7 +85,7 @@ struct Lesson9: AppDelegate
var sampler: OpaquePointer? = nil
var texture: OpaquePointer? = nil
var projection: matrix_float4x4 = .init(1.0)
var projection: simd_float4x4 = .init(1.0)
var twinkle = false
var stars: [Star] = []
@@ -240,7 +240,7 @@ struct Lesson9: AppDelegate
var instanceIDX = 0
for (starIDX, star) in self.stars.enumerated()
{
var model = matrix_float4x4.translation(.init(0.0, 0.0, self.zoom))
var model = simd_float4x4.translation(.init(0.0, 0.0, self.zoom))
model.rotate(angle: self.tilt, axis: .init(1.0, 0.0, 0.0))
model.rotate(angle: star.angle, axis: .init(0.0, 1.0, 0.0))
model.translate(.init(star.distance, 0.0, 0.0))
@@ -305,7 +305,7 @@ struct Lesson9: AppDelegate
SDL_BindGPUVertexStorageBuffers(renderPass, 0, &self.instanceBuffer, 1)
// Push shader uniforms
SDL_PushGPUVertexUniformData(cmd, 0, &self.projection, UInt32(MemoryLayout<matrix_float4x4>.size))
SDL_PushGPUVertexUniformData(cmd, 0, &self.projection, UInt32(MemoryLayout<simd_float4x4>.size))
// Draw star instances
SDL_DrawGPUIndexedPrimitives(renderPass, UInt32(Self.indices.count), UInt32(numInstances), 0, 0, 0)

View File

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: Zlib
*/
import Foundation
import simd
public extension simd_float4x4

View File

@@ -135,9 +135,9 @@ public extension NeHeContext
info.format = SDL_GPU_SHADERFORMAT_SPIRV
return (
try loadShader(bundle.url(forResource: name, withExtension: "vtx.spv"),
info, SDL_GPU_SHADERSTAGE_VERTEX, "main"),
info, SDL_GPU_SHADERSTAGE_VERTEX, "VertexMain"),
try loadShader(bundle.url(forResource: name, withExtension: "frg.spv"),
info, SDL_GPU_SHADERSTAGE_FRAGMENT, "main"))
info, SDL_GPU_SHADERSTAGE_FRAGMENT, "FragmentMain"))
}
else if availableFormats & SDL_GPU_SHADERFORMAT_DXIL == SDL_GPU_SHADERFORMAT_DXIL
{