Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbda307b

Browse files
committed
add support for optional returns
1 parenta7aca68 commitbda307b

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

‎Demos/DemoBoids/main.swift‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,24 @@ try withGLFW {
9696

9797

9898
letvertexBuffer= vertexData.withUnsafeBytes{ bytes->Bufferin
99-
letbuffer= device.createBuffer(descriptor:BufferDescriptor(
99+
guardlet buffer= device.createBuffer(descriptor:BufferDescriptor(
100100
usage:.vertex,
101101
size:UInt64(bytes.count),
102-
mappedAtCreation:true))
102+
mappedAtCreation:true))else{
103+
fatalError("Failed to create buffer")
104+
}
103105
buffer.getMappedRange().copyMemory(from: bytes.baseAddress!, byteCount: bytes.count)
104106
buffer.unmap()
105107
return buffer
106108
}
107109

108110
letsimParamBuffer=withUnsafeBytes(of: simParams){ bytesin
109-
letbuffer= device.createBuffer(descriptor:BufferDescriptor(
111+
guardlet buffer= device.createBuffer(descriptor:BufferDescriptor(
110112
usage:.uniform,
111113
size:UInt64(bytes.count),
112-
mappedAtCreation:true))
114+
mappedAtCreation:true))else{
115+
fatalError("Failed to create buffer")
116+
}
113117
buffer.getMappedRange().copyMemory(from: bytes.baseAddress!, byteCount: bytes.count)
114118
buffer.unmap()
115119
return buffer
@@ -128,10 +132,12 @@ try withGLFW {
128132

129133
particles.withUnsafeBytes{ bytesin
130134
for_in0..<2{
131-
letbuffer= device.createBuffer(descriptor:BufferDescriptor(
135+
guardlet buffer= device.createBuffer(descriptor:BufferDescriptor(
132136
usage:[.vertex,.storage],
133137
size:UInt64(bytes.count),
134-
mappedAtCreation:true))
138+
mappedAtCreation:true))else{
139+
fatalError("Failed to create buffer")
140+
}
135141
buffer.getMappedRange().copyMemory(from: bytes.baseAddress!, byteCount: bytes.count)
136142
buffer.unmap()
137143
particleBuffers.append(buffer)

‎Demos/DemoCube/main.swift‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,25 @@ try withGLFW {
104104
format: window.preferredTextureFormat)])))
105105

106106
letvertexBuffer= cubeVertices.withUnsafeBytes{ vertexBytes->Bufferin
107-
letvertexBuffer= device.createBuffer(descriptor:BufferDescriptor(
107+
guardlet vertexBuffer= device.createBuffer(descriptor:BufferDescriptor(
108108
usage:.vertex,
109109
size:UInt64(vertexBytes.count),
110-
mappedAtCreation:true))
110+
mappedAtCreation:true))else{
111+
fatalError("Failed to create buffer")
112+
}
111113
letptr= vertexBuffer.getMappedRange(offset:0, size:0)
112114
ptr?.copyMemory(from: vertexBytes.baseAddress!, byteCount: vertexBytes.count)
113115
vertexBuffer.unmap()
114116
return vertexBuffer
115117
}
116118

117119
letindexBuffer= cubeIndices.withUnsafeBytes{ indexBytes->Bufferin
118-
letindexBuffer= device.createBuffer(descriptor:BufferDescriptor(
120+
guardlet indexBuffer= device.createBuffer(descriptor:BufferDescriptor(
119121
usage:.index,
120122
size:UInt64(indexBytes.count),
121-
mappedAtCreation:true))
123+
mappedAtCreation:true))else{
124+
fatalError("Failed to create buffer")
125+
}
122126
letptr= indexBuffer.getMappedRange(offset:0, size:0)
123127
ptr?.copyMemory(from: indexBytes.baseAddress!, byteCount: indexBytes.count)
124128
indexBuffer.unmap()
@@ -131,7 +135,7 @@ try withGLFW {
131135

132136
letcameraBuffer= device.createBuffer(descriptor:BufferDescriptor(
133137
usage:[.uniform,.copyDst],
134-
size:UInt64(MemoryLayout<Camera>.size)))
138+
size:UInt64(MemoryLayout<Camera>.size)))!
135139

136140
letbindGroup= device.createBindGroup(descriptor:BindGroupDescriptor(
137141
layout: bindGroupLayout,

‎Demos/DemoTriangle/main.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ try withGLFW {
8787
]
8888

8989
letvertexBuffer= vertexData.withUnsafeBytes{ vertexBytes->Bufferin
90-
letvertexBuffer= device.createBuffer(descriptor:BufferDescriptor(
90+
guardlet vertexBuffer= device.createBuffer(descriptor:BufferDescriptor(
9191
usage:.vertex,
9292
size:UInt64(vertexBytes.count),
93-
mappedAtCreation:true))
93+
mappedAtCreation:true))else{
94+
fatalError("Failed to create buffer")
95+
}
9496
letptr= vertexBuffer.getMappedRange(offset:0, size:0)
9597
ptr?.copyMemory(from: vertexBytes.baseAddress!, byteCount: vertexBytes.count)
9698
vertexBuffer.unmap()

‎Sources/generate-webgpu/Decoding/DawnData.swift‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ extension Extensibility: Decodable {
8080
}
8181
}
8282

83+
structReturns:Decodable{
84+
vartype:String
85+
@DefaultFallbackvaroptional:Bool
86+
87+
init(from decoder:anyDecoder)throws{
88+
do{
89+
letcontainer=try decoder.singleValueContainer()
90+
type=try container.decode(String.self)
91+
optional=false
92+
}catchDecodingError.typeMismatch{
93+
letcontainer=try decoder.container(keyedBy:String.self)
94+
type=try container.decode(String.self, forKey:"type")
95+
optional=try container.decodeIfPresent(Bool.self, forKey:"optional")??false
96+
}
97+
}
98+
}
99+
83100

84101
// MARK: Custom Decoders
85102

@@ -124,7 +141,7 @@ typealias RecordData = [RecordMemberData]
124141
structMethodData:Taggable,Decodable{
125142
@DefaultFallbackvartags:Set<String>
126143
varname:String
127-
varreturns:String?
144+
varreturns:Returns?
128145
@DefaultFallbackvarargs:RecordData
129146
}
130147

@@ -177,7 +194,7 @@ struct ConstantTypeData: TypeData, Decodable {
177194
structFunctionTypeData:TypeData,Decodable{
178195
varcategory:Category
179196
@DefaultFallbackvartags:Set<String>
180-
varreturns:String?
197+
varreturns:Returns?
181198
@DefaultFallbackvarargs:RecordData
182199
}
183200

‎Sources/generate-webgpu/Decoding/DefaultFallback.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension DefaultFallback: DefaultFallbackProtocol {
1212

1313
init(from decoder:Decoder)throws{
1414
letcontainer=try decoder.singleValueContainer()
15-
self.wrappedValue=(try? container.decode(T.self))??T()
15+
self.wrappedValue=(try container.decode(T.self))
1616
}
1717
}
1818

‎Sources/generate-webgpu/Model/FunctionPointerType.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
classFunctionPointerType:Type{
22
letreturnTypeName:String?
3+
letisReturnOptional:Bool
34
letarguments:Record
45

56
weakvarreturnType:Type?
67

78
init(name:String, data:FunctionTypeData){
8-
returnTypeName= data.returns
9+
returnTypeName= data.returns?.type
10+
isReturnOptional= data.returns?.optional??false
911
arguments=Record(data: data.args.filter{ $0.isEnabled}, context:.function)
1012
super.init(name: name, data: data)
1113
}
@@ -49,7 +51,7 @@ class FunctionPointerType: Type {
4951
}
5052

5153
guardlet returnType= returnTypeelse{returnnil}
52-
if returnType.category==.functionPointer{
54+
ifisReturnOptional ||returnType.category==.functionPointer{
5355
return returnType.swiftName+"?"
5456
}
5557
return returnType.swiftName

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp