@@ -21,6 +21,32 @@ base class ColorAttachment {
2121
2222 Texture texture;
2323 Texture ? resolveTexture;
24+
25+ void _assertValid () {
26+ if (resolveTexture != null ) {
27+ assert (resolveTexture! .format == texture.format,
28+ "ColorAttachment MSAA resolve texture must have the same format as the texture" );
29+ assert (
30+ resolveTexture! .width == texture.width &&
31+ resolveTexture! .height == texture.height,
32+ "ColorAttachment MSAA resolve texture must have the same dimensions as the texture" );
33+ assert (resolveTexture! .sampleCount == 1 ,
34+ "ColorAttachment MSAA resolve texture must have a sample count of 1" );
35+ assert (texture.sampleCount > 1 ,
36+ "ColorAttachment must have a sample count greater than 1 when a MSAA resolve texture is set" );
37+ assert (
38+ storeAction == StoreAction .multisampleResolve ||
39+ storeAction == StoreAction .storeAndMultisampleResolve,
40+ "ColorAttachment StoreAction must be multisampleResolve or storeAndMultisampleResolve when a resolve texture is set" );
41+ assert (resolveTexture! .storageMode != StorageMode .deviceTransient,
42+ "ColorAttachment MSAA resolve texture must not have a storage mode of deviceTransient" );
43+ }
44+
45+ assert (
46+ texture.storageMode != StorageMode .deviceTransient ||
47+ loadAction != LoadAction .load,
48+ "ColorAttachment loadAction must not be load when the texture has a storage mode of deviceTransient" );
49+ }
2450}
2551
2652base class DepthStencilAttachment {
@@ -43,6 +69,43 @@ base class DepthStencilAttachment {
4369 int stencilClearValue;
4470
4571 Texture texture;
72+ Texture ? resolveTexture;
73+
74+ void _assertValid () {
75+ if (resolveTexture != null ) {
76+ assert (resolveTexture! .format == texture.format,
77+ "DepthStencilAttachment MSAA resolve texture must have the same format as the texture" );
78+ assert (
79+ resolveTexture! .width == texture.width &&
80+ resolveTexture! .height == texture.height,
81+ "DepthStencilAttachment MSAA resolve texture must have the same dimensions as the texture" );
82+ assert (resolveTexture! .sampleCount == 1 ,
83+ "DepthStencilAttachment MSAA resolve texture must have a sample count of 1" );
84+ assert (texture.sampleCount > 1 ,
85+ "DepthStencilAttachment must have a sample count greater than 1 when a MSAA resolve texture is set" );
86+ assert (
87+ depthStoreAction == StoreAction .multisampleResolve ||
88+ depthStoreAction == StoreAction .storeAndMultisampleResolve,
89+ "DepthStencilAttachment depthStoreAction must be multisampleResolve or storeAndMultisampleResolve when a resolve texture is set" );
90+ assert (
91+ stencilStoreAction == StoreAction .multisampleResolve ||
92+ stencilStoreAction == StoreAction .storeAndMultisampleResolve,
93+ "DepthStencilAttachment stencilStoreAction must be multisampleResolve or storeAndMultisampleResolve when a resolve texture is set" );
94+ assert (resolveTexture! .storageMode != StorageMode .deviceTransient,
95+ "DepthStencilAttachment MSAA resolve texture must not have a storage mode of deviceTransient" );
96+ }
97+
98+ if (texture.storageMode == StorageMode .deviceTransient) {
99+ assert (
100+ texture.storageMode != StorageMode .deviceTransient ||
101+ depthLoadAction != LoadAction .load,
102+ "DepthStencilAttachment depthLoadAction must not be load when the texture has a storage mode of deviceTransient" );
103+ assert (
104+ texture.storageMode != StorageMode .deviceTransient ||
105+ stencilLoadAction != LoadAction .load,
106+ "DepthStencilAttachment stencilLoadAction must not be load when the texture has a storage mode of deviceTransient" );
107+ }
108+ }
46109}
47110
48111base class StencilConfig {
@@ -117,6 +180,15 @@ base class RenderTarget {
117180 colorAttachments: [colorAttachment],
118181 depthStencilAttachment: depthStencilAttachment);
119182
183+ _assertValid () {
184+ for (final color in colorAttachments) {
185+ color._assertValid ();
186+ }
187+ if (depthStencilAttachment != null ) {
188+ depthStencilAttachment! ._assertValid ();
189+ }
190+ }
191+
120192 final List <ColorAttachment > colorAttachments;
121193 final DepthStencilAttachment ? depthStencilAttachment;
122194}
@@ -132,7 +204,10 @@ int _colorToInt(ui.Color color) {
132204
133205base class RenderPass extends NativeFieldWrapperClass1 {
134206 /// Creates a new RenderPass.
135- RenderPass ._(CommandBuffer commandBuffer, RenderTarget renderTarget) {
207+ RenderPass ._(GpuContext gpuContext, CommandBuffer commandBuffer,
208+ RenderTarget renderTarget) {
209+ renderTarget._assertValid ();
210+
136211 _initialize ();
137212 String ? error;
138213 for (final (index, color) in renderTarget.colorAttachments.indexed) {
@@ -156,7 +231,8 @@ base class RenderPass extends NativeFieldWrapperClass1 {
156231 ds.stencilLoadAction.index,
157232 ds.stencilStoreAction.index,
158233 ds.stencilClearValue,
159- ds.texture);
234+ ds.texture,
235+ ds.resolveTexture);
160236 if (error != null ) {
161237 throw Exception (error);
162238 }
@@ -291,8 +367,8 @@ base class RenderPass extends NativeFieldWrapperClass1 {
291367 Texture ? resolveTexture);
292368
293369 @Native <
294- Handle Function (
295- Pointer <Void >, Int , Int , Float , Int , Int , Int , Pointer < Void > )> (
370+ Handle Function (Pointer < Void >, Int , Int , Float , Int , Int , Int ,
371+ Pointer <Void >, Handle )> (
296372 symbol: 'InternalFlutterGpu_RenderPass_SetDepthStencilAttachment' )
297373 external String ? _setDepthStencilAttachment (
298374 int depthLoadAction,
@@ -301,7 +377,8 @@ base class RenderPass extends NativeFieldWrapperClass1 {
301377 int stencilLoadAction,
302378 int stencilStoreAction,
303379 int stencilClearValue,
304- Texture texture);
380+ Texture texture,
381+ Texture ? resolveTexture);
305382
306383 @Native < Handle Function (Pointer <Void >, Pointer <Void >)> (
307384 symbol: 'InternalFlutterGpu_RenderPass_Begin' )
0 commit comments