Skip to content

Commit 7619314

Browse files
authored
Transcoded version of performance sample texture_compression_comparison based on Vulkan-Hpp (#1102)
1 parent a7ee236 commit 7619314

File tree

19 files changed

+730
-46
lines changed

19 files changed

+730
-46
lines changed

antora/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
*** xref:samples/performance/hpp_swapchain_images/README.adoc[Swapchain images (Vulkan-Hpp)]
112112
** xref:samples/performance/texture_compression_basisu/README.adoc[Texture compression basisu]
113113
** xref:samples/performance/texture_compression_comparison/README.adoc[Texture compression comparison]
114+
*** xref:samples/performance/hpp_texture_compression_comparison/README.adoc[Texture compression comparison (Vulkan-Hpp)]
114115
** xref:samples/performance/wait_idle/README.adoc[Wait idle]
115116
* xref:samples/tooling/README.adoc[Tooling samples]
116117
** xref:samples/tooling/profiles/README.adoc[Profiles]

framework/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ set(SCENE_GRAPH_FILES
148148
scene_graph/node.h
149149
scene_graph/scene.h
150150
scene_graph/script.h
151+
scene_graph/hpp_scene.h
151152
# Source Files
152153
scene_graph/component.cpp
153154
scene_graph/node.cpp
@@ -173,7 +174,10 @@ set(SCENE_GRAPH_COMPONENT_FILES
173174
scene_graph/components/image/ktx.h
174175
scene_graph/components/image/stb.h
175176
scene_graph/components/hpp_image.h
177+
scene_graph/components/hpp_material.h
178+
scene_graph/components/hpp_mesh.h
176179
scene_graph/components/hpp_sub_mesh.h
180+
scene_graph/components/hpp_texture.h
177181
# Source Files
178182
scene_graph/components/aabb.cpp
179183
scene_graph/components/camera.cpp

framework/common/hpp_utils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
1+
/* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -20,6 +20,7 @@
2020
#include <common/utils.h>
2121

2222
#include <rendering/hpp_render_context.h>
23+
#include <scene_graph/hpp_scene.h>
2324

2425
/**
2526
* @brief facade helper functions around the functions in common/utils.h, providing a vulkan.hpp-based interface
@@ -28,9 +29,9 @@ namespace vkb
2829
{
2930
namespace common
3031
{
31-
inline sg::Node &add_free_camera(sg::Scene &scene, const std::string &node_name, vk::Extent2D const &extent)
32+
inline sg::Node &add_free_camera(vkb::scene_graph::HPPScene &scene, const std::string &node_name, vk::Extent2D const &extent)
3233
{
33-
return vkb::add_free_camera(scene, node_name, static_cast<VkExtent2D>(extent));
34+
return vkb::add_free_camera(reinterpret_cast<vkb::sg::Scene &>(scene), node_name, static_cast<VkExtent2D>(extent));
3435
}
3536

3637
inline void screenshot(vkb::rendering::HPPRenderContext &render_context, const std::string &filename)

framework/hpp_gltf_loader.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <core/hpp_device.h>
2323
#include <scene_graph/components/hpp_sub_mesh.h>
24+
#include <scene_graph/hpp_scene.h>
2425

2526
namespace vkb
2627
{
@@ -32,8 +33,6 @@ namespace vkb
3233
class HPPGLTFLoader : private vkb::GLTFLoader
3334
{
3435
public:
35-
using vkb::GLTFLoader::read_scene_from_file;
36-
3736
HPPGLTFLoader(vkb::core::HPPDevice &device) :
3837
GLTFLoader(reinterpret_cast<vkb::Device &>(device))
3938
{}
@@ -44,5 +43,10 @@ class HPPGLTFLoader : private vkb::GLTFLoader
4443
return std::unique_ptr<vkb::scene_graph::components::HPPSubMesh>(reinterpret_cast<vkb::scene_graph::components::HPPSubMesh *>(
4544
vkb::GLTFLoader::read_model_from_file(file_name, index, storage_buffer, static_cast<VkBufferUsageFlags>(additional_buffer_usage_flags)).release()));
4645
}
46+
47+
std::unique_ptr<vkb::scene_graph::HPPScene> read_scene_from_file(const std::string &file_name, int scene_index = -1)
48+
{
49+
return std::unique_ptr<vkb::scene_graph::HPPScene>(reinterpret_cast<vkb::scene_graph::HPPScene *>(vkb::GLTFLoader::read_scene_from_file(file_name, scene_index).release()));
50+
}
4751
};
4852
} // namespace vkb

framework/rendering/subpasses/hpp_forward_subpass.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
1+
/* Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -36,14 +36,14 @@ class HPPForwardSubpass : public vkb::ForwardSubpass
3636
{
3737
public:
3838
HPPForwardSubpass(vkb::rendering::HPPRenderContext &render_context,
39-
vkb::ShaderSource && vertex_shader,
40-
vkb::ShaderSource && fragment_shader,
41-
vkb::sg::Scene & scene,
42-
vkb::sg::Camera & camera) :
39+
vkb::ShaderSource &&vertex_shader,
40+
vkb::ShaderSource &&fragment_shader,
41+
vkb::scene_graph::HPPScene &scene,
42+
vkb::sg::Camera &camera) :
4343
vkb::ForwardSubpass(reinterpret_cast<vkb::RenderContext &>(render_context),
4444
std::forward<ShaderSource>(vertex_shader),
4545
std::forward<ShaderSource>(fragment_shader),
46-
scene,
46+
reinterpret_cast<vkb::sg::Scene &>(scene),
4747
camera)
4848
{}
4949
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 the "License";
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include "hpp_texture.h"
21+
#include "material.h"
22+
23+
namespace vkb
24+
{
25+
namespace scene_graph
26+
{
27+
namespace components
28+
{
29+
/**
30+
* @brief facade class around vkb::sg::Material, providing a vulkan.hpp-based interface
31+
*
32+
* See vkb::sb::Material for documentation
33+
*/
34+
class HPPMaterial : private vkb::sg::Material
35+
{
36+
public:
37+
std::unordered_map<std::string, vkb::scene_graph::components::HPPTexture *> const &get_textures() const
38+
{
39+
return reinterpret_cast<std::unordered_map<std::string, vkb::scene_graph::components::HPPTexture *> const &>(vkb::sg::Material::textures);
40+
}
41+
};
42+
} // namespace components
43+
} // namespace scene_graph
44+
} // namespace vkb
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 the "License";
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include "hpp_sub_mesh.h"
21+
#include "mesh.h"
22+
23+
namespace vkb
24+
{
25+
namespace scene_graph
26+
{
27+
namespace components
28+
{
29+
/**
30+
* @brief facade class around vkb::sg::Mesh, providing a vulkan.hpp-based interface
31+
*
32+
* See vkb::sb::Mesh for documentation
33+
*/
34+
class HPPMesh : private vkb::sg::Mesh
35+
{
36+
public:
37+
std::vector<vkb::scene_graph::components::HPPSubMesh *> const &get_submeshes() const
38+
{
39+
return reinterpret_cast<std::vector<vkb::scene_graph::components::HPPSubMesh *> const &>(vkb::sg::Mesh::get_submeshes());
40+
}
41+
};
42+
} // namespace components
43+
} // namespace scene_graph
44+
} // namespace vkb

