@@ -782,11 +782,6 @@ extension WebGPU.CommandEncoder {
782782 return nil
783783 }
784784
785- private func isRenderableTextureView( texture: WebGPU . TextureView ) -> Bool {
786- let textureDimension = texture. dimension ( )
787-
788- return ( texture. usage ( ) & WGPUTextureUsage_RenderAttachment . rawValue) != 0 && ( textureDimension == WGPUTextureViewDimension_2D || textureDimension == WGPUTextureViewDimension_2DArray || textureDimension == WGPUTextureViewDimension_3D) && texture. mipLevelCount ( ) == 1 && texture. arrayLayerCount ( ) <= 1
789- }
790785 private func loadAction( loadOp: WGPULoadOp ) -> MTLLoadAction {
791786 switch ( loadOp) {
792787 case WGPULoadOp_Load:
@@ -904,8 +899,11 @@ extension WebGPU.CommandEncoder {
904899 attachment. clearValue. b,
905900 attachment. clearValue. a)
906901
907- let texture = WebGPU . fromAPI ( attachment. view)
908- if !WebGPU_Internal. isValidToUseWithTextureViewCommandEncoder ( texture, self ) {
902+ var texture =
903+ attachment. view != nil
904+ ? WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. view) )
905+ : WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. texture) )
906+ if !WebGPU_Internal. isValidToUseWith ( texture, self ) {
909907 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " device mismatch " )
910908 }
911909 if textureWidth != 0 &&
@@ -930,7 +928,7 @@ extension WebGPU.CommandEncoder {
930928 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " color attachment is not renderable " )
931929 }
932930
933- if !isRenderableTextureView( texture : texture) {
931+ if !WebGPU . isRenderableTextureView ( texture) {
934932 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " texture view is not renderable " )
935933 }
936934 }
@@ -947,17 +945,20 @@ extension WebGPU.CommandEncoder {
947945 mtlAttachment. level = 0
948946 mtlAttachment. slice = 0
949947 var depthSliceOrArrayLayer : UInt64 = 0
950- let textureDimension = texture. dimension ( )
951948 if attachment. depthSlice. hasValue {
952- if textureDimension != WGPUTextureViewDimension_3D {
949+ if !texture . is3DTexture ( ) {
953950 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depthSlice specified on 2D texture " )
954951 }
955952 depthSliceOrArrayLayer = textureIsDestroyed ? 0 : UInt64 ( attachment. depthSlice. value!)
956953 if depthSliceOrArrayLayer >= texture. depthOrArrayLayers ( ) {
957- return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depthSlice is greater than texture's depth or array layers " )
954+ return WebGPU . RenderPassEncoder. createInvalid (
955+ self ,
956+ m_device. ptr ( ) ,
957+ " depthSlice is greater than texture's depth or array layers "
958+ )
958959 }
959960 } else {
960- if textureDimension == WGPUTextureViewDimension_3D {
961+ if texture . is3DTexture ( ) {
961962 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " textureDimension is 3D and no depth slice is specified " )
962963 }
963964 depthSliceOrArrayLayer = UInt64 ( textureIsDestroyed ? 0 : texture. baseArrayLayer ( ) )
@@ -967,14 +968,18 @@ extension WebGPU.CommandEncoder {
967968 let depthAndMipLevel : UInt64 = depthSliceOrArrayLayer | ( UInt64 ( baseMipLevel) << 32 )
968969 if depthSlices [ bridgedTexture] != nil {
969970 if depthSlices [ bridgedTexture] !. contains ( depthAndMipLevel) {
970- return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " attempting to render to overlapping color attachment " )
971+ return WebGPU . RenderPassEncoder. createInvalid (
972+ self ,
973+ m_device. ptr ( ) ,
974+ " attempting to render to overlapping color attachment "
975+ )
971976 }
972977 depthSlices [ bridgedTexture] !. insert ( depthAndMipLevel)
973978 } else {
974979 depthSlices [ bridgedTexture] = [ depthAndMipLevel]
975980 }
976981
977- mtlAttachment. depthPlane = Int ( textureDimension == WGPUTextureViewDimension_3D ? depthSliceOrArrayLayer : 0 )
982+ mtlAttachment. depthPlane = texture . is3DTexture ( ) ? Int ( depthSliceOrArrayLayer) : 0
978983 mtlAttachment. slice = 0
979984 mtlAttachment. loadAction = loadAction ( loadOp: attachment. loadOp)
980985 mtlAttachment. storeAction = storeAction ( storeOp: attachment. storeOp, hasResolveTarget: attachment. resolveTarget != nil )
@@ -985,16 +990,15 @@ extension WebGPU.CommandEncoder {
985990 textureToClear = mtlAttachment. texture
986991 }
987992
988- if let rateMap = texture. rasterizationMapForSlice ( texture. parentRelativeSlice ( ) ) {
989- mtlDescriptor. rasterizationRateMap = rateMap
990- }
991-
992993 var compositorTexture = texture
993994 if attachment. resolveTarget != nil {
994- let resolveTarget = WebGPU . fromAPI ( attachment. resolveTarget)
995+ var resolveTarget =
996+ attachment. resolveTarget != nil
997+ ? WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. resolveTarget) )
998+ : WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. resolveTexture) )
995999 compositorTexture = resolveTarget
9961000
997- if !WebGPU_Internal. isValidToUseWithTextureViewCommandEncoder ( resolveTarget, self ) {
1001+ if !WebGPU_Internal. isValidToUseWith ( resolveTarget, self ) {
9981002 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " resolve target created from different device " )
9991003 }
10001004 resolveTarget. setCommandEncoder ( self )
@@ -1007,7 +1011,7 @@ extension WebGPU.CommandEncoder {
10071011 || resolveTexture!. sampleCount != 1
10081012 || isMultisampleTexture ( texture: resolveTexture!)
10091013 || !isMultisampleTexture( texture: mtlTexture!)
1010- || !isRenderableTextureView( texture : resolveTarget)
1014+ || !WebGPU . isRenderableTextureView ( resolveTarget)
10111015 || mtlTexture!. pixelFormat != resolveTexture!. pixelFormat
10121016 || !WebGPU. Texture. supportsResolve ( resolveTarget. format ( ) , m_device. ptr ( ) ) {
10131017 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " resolve target is invalid " )
@@ -1031,24 +1035,30 @@ extension WebGPU.CommandEncoder {
10311035 let textureWithResolve = TextureAndClearColor ( texture: textureToClear!)
10321036 attachmentsToClear [ i as NSNumber ] = textureWithResolve
10331037 if textureToClear != nil {
1034- // FIXME: rdar://138042799 remove default argument.
1035- texture. setPreviouslyCleared ( 0 , 0 )
1038+ texture. setPreviouslyCleared ( )
10361039 }
10371040 if attachment. resolveTarget != nil {
10381041 // FIXME: rdar://138042799 remove default argument.
10391042 WebGPU . fromAPI ( attachment. resolveTarget) . setPreviouslyCleared ( 0 , 0 )
10401043 }
1044+ if attachment. resolveTexture != nil {
1045+ WebGPU . fromAPI ( attachment. resolveTexture) . setPreviouslyCleared ( )
1046+ }
10411047 }
10421048 }
10431049 }
10441050
1045- var depthReadOnly = false , stencilReadOnly = false
1051+ var depthReadOnly = false
1052+ var stencilReadOnly = false
10461053 var hasStencilComponent = false
10471054 var depthStencilAttachmentToClear : MTLTexture ? = nil
10481055 var depthAttachmentToClear = false
1049- if let attachment = wgpuGetRenderPassDescriptorDepthSencilAttachment ( descriptorSpan) ? [ 0 ] {
1050- let textureView = WebGPU . fromAPI ( attachment. view)
1051- if !WebGPU_Internal. isValidToUseWithTextureViewCommandEncoder ( textureView, self ) {
1056+ if let attachment = wgpuGetRenderPassDescriptorDepthStencilAttachment ( descriptorSpan) ? [ 0 ] {
1057+ let textureView =
1058+ attachment. view != nil
1059+ ? WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. view) )
1060+ : WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. texture) )
1061+ if !WebGPU_Internal. isValidToUseWith ( textureView, self ) {
10521062 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depth stencil texture device mismatch " )
10531063 }
10541064 let metalDepthStencilTexture = textureView. texture ( )
@@ -1061,10 +1071,17 @@ extension WebGPU.CommandEncoder {
10611071 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depth stencil texture dimensions mismatch " )
10621072 }
10631073 if textureView. arrayLayerCount ( ) > 1 || textureView. mipLevelCount ( ) > 1 {
1064- return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depth stencil texture has more than one array layer or mip level " )
1074+ return WebGPU . RenderPassEncoder. createInvalid (
1075+ self ,
1076+ m_device. ptr ( ) ,
1077+ " depth stencil texture has more than one array layer or mip level "
1078+ )
10651079 }
10661080
1067- if !WebGPU. Texture. isDepthStencilRenderableFormat ( textureView. format ( ) , m_device. ptr ( ) ) || !isRenderableTextureView( texture: textureView) {
1081+ if !WebGPU. Texture. isDepthStencilRenderableFormat (
1082+ textureView. format ( ) ,
1083+ m_device. ptr ( )
1084+ ) || !WebGPU. isRenderableTextureView ( textureView) {
10681085 return WebGPU . RenderPassEncoder. createInvalid ( self , m_device. ptr ( ) , " depth stencil texture is not renderable " )
10691086 }
10701087 }
@@ -1118,10 +1135,13 @@ extension WebGPU.CommandEncoder {
11181135 }
11191136
11201137 var stencilAttachmentToClear = false
1121- if let attachment = wgpuGetRenderPassDescriptorDepthSencilAttachment ( descriptorSpan) ? [ 0 ] {
1138+ if let attachment = wgpuGetRenderPassDescriptorDepthStencilAttachment ( descriptorSpan) ? [ 0 ] {
11221139 let mtlAttachment = mtlDescriptor. stencilAttachment
11231140 stencilReadOnly = attachment. stencilReadOnly != 0
1124- let textureView = WebGPU . fromAPI ( attachment. view)
1141+ var textureView =
1142+ attachment. view != nil
1143+ ? WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. view) )
1144+ : WebGPU . TextureOrTextureView ( WebGPU . fromAPI ( attachment. texture) )
11251145 if hasStencilComponent {
11261146 mtlAttachment!. texture = textureView. texture ( )
11271147 }
@@ -1165,7 +1185,7 @@ extension WebGPU.CommandEncoder {
11651185 }
11661186
11671187 if attachmentsToClear. count != 0 || depthStencilAttachmentToClear != nil {
1168- let attachment = wgpuGetRenderPassDescriptorDepthSencilAttachment ( descriptorSpan) ? [ 0 ]
1188+ let attachment = wgpuGetRenderPassDescriptorDepthStencilAttachment ( descriptorSpan) ? [ 0 ]
11691189 if attachment != nil && depthStencilAttachmentToClear != nil {
11701190 // FIXME: rdar://138042799 remove default argument.
11711191 WebGPU . fromAPI ( attachment!. view) . setPreviouslyCleared ( 0 , 0 )
@@ -1514,13 +1534,13 @@ extension WebGPU.CommandEncoder {
15141534 return
15151535 }
15161536 let apiBuffer = WebGPU . fromAPI ( source. buffer)
1517- apiBuffer. setCommandEncoder ( self , false )
1537+ apiBuffer. setCommandEncoder ( self , false )
15181538 destinationTexture. setCommandEncoder ( self )
15191539 guard copySize. width != 0 || copySize. height != 0 || copySize. depthOrArrayLayers != 0 , !apiBuffer. isDestroyed ( ) , !destinationTexture. isDestroyed ( ) else {
15201540 return
15211541 }
15221542 guard let blitCommandEncoder = self . ensureBlitCommandEncoder ( ) else {
1523- return
1543+ return
15241544 }
15251545 var sourceBytesPerRow : UInt = UInt ( source. layout. bytesPerRow)
15261546 guard let sourceBuffer = apiBuffer. buffer ( ) else {
0 commit comments