Skip to content

Commit 583b72b

Browse files
committed
add sampler type in DescriptorSetLayout
[**New Material Version**]
1 parent 36e7759 commit 583b72b

21 files changed

+193
-80
lines changed

NEW_RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ for next branch cut* header.
77
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
88

99
## Release notes for next branch cut
10+
11+
- materials: sampler now export their type in the material binary [⚠️ **New Material Version**]

filament/backend/include/backend/DriverEnums.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,14 @@ static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage t
234234
}
235235

236236
enum class DescriptorType : uint8_t {
237+
SAMPLER_FLOAT,
238+
SAMPLER_INT,
239+
SAMPLER_UINT,
240+
SAMPLER_DEPTH,
241+
SAMPLER_EXTERNAL,
237242
UNIFORM_BUFFER,
238243
SHADER_STORAGE_BUFFER,
239-
SAMPLER,
240244
INPUT_ATTACHMENT,
241-
SAMPLER_EXTERNAL
242245
};
243246

244247
enum class DescriptorFlags : uint8_t {
@@ -251,6 +254,9 @@ using descriptor_set_t = uint8_t;
251254
using descriptor_binding_t = uint8_t;
252255

253256
struct DescriptorSetLayoutBinding {
257+
static bool isSampler(DescriptorType type) noexcept {
258+
return int(type) <= int(DescriptorType::SAMPLER_EXTERNAL);
259+
}
254260
DescriptorType type;
255261
ShaderStageFlags stageFlags;
256262
descriptor_binding_t binding;

filament/backend/src/metal/MetalDriver.mm

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,22 +672,32 @@
672672
// nothing to do, timer query was constructed in createTimerQueryS
673673
}
674674

675-
const char* toString(DescriptorType type) {
675+
UTILS_UNUSED
676+
static const char* toString(DescriptorType const type) noexcept {
676677
switch (type) {
677678
case DescriptorType::UNIFORM_BUFFER:
678679
return "UNIFORM_BUFFER";
679680
case DescriptorType::SHADER_STORAGE_BUFFER:
680681
return "SHADER_STORAGE_BUFFER";
681-
case DescriptorType::SAMPLER:
682-
return "SAMPLER";
682+
case DescriptorType::SAMPLER_INT:
683+
return "SAMPLER_INT";
684+
case DescriptorType::SAMPLER_UINT:
685+
return "SAMPLER_UINT";
686+
case DescriptorType::SAMPLER_FLOAT:
687+
return "SAMPLER_FLOAT";
688+
case DescriptorType::SAMPLER_DEPTH:
689+
return "SAMPLER_DEPTH";
683690
case DescriptorType::INPUT_ATTACHMENT:
684691
return "INPUT_ATTACHMENT";
685692
case DescriptorType::SAMPLER_EXTERNAL:
686693
return "SAMPLER_EXTERNAL";
687694
}
695+
// should never get here
696+
return "UNKNOWN";
688697
}
689698

690-
const char* toString(ShaderStageFlags flags) {
699+
UTILS_UNUSED
700+
static const char* toString(ShaderStageFlags flags) {
691701
std::vector<const char*> stages;
692702
if (any(flags & ShaderStageFlags::VERTEX)) {
693703
stages.push_back("VERTEX");

filament/backend/src/metal/MetalHandles.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,10 @@ static void func(void* user) {
13561356
[arguments addObject:bufferArgument];
13571357
break;
13581358
}
1359-
case DescriptorType::SAMPLER:
1359+
case DescriptorType::SAMPLER_FLOAT:
1360+
case DescriptorType::SAMPLER_INT:
1361+
case DescriptorType::SAMPLER_UINT:
1362+
case DescriptorType::SAMPLER_DEPTH:
13601363
case DescriptorType::SAMPLER_EXTERNAL: {
13611364
MTLArgumentDescriptor* textureArgument = [MTLArgumentDescriptor argumentDescriptor];
13621365
textureArgument.index = binding.binding * 2;
@@ -1472,7 +1475,10 @@ static void func(void* user) {
14721475
atIndex:binding.binding * 2];
14731476
break;
14741477
}
1475-
case DescriptorType::SAMPLER:
1478+
case DescriptorType::SAMPLER_FLOAT:
1479+
case DescriptorType::SAMPLER_INT:
1480+
case DescriptorType::SAMPLER_UINT:
1481+
case DescriptorType::SAMPLER_DEPTH:
14761482
case DescriptorType::SAMPLER_EXTERNAL: {
14771483
auto found = textures.find(binding.binding);
14781484
if (found == textures.end()) {

filament/backend/src/opengl/BindingMap.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ class BindingMap {
6969
assert_invariant(set < MAX_DESCRIPTOR_SET_COUNT);
7070
assert_invariant(binding < MAX_DESCRIPTOR_COUNT);
7171
assert_invariant(entry.binding < 128); // we reserve 1 bit for the type right now
72-
mStorage[set][binding] = { (uint8_t)entry.binding,
73-
entry.type == DescriptorType::SAMPLER ||
74-
entry.type == DescriptorType::SAMPLER_EXTERNAL };
72+
mStorage[set][binding] = { uint8_t(entry.binding),
73+
DescriptorSetLayoutBinding::isSampler(entry.type) };
7574
mActiveDescriptors[set].set(binding);
7675
}
7776

filament/backend/src/opengl/GLDescriptorSet.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ GLDescriptorSet::GLDescriptorSet(OpenGLContext& gl, DescriptorSetLayoutHandle ds
9595
}
9696
break;
9797
}
98-
case DescriptorType::SAMPLER:
98+
99+
case DescriptorType::SAMPLER_FLOAT:
100+
case DescriptorType::SAMPLER_INT:
101+
case DescriptorType::SAMPLER_UINT:
102+
case DescriptorType::SAMPLER_DEPTH:
99103
case DescriptorType::SAMPLER_EXTERNAL:
100104
if (UTILS_UNLIKELY(gl.isES2())) {
101105
desc.emplace<SamplerGLES2>();

filament/backend/src/opengl/OpenGLProgram.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ void OpenGLProgram::initializeProgramState(OpenGLContext& context, GLuint progra
175175
}
176176
break;
177177
}
178-
case DescriptorType::SAMPLER:
178+
case DescriptorType::SAMPLER_FLOAT:
179+
case DescriptorType::SAMPLER_INT:
180+
case DescriptorType::SAMPLER_UINT:
181+
case DescriptorType::SAMPLER_DEPTH:
179182
case DescriptorType::SAMPLER_EXTERNAL: {
180183
if (!entry.name.empty()) {
181184
GLint const loc = glGetUniformLocation(program, entry.name.c_str());

filament/backend/src/vulkan/VulkanHandles.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ BitmaskGroup fromBackendLayout(DescriptorSetLayout const& layout) {
9393
case DescriptorType::SAMPLER_EXTERNAL:
9494
fromStageFlags(binding.stageFlags, binding.binding, mask.externalSampler);
9595
UTILS_FALLTHROUGH;
96-
case DescriptorType::SAMPLER: {
96+
97+
case DescriptorType::SAMPLER_FLOAT:
98+
case DescriptorType::SAMPLER_INT:
99+
case DescriptorType::SAMPLER_UINT:
100+
case DescriptorType::SAMPLER_DEPTH: {
97101
fromStageFlags(binding.stageFlags, binding.binding, mask.sampler);
98102
break;
99103
}

filament/backend/src/webgpu/WebGPUHandles.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ WebGPUDescriptorSetLayout::WebGPUDescriptorSetLayout(DescriptorSetLayout const&
254254

255255
unsigned int samplerCount =
256256
std::count_if(layout.bindings.begin(), layout.bindings.end(), [](auto& fEntry) {
257-
return fEntry.type == DescriptorType::SAMPLER ||
258-
fEntry.type == DescriptorType::SAMPLER_EXTERNAL;
257+
return DescriptorSetLayoutBinding::isSampler(fEntry.type);
259258
});
260259

261260

@@ -271,8 +270,11 @@ WebGPUDescriptorSetLayout::WebGPUDescriptorSetLayout(DescriptorSetLayout const&
271270
entryInfo.binding = wEntry.binding;
272271

273272
switch (fEntry.type) {
274-
case DescriptorType::SAMPLER_EXTERNAL:
275-
case DescriptorType::SAMPLER: {
273+
case DescriptorType::SAMPLER_FLOAT:
274+
case DescriptorType::SAMPLER_INT:
275+
case DescriptorType::SAMPLER_UINT:
276+
case DescriptorType::SAMPLER_DEPTH:
277+
case DescriptorType::SAMPLER_EXTERNAL: {
276278
auto& samplerEntry = wEntries.emplace_back();
277279
auto& samplerEntryInfo = mBindGroupEntries.emplace_back();
278280
samplerEntry.binding = fEntry.binding * 2 + 1;

filament/backend/test/SharedShaders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ std::vector<UniformConfig> GetUniformConfig(ShaderUniformType type) {
184184
"backend_test", "test_tex", 0,
185185
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
186186
return {{
187-
"test_tex", DescriptorType::SAMPLER, samplerInfo
187+
"test_tex", DescriptorType::SAMPLER_FLOAT, samplerInfo
188188
}};
189189
}
190190
default:

0 commit comments

Comments
 (0)