-
Notifications
You must be signed in to change notification settings - Fork 70
[Dawn] Implement doBuffer in Dawn backend #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
156d5bd
initial commit
sarahM0 d72da4c
set amber buffer
sarahM0 8934f85
adding if conditions
sarahM0 e1f76f4
Merge branch 'master' of github.com:sarahM0/amber into ssb
sarahM0 935bfd2
update tests
sarahM0 d59c441
add multiple descriptor set support
sarahM0 30a072f
clean up test script - fix a few unsupported formats in tests
sarahM0 06a8f39
Merge branch 'master' into ssb
sarahM0 797d326
clean up test script
sarahM0 ca97043
Merge branch 'ssb' of github.com:sarahM0/amber into ssb
sarahM0 47a4769
test script clean up
sarahM0 38b83e4
dawn does not support geom shaders or tessellation
sarahM0 658bccc
no need to resize in ssbo
sarahM0 ca8a6ee
revert command_parser.cc - nit buffer_)
sarahM0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ static const float kLodMax = 1000.0; | |
| static const uint32_t kMaxColorAttachments = 4u; | ||
| static const uint32_t kMaxVertexInputs = 16u; | ||
| static const uint32_t kMaxVertexAttributes = 16u; | ||
| static const uint32_t kMaxDawnBindGroup = 4u; | ||
|
|
||
| // This structure is a container for a few variables that are created during | ||
| // CreateRenderPipelineDescriptor and CreateRenderPassDescriptor and we want to | ||
|
|
@@ -291,7 +292,7 @@ MapResult MapTextureToHostBuffer(const RenderPipelineInfo& render_pipeline, | |
| return map; | ||
| } | ||
|
|
||
| // creates a dawn buffer for TransferDst | ||
| // Creates a dawn buffer of |size| bytes with TransferDst and the given usage | ||
| // copied from Dawn utils source code | ||
| ::dawn::Buffer CreateBufferFromData(const ::dawn::Device& device, | ||
| const void* data, | ||
|
|
@@ -302,11 +303,12 @@ ::dawn::Buffer CreateBufferFromData(const ::dawn::Device& device, | |
| descriptor.usage = usage | ::dawn::BufferUsageBit::TransferDst; | ||
|
|
||
| ::dawn::Buffer buffer = device.CreateBuffer(&descriptor); | ||
| buffer.SetSubData(0, size, reinterpret_cast<const uint8_t*>(data)); | ||
| if (data != nullptr) | ||
| buffer.SetSubData(0, size, reinterpret_cast<const uint8_t*>(data)); | ||
| return buffer; | ||
| } | ||
|
|
||
| // creates a default sampler descriptor. It does not set the sampling | ||
| // Creates a default sampler descriptor. It does not set the sampling | ||
| // coordinates meaning it's set to default, normalized. | ||
| // copied from Dawn utils source code | ||
| ::dawn::SamplerDescriptor GetDefaultSamplerDescriptor() { | ||
|
|
@@ -402,15 +404,10 @@ ::dawn::BindGroupLayout MakeBindGroupLayout( | |
| // Copied from Dawn utils source code. | ||
| ::dawn::PipelineLayout MakeBasicPipelineLayout( | ||
| const ::dawn::Device& device, | ||
| const ::dawn::BindGroupLayout* bindGroupLayout) { | ||
| std::vector<::dawn::BindGroupLayout> bindingInitializer) { | ||
| ::dawn::PipelineLayoutDescriptor descriptor; | ||
| if (bindGroupLayout) { | ||
| descriptor.bindGroupLayoutCount = 1; | ||
| descriptor.bindGroupLayouts = bindGroupLayout; | ||
| } else { | ||
| descriptor.bindGroupLayoutCount = 0; | ||
| descriptor.bindGroupLayouts = nullptr; | ||
| } | ||
| descriptor.bindGroupLayoutCount = bindingInitializer.size(); | ||
| descriptor.bindGroupLayouts = bindingInitializer.data(); | ||
| return device.CreatePipelineLayout(&descriptor); | ||
| } | ||
|
|
||
|
|
@@ -504,6 +501,9 @@ Result GetDawnVertexFormat(const ::amber::Format& amber_format, | |
| case FormatType::kR8G8B8A8_UNORM: | ||
| dawn_format = ::dawn::VertexFormat::UChar4Norm; | ||
| break; | ||
| case FormatType::kR8G8B8A8_SNORM: | ||
| dawn_format = ::dawn::VertexFormat::Char4Norm; | ||
| break; | ||
| default: | ||
| return Result( | ||
| "Amber vertex format " + | ||
|
|
@@ -772,11 +772,8 @@ Result DawnPipelineHelper::CreateRenderPipelineDescriptor( | |
| depth_stencil_format = ::dawn::TextureFormat::D32FloatS8Uint; | ||
| } | ||
|
|
||
| if (render_pipeline.bind_group) | ||
| renderPipelineDescriptor.layout = | ||
| MakeBasicPipelineLayout(device, &render_pipeline.bind_group_layout); | ||
| else | ||
| renderPipelineDescriptor.layout = MakeBasicPipelineLayout(device, nullptr); | ||
| renderPipelineDescriptor.layout = | ||
| MakeBasicPipelineLayout(device, render_pipeline.bind_group_layouts); | ||
|
|
||
| renderPipelineDescriptor.primitiveTopology = | ||
| ::dawn::PrimitiveTopology::TriangleList; | ||
|
|
@@ -1046,8 +1043,10 @@ Result EngineDawn::DoDrawRect(const DrawRectCommand* command) { | |
| ::dawn::RenderPassEncoder pass = | ||
| encoder.BeginRenderPass(renderPassDescriptor); | ||
| pass.SetPipeline(pipeline); | ||
| if (render_pipeline->bind_group) { | ||
| pass.SetBindGroup(0, render_pipeline->bind_group, 0, nullptr); | ||
| for (uint32_t i = 0; i < render_pipeline->bind_groups.size(); i++) { | ||
| if (render_pipeline->bind_groups[i]) { | ||
| pass.SetBindGroup(i, render_pipeline->bind_groups[i], 0, nullptr); | ||
| } | ||
| } | ||
| pass.SetVertexBuffers(0, 1, &vertex_buffer, vertexBufferOffsets); | ||
| pass.SetIndexBuffer(index_buffer, 0); | ||
|
|
@@ -1115,10 +1114,11 @@ Result EngineDawn::DoDrawArrays(const DrawArraysCommand* command) { | |
| ::dawn::RenderPassEncoder pass = | ||
| encoder.BeginRenderPass(renderPassDescriptor); | ||
| pass.SetPipeline(pipeline); | ||
| if (render_pipeline->bind_group) { | ||
| pass.SetBindGroup(0, render_pipeline->bind_group, 0, nullptr); | ||
| for (uint32_t i = 0; i < render_pipeline->bind_groups.size(); i++) { | ||
| if (render_pipeline->bind_groups[i]) { | ||
| pass.SetBindGroup(i, render_pipeline->bind_groups[i], 0, nullptr); | ||
| } | ||
| } | ||
|
|
||
| // TODO(sarahM0): figure out what are startSlot, count and offsets | ||
| for (uint32_t i = 0; i < render_pipeline->vertex_buffers.size(); i++) { | ||
| pass.SetVertexBuffers(i, /* startSlot */ | ||
|
|
@@ -1158,8 +1158,34 @@ Result EngineDawn::DoPatchParameterVertices( | |
| return Result("Dawn:DoPatch not implemented"); | ||
| } | ||
|
|
||
| Result EngineDawn::DoBuffer(const BufferCommand*) { | ||
| return Result("Dawn:DoBuffer not implemented"); | ||
| Result EngineDawn::DoBuffer(const BufferCommand* command) { | ||
| Result result; | ||
|
|
||
| // TODO(SarahM0): Make this work for compute pipeline | ||
| RenderPipelineInfo* render_pipeline = GetRenderPipeline(command); | ||
| if (!render_pipeline) | ||
| return Result("DoBuffer: invoked on invalid or missing render pipeline"); | ||
| if (!command->IsSSBO() && !command->IsUniform()) | ||
| return Result("DoBuffer: only supports SSBO and uniform buffer type"); | ||
|
|
||
| if (render_pipeline->buffer_map_.find( | ||
| {command->GetDescriptorSet(), command->GetBinding()}) != | ||
| render_pipeline->buffer_map_.end()) { | ||
| auto dawn_buffer_index = | ||
| render_pipeline | ||
| ->buffer_map_[{command->GetDescriptorSet(), command->GetBinding()}]; | ||
| ::dawn::Buffer& dawn_buffer = render_pipeline->buffers[dawn_buffer_index]; | ||
|
|
||
| Buffer* amber_buffer = command->GetBuffer(); | ||
| if (amber_buffer) { | ||
| amber_buffer->SetDataWithOffset(command->GetValues(), | ||
| command->GetOffset()); | ||
|
|
||
| dawn_buffer.SetSubData(0, amber_buffer->GetSizeInBytes(), | ||
| amber_buffer->ValuePtr()->data()); | ||
| } | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| Result EngineDawn::AttachBuffersAndTextures( | ||
|
|
@@ -1177,7 +1203,8 @@ Result EngineDawn::AttachBuffersAndTextures( | |
| auto* amber_format = | ||
| render_pipeline->pipeline->GetColorAttachments()[0].buffer->GetFormat(); | ||
| if (!amber_format) | ||
| return Result("Color attachment 0 has no format!"); | ||
| return Result( | ||
| "AttachBuffersAndTextures: Color attachment 0 has no format!"); | ||
| ::dawn::TextureFormat fb_format{}; | ||
| result = GetDawnTextureFormat(*amber_format, &fb_format); | ||
| if (!result.IsSuccess()) | ||
|
|
@@ -1213,7 +1240,9 @@ Result EngineDawn::AttachBuffersAndTextures( | |
| if (!depth_stencil_texture_) { | ||
| auto* amber_depth_stencil_format = depthBuffer->GetFormat(); | ||
| if (!amber_depth_stencil_format) | ||
| return Result("The depth/stencil attachment has no format!"); | ||
| return Result( | ||
| "AttachBuffersAndTextures: The depth/stencil attachment has no " | ||
| "format!"); | ||
| ::dawn::TextureFormat depth_stencil_format{}; | ||
| result = GetDawnTextureFormat(*amber_depth_stencil_format, | ||
| &depth_stencil_format); | ||
|
|
@@ -1248,14 +1277,19 @@ Result EngineDawn::AttachBuffersAndTextures( | |
|
|
||
| // Do not attach pushConstants | ||
| if (render_pipeline->pipeline->GetPushConstantBuffer().buffer != nullptr) { | ||
| return Result("Dawn does not support push constants!"); | ||
| return Result( | ||
| "AttachBuffersAndTextures: Dawn does not support push constants!"); | ||
| } | ||
|
|
||
| ::dawn::ShaderStageBit kAllStages = | ||
| ::dawn::ShaderStageBit::Vertex | ::dawn::ShaderStageBit::Fragment; | ||
| std::vector<BindingInitializationHelper> bindingInitalizerHelper; | ||
| std::vector<::dawn::BindGroupLayoutBinding> bindings; | ||
| std::vector<std::vector<BindingInitializationHelper>> bindingInitalizerHelper( | ||
| kMaxDawnBindGroup); | ||
| std::vector<std::vector<::dawn::BindGroupLayoutBinding>> layouts_info( | ||
| kMaxDawnBindGroup); | ||
| uint32_t max_descriptor_set = 0; | ||
|
|
||
| // Attach storage/uniform buffers | ||
| for (const auto& buf_info : render_pipeline->pipeline->GetBuffers()) { | ||
| ::dawn::BufferUsageBit bufferUsage; | ||
| ::dawn::BindingType bindingType; | ||
|
|
@@ -1271,35 +1305,62 @@ Result EngineDawn::AttachBuffersAndTextures( | |
| break; | ||
| } | ||
| default: { | ||
| return Result("Dawn: CreatePipeline - unknown buffer type: " + | ||
| return Result("AttachBuffersAndTextures: unknown buffer type: " + | ||
| std::to_string(static_cast<uint32_t>( | ||
| buf_info.buffer->GetBufferType()))); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| ::dawn::Buffer buffer = | ||
| if (buf_info.descriptor_set > kMaxDawnBindGroup - 1) { | ||
| return Result( | ||
| "AttachBuffersAndTextures: Dawn has maximum of 4 bindGroups " | ||
| "(descriptor sets)"); | ||
| } | ||
|
|
||
| render_pipeline->buffers.emplace_back( | ||
| CreateBufferFromData(*device_, buf_info.buffer->ValuePtr()->data(), | ||
| buf_info.buffer->GetSizeInBytes(), | ||
| bufferUsage | ::dawn::BufferUsageBit::TransferSrc | | ||
| ::dawn::BufferUsageBit::TransferDst); | ||
| ::dawn::BufferUsageBit::TransferDst)); | ||
|
|
||
| ::dawn::BindGroupLayoutBinding bglb; | ||
| bglb.binding = buf_info.binding; | ||
| bglb.visibility = kAllStages; | ||
| bglb.type = bindingType; | ||
| bindings.push_back(bglb); | ||
| render_pipeline->buffer_map_[{buf_info.descriptor_set, buf_info.binding}] = | ||
| render_pipeline->buffers.size() - 1; | ||
|
|
||
| render_pipeline->used_descriptor_set.insert(buf_info.descriptor_set); | ||
| max_descriptor_set = std::max(max_descriptor_set, buf_info.descriptor_set); | ||
|
|
||
| ::dawn::BindGroupLayoutBinding layout_info; | ||
| layout_info.binding = buf_info.binding; | ||
| layout_info.visibility = kAllStages; | ||
| layout_info.type = bindingType; | ||
| layouts_info[buf_info.descriptor_set].push_back(layout_info); | ||
|
|
||
| BindingInitializationHelper tempBinding = BindingInitializationHelper( | ||
| buf_info.binding, buffer, 0, buf_info.buffer->GetSizeInBytes()); | ||
| bindingInitalizerHelper.push_back(tempBinding); | ||
| buf_info.binding, render_pipeline->buffers.back(), 0, | ||
| buf_info.buffer->GetSizeInBytes()); | ||
| bindingInitalizerHelper[buf_info.descriptor_set].push_back(tempBinding); | ||
| } | ||
|
|
||
| if (bindings.size() > 0 && bindingInitalizerHelper.size() > 0) { | ||
| render_pipeline->bind_group_layout = | ||
| MakeBindGroupLayout(*device_, bindings); | ||
| render_pipeline->bind_group = MakeBindGroup( | ||
| *device_, render_pipeline->bind_group_layout, bindingInitalizerHelper); | ||
| // TODO(sarahM0): fix issue: Add support for doBuffer with sparse descriptor | ||
| // sets #573 | ||
| if (render_pipeline->used_descriptor_set.size() != 0 && | ||
| render_pipeline->used_descriptor_set.size() != max_descriptor_set + 1) { | ||
| return Result( | ||
| "AttachBuffersAndTextures: Sparse descriptor_set is not supported"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good! |
||
| } | ||
|
|
||
| for (uint32_t i = 0; i < kMaxDawnBindGroup; i++) { | ||
| if (layouts_info[i].size() > 0 && bindingInitalizerHelper[i].size() > 0) { | ||
| ::dawn::BindGroupLayout bindGroupLayout = | ||
| MakeBindGroupLayout(*device_, layouts_info[i]); | ||
| render_pipeline->bind_group_layouts.push_back(bindGroupLayout); | ||
|
|
||
| ::dawn::BindGroup bindGroup = | ||
| MakeBindGroup(*device_, render_pipeline->bind_group_layouts[i], | ||
| bindingInitalizerHelper[i]); | ||
| render_pipeline->bind_groups.push_back(bindGroup); | ||
| } | ||
| } | ||
|
|
||
| return {}; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this does not support compute pipeline yet, just return error message for compute pipeline here?