Skip to content

Commit 80852d6

Browse files
poweifengbejadopixelflingerz3moon
authored
Add Descriptor Sets to Filament (#8165)
We add the concept of the descriptor set as a way to describe shader resources into Filament. This is a comprehensive change across Filament. Info on descriptor sets is available here: https://docs.vulkan.org/spec/latest/chapters/descriptorsets.html Co-authored-by: Benjamin Doherty <[email protected]> Co-authored-by: Mathias Agopian <[email protected]> Co-authored-by: Sungun Park <[email protected]>
1 parent 3d4fc78 commit 80852d6

File tree

177 files changed

+9683
-5426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+9683
-5426
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ A new header is inserted each time a *tag* is created.
77
Instead, if you are authoring a PR for the main branch, add your release note to
88
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
99

10-
## v1.54.6
11-
10+
## v1.55.0
11+
- Add descriptor sets to describe shader resources. [⚠️ **New Material Version**]
1212

1313
## v1.54.5
1414

filament/CMakeLists.txt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(SRCS
6666
src/FrameSkipper.cpp
6767
src/Froxelizer.cpp
6868
src/Frustum.cpp
69+
src/HwDescriptorSetLayoutFactory.cpp
6970
src/HwRenderPrimitiveFactory.cpp
7071
src/HwVertexBufferInfoFactory.cpp
7172
src/IndexBuffer.cpp
@@ -76,8 +77,6 @@ set(SRCS
7677
src/MaterialInstance.cpp
7778
src/MaterialParser.cpp
7879
src/MorphTargetBuffer.cpp
79-
src/PerViewUniforms.cpp
80-
src/PerShadowMapUniforms.cpp
8180
src/PostProcessManager.cpp
8281
src/RenderPass.cpp
8382
src/RenderPrimitive.cpp
@@ -126,6 +125,12 @@ set(SRCS
126125
src/details/Texture.cpp
127126
src/details/VertexBuffer.cpp
128127
src/details/View.cpp
128+
src/ds/ColorPassDescriptorSet.cpp
129+
src/ds/DescriptorSet.cpp
130+
src/ds/DescriptorSetLayout.cpp
131+
src/ds/PostProcessDescriptorSet.cpp
132+
src/ds/ShadowMapDescriptorSet.cpp
133+
src/ds/SsrPassDescriptorSet.cpp
129134
src/fg/Blackboard.cpp
130135
src/fg/DependencyGraph.cpp
131136
src/fg/FrameGraph.cpp
@@ -149,23 +154,21 @@ set(PRIVATE_HDRS
149154
src/FrameInfo.h
150155
src/FrameSkipper.h
151156
src/Froxelizer.h
157+
src/HwDescriptorSetLayoutFactory.h
152158
src/HwRenderPrimitiveFactory.h
153159
src/HwVertexBufferInfoFactory.h
154160
src/Intersections.h
155161
src/MaterialParser.h
156-
src/PerViewUniforms.h
157-
src/PerShadowMapUniforms.h
158162
src/PIDController.h
159163
src/PostProcessManager.h
160-
src/RendererUtils.h
161164
src/RenderPass.h
162165
src/RenderPrimitive.h
166+
src/RendererUtils.h
163167
src/ResourceAllocator.h
164168
src/ResourceList.h
165169
src/ShadowMap.h
166170
src/ShadowMapManager.h
167171
src/SharedHandle.h
168-
src/TypedUniformBuffer.h
169172
src/UniformBuffer.h
170173
src/components/CameraManager.h
171174
src/components/LightManager.h
@@ -193,6 +196,14 @@ set(PRIVATE_HDRS
193196
src/details/Texture.h
194197
src/details/VertexBuffer.h
195198
src/details/View.h
199+
src/downcast.h
200+
src/ds/ColorPassDescriptorSet.h
201+
src/ds/DescriptorSetLayout.h
202+
src/ds/PostProcessDescriptorSet.h
203+
src/ds/ShadowMapDescriptorSet.h
204+
src/ds/SsrPassDescriptorSet.h
205+
src/ds/TypedBuffer.h
206+
src/ds/TypedUniformBuffer.h
196207
src/fg/Blackboard.h
197208
src/fg/FrameGraph.h
198209
src/fg/FrameGraphId.h
@@ -210,7 +221,6 @@ set(PRIVATE_HDRS
210221
src/materials/fsr/ffx_a.h
211222
src/materials/fsr/ffx_fsr1.h
212223
src/materials/fsr/ffx_fsr1_mobile.fs
213-
src/downcast.h
214224
)
215225

216226
set(MATERIAL_SRCS

filament/backend/CMakeLists.txt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(PUBLIC_HDRS
1212
include/backend/AcquiredImage.h
1313
include/backend/BufferDescriptor.h
1414
include/backend/CallbackHandler.h
15+
include/backend/DescriptorSetOffsetArray.h
1516
include/backend/DriverApiForward.h
1617
include/backend/DriverEnums.h
1718
include/backend/Handle.h
@@ -69,9 +70,13 @@ set(PRIVATE_HDRS
6970
if (FILAMENT_SUPPORTS_OPENGL AND NOT FILAMENT_USE_EXTERNAL_GLES3)
7071
list(APPEND SRCS
7172
include/backend/platforms/OpenGLPlatform.h
73+
src/opengl/BindingMap.h
7274
src/opengl/gl_headers.cpp
7375
src/opengl/gl_headers.h
7476
src/opengl/GLBufferObject.h
77+
src/opengl/GLDescriptorSet.cpp
78+
src/opengl/GLDescriptorSet.h
79+
src/opengl/GLDescriptorSetLayout.h
7580
src/opengl/GLTexture.h
7681
src/opengl/GLUtils.cpp
7782
src/opengl/GLUtils.h
@@ -508,21 +513,38 @@ endif()
508513

509514
# ==================================================================================================
510515
# Compute tests
516+
#
517+
#if (NOT IOS AND NOT WEBGL)
518+
#
519+
#add_executable(compute_test
520+
# test/ComputeTest.cpp
521+
# test/Arguments.cpp
522+
# test/test_ComputeBasic.cpp
523+
# )
524+
#
525+
#target_link_libraries(compute_test PRIVATE
526+
# backend
527+
# getopt
528+
# gtest
529+
# )
530+
#
531+
#set_target_properties(compute_test PROPERTIES FOLDER Tests)
532+
#
533+
#endif()
511534

512-
if (NOT IOS AND NOT WEBGL)
535+
# ==================================================================================================
536+
# Metal utils tests
513537

514-
add_executable(compute_test
515-
test/ComputeTest.cpp
516-
test/Arguments.cpp
517-
test/test_ComputeBasic.cpp
518-
)
538+
if (APPLE AND NOT IOS)
539+
540+
add_executable(metal_utils_test test/MetalTest.mm)
519541

520-
target_link_libraries(compute_test PRIVATE
542+
target_link_libraries(metal_utils_test PRIVATE
521543
backend
522544
getopt
523545
gtest
524546
)
525547

526-
set_target_properties(compute_test PROPERTIES FOLDER Tests)
548+
set_target_properties(metal_utils_test PROPERTIES FOLDER Tests)
527549

528550
endif()
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TNT_FILAMENT_BACKEND_COMMANDSTREAMVECTOR_H
18+
#define TNT_FILAMENT_BACKEND_COMMANDSTREAMVECTOR_H
19+
20+
#include <backend/DriverApiForward.h>
21+
22+
#include <initializer_list>
23+
#include <memory>
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
28+
29+
namespace filament::backend {
30+
31+
void* allocateFromCommandStream(DriverApi& driver, size_t size, size_t alignment) noexcept;
32+
33+
class DescriptorSetOffsetArray {
34+
public:
35+
using value_type = uint32_t;
36+
using reference = value_type&;
37+
using const_reference = value_type const&;
38+
using size_type = uint32_t;
39+
using difference_type = int32_t;
40+
using pointer = value_type*;
41+
using const_pointer = value_type const*;
42+
using iterator = pointer;
43+
using const_iterator = const_pointer;
44+
45+
DescriptorSetOffsetArray() noexcept = default;
46+
47+
~DescriptorSetOffsetArray() noexcept = default;
48+
49+
DescriptorSetOffsetArray(size_type size, DriverApi& driver) noexcept {
50+
mOffsets = (value_type *)allocateFromCommandStream(driver,
51+
size * sizeof(value_type), alignof(value_type));
52+
std::uninitialized_fill_n(mOffsets, size, 0);
53+
}
54+
55+
DescriptorSetOffsetArray(std::initializer_list<uint32_t> list, DriverApi& driver) noexcept {
56+
mOffsets = (value_type *)allocateFromCommandStream(driver,
57+
list.size() * sizeof(value_type), alignof(value_type));
58+
std::uninitialized_copy(list.begin(), list.end(), mOffsets);
59+
}
60+
61+
DescriptorSetOffsetArray(DescriptorSetOffsetArray const&) = delete;
62+
DescriptorSetOffsetArray& operator=(DescriptorSetOffsetArray const&) = delete;
63+
64+
DescriptorSetOffsetArray(DescriptorSetOffsetArray&& rhs) noexcept
65+
: mOffsets(rhs.mOffsets) {
66+
rhs.mOffsets = nullptr;
67+
}
68+
69+
DescriptorSetOffsetArray& operator=(DescriptorSetOffsetArray&& rhs) noexcept {
70+
if (this != &rhs) {
71+
mOffsets = rhs.mOffsets;
72+
rhs.mOffsets = nullptr;
73+
}
74+
return *this;
75+
}
76+
77+
bool empty() const noexcept { return mOffsets == nullptr; }
78+
79+
value_type* data() noexcept { return mOffsets; }
80+
const value_type* data() const noexcept { return mOffsets; }
81+
82+
83+
reference operator[](size_type n) noexcept {
84+
return *(data() + n);
85+
}
86+
87+
const_reference operator[](size_type n) const noexcept {
88+
return *(data() + n);
89+
}
90+
91+
void clear() noexcept {
92+
mOffsets = nullptr;
93+
}
94+
95+
private:
96+
value_type *mOffsets = nullptr;
97+
};
98+
99+
} // namespace filament::backend
100+
101+
#endif //TNT_FILAMENT_BACKEND_COMMANDSTREAMVECTOR_H

0 commit comments

Comments
 (0)