Skip to content

Commit

Permalink
read-write texture feature (#115)
Browse files Browse the repository at this point in the history
* add readWriteTexture feature

* naming fix

* update ignore list
  • Loading branch information
eugenebokhan authored Dec 8, 2020
1 parent dcb3420 commit cc61ddc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Demo/Demo.xcodeproj/xcuserdata/
Demo/Demo.xcworkspace/xcuserdata/
*gen
.swiftpm
.build
19 changes: 19 additions & 0 deletions Sources/Alloy/Core/Extensions/Metal/MTLDevice+Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Metal

public enum Feature {
case nonUniformThreadgroups
case readWriteTextures(MTLPixelFormat)
}

public extension MTLDevice {
Expand All @@ -15,6 +16,24 @@ public extension MTLDevice {
#elseif os(macOS)
return self.supportsFeatureSet(.macOS_GPUFamily1_v3)
#endif

case let .readWriteTextures(pixelFormat):
let tierOneSupportedPixelFormats: Set<MTLPixelFormat> = [
.r32Float, .r32Uint, .r32Sint
]
let tierTwoSupportedPixelFormats: Set<MTLPixelFormat> = tierOneSupportedPixelFormats.union([
.rgba32Float, .rgba32Uint, .rgba32Sint, .rgba16Float,
.rgba16Uint, .rgba16Sint, .rgba8Unorm, .rgba8Uint,
.rgba8Sint, .r16Float, .r16Uint, .r16Sint,
.r8Unorm, .r8Uint, .r8Sint
])

switch self.readWriteTextureSupport {
case .tier1: return tierOneSupportedPixelFormats.contains(pixelFormat)
case .tier2: return tierTwoSupportedPixelFormats.contains(pixelFormat)
case .tierNone: return false
@unknown default: return false
}
}
}
}

0 comments on commit cc61ddc

Please sign in to comment.