Deprecate BG[L]Desc::binding[s|Count] in favor of entr[ies|yCount]
Bug: dawn:22 Change-Id: I02188d70103a1bee25b9b2024a2ea9f785656236 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19862 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
be08000cb5
commit
3966eb1175
12
dawn.json
12
dawn.json
|
@ -77,8 +77,10 @@
|
|||
"members": [
|
||||
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen", "optional": true},
|
||||
{"name": "layout", "type": "bind group layout"},
|
||||
{"name": "binding count", "type": "uint32_t"},
|
||||
{"name": "bindings", "type": "bind group entry", "annotation": "const*", "length": "binding count"}
|
||||
{"name": "binding count", "type": "uint32_t", "default": 0},
|
||||
{"name": "bindings", "type": "bind group entry", "annotation": "const*", "length": "binding count"},
|
||||
{"name": "entry count", "type": "uint32_t", "default": 0},
|
||||
{"name": "entries", "type": "bind group entry", "annotation": "const*", "length": "entry count"}
|
||||
]
|
||||
},
|
||||
"bind group layout": {
|
||||
|
@ -104,8 +106,10 @@
|
|||
"extensible": true,
|
||||
"members": [
|
||||
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen", "optional": true},
|
||||
{"name": "binding count", "type": "uint32_t"},
|
||||
{"name": "bindings", "type": "bind group layout entry", "annotation": "const*", "length": "binding count"}
|
||||
{"name": "binding count", "type": "uint32_t", "default": 0},
|
||||
{"name": "bindings", "type": "bind group layout entry", "annotation": "const*", "length": "binding count"},
|
||||
{"name": "entry count", "type": "uint32_t", "default": 0},
|
||||
{"name": "entries", "type": "bind group layout entry", "annotation": "const*", "length": "entry count"}
|
||||
]
|
||||
},
|
||||
"binding type": {
|
||||
|
|
|
@ -29,22 +29,22 @@ namespace dawn_native {
|
|||
// Helper functions to perform binding-type specific validation
|
||||
|
||||
MaybeError ValidateBufferBinding(const DeviceBase* device,
|
||||
const BindGroupEntry& binding,
|
||||
const BindGroupEntry& entry,
|
||||
wgpu::BufferUsage requiredUsage) {
|
||||
if (binding.buffer == nullptr || binding.sampler != nullptr ||
|
||||
binding.textureView != nullptr) {
|
||||
if (entry.buffer == nullptr || entry.sampler != nullptr ||
|
||||
entry.textureView != nullptr) {
|
||||
return DAWN_VALIDATION_ERROR("expected buffer binding");
|
||||
}
|
||||
DAWN_TRY(device->ValidateObject(binding.buffer));
|
||||
DAWN_TRY(device->ValidateObject(entry.buffer));
|
||||
|
||||
uint64_t bufferSize = binding.buffer->GetSize();
|
||||
uint64_t bufferSize = entry.buffer->GetSize();
|
||||
|
||||
// Handle wgpu::WholeSize, avoiding overflows.
|
||||
if (binding.offset > bufferSize) {
|
||||
if (entry.offset > bufferSize) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer binding doesn't fit in the buffer");
|
||||
}
|
||||
uint64_t bindingSize =
|
||||
(binding.size == wgpu::kWholeSize) ? bufferSize - binding.offset : binding.size;
|
||||
(entry.size == wgpu::kWholeSize) ? bufferSize - entry.offset : entry.size;
|
||||
|
||||
if (bindingSize > bufferSize) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer binding size larger than the buffer");
|
||||
|
@ -56,16 +56,16 @@ namespace dawn_native {
|
|||
|
||||
// Note that no overflow can happen because we already checked that
|
||||
// bufferSize >= bindingSize
|
||||
if (binding.offset > bufferSize - bindingSize) {
|
||||
if (entry.offset > bufferSize - bindingSize) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer binding doesn't fit in the buffer");
|
||||
}
|
||||
|
||||
if (!IsAligned(binding.offset, 256)) {
|
||||
if (!IsAligned(entry.offset, 256)) {
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"Buffer offset for bind group needs to be 256-byte aligned");
|
||||
}
|
||||
|
||||
if (!(binding.buffer->GetUsage() & requiredUsage)) {
|
||||
if (!(entry.buffer->GetUsage() & requiredUsage)) {
|
||||
return DAWN_VALIDATION_ERROR("buffer binding usage mismatch");
|
||||
}
|
||||
|
||||
|
@ -73,16 +73,16 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
MaybeError ValidateTextureBinding(const DeviceBase* device,
|
||||
const BindGroupEntry& binding,
|
||||
const BindGroupEntry& entry,
|
||||
wgpu::TextureUsage requiredUsage,
|
||||
const BindingInfo& bindingInfo) {
|
||||
if (binding.textureView == nullptr || binding.sampler != nullptr ||
|
||||
binding.buffer != nullptr) {
|
||||
if (entry.textureView == nullptr || entry.sampler != nullptr ||
|
||||
entry.buffer != nullptr) {
|
||||
return DAWN_VALIDATION_ERROR("expected texture binding");
|
||||
}
|
||||
DAWN_TRY(device->ValidateObject(binding.textureView));
|
||||
DAWN_TRY(device->ValidateObject(entry.textureView));
|
||||
|
||||
TextureBase* texture = binding.textureView->GetTexture();
|
||||
TextureBase* texture = entry.textureView->GetTexture();
|
||||
|
||||
if (!(texture->GetUsage() & requiredUsage)) {
|
||||
return DAWN_VALIDATION_ERROR("texture binding usage mismatch");
|
||||
|
@ -110,7 +110,7 @@ namespace dawn_native {
|
|||
break;
|
||||
}
|
||||
|
||||
if (binding.textureView->GetDimension() != bindingInfo.viewDimension) {
|
||||
if (entry.textureView->GetDimension() != bindingInfo.viewDimension) {
|
||||
return DAWN_VALIDATION_ERROR("texture view dimension mismatch");
|
||||
}
|
||||
|
||||
|
@ -118,22 +118,22 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
MaybeError ValidateSamplerBinding(const DeviceBase* device,
|
||||
const BindGroupEntry& binding,
|
||||
const BindGroupEntry& entry,
|
||||
wgpu::BindingType bindingType) {
|
||||
if (binding.sampler == nullptr || binding.textureView != nullptr ||
|
||||
binding.buffer != nullptr) {
|
||||
if (entry.sampler == nullptr || entry.textureView != nullptr ||
|
||||
entry.buffer != nullptr) {
|
||||
return DAWN_VALIDATION_ERROR("expected sampler binding");
|
||||
}
|
||||
DAWN_TRY(device->ValidateObject(binding.sampler));
|
||||
DAWN_TRY(device->ValidateObject(entry.sampler));
|
||||
|
||||
switch (bindingType) {
|
||||
case wgpu::BindingType::Sampler:
|
||||
if (binding.sampler->HasCompareFunction()) {
|
||||
if (entry.sampler->HasCompareFunction()) {
|
||||
return DAWN_VALIDATION_ERROR("Did not expect comparison sampler");
|
||||
}
|
||||
break;
|
||||
case wgpu::BindingType::ComparisonSampler:
|
||||
if (!binding.sampler->HasCompareFunction()) {
|
||||
if (!entry.sampler->HasCompareFunction()) {
|
||||
return DAWN_VALIDATION_ERROR("Expected comparison sampler");
|
||||
}
|
||||
break;
|
||||
|
@ -153,17 +153,17 @@ namespace dawn_native {
|
|||
}
|
||||
|
||||
DAWN_TRY(device->ValidateObject(descriptor->layout));
|
||||
if (descriptor->bindingCount != descriptor->layout->GetBindingCount()) {
|
||||
if (descriptor->entryCount != descriptor->layout->GetBindingCount()) {
|
||||
return DAWN_VALIDATION_ERROR("numBindings mismatch");
|
||||
}
|
||||
|
||||
const BindGroupLayoutBase::BindingMap& bindingMap = descriptor->layout->GetBindingMap();
|
||||
|
||||
std::bitset<kMaxBindingsPerGroup> bindingsSet;
|
||||
for (uint32_t i = 0; i < descriptor->bindingCount; ++i) {
|
||||
const BindGroupEntry& binding = descriptor->bindings[i];
|
||||
for (uint32_t i = 0; i < descriptor->entryCount; ++i) {
|
||||
const BindGroupEntry& entry = descriptor->entries[i];
|
||||
|
||||
const auto& it = bindingMap.find(BindingNumber(binding.binding));
|
||||
const auto& it = bindingMap.find(BindingNumber(entry.binding));
|
||||
if (it == bindingMap.end()) {
|
||||
return DAWN_VALIDATION_ERROR("setting non-existent binding");
|
||||
}
|
||||
|
@ -180,25 +180,25 @@ namespace dawn_native {
|
|||
// Perform binding-type specific validation.
|
||||
switch (bindingInfo.type) {
|
||||
case wgpu::BindingType::UniformBuffer:
|
||||
DAWN_TRY(ValidateBufferBinding(device, binding, wgpu::BufferUsage::Uniform));
|
||||
DAWN_TRY(ValidateBufferBinding(device, entry, wgpu::BufferUsage::Uniform));
|
||||
break;
|
||||
case wgpu::BindingType::StorageBuffer:
|
||||
case wgpu::BindingType::ReadonlyStorageBuffer:
|
||||
DAWN_TRY(ValidateBufferBinding(device, binding, wgpu::BufferUsage::Storage));
|
||||
DAWN_TRY(ValidateBufferBinding(device, entry, wgpu::BufferUsage::Storage));
|
||||
break;
|
||||
case wgpu::BindingType::SampledTexture:
|
||||
DAWN_TRY(ValidateTextureBinding(device, binding, wgpu::TextureUsage::Sampled,
|
||||
DAWN_TRY(ValidateTextureBinding(device, entry, wgpu::TextureUsage::Sampled,
|
||||
bindingInfo));
|
||||
break;
|
||||
case wgpu::BindingType::Sampler:
|
||||
case wgpu::BindingType::ComparisonSampler:
|
||||
DAWN_TRY(ValidateSamplerBinding(device, binding, bindingInfo.type));
|
||||
DAWN_TRY(ValidateSamplerBinding(device, entry, bindingInfo.type));
|
||||
break;
|
||||
// TODO(jiawei.shao@intel.com): support creating bind group with read-only and
|
||||
// write-only storage textures.
|
||||
case wgpu::BindingType::ReadonlyStorageTexture:
|
||||
case wgpu::BindingType::WriteonlyStorageTexture:
|
||||
DAWN_TRY(ValidateTextureBinding(device, binding, wgpu::TextureUsage::Storage,
|
||||
DAWN_TRY(ValidateTextureBinding(device, entry, wgpu::TextureUsage::Storage,
|
||||
bindingInfo));
|
||||
break;
|
||||
case wgpu::BindingType::StorageTexture:
|
||||
|
@ -231,36 +231,36 @@ namespace dawn_native {
|
|||
new (&mBindingData.bindings[i]) Ref<ObjectBase>();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < descriptor->bindingCount; ++i) {
|
||||
const BindGroupEntry& binding = descriptor->bindings[i];
|
||||
for (uint32_t i = 0; i < descriptor->entryCount; ++i) {
|
||||
const BindGroupEntry& entry = descriptor->entries[i];
|
||||
|
||||
BindingIndex bindingIndex =
|
||||
descriptor->layout->GetBindingIndex(BindingNumber(binding.binding));
|
||||
descriptor->layout->GetBindingIndex(BindingNumber(entry.binding));
|
||||
ASSERT(bindingIndex < mLayout->GetBindingCount());
|
||||
|
||||
// Only a single binding type should be set, so once we found it we can skip to the
|
||||
// next loop iteration.
|
||||
|
||||
if (binding.buffer != nullptr) {
|
||||
if (entry.buffer != nullptr) {
|
||||
ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr);
|
||||
mBindingData.bindings[bindingIndex] = binding.buffer;
|
||||
mBindingData.bufferData[bindingIndex].offset = binding.offset;
|
||||
uint64_t bufferSize = (binding.size == wgpu::kWholeSize)
|
||||
? binding.buffer->GetSize() - binding.offset
|
||||
: binding.size;
|
||||
mBindingData.bindings[bindingIndex] = entry.buffer;
|
||||
mBindingData.bufferData[bindingIndex].offset = entry.offset;
|
||||
uint64_t bufferSize = (entry.size == wgpu::kWholeSize)
|
||||
? entry.buffer->GetSize() - entry.offset
|
||||
: entry.size;
|
||||
mBindingData.bufferData[bindingIndex].size = bufferSize;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (binding.textureView != nullptr) {
|
||||
if (entry.textureView != nullptr) {
|
||||
ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr);
|
||||
mBindingData.bindings[bindingIndex] = binding.textureView;
|
||||
mBindingData.bindings[bindingIndex] = entry.textureView;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (binding.sampler != nullptr) {
|
||||
if (entry.sampler != nullptr) {
|
||||
ASSERT(mBindingData.bindings[bindingIndex].Get() == nullptr);
|
||||
mBindingData.bindings[bindingIndex] = binding.sampler;
|
||||
mBindingData.bindings[bindingIndex] = entry.sampler;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,26 +102,26 @@ namespace dawn_native {
|
|||
std::set<BindingNumber> bindingsSet;
|
||||
uint32_t dynamicUniformBufferCount = 0;
|
||||
uint32_t dynamicStorageBufferCount = 0;
|
||||
for (BindingIndex i = 0; i < descriptor->bindingCount; ++i) {
|
||||
const BindGroupLayoutEntry& binding = descriptor->bindings[i];
|
||||
BindingNumber bindingNumber = BindingNumber(binding.binding);
|
||||
for (uint32_t i = 0; i < descriptor->entryCount; ++i) {
|
||||
const BindGroupLayoutEntry& entry = descriptor->entries[i];
|
||||
BindingNumber bindingNumber = BindingNumber(entry.binding);
|
||||
|
||||
DAWN_TRY(ValidateShaderStage(binding.visibility));
|
||||
DAWN_TRY(ValidateBindingType(binding.type));
|
||||
DAWN_TRY(ValidateTextureComponentType(binding.textureComponentType));
|
||||
DAWN_TRY(ValidateShaderStage(entry.visibility));
|
||||
DAWN_TRY(ValidateBindingType(entry.type));
|
||||
DAWN_TRY(ValidateTextureComponentType(entry.textureComponentType));
|
||||
|
||||
if (binding.viewDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
DAWN_TRY(ValidateTextureViewDimension(binding.viewDimension));
|
||||
if (entry.viewDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
DAWN_TRY(ValidateTextureViewDimension(entry.viewDimension));
|
||||
|
||||
// TODO(dawn:22): Remove this once users use viewDimension
|
||||
if (binding.textureDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
if (entry.textureDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"Cannot use both viewDimension and textureDimension");
|
||||
}
|
||||
} else {
|
||||
// TODO(dawn:22): Remove this once users use viewDimension
|
||||
if (binding.textureDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
DAWN_TRY(ValidateTextureViewDimension(binding.textureDimension));
|
||||
if (entry.textureDimension != wgpu::TextureViewDimension::Undefined) {
|
||||
DAWN_TRY(ValidateTextureViewDimension(entry.textureDimension));
|
||||
device->EmitDeprecationWarning(
|
||||
"BindGroupLayoutEntry::textureDimension is deprecated, use viewDimension "
|
||||
"instead");
|
||||
|
@ -132,21 +132,19 @@ namespace dawn_native {
|
|||
return DAWN_VALIDATION_ERROR("some binding index was specified more than once");
|
||||
}
|
||||
|
||||
DAWN_TRY(
|
||||
ValidateBindingTypeWithShaderStageVisibility(binding.type, binding.visibility));
|
||||
DAWN_TRY(ValidateBindingTypeWithShaderStageVisibility(entry.type, entry.visibility));
|
||||
|
||||
DAWN_TRY(
|
||||
ValidateStorageTextureFormat(device, binding.type, binding.storageTextureFormat));
|
||||
DAWN_TRY(ValidateStorageTextureFormat(device, entry.type, entry.storageTextureFormat));
|
||||
|
||||
switch (binding.type) {
|
||||
switch (entry.type) {
|
||||
case wgpu::BindingType::UniformBuffer:
|
||||
if (binding.hasDynamicOffset) {
|
||||
if (entry.hasDynamicOffset) {
|
||||
++dynamicUniformBufferCount;
|
||||
}
|
||||
break;
|
||||
case wgpu::BindingType::StorageBuffer:
|
||||
case wgpu::BindingType::ReadonlyStorageBuffer:
|
||||
if (binding.hasDynamicOffset) {
|
||||
if (entry.hasDynamicOffset) {
|
||||
++dynamicStorageBufferCount;
|
||||
}
|
||||
break;
|
||||
|
@ -155,7 +153,7 @@ namespace dawn_native {
|
|||
case wgpu::BindingType::ComparisonSampler:
|
||||
case wgpu::BindingType::ReadonlyStorageTexture:
|
||||
case wgpu::BindingType::WriteonlyStorageTexture:
|
||||
if (binding.hasDynamicOffset) {
|
||||
if (entry.hasDynamicOffset) {
|
||||
return DAWN_VALIDATION_ERROR("Samplers and textures cannot be dynamic");
|
||||
}
|
||||
break;
|
||||
|
@ -163,7 +161,7 @@ namespace dawn_native {
|
|||
return DAWN_VALIDATION_ERROR("storage textures aren't supported (yet)");
|
||||
}
|
||||
|
||||
if (binding.multisampled) {
|
||||
if (entry.multisampled) {
|
||||
return DAWN_VALIDATION_ERROR(
|
||||
"BindGroupLayoutEntry::multisampled must be false (for now)");
|
||||
}
|
||||
|
@ -273,9 +271,9 @@ namespace dawn_native {
|
|||
|
||||
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
|
||||
const BindGroupLayoutDescriptor* descriptor)
|
||||
: CachedObject(device), mBindingCount(descriptor->bindingCount) {
|
||||
: CachedObject(device), mBindingCount(descriptor->entryCount) {
|
||||
std::vector<BindGroupLayoutEntry> sortedBindings(
|
||||
descriptor->bindings, descriptor->bindings + descriptor->bindingCount);
|
||||
descriptor->entries, descriptor->entries + descriptor->entryCount);
|
||||
|
||||
std::sort(sortedBindings.begin(), sortedBindings.end(), SortBindingsCompare);
|
||||
|
||||
|
|
|
@ -731,10 +731,25 @@ namespace dawn_native {
|
|||
MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result,
|
||||
const BindGroupDescriptor* descriptor) {
|
||||
DAWN_TRY(ValidateIsAlive());
|
||||
if (IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateBindGroupDescriptor(this, descriptor));
|
||||
|
||||
// TODO(dawn:22): Remove this once users use entries/entryCount
|
||||
BindGroupDescriptor fixedDescriptor = *descriptor;
|
||||
if (fixedDescriptor.bindingCount != 0) {
|
||||
if (fixedDescriptor.entryCount != 0) {
|
||||
return DAWN_VALIDATION_ERROR("Cannot use bindings and entries at the same time");
|
||||
} else {
|
||||
EmitDeprecationWarning(
|
||||
"BindGroupEntry::bindings/bindingCount is deprecated, use entries/entryCount "
|
||||
"instead");
|
||||
fixedDescriptor.entryCount = fixedDescriptor.bindingCount;
|
||||
fixedDescriptor.entries = fixedDescriptor.bindings;
|
||||
}
|
||||
}
|
||||
DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(descriptor));
|
||||
|
||||
if (IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateBindGroupDescriptor(this, &fixedDescriptor));
|
||||
}
|
||||
DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(&fixedDescriptor));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -742,10 +757,25 @@ namespace dawn_native {
|
|||
BindGroupLayoutBase** result,
|
||||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
DAWN_TRY(ValidateIsAlive());
|
||||
if (IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
|
||||
|
||||
// TODO(dawn:22): Remove this once users use entries/entryCount
|
||||
BindGroupLayoutDescriptor fixedDescriptor = *descriptor;
|
||||
if (fixedDescriptor.bindingCount != 0) {
|
||||
if (fixedDescriptor.entryCount != 0) {
|
||||
return DAWN_VALIDATION_ERROR("Cannot use bindings and entries at the same time");
|
||||
} else {
|
||||
EmitDeprecationWarning(
|
||||
"BindGroupLayoutEntry::bindings/bindingCount is deprecated, use "
|
||||
"entries/entryCount instead");
|
||||
fixedDescriptor.entryCount = fixedDescriptor.bindingCount;
|
||||
fixedDescriptor.entries = fixedDescriptor.bindings;
|
||||
}
|
||||
}
|
||||
DAWN_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor));
|
||||
|
||||
if (IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, &fixedDescriptor));
|
||||
}
|
||||
DAWN_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(&fixedDescriptor));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ namespace dawn_native {
|
|||
// a Ref<BindGroupLayoutBase>, then the VkDevice will be destroyed before the
|
||||
// VkDescriptorSetLayout.
|
||||
BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 0;
|
||||
desc.bindings = nullptr;
|
||||
desc.entryCount = 0;
|
||||
desc.entries = nullptr;
|
||||
|
||||
BindGroupLayoutBase* bgl = nullptr;
|
||||
if (GetDevice()->ConsumedError(GetDevice()->GetOrCreateBindGroupLayout(&desc), &bgl)) {
|
||||
|
|
|
@ -126,13 +126,13 @@ namespace dawn_native {
|
|||
|
||||
// Data which BindGroupLayoutDescriptor will point to for creation
|
||||
std::array<std::array<BindGroupLayoutEntry, kMaxBindingsPerGroup>, kMaxBindGroups>
|
||||
bindingData = {};
|
||||
entryData = {};
|
||||
|
||||
// A map of bindings to the index in |bindingData|
|
||||
// A map of bindings to the index in |entryData|
|
||||
std::array<std::map<BindingNumber, BindingIndex>, kMaxBindGroups> usedBindingsMap = {};
|
||||
|
||||
// A counter of how many bindings we've populated in |bindingData|
|
||||
std::array<uint32_t, kMaxBindGroups> bindingCounts = {};
|
||||
// A counter of how many bindings we've populated in |entryData|
|
||||
std::array<uint32_t, kMaxBindGroups> entryCounts = {};
|
||||
|
||||
uint32_t bindGroupLayoutCount = 0;
|
||||
for (uint32_t moduleIndex = 0; moduleIndex < count; ++moduleIndex) {
|
||||
|
@ -170,7 +170,7 @@ namespace dawn_native {
|
|||
{
|
||||
const auto& it = usedBindingsMap[group].find(bindingNumber);
|
||||
if (it != usedBindingsMap[group].end()) {
|
||||
if (bindingSlot == bindingData[group][it->second]) {
|
||||
if (bindingSlot == entryData[group][it->second]) {
|
||||
// Already used and the data is the same. Continue.
|
||||
continue;
|
||||
} else {
|
||||
|
@ -181,12 +181,12 @@ namespace dawn_native {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t currentBindingCount = bindingCounts[group];
|
||||
bindingData[group][currentBindingCount] = bindingSlot;
|
||||
uint32_t currentBindingCount = entryCounts[group];
|
||||
entryData[group][currentBindingCount] = bindingSlot;
|
||||
|
||||
usedBindingsMap[group][bindingNumber] = currentBindingCount;
|
||||
|
||||
bindingCounts[group]++;
|
||||
entryCounts[group]++;
|
||||
|
||||
bindGroupLayoutCount = std::max(bindGroupLayoutCount, group + 1);
|
||||
}
|
||||
|
@ -196,8 +196,8 @@ namespace dawn_native {
|
|||
std::array<BindGroupLayoutBase*, kMaxBindGroups> bindGroupLayouts = {};
|
||||
for (uint32_t group = 0; group < bindGroupLayoutCount; ++group) {
|
||||
BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindings = bindingData[group].data();
|
||||
desc.bindingCount = bindingCounts[group];
|
||||
desc.entries = entryData[group].data();
|
||||
desc.entryCount = entryCounts[group];
|
||||
|
||||
// We should never produce a bad descriptor.
|
||||
ASSERT(!ValidateBindGroupLayoutDescriptor(device, &desc).IsError());
|
||||
|
|
|
@ -750,11 +750,11 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) {
|
|||
TEST_P(BindGroupTests, BindGroupLayoutVisibilityCanBeNone) {
|
||||
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
|
||||
|
||||
wgpu::BindGroupLayoutEntry binding = {0, wgpu::ShaderStage::None,
|
||||
wgpu::BindingType::UniformBuffer};
|
||||
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::None,
|
||||
wgpu::BindingType::UniformBuffer};
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
wgpu::BindGroupLayout layout = device.CreateBindGroupLayout(&descriptor);
|
||||
|
||||
wgpu::RenderPipeline pipeline = MakeTestPipeline(renderPass, {}, {layout});
|
||||
|
|
|
@ -79,8 +79,8 @@ TEST_P(DeprecationTests, BGLEntryTextureDimensionIsDeprecated) {
|
|||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
EXPECT_DEPRECATION_WARNING(device.CreateBindGroupLayout(&bglDesc));
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ TEST_P(DeprecationTests, BGLEntryTextureDimensionAndViewUndefinedEmitsNoWarning)
|
|||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
device.CreateBindGroupLayout(&bglDesc);
|
||||
}
|
||||
|
@ -106,8 +106,8 @@ TEST_P(DeprecationTests, BGLEntryTextureAndViewDimensionIsInvalid) {
|
|||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&bglDesc));
|
||||
}
|
||||
|
@ -121,8 +121,8 @@ TEST_P(DeprecationTests, BGLEntryTextureDimensionStateTracking) {
|
|||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
wgpu::BindGroupLayout layout;
|
||||
EXPECT_DEPRECATION_WARNING(layout = device.CreateBindGroupLayout(&bglDesc));
|
||||
|
@ -152,6 +152,161 @@ TEST_P(DeprecationTests, BGLEntryTextureDimensionStateTracking) {
|
|||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, arrayView}}));
|
||||
}
|
||||
|
||||
// Test for BindGroupLayout::bindings/bindingCount -> entries/entryCount
|
||||
|
||||
// Test that creating a BGL with bindings emits a deprecation warning.
|
||||
TEST_P(DeprecationTests, BGLDescBindingIsDeprecated) {
|
||||
wgpu::BindGroupLayoutEntry entryDesc = {
|
||||
.type = wgpu::BindingType::Sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
};
|
||||
EXPECT_DEPRECATION_WARNING(device.CreateBindGroupLayout(&bglDesc));
|
||||
}
|
||||
|
||||
// Test that creating a BGL with both entries and bindings is an error
|
||||
TEST_P(DeprecationTests, BGLDescBindingAndEntriesIsInvalid) {
|
||||
wgpu::BindGroupLayoutEntry entryDesc = {
|
||||
.type = wgpu::BindingType::Sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&bglDesc));
|
||||
}
|
||||
|
||||
// Test that creating a BGL with both entries and bindings to 0 doesn't emit warnings
|
||||
TEST_P(DeprecationTests, BGLDescBindingAndEntriesBothZeroEmitsNoWarning) {
|
||||
// TODO(cwallez@chromium.org): In Vulkan it is disallowed to create 0-sized descriptor pools
|
||||
// but the Vulkan backend doesn't special case it yet.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan());
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 0,
|
||||
.bindings = nullptr,
|
||||
.entryCount = 0,
|
||||
.entries = nullptr,
|
||||
};
|
||||
device.CreateBindGroupLayout(&bglDesc);
|
||||
}
|
||||
|
||||
// Test that creating a BGL with bindings still does correct state tracking
|
||||
TEST_P(DeprecationTests, BGLDescBindingStateTracking) {
|
||||
wgpu::BindGroupLayoutEntry entryDesc = {
|
||||
.binding = 0,
|
||||
.type = wgpu::BindingType::Sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
};
|
||||
wgpu::BindGroupLayout layout;
|
||||
EXPECT_DEPRECATION_WARNING(layout = device.CreateBindGroupLayout(&bglDesc));
|
||||
|
||||
// Test a case where if |bindings| wasn't taken into account, no validation error would happen
|
||||
// because the layout would be empty
|
||||
wgpu::BindGroupDescriptor badBgDesc = {
|
||||
.layout = layout,
|
||||
.entryCount = 0,
|
||||
.entries = nullptr,
|
||||
};
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&badBgDesc));
|
||||
}
|
||||
|
||||
// Test for BindGroup::bindings/bindingCount -> entries/entryCount
|
||||
|
||||
// Test that creating a BG with bindings emits a deprecation warning.
|
||||
TEST_P(DeprecationTests, BGDescBindingIsDeprecated) {
|
||||
wgpu::SamplerDescriptor samplerDesc = {};
|
||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
||||
|
||||
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
|
||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler}});
|
||||
|
||||
wgpu::BindGroupEntry entryDesc = {
|
||||
.binding = 0,
|
||||
.sampler = sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupDescriptor bgDesc = {
|
||||
.layout = layout,
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
};
|
||||
EXPECT_DEPRECATION_WARNING(device.CreateBindGroup(&bgDesc));
|
||||
}
|
||||
|
||||
// Test that creating a BG with both entries and bindings is an error
|
||||
TEST_P(DeprecationTests, BGDescBindingAndEntriesIsInvalid) {
|
||||
wgpu::SamplerDescriptor samplerDesc = {};
|
||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
||||
|
||||
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
|
||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler}});
|
||||
|
||||
wgpu::BindGroupEntry entryDesc = {
|
||||
.binding = 0,
|
||||
.sampler = sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupDescriptor bgDesc = {
|
||||
.layout = layout,
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
.entryCount = 1,
|
||||
.entries = &entryDesc,
|
||||
};
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&bgDesc));
|
||||
}
|
||||
|
||||
// Test that creating a BG with both entries and bindings to 0 doesn't emit warnings
|
||||
TEST_P(DeprecationTests, BGDescBindingAndEntriesBothZeroEmitsNoWarning) {
|
||||
// TODO(cwallez@chromium.org): In Vulkan it is disallowed to create 0-sized descriptor pools
|
||||
// but the Vulkan backend doesn't special case it yet.
|
||||
DAWN_SKIP_TEST_IF(IsVulkan());
|
||||
|
||||
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {});
|
||||
|
||||
wgpu::BindGroupDescriptor bgDesc = {
|
||||
.layout = layout,
|
||||
.bindingCount = 0,
|
||||
.bindings = nullptr,
|
||||
.entryCount = 0,
|
||||
.entries = nullptr,
|
||||
};
|
||||
device.CreateBindGroup(&bgDesc);
|
||||
}
|
||||
|
||||
// Test that creating a BG with bindings still does correct state tracking
|
||||
TEST_P(DeprecationTests, BGDescBindingStateTracking) {
|
||||
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {});
|
||||
|
||||
// Test a case where if |bindings| wasn't taken into account, no validation error would happen
|
||||
// because it would match the empty layout.
|
||||
wgpu::SamplerDescriptor samplerDesc = {};
|
||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
||||
|
||||
wgpu::BindGroupEntry entryDesc = {
|
||||
.binding = 0,
|
||||
.sampler = sampler,
|
||||
};
|
||||
|
||||
wgpu::BindGroupDescriptor bgDesc = {
|
||||
.layout = layout,
|
||||
.bindingCount = 1,
|
||||
.bindings = &entryDesc,
|
||||
};
|
||||
EXPECT_DEPRECATION_WARNING(ASSERT_DEVICE_ERROR(device.CreateBindGroup(&bgDesc)));
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(DeprecationTests,
|
||||
D3D12Backend(),
|
||||
MetalBackend(),
|
||||
|
|
|
@ -105,11 +105,11 @@ TEST_P(DeviceLostTest, SubmitFails) {
|
|||
TEST_P(DeviceLostTest, CreateBindGroupLayoutFails) {
|
||||
SetCallbackAndLoseForTesting();
|
||||
|
||||
wgpu::BindGroupLayoutEntry binding = {0, wgpu::ShaderStage::None,
|
||||
wgpu::BindingType::UniformBuffer};
|
||||
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::None,
|
||||
wgpu::BindingType::UniformBuffer};
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor));
|
||||
}
|
||||
|
||||
|
@ -139,18 +139,18 @@ TEST_P(DeviceLostTest, GetBindGroupLayoutFails) {
|
|||
TEST_P(DeviceLostTest, CreateBindGroupFails) {
|
||||
SetCallbackAndLoseForTesting();
|
||||
|
||||
wgpu::BindGroupEntry binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.buffer = nullptr;
|
||||
binding.offset = 0;
|
||||
binding.size = 0;
|
||||
wgpu::BindGroupEntry entry;
|
||||
entry.binding = 0;
|
||||
entry.sampler = nullptr;
|
||||
entry.textureView = nullptr;
|
||||
entry.buffer = nullptr;
|
||||
entry.offset = 0;
|
||||
entry.size = 0;
|
||||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = nullptr;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,24 +23,24 @@ TEST_P(StorageTextureTests, BindGroupLayoutWithStorageTextureBindingType) {
|
|||
// wgpu::BindingType::ReadonlyStorageTexture is a valid binding type to create a bind group
|
||||
// layout.
|
||||
{
|
||||
wgpu::BindGroupLayoutEntry binding = {0, wgpu::ShaderStage::Compute,
|
||||
wgpu::BindingType::ReadonlyStorageTexture};
|
||||
binding.storageTextureFormat = wgpu::TextureFormat::R32Float;
|
||||
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::Compute,
|
||||
wgpu::BindingType::ReadonlyStorageTexture};
|
||||
entry.storageTextureFormat = wgpu::TextureFormat::R32Float;
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
device.CreateBindGroupLayout(&descriptor);
|
||||
}
|
||||
|
||||
// wgpu::BindingType::WriteonlyStorageTexture is a valid binding type to create a bind group
|
||||
// layout.
|
||||
{
|
||||
wgpu::BindGroupLayoutEntry binding = {0, wgpu::ShaderStage::Compute,
|
||||
wgpu::BindingType::WriteonlyStorageTexture};
|
||||
binding.storageTextureFormat = wgpu::TextureFormat::R32Float;
|
||||
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::Compute,
|
||||
wgpu::BindingType::WriteonlyStorageTexture};
|
||||
entry.storageTextureFormat = wgpu::TextureFormat::R32Float;
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
device.CreateBindGroupLayout(&descriptor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,8 +75,8 @@ TEST_F(BindGroupValidationTest, NextInChainNullptr) {
|
|||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.bindingCount = 0;
|
||||
descriptor.bindings = nullptr;
|
||||
descriptor.entryCount = 0;
|
||||
descriptor.entries = nullptr;
|
||||
|
||||
// Control case: check that nextInChain = nullptr is valid
|
||||
descriptor.nextInChain = nullptr;
|
||||
|
@ -88,15 +88,15 @@ TEST_F(BindGroupValidationTest, NextInChainNullptr) {
|
|||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
}
|
||||
|
||||
// Check constraints on bindingCount
|
||||
TEST_F(BindGroupValidationTest, bindingCountMismatch) {
|
||||
// Check constraints on entryCount
|
||||
TEST_F(BindGroupValidationTest, EntryCountMismatch) {
|
||||
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
|
||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler}});
|
||||
|
||||
// Control case: check that a descriptor with one binding is ok
|
||||
utils::MakeBindGroup(device, layout, {{0, mSampler}});
|
||||
|
||||
// Check that bindingCount != layout.bindingCount fails.
|
||||
// Check that entryCount != layout.entryCount fails.
|
||||
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {}));
|
||||
}
|
||||
|
||||
|
@ -149,8 +149,8 @@ TEST_F(BindGroupValidationTest, SamplerBindingType) {
|
|||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
@ -198,8 +198,8 @@ TEST_F(BindGroupValidationTest, TextureBindingType) {
|
|||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
@ -252,8 +252,8 @@ TEST_F(BindGroupValidationTest, BufferBindingType) {
|
|||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &binding;
|
||||
|
||||
// Not setting anything fails
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
|
||||
|
@ -473,8 +473,8 @@ class BindGroupLayoutValidationTest : public ValidationTest {
|
|||
bool expected) {
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
|
||||
descriptor.bindingCount = count;
|
||||
descriptor.bindings = binding;
|
||||
descriptor.entryCount = count;
|
||||
descriptor.entries = binding;
|
||||
|
||||
if (!expected) {
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor));
|
||||
|
@ -526,23 +526,23 @@ TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutEntryUnbounded) {
|
|||
|
||||
// Test that there can't be more than kMaxBindingPerGroup bindings per group
|
||||
TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutMaxBindings) {
|
||||
wgpu::BindGroupLayoutEntry bindings[kMaxBindingsPerGroup + 1];
|
||||
wgpu::BindGroupLayoutEntry entries[kMaxBindingsPerGroup + 1];
|
||||
|
||||
for (uint32_t i = 0; i < kMaxBindingsPerGroup + 1; i++) {
|
||||
bindings[i].type = wgpu::BindingType::UniformBuffer;
|
||||
bindings[i].binding = i;
|
||||
bindings[i].visibility = wgpu::ShaderStage::Compute;
|
||||
entries[i].type = wgpu::BindingType::UniformBuffer;
|
||||
entries[i].binding = i;
|
||||
entries[i].visibility = wgpu::ShaderStage::Compute;
|
||||
}
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc;
|
||||
desc.bindings = bindings;
|
||||
desc.entries = entries;
|
||||
|
||||
// Control case: kMaxBindingsPerGroup bindings is allowed.
|
||||
desc.bindingCount = kMaxBindingsPerGroup;
|
||||
desc.entryCount = kMaxBindingsPerGroup;
|
||||
device.CreateBindGroupLayout(&desc);
|
||||
|
||||
// Error case: kMaxBindingsPerGroup + 1 bindings is not allowed.
|
||||
desc.bindingCount = kMaxBindingsPerGroup + 1;
|
||||
desc.entryCount = kMaxBindingsPerGroup + 1;
|
||||
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&desc));
|
||||
}
|
||||
|
||||
|
@ -594,8 +594,8 @@ TEST_F(BindGroupLayoutValidationTest, BindGroupLayoutVisibilityNone) {
|
|||
wgpu::BindGroupLayoutEntry binding = {0, wgpu::ShaderStage::None,
|
||||
wgpu::BindingType::UniformBuffer};
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &binding;
|
||||
device.CreateBindGroupLayout(&descriptor);
|
||||
}
|
||||
|
||||
|
@ -642,8 +642,8 @@ TEST_F(BindGroupLayoutValidationTest, DynamicBufferNumberLimit) {
|
|||
auto MakeBindGroupLayout = [&](wgpu::BindGroupLayoutEntry* binding,
|
||||
uint32_t count) -> wgpu::BindGroupLayout {
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = count;
|
||||
descriptor.bindings = binding;
|
||||
descriptor.entryCount = count;
|
||||
descriptor.entries = binding;
|
||||
return device.CreateBindGroupLayout(&descriptor);
|
||||
};
|
||||
|
||||
|
@ -1055,8 +1055,8 @@ class SetBindGroupPersistenceValidationTest : public ValidationTest {
|
|||
|
||||
// Create the bind group layout.
|
||||
wgpu::BindGroupLayoutDescriptor bglDescriptor;
|
||||
bglDescriptor.bindingCount = static_cast<uint32_t>(bindings.size());
|
||||
bglDescriptor.bindings = bindings.data();
|
||||
bglDescriptor.entryCount = static_cast<uint32_t>(bindings.size());
|
||||
bglDescriptor.entries = bindings.data();
|
||||
bindGroupLayouts[l] = device.CreateBindGroupLayout(&bglDescriptor);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,8 +108,8 @@ TEST_F(GetBindGroupLayoutTests, DefaultShaderStageAndDynamicOffsets) {
|
|||
binding.multisampled = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
// Check that visibility and dynamic offsets match
|
||||
binding.hasDynamicOffset = false;
|
||||
|
@ -157,8 +157,8 @@ TEST_F(GetBindGroupLayoutTests, ComputePipeline) {
|
|||
binding.hasDynamicOffset = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
EXPECT_EQ(device.CreateBindGroupLayout(&desc).Get(), pipeline.GetBindGroupLayout(0).Get());
|
||||
}
|
||||
|
@ -171,8 +171,8 @@ TEST_F(GetBindGroupLayoutTests, BindingType) {
|
|||
binding.multisampled = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
{
|
||||
// Storage buffer binding is not supported in vertex shader.
|
||||
|
@ -243,8 +243,8 @@ TEST_F(GetBindGroupLayoutTests, Multisampled) {
|
|||
binding.hasDynamicOffset = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
{
|
||||
binding.multisampled = false;
|
||||
|
@ -281,8 +281,8 @@ TEST_F(GetBindGroupLayoutTests, ViewDimension) {
|
|||
binding.multisampled = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
{
|
||||
binding.viewDimension = wgpu::TextureViewDimension::e1D;
|
||||
|
@ -355,8 +355,8 @@ TEST_F(GetBindGroupLayoutTests, TextureComponentType) {
|
|||
binding.multisampled = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
{
|
||||
binding.textureComponentType = wgpu::TextureComponentType::Float;
|
||||
|
@ -398,8 +398,8 @@ TEST_F(GetBindGroupLayoutTests, BindingIndices) {
|
|||
binding.multisampled = false;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 1;
|
||||
desc.bindings = &binding;
|
||||
desc.entryCount = 1;
|
||||
desc.entries = &binding;
|
||||
|
||||
{
|
||||
binding.binding = 0;
|
||||
|
@ -605,8 +605,8 @@ TEST_F(GetBindGroupLayoutTests, UnusedIndex) {
|
|||
void main() {})");
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor desc = {};
|
||||
desc.bindingCount = 0;
|
||||
desc.bindings = nullptr;
|
||||
desc.entryCount = 0;
|
||||
desc.entries = nullptr;
|
||||
|
||||
wgpu::BindGroupLayout emptyBindGroupLayout = device.CreateBindGroupLayout(&desc);
|
||||
|
||||
|
@ -625,8 +625,8 @@ TEST_F(GetBindGroupLayoutTests, Reflection) {
|
|||
binding.visibility = wgpu::ShaderStage::Vertex;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor bglDesc = {};
|
||||
bglDesc.bindingCount = 1;
|
||||
bglDesc.bindings = &binding;
|
||||
bglDesc.entryCount = 1;
|
||||
bglDesc.entries = &binding;
|
||||
|
||||
wgpu::BindGroupLayout bindGroupLayout = device.CreateBindGroupLayout(&bglDesc);
|
||||
|
||||
|
@ -663,8 +663,8 @@ TEST_F(GetBindGroupLayoutTests, Reflection) {
|
|||
|
||||
{
|
||||
wgpu::BindGroupLayoutDescriptor emptyDesc = {};
|
||||
emptyDesc.bindingCount = 0;
|
||||
emptyDesc.bindings = nullptr;
|
||||
emptyDesc.entryCount = 0;
|
||||
emptyDesc.entries = nullptr;
|
||||
|
||||
wgpu::BindGroupLayout emptyBindGroupLayout = device.CreateBindGroupLayout(&emptyDesc);
|
||||
|
||||
|
|
|
@ -381,11 +381,12 @@ TEST_F(StorageTextureValidationTests, BindGroupLayoutWithStorageTextureBindingTy
|
|||
{wgpu::ShaderStage::Compute, wgpu::BindingType::StorageTexture, false}}};
|
||||
|
||||
for (const auto& testSpec : kTestSpecs) {
|
||||
wgpu::BindGroupLayoutEntry binding = {0, testSpec.stage, testSpec.type};
|
||||
binding.storageTextureFormat = wgpu::TextureFormat::R32Uint;
|
||||
wgpu::BindGroupLayoutEntry entry = {0, testSpec.stage, testSpec.type};
|
||||
entry.storageTextureFormat = wgpu::TextureFormat::R32Uint;
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = 1;
|
||||
descriptor.bindings = &binding;
|
||||
descriptor.entryCount = 1;
|
||||
descriptor.entries = &entry;
|
||||
|
||||
if (testSpec.valid) {
|
||||
device.CreateBindGroupLayout(&descriptor);
|
||||
|
|
|
@ -49,8 +49,8 @@ TEST_F(WireArgumentTests, ValueArgument) {
|
|||
TEST_F(WireArgumentTests, ValueArrayArgument) {
|
||||
// Create a bindgroup.
|
||||
WGPUBindGroupLayoutDescriptor bglDescriptor = {};
|
||||
bglDescriptor.bindingCount = 0;
|
||||
bglDescriptor.bindings = nullptr;
|
||||
bglDescriptor.entryCount = 0;
|
||||
bglDescriptor.entries = nullptr;
|
||||
|
||||
WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor);
|
||||
WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
|
||||
|
@ -58,8 +58,8 @@ TEST_F(WireArgumentTests, ValueArrayArgument) {
|
|||
|
||||
WGPUBindGroupDescriptor bindGroupDescriptor = {};
|
||||
bindGroupDescriptor.layout = bgl;
|
||||
bindGroupDescriptor.bindingCount = 0;
|
||||
bindGroupDescriptor.bindings = nullptr;
|
||||
bindGroupDescriptor.entryCount = 0;
|
||||
bindGroupDescriptor.entries = nullptr;
|
||||
|
||||
WGPUBindGroup bindGroup = wgpuDeviceCreateBindGroup(device, &bindGroupDescriptor);
|
||||
WGPUBindGroup apiBindGroup = api.GetNewBindGroup();
|
||||
|
@ -284,8 +284,8 @@ TEST_F(WireArgumentTests, StructureOfValuesArgument) {
|
|||
// Test that the wire is able to send structures that contain objects
|
||||
TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) {
|
||||
WGPUBindGroupLayoutDescriptor bglDescriptor = {};
|
||||
bglDescriptor.bindingCount = 0;
|
||||
bglDescriptor.bindings = nullptr;
|
||||
bglDescriptor.entryCount = 0;
|
||||
bglDescriptor.entries = nullptr;
|
||||
|
||||
WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor);
|
||||
WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
|
||||
|
@ -313,7 +313,7 @@ TEST_F(WireArgumentTests, StructureOfObjectArrayArgument) {
|
|||
// Test that the wire is able to send structures that contain objects
|
||||
TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) {
|
||||
static constexpr int NUM_BINDINGS = 3;
|
||||
WGPUBindGroupLayoutEntry bindings[NUM_BINDINGS]{
|
||||
WGPUBindGroupLayoutEntry entries[NUM_BINDINGS]{
|
||||
{0,
|
||||
WGPUShaderStage_Vertex,
|
||||
WGPUBindingType_Sampler,
|
||||
|
@ -343,24 +343,24 @@ TEST_F(WireArgumentTests, StructureOfStructureArrayArgument) {
|
|||
WGPUTextureFormat_RGBA8Unorm},
|
||||
};
|
||||
WGPUBindGroupLayoutDescriptor bglDescriptor = {};
|
||||
bglDescriptor.bindingCount = NUM_BINDINGS;
|
||||
bglDescriptor.bindings = bindings;
|
||||
bglDescriptor.entryCount = NUM_BINDINGS;
|
||||
bglDescriptor.entries = entries;
|
||||
|
||||
wgpuDeviceCreateBindGroupLayout(device, &bglDescriptor);
|
||||
WGPUBindGroupLayout apiBgl = api.GetNewBindGroupLayout();
|
||||
EXPECT_CALL(
|
||||
api,
|
||||
DeviceCreateBindGroupLayout(
|
||||
apiDevice, MatchesLambda([bindings](const WGPUBindGroupLayoutDescriptor* desc) -> bool {
|
||||
apiDevice, MatchesLambda([entries](const WGPUBindGroupLayoutDescriptor* desc) -> bool {
|
||||
for (int i = 0; i < NUM_BINDINGS; ++i) {
|
||||
const auto& a = desc->bindings[i];
|
||||
const auto& b = bindings[i];
|
||||
const auto& a = desc->entries[i];
|
||||
const auto& b = entries[i];
|
||||
if (a.binding != b.binding || a.visibility != b.visibility ||
|
||||
a.type != b.type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return desc->nextInChain == nullptr && desc->bindingCount == 3;
|
||||
return desc->nextInChain == nullptr && desc->entryCount == 3;
|
||||
})))
|
||||
.WillOnce(Return(apiBgl));
|
||||
|
||||
|
|
|
@ -166,11 +166,11 @@ TEST_F(WireMultipleDeviceTests, DifferentDeviceObjectCreationIsError) {
|
|||
|
||||
wireA.FlushClient();
|
||||
|
||||
std::array<WGPUBindGroupBinding, 2> bindings = {};
|
||||
std::array<WGPUBindGroupBinding, 2> entries = {};
|
||||
|
||||
// Create a buffer on wire A.
|
||||
WGPUBufferDescriptor bufferDesc = {};
|
||||
bindings[0].buffer = wgpuDeviceCreateBuffer(wireA.ClientDevice(), &bufferDesc);
|
||||
entries[0].buffer = wgpuDeviceCreateBuffer(wireA.ClientDevice(), &bufferDesc);
|
||||
EXPECT_CALL(*wireA.Api(), DeviceCreateBuffer(wireA.ServerDevice(), _))
|
||||
.WillOnce(Return(wireA.Api()->GetNewBuffer()));
|
||||
|
||||
|
@ -178,7 +178,7 @@ TEST_F(WireMultipleDeviceTests, DifferentDeviceObjectCreationIsError) {
|
|||
|
||||
// Create a sampler on wire B.
|
||||
WGPUSamplerDescriptor samplerDesc = {};
|
||||
bindings[1].sampler = wgpuDeviceCreateSampler(wireB.ClientDevice(), &samplerDesc);
|
||||
entries[1].sampler = wgpuDeviceCreateSampler(wireB.ClientDevice(), &samplerDesc);
|
||||
EXPECT_CALL(*wireB.Api(), DeviceCreateSampler(wireB.ServerDevice(), _))
|
||||
.WillOnce(Return(wireB.Api()->GetNewSampler()));
|
||||
|
||||
|
@ -187,8 +187,8 @@ TEST_F(WireMultipleDeviceTests, DifferentDeviceObjectCreationIsError) {
|
|||
// Create a bind group on wire A using the bgl (A), buffer (A), and sampler (B).
|
||||
WGPUBindGroupDescriptor bgDesc = {};
|
||||
bgDesc.layout = bglA;
|
||||
bgDesc.bindingCount = bindings.size();
|
||||
bgDesc.bindings = bindings.data();
|
||||
bgDesc.entryCount = entries.size();
|
||||
bgDesc.entries = entries.data();
|
||||
WGPUBindGroup bindGroupA = wgpuDeviceCreateBindGroup(wireA.ClientDevice(), &bgDesc);
|
||||
|
||||
// It should inject an error because the sampler is from a different device.
|
||||
|
|
|
@ -27,7 +27,7 @@ class WireOptionalTests : public WireTest {
|
|||
// Test passing nullptr instead of objects - object as value version
|
||||
TEST_F(WireOptionalTests, OptionalObjectValue) {
|
||||
WGPUBindGroupLayoutDescriptor bglDesc = {};
|
||||
bglDesc.bindingCount = 0;
|
||||
bglDesc.entryCount = 0;
|
||||
WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bglDesc);
|
||||
|
||||
WGPUBindGroupLayout apiBindGroupLayout = api.GetNewBindGroupLayout();
|
||||
|
@ -35,27 +35,27 @@ TEST_F(WireOptionalTests, OptionalObjectValue) {
|
|||
.WillOnce(Return(apiBindGroupLayout));
|
||||
|
||||
// The `sampler`, `textureView` and `buffer` members of a binding are optional.
|
||||
WGPUBindGroupEntry binding;
|
||||
binding.binding = 0;
|
||||
binding.sampler = nullptr;
|
||||
binding.textureView = nullptr;
|
||||
binding.buffer = nullptr;
|
||||
WGPUBindGroupEntry entry;
|
||||
entry.binding = 0;
|
||||
entry.sampler = nullptr;
|
||||
entry.textureView = nullptr;
|
||||
entry.buffer = nullptr;
|
||||
|
||||
WGPUBindGroupDescriptor bgDesc = {};
|
||||
bgDesc.layout = bgl;
|
||||
bgDesc.bindingCount = 1;
|
||||
bgDesc.bindings = &binding;
|
||||
bgDesc.entryCount = 1;
|
||||
bgDesc.entries = &entry;
|
||||
|
||||
wgpuDeviceCreateBindGroup(device, &bgDesc);
|
||||
|
||||
WGPUBindGroup apiDummyBindGroup = api.GetNewBindGroup();
|
||||
EXPECT_CALL(api, DeviceCreateBindGroup(
|
||||
apiDevice, MatchesLambda([](const WGPUBindGroupDescriptor* desc) -> bool {
|
||||
return desc->nextInChain == nullptr && desc->bindingCount == 1 &&
|
||||
desc->bindings[0].binding == 0 &&
|
||||
desc->bindings[0].sampler == nullptr &&
|
||||
desc->bindings[0].buffer == nullptr &&
|
||||
desc->bindings[0].textureView == nullptr;
|
||||
return desc->nextInChain == nullptr && desc->entryCount == 1 &&
|
||||
desc->entries[0].binding == 0 &&
|
||||
desc->entries[0].sampler == nullptr &&
|
||||
desc->entries[0].buffer == nullptr &&
|
||||
desc->entries[0].textureView == nullptr;
|
||||
})))
|
||||
.WillOnce(Return(apiDummyBindGroup));
|
||||
|
||||
|
|
|
@ -271,16 +271,15 @@ namespace utils {
|
|||
|
||||
wgpu::BindGroupLayout MakeBindGroupLayout(
|
||||
const wgpu::Device& device,
|
||||
std::initializer_list<wgpu::BindGroupLayoutEntry> bindingsInitializer) {
|
||||
|
||||
std::vector<wgpu::BindGroupLayoutEntry> bindings;
|
||||
for (const wgpu::BindGroupLayoutEntry& binding : bindingsInitializer) {
|
||||
bindings.push_back(binding);
|
||||
std::initializer_list<wgpu::BindGroupLayoutEntry> entriesInitializer) {
|
||||
std::vector<wgpu::BindGroupLayoutEntry> entries;
|
||||
for (const wgpu::BindGroupLayoutEntry& entry : entriesInitializer) {
|
||||
entries.push_back(entry);
|
||||
}
|
||||
|
||||
wgpu::BindGroupLayoutDescriptor descriptor;
|
||||
descriptor.bindingCount = static_cast<uint32_t>(bindings.size());
|
||||
descriptor.bindings = bindings.data();
|
||||
descriptor.entryCount = static_cast<uint32_t>(entries.size());
|
||||
descriptor.entries = entries.data();
|
||||
return device.CreateBindGroupLayout(&descriptor);
|
||||
}
|
||||
|
||||
|
@ -317,16 +316,16 @@ namespace utils {
|
|||
wgpu::BindGroup MakeBindGroup(
|
||||
const wgpu::Device& device,
|
||||
const wgpu::BindGroupLayout& layout,
|
||||
std::initializer_list<BindingInitializationHelper> bindingsInitializer) {
|
||||
std::vector<wgpu::BindGroupEntry> bindings;
|
||||
for (const BindingInitializationHelper& helper : bindingsInitializer) {
|
||||
bindings.push_back(helper.GetAsBinding());
|
||||
std::initializer_list<BindingInitializationHelper> entriesInitializer) {
|
||||
std::vector<wgpu::BindGroupEntry> entries;
|
||||
for (const BindingInitializationHelper& helper : entriesInitializer) {
|
||||
entries.push_back(helper.GetAsBinding());
|
||||
}
|
||||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.bindingCount = bindings.size();
|
||||
descriptor.bindings = bindings.data();
|
||||
descriptor.entryCount = entries.size();
|
||||
descriptor.entries = entries.data();
|
||||
|
||||
return device.CreateBindGroup(&descriptor);
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace utils {
|
|||
const wgpu::BindGroupLayout* bindGroupLayout);
|
||||
wgpu::BindGroupLayout MakeBindGroupLayout(
|
||||
const wgpu::Device& device,
|
||||
std::initializer_list<wgpu::BindGroupLayoutEntry> bindingsInitializer);
|
||||
std::initializer_list<wgpu::BindGroupLayoutEntry> entriesInitializer);
|
||||
|
||||
// Helpers to make creating bind groups look nicer:
|
||||
//
|
||||
|
@ -124,7 +124,7 @@ namespace utils {
|
|||
wgpu::BindGroup MakeBindGroup(
|
||||
const wgpu::Device& device,
|
||||
const wgpu::BindGroupLayout& layout,
|
||||
std::initializer_list<BindingInitializationHelper> bindingsInitializer);
|
||||
std::initializer_list<BindingInitializationHelper> entriesInitializer);
|
||||
|
||||
} // namespace utils
|
||||
|
||||
|
|
Loading…
Reference in New Issue