mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Support and pack unbounded binding numbers in the BGL
Also fixes a bug where we weren't validating duplicating bindings in the shader, and where dynamic offset validation could be incorrectly fetching the wrong bindings. Bug: dawn:354 Change-Id: I93178c34eb4d43119e8b9de5738ae4596e9277cd Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17240 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
11652ff8f8
commit
a80993da44
@@ -239,10 +239,12 @@ namespace dawn_native { namespace opengl {
|
||||
uint32_t dynamicOffsetCount,
|
||||
uint64_t* dynamicOffsets) {
|
||||
const auto& indices = ToBackend(mPipelineLayout)->GetBindingIndexInfo()[index];
|
||||
const auto& layout = group->GetLayout()->GetBindingInfo();
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& layout =
|
||||
group->GetLayout()->GetBindingInfo();
|
||||
uint32_t currentDynamicIndex = 0;
|
||||
|
||||
for (uint32_t bindingIndex : IterateBitSet(layout.mask)) {
|
||||
for (BindingIndex bindingIndex = 0; bindingIndex < layout.bindingCount;
|
||||
++bindingIndex) {
|
||||
switch (layout.types[bindingIndex]) {
|
||||
case wgpu::BindingType::UniformBuffer: {
|
||||
BufferBinding binding = group->GetBindingAsBufferBinding(bindingIndex);
|
||||
|
||||
@@ -107,19 +107,20 @@ namespace dawn_native { namespace opengl {
|
||||
const auto& indices = layout->GetBindingIndexInfo();
|
||||
|
||||
for (uint32_t group : IterateBitSet(layout->GetBindGroupLayoutsMask())) {
|
||||
const auto& groupInfo = layout->GetBindGroupLayout(group)->GetBindingInfo();
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& groupInfo =
|
||||
layout->GetBindGroupLayout(group)->GetBindingInfo();
|
||||
|
||||
for (uint32_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {
|
||||
if (!groupInfo.mask[binding]) {
|
||||
continue;
|
||||
}
|
||||
for (const auto& it : layout->GetBindGroupLayout(group)->GetBindingMap()) {
|
||||
BindingNumber bindingNumber = it.first;
|
||||
BindingIndex bindingIndex = it.second;
|
||||
|
||||
std::string name = GetBindingName(group, binding);
|
||||
switch (groupInfo.types[binding]) {
|
||||
std::string name = GetBindingName(group, bindingNumber);
|
||||
switch (groupInfo.types[bindingIndex]) {
|
||||
case wgpu::BindingType::UniformBuffer: {
|
||||
GLint location = gl.GetUniformBlockIndex(mProgram, name.c_str());
|
||||
if (location != -1) {
|
||||
gl.UniformBlockBinding(mProgram, location, indices[group][binding]);
|
||||
gl.UniformBlockBinding(mProgram, location,
|
||||
indices[group][bindingIndex]);
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -129,7 +130,7 @@ namespace dawn_native { namespace opengl {
|
||||
mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
|
||||
if (location != GL_INVALID_INDEX) {
|
||||
gl.ShaderStorageBlockBinding(mProgram, location,
|
||||
indices[group][binding]);
|
||||
indices[group][bindingIndex]);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
||||
@@ -28,30 +28,28 @@ namespace dawn_native { namespace opengl {
|
||||
GLuint ssboIndex = 0;
|
||||
|
||||
for (uint32_t group : IterateBitSet(GetBindGroupLayoutsMask())) {
|
||||
const auto& groupInfo = GetBindGroupLayout(group)->GetBindingInfo();
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& groupInfo =
|
||||
GetBindGroupLayout(group)->GetBindingInfo();
|
||||
|
||||
for (size_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {
|
||||
if (!groupInfo.mask[binding]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (groupInfo.types[binding]) {
|
||||
for (BindingIndex bindingIndex = 0; bindingIndex < groupInfo.bindingCount;
|
||||
++bindingIndex) {
|
||||
switch (groupInfo.types[bindingIndex]) {
|
||||
case wgpu::BindingType::UniformBuffer:
|
||||
mIndexInfo[group][binding] = uboIndex;
|
||||
mIndexInfo[group][bindingIndex] = uboIndex;
|
||||
uboIndex++;
|
||||
break;
|
||||
case wgpu::BindingType::Sampler:
|
||||
mIndexInfo[group][binding] = samplerIndex;
|
||||
mIndexInfo[group][bindingIndex] = samplerIndex;
|
||||
samplerIndex++;
|
||||
break;
|
||||
case wgpu::BindingType::SampledTexture:
|
||||
mIndexInfo[group][binding] = sampledTextureIndex;
|
||||
mIndexInfo[group][bindingIndex] = sampledTextureIndex;
|
||||
sampledTextureIndex++;
|
||||
break;
|
||||
|
||||
case wgpu::BindingType::StorageBuffer:
|
||||
case wgpu::BindingType::ReadonlyStorageBuffer:
|
||||
mIndexInfo[group][binding] = ssboIndex;
|
||||
mIndexInfo[group][bindingIndex] = ssboIndex;
|
||||
ssboIndex++;
|
||||
break;
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
DAWN_TRY(ExtractSpirvInfo(*compiler));
|
||||
|
||||
const auto& bindingInfo = GetBindingInfo();
|
||||
const ShaderModuleBase::ModuleBindingInfo& bindingInfo = GetBindingInfo();
|
||||
|
||||
// Extract bindings names so that it can be used to get its location in program.
|
||||
// Now translate the separate sampler / textures into combined ones and store their info.
|
||||
@@ -173,19 +173,18 @@ namespace dawn_native { namespace opengl {
|
||||
// Also unsets the SPIRV "Binding" decoration as it outputs "layout(binding=)" which
|
||||
// isn't supported on OSX's OpenGL.
|
||||
for (uint32_t group = 0; group < kMaxBindGroups; ++group) {
|
||||
for (uint32_t binding = 0; binding < kMaxBindingsPerGroup; ++binding) {
|
||||
const auto& info = bindingInfo[group][binding];
|
||||
if (info.used) {
|
||||
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
|
||||
mSpvcContext.SetName(info.base_type_id, GetBindingName(group, binding));
|
||||
mSpvcContext.UnsetDecoration(info.id, shaderc_spvc_decoration_binding);
|
||||
mSpvcContext.UnsetDecoration(info.id,
|
||||
shaderc_spvc_decoration_descriptorset);
|
||||
} else {
|
||||
compiler->set_name(info.base_type_id, GetBindingName(group, binding));
|
||||
compiler->unset_decoration(info.id, spv::DecorationBinding);
|
||||
compiler->unset_decoration(info.id, spv::DecorationDescriptorSet);
|
||||
}
|
||||
for (const auto& it : bindingInfo[group]) {
|
||||
BindingNumber bindingNumber = it.first;
|
||||
const auto& info = it.second;
|
||||
|
||||
if (GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) {
|
||||
mSpvcContext.SetName(info.base_type_id, GetBindingName(group, bindingNumber));
|
||||
mSpvcContext.UnsetDecoration(info.id, shaderc_spvc_decoration_binding);
|
||||
mSpvcContext.UnsetDecoration(info.id, shaderc_spvc_decoration_descriptorset);
|
||||
} else {
|
||||
compiler->set_name(info.base_type_id, GetBindingName(group, bindingNumber));
|
||||
compiler->unset_decoration(info.id, spv::DecorationBinding);
|
||||
compiler->unset_decoration(info.id, spv::DecorationDescriptorSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user