mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Add TypedInteger
This CL adds a TypedInteger helper which provides additional type
safety in Dawn. It is a compile-time restriction that prevents integers
of different types from being used interchangably in Debug builds.
It also adds ityp::{array,bitset,span} as helper classes to wrap std::
versions (not span). These accept a template paramter as the Index type
so that typed integers, or enum classes, may be used as a type-safe
index.
For now, bind group layout binding indices use TypedInteger. Future
CLs will convert other indices to be type-safe as well.
Bug: dawn:442
Change-Id: I5b63b1e4f6154322db0227a7788a4e9b8303410e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19902
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
3f4f356611
commit
7a4685f448
@@ -241,7 +241,7 @@ namespace dawn_native { namespace opengl {
|
||||
const auto& indices = ToBackend(mPipelineLayout)->GetBindingIndexInfo()[index];
|
||||
uint32_t currentDynamicOffsetIndex = 0;
|
||||
|
||||
for (BindingIndex bindingIndex = 0;
|
||||
for (BindingIndex bindingIndex{0};
|
||||
bindingIndex < group->GetLayout()->GetBindingCount(); ++bindingIndex) {
|
||||
const BindingInfo& bindingInfo =
|
||||
group->GetLayout()->GetBindingInfo(bindingIndex);
|
||||
|
||||
@@ -183,20 +183,29 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
gl.Uniform1i(location, textureUnit);
|
||||
|
||||
GLuint textureIndex =
|
||||
indices[combined.textureLocation.group][combined.textureLocation.binding];
|
||||
mUnitsForTextures[textureIndex].push_back(textureUnit);
|
||||
bool shouldUseFiltering;
|
||||
{
|
||||
const BindGroupLayoutBase* bgl =
|
||||
layout->GetBindGroupLayout(combined.textureLocation.group);
|
||||
BindingIndex bindingIndex =
|
||||
bgl->GetBindingIndex(combined.textureLocation.binding);
|
||||
|
||||
const BindGroupLayoutBase* bgl =
|
||||
layout->GetBindGroupLayout(combined.textureLocation.group);
|
||||
Format::Type componentType =
|
||||
bgl->GetBindingInfo(bgl->GetBindingIndex(combined.textureLocation.binding))
|
||||
.textureComponentType;
|
||||
bool shouldUseFiltering = componentType == Format::Type::Float;
|
||||
GLuint textureIndex = indices[combined.textureLocation.group][bindingIndex];
|
||||
mUnitsForTextures[textureIndex].push_back(textureUnit);
|
||||
|
||||
GLuint samplerIndex =
|
||||
indices[combined.samplerLocation.group][combined.samplerLocation.binding];
|
||||
mUnitsForSamplers[samplerIndex].push_back({textureUnit, shouldUseFiltering});
|
||||
Format::Type componentType =
|
||||
bgl->GetBindingInfo(bindingIndex).textureComponentType;
|
||||
shouldUseFiltering = componentType == Format::Type::Float;
|
||||
}
|
||||
{
|
||||
const BindGroupLayoutBase* bgl =
|
||||
layout->GetBindGroupLayout(combined.samplerLocation.group);
|
||||
BindingIndex bindingIndex =
|
||||
bgl->GetBindingIndex(combined.samplerLocation.binding);
|
||||
|
||||
GLuint samplerIndex = indices[combined.samplerLocation.group][bindingIndex];
|
||||
mUnitsForSamplers[samplerIndex].push_back({textureUnit, shouldUseFiltering});
|
||||
}
|
||||
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace dawn_native { namespace opengl {
|
||||
for (uint32_t group : IterateBitSet(GetBindGroupLayoutsMask())) {
|
||||
const BindGroupLayoutBase* bgl = GetBindGroupLayout(group);
|
||||
|
||||
for (BindingIndex bindingIndex = 0; bindingIndex < bgl->GetBindingCount();
|
||||
for (BindingIndex bindingIndex{0}; bindingIndex < bgl->GetBindingCount();
|
||||
++bindingIndex) {
|
||||
switch (bgl->GetBindingInfo(bindingIndex).type) {
|
||||
case wgpu::BindingType::UniformBuffer:
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "dawn_native/PipelineLayout.h"
|
||||
|
||||
#include "common/ityp_array.h"
|
||||
#include "dawn_native/BindingInfo.h"
|
||||
#include "dawn_native/opengl/opengl_platform.h"
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
@@ -28,7 +30,7 @@ namespace dawn_native { namespace opengl {
|
||||
PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor);
|
||||
|
||||
using BindingIndexInfo =
|
||||
std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
||||
std::array<ityp::array<BindingIndex, GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
||||
const BindingIndexInfo& GetBindingIndexInfo() const;
|
||||
|
||||
GLuint GetTextureUnitsUsed() const;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
std::string GetBindingName(uint32_t group, uint32_t binding) {
|
||||
std::string GetBindingName(uint32_t group, BindingNumber bindingNumber) {
|
||||
std::ostringstream o;
|
||||
o << "dawn_binding_" << group << "_" << binding;
|
||||
o << "dawn_binding_" << group << "_" << static_cast<uint32_t>(bindingNumber);
|
||||
return o.str();
|
||||
}
|
||||
|
||||
@@ -42,8 +42,9 @@ namespace dawn_native { namespace opengl {
|
||||
std::string CombinedSampler::GetName() const {
|
||||
std::ostringstream o;
|
||||
o << "dawn_combined";
|
||||
o << "_" << samplerLocation.group << "_" << samplerLocation.binding;
|
||||
o << "_with_" << textureLocation.group << "_" << textureLocation.binding;
|
||||
o << "_" << samplerLocation.group << "_" << static_cast<uint32_t>(samplerLocation.binding);
|
||||
o << "_with_" << textureLocation.group << "_"
|
||||
<< static_cast<uint32_t>(textureLocation.binding);
|
||||
return o.str();
|
||||
}
|
||||
|
||||
@@ -143,12 +144,19 @@ namespace dawn_native { namespace opengl {
|
||||
mSpvcContext.GetDecoration(sampler.sampler_id,
|
||||
shaderc_spvc_decoration_descriptorset,
|
||||
&info.samplerLocation.group);
|
||||
uint32_t samplerBinding;
|
||||
mSpvcContext.GetDecoration(sampler.sampler_id, shaderc_spvc_decoration_binding,
|
||||
&info.samplerLocation.binding);
|
||||
&samplerBinding);
|
||||
info.samplerLocation.binding = BindingNumber(samplerBinding);
|
||||
|
||||
mSpvcContext.GetDecoration(sampler.image_id, shaderc_spvc_decoration_descriptorset,
|
||||
&info.textureLocation.group);
|
||||
|
||||
uint32_t textureBinding;
|
||||
mSpvcContext.GetDecoration(sampler.image_id, shaderc_spvc_decoration_binding,
|
||||
&info.textureLocation.binding);
|
||||
&textureBinding);
|
||||
info.textureLocation.binding = BindingNumber(textureBinding);
|
||||
|
||||
mSpvcContext.SetName(sampler.combined_id, info.GetName());
|
||||
}
|
||||
} else {
|
||||
@@ -158,12 +166,12 @@ namespace dawn_native { namespace opengl {
|
||||
auto& info = mCombinedInfo.back();
|
||||
info.samplerLocation.group =
|
||||
compiler->get_decoration(combined.sampler_id, spv::DecorationDescriptorSet);
|
||||
info.samplerLocation.binding =
|
||||
compiler->get_decoration(combined.sampler_id, spv::DecorationBinding);
|
||||
info.samplerLocation.binding = BindingNumber(
|
||||
compiler->get_decoration(combined.sampler_id, spv::DecorationBinding));
|
||||
info.textureLocation.group =
|
||||
compiler->get_decoration(combined.image_id, spv::DecorationDescriptorSet);
|
||||
info.textureLocation.binding =
|
||||
compiler->get_decoration(combined.image_id, spv::DecorationBinding);
|
||||
info.textureLocation.binding = BindingNumber(
|
||||
compiler->get_decoration(combined.image_id, spv::DecorationBinding));
|
||||
compiler->set_name(combined.combined_id, info.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace dawn_native { namespace opengl {
|
||||
|
||||
class Device;
|
||||
|
||||
std::string GetBindingName(uint32_t group, uint32_t binding);
|
||||
std::string GetBindingName(uint32_t group, BindingNumber bindingNumber);
|
||||
|
||||
struct BindingLocation {
|
||||
uint32_t group;
|
||||
uint32_t binding;
|
||||
BindingNumber binding;
|
||||
};
|
||||
bool operator<(const BindingLocation& a, const BindingLocation& b);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user