framework/scene_graph/components/hpp_sub_mesh.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
1+
/* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -18,6 +18,7 @@
1818
#pragma once
1919

2020
#include <core/hpp_buffer.h>
21+
#include <scene_graph/components/hpp_material.h>
2122
#include <scene_graph/components/sub_mesh.h>
2223

2324
namespace vkb
@@ -46,6 +47,11 @@ class HPPSubMesh : private vkb::sg::SubMesh
4647
return static_cast<vk::IndexType>(vkb::sg::SubMesh::index_type);
4748
}
4849

50+
vkb::scene_graph::components::HPPMaterial const *get_material() const
51+
{
52+
return reinterpret_cast<vkb::scene_graph::components::HPPMaterial const *>(vkb::sg::SubMesh::get_material());
53+
}
54+
4955
vkb::core::HPPBuffer const &get_vertex_buffer(std::string const &name) const
5056
{
5157
return reinterpret_cast<vkb::core::HPPBuffer const &>(vkb::sg::SubMesh::vertex_buffers.at(name));
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 the "License";
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include "hpp_image.h"
21+
#include "texture.h"
22+
23+
namespace vkb
24+
{
25+
namespace scene_graph
26+
{
27+
namespace components
28+
{
29+
/**
30+
* @brief facade class around vkb::sg::Texture, providing a vulkan.hpp-based interface
31+
*
32+
* See vkb::sb::Texture for documentation
33+
*/
34+
class HPPTexture : private vkb::sg::Texture
35+
{
36+
public:
37+
vkb::scene_graph::components::HPPImage *get_image()
38+
{
39+
return reinterpret_cast<vkb::scene_graph::components::HPPImage *>(vkb::sg::Texture::get_image());
40+
}
41+
42+
void set_image(vkb::scene_graph::components::HPPImage &image)
43+
{
44+
vkb::sg::Texture::set_image(reinterpret_cast<vkb::sg::Image &>(image));
45+
}
46+
};
47+
} // namespace components
48+
} // namespace scene_graph
49+
} // namespace vkb

framework/scene_graph/hpp_scene.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 the "License";
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#include "components/hpp_mesh.h"
21+
#include "scene.h"
22+
#include "scene_graph/script.h"
23+
#include "scene_graph/scripts/animation.h"
24+
25+
namespace vkb
26+
{
27+
namespace scene_graph
28+
{
29+
/**
30+
* @brief facade class around vkb::sg::Scene, providing a vulkan.hpp-based interface
31+
*
32+
* See vkb::sb::Scene for documentation
33+
*/
34+
class HPPScene : private vkb::sg::Scene
35+
{
36+
public:
37+
template <class T>
38+
std::vector<T *> get_components() const
39+
{
40+
if constexpr (std::is_same<T, vkb::sg::Script>::value)
41+
{
42+
return vkb::sg::Scene::get_components<T>();
43+
}
44+
else if constexpr (std::is_same<T, vkb::scene_graph::components::HPPMesh>::value)
45+
{
46+
std::vector<vkb::sg::Mesh *> meshes = vkb::sg::Scene::get_components<vkb::sg::Mesh>();
47+
return *reinterpret_cast<std::vector<T *> *>(&meshes);
48+
}
49+
else
50+
{
51+
assert(false); // path never passed -> Please add a type-check here!
52+
return {};
53+
}
54+
}
55+
56+
template <class T>
57+
bool has_component() const
58+
{
59+
if constexpr (std::is_same<T, vkb::sg::Animation>::value || std::is_same<T, vkb::sg::Script>::value)
60+
{
61+
return vkb::sg::Scene::has_component(typeid(T));
62+
}
63+
else
64+
{
65+
assert(false); // path never passed -> Please add a type-check here!
66+
return false;
67+
}
68+
}
69+
};
70+
} // namespace scene_graph
71+
} // namespace vkb

0 commit comments

Comments
 (0)