[Flutter GPU] Fix MSAA sample size and HostBuffer alignment. (flutter/engine#56218)
- Align HostBuffer emplacements properly (fix Metal validation failures). - Correctly set the pipeline sample size. - Throw an error when attempting to bind `deviceTransient` textures.
This commit is contained in:
@@ -212,7 +212,11 @@ base class HostBuffer {
|
||||
offsetInBytes: 0, lengthInBytes: bytes.lengthInBytes);
|
||||
}
|
||||
|
||||
int padding = _offsetCursor % _gpuContext.minimumUniformByteAlignment;
|
||||
int padding = _gpuContext.minimumUniformByteAlignment -
|
||||
(_offsetCursor % _gpuContext.minimumUniformByteAlignment);
|
||||
// If the padding is the full alignment size, then we're already aligned.
|
||||
// So reset the padding to zero.
|
||||
padding %= _gpuContext.minimumUniformByteAlignment;
|
||||
if (_offsetCursor + padding >= blockLengthInBytes) {
|
||||
DeviceBuffer buffer = _allocateNewBlock(blockLengthInBytes);
|
||||
_buffers[_frameCursor].add(buffer);
|
||||
|
||||
@@ -250,6 +250,14 @@ base class RenderPass extends NativeFieldWrapperClass1 {
|
||||
sampler = SamplerOptions();
|
||||
}
|
||||
|
||||
assert(() {
|
||||
if (texture.storageMode == StorageMode.deviceTransient) {
|
||||
throw Exception(
|
||||
"Textures with StorageMode.deviceTransient cannot be bound to a RenderPass");
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
|
||||
bool success = _bindTexture(
|
||||
slot.shader,
|
||||
slot.uniformName,
|
||||
|
||||
@@ -102,6 +102,9 @@ std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>>
|
||||
RenderPass::GetOrCreatePipeline() {
|
||||
// Infer the pipeline layout based on the shape of the RenderTarget.
|
||||
auto pipeline_desc = pipeline_descriptor_;
|
||||
|
||||
pipeline_desc.SetSampleCount(render_target_.GetSampleCount());
|
||||
|
||||
for (const auto& it : render_target_.GetColorAttachments()) {
|
||||
auto& color = GetColorAttachmentDescriptor(it.first);
|
||||
color.format = render_target_.GetRenderTargetPixelFormat();
|
||||
|
||||
@@ -171,7 +171,8 @@ void main() async {
|
||||
|
||||
final gpu.BufferView view1 = hostBuffer
|
||||
.emplace(Int8List.fromList(<int>[0, 1, 2, 3]).buffer.asByteData());
|
||||
expect(view1.offsetInBytes, greaterThanOrEqualTo(4));
|
||||
expect(view1.offsetInBytes,
|
||||
equals(gpu.gpuContext.minimumUniformByteAlignment));
|
||||
expect(view1.lengthInBytes, 4);
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
@@ -416,6 +417,29 @@ void main() async {
|
||||
}
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
test('RenderPass.bindTexture throws for deviceTransient Textures', () async {
|
||||
final state = createSimpleRenderPass();
|
||||
|
||||
final gpu.RenderPipeline pipeline = createUnlitRenderPipeline();
|
||||
// Although this is a non-texture uniform slot, it'll work fine for the
|
||||
// purposes of testing this error.
|
||||
final gpu.UniformSlot vertInfo =
|
||||
pipeline.vertexShader.getUniformSlot('VertInfo');
|
||||
|
||||
final gpu.Texture texture = gpu.gpuContext
|
||||
.createTexture(gpu.StorageMode.deviceTransient, 100, 100)!;
|
||||
|
||||
try {
|
||||
state.renderPass.bindTexture(vertInfo, texture);
|
||||
fail('Exception not thrown when binding a transient texture.');
|
||||
} catch (e) {
|
||||
expect(
|
||||
e.toString(),
|
||||
contains(
|
||||
'Textures with StorageMode.deviceTransient cannot be bound to a RenderPass'));
|
||||
}
|
||||
}, skip: !impellerEnabled);
|
||||
|
||||
// Performs no draw calls. Just clears the render target to a solid green color.
|
||||
test('Can render clear color', () async {
|
||||
final state = createSimpleRenderPass(clearColor: Colors.lime);
|
||||
|
||||
Reference in New Issue
Block a user