Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ set(SCENE_GRAPH_COMPONENT_FILES
scene_graph/components/material.cpp
scene_graph/components/mesh.cpp
scene_graph/components/pbr_material.cpp
scene_graph/components/sampler.cpp
scene_graph/components/sub_mesh.cpp
scene_graph/components/texture.cpp
scene_graph/components/transform.cpp
Expand Down
10 changes: 5 additions & 5 deletions framework/gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_
scene.set_components(std::move(light_components));

// Load samplers
std::vector<std::unique_ptr<sg::Sampler>>
std::vector<std::unique_ptr<vkb::scene_graph::components::SamplerC>>
sampler_components(model.samplers.size());

for (size_t sampler_index = 0; sampler_index < model.samplers.size(); sampler_index++)
Expand Down Expand Up @@ -625,7 +625,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_

// Load textures
auto images = scene.get_components<sg::Image>();
auto samplers = scene.get_components<sg::Sampler>();
auto samplers = scene.get_components<vkb::scene_graph::components::SamplerC>();
auto default_sampler_linear = create_default_sampler(TINYGLTF_TEXTURE_FILTER_LINEAR);
auto default_sampler_nearest = create_default_sampler(TINYGLTF_TEXTURE_FILTER_NEAREST);
bool used_nearest_sampler = false;
Expand Down Expand Up @@ -1496,7 +1496,7 @@ std::unique_ptr<sg::Image> GLTFLoader::parse_image(tinygltf::Image &gltf_image)
return image;
}

std::unique_ptr<sg::Sampler> GLTFLoader::parse_sampler(const tinygltf::Sampler &gltf_sampler) const
std::unique_ptr<vkb::scene_graph::components::SamplerC> GLTFLoader::parse_sampler(const tinygltf::Sampler &gltf_sampler) const
{
auto name = gltf_sampler.name;

Expand All @@ -1521,7 +1521,7 @@ std::unique_ptr<sg::Sampler> GLTFLoader::parse_sampler(const tinygltf::Sampler &
core::Sampler vk_sampler{device, sampler_info};
vk_sampler.set_debug_name(gltf_sampler.name);

return std::make_unique<sg::Sampler>(name, std::move(vk_sampler));
return std::make_unique<vkb::scene_graph::components::SamplerC>(name, std::move(vk_sampler));
}

std::unique_ptr<sg::Texture> GLTFLoader::parse_texture(const tinygltf::Texture &gltf_texture) const
Expand All @@ -1535,7 +1535,7 @@ std::unique_ptr<sg::PBRMaterial> GLTFLoader::create_default_material()
return parse_material(gltf_material);
}

std::unique_ptr<sg::Sampler> GLTFLoader::create_default_sampler(int filter)
std::unique_ptr<vkb::scene_graph::components::SamplerC> GLTFLoader::create_default_sampler(int filter)
{
tinygltf::Sampler gltf_sampler;

Expand Down
5 changes: 3 additions & 2 deletions framework/gltf_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define TINYGLTF_NO_EXTERNAL_IMAGE
#include <tiny_gltf.h>

#include "scene_graph/components/sampler.h"
#include "scene_graph/node.h"
#include "timer.h"

Expand Down Expand Up @@ -102,13 +103,13 @@ class GLTFLoader

virtual std::unique_ptr<sg::Image> parse_image(tinygltf::Image &gltf_image) const;

virtual std::unique_ptr<sg::Sampler> parse_sampler(const tinygltf::Sampler &gltf_sampler) const;
virtual std::unique_ptr<vkb::scene_graph::components::SamplerC> parse_sampler(const tinygltf::Sampler &gltf_sampler) const;

virtual std::unique_ptr<sg::Texture> parse_texture(const tinygltf::Texture &gltf_texture) const;

virtual std::unique_ptr<sg::PBRMaterial> create_default_material();

virtual std::unique_ptr<sg::Sampler> create_default_sampler(int filter);
virtual std::unique_ptr<vkb::scene_graph::components::SamplerC> create_default_sampler(int filter);

virtual std::unique_ptr<sg::Camera> create_default_camera();

Expand Down
2 changes: 1 addition & 1 deletion framework/rendering/subpasses/geometry_subpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void GeometrySubpass::draw_submesh(vkb::core::CommandBufferC &command_buffer, sg
if (auto layout_binding = descriptor_set_layout.get_layout_binding(texture.first))
{
command_buffer.bind_image(texture.second->get_image()->get_vk_image_view(),
texture.second->get_sampler()->vk_sampler,
texture.second->get_sampler()->get_core_sampler(),
0, layout_binding->binding, 0);
}
}
Expand Down
34 changes: 0 additions & 34 deletions framework/scene_graph/components/sampler.cpp

This file was deleted.

68 changes: 56 additions & 12 deletions framework/scene_graph/components/sampler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (c) 2018-2019, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,30 +18,73 @@

#pragma once

#include <memory>
#include <string>
#include <typeinfo>
#include <vector>

#include "core/hpp_sampler.h"
#include "core/sampler.h"
#include "scene_graph/component.h"

namespace vkb
{
namespace sg
namespace scene_graph
{
namespace components
{
class Sampler : public Component
template <vkb::BindingType bindingType>
class Sampler : public vkb::sg::Component
{
public:
Sampler(const std::string &name, core::Sampler &&vk_sampler);
using CoreSamplerType = typename std::conditional<bindingType == BindingType::Cpp, vkb::core::HPPSampler, vkb::core::Sampler>::type;

public:
Sampler(std::string const &name, CoreSamplerType &&core_sampler);

Sampler(Sampler &&other) = default;
virtual ~Sampler() = default;

virtual ~Sampler() = default;
CoreSamplerType const &get_core_sampler() const;

virtual std::type_index get_type() override;

core::Sampler vk_sampler;
private:
vkb::core::HPPSampler core_sampler;
};
} // namespace sg

using SamplerC = Sampler<vkb::BindingType::C>;
using SamplerCpp = Sampler<vkb::BindingType::Cpp>;

// Member function definitions

template <>
inline Sampler<vkb::BindingType::Cpp>::Sampler(std::string const &name, vkb::core::HPPSampler &&core_sampler_) :
Component{name},
core_sampler{std::move(core_sampler_)}
{
}

template <>
inline Sampler<vkb::BindingType::C>::Sampler(std::string const &name, vkb::core::Sampler &&core_sampler_) :
Component{name},
core_sampler{std::move(reinterpret_cast<vkb::core::HPPSampler &&>(core_sampler_))}
{
}

template <vkb::BindingType bindingType>
inline typename Sampler<bindingType>::CoreSamplerType const &Sampler<bindingType>::get_core_sampler() const
{
if constexpr (bindingType == BindingType::Cpp)
{
return core_sampler;
}
else
{
return reinterpret_cast<vkb::core::Sampler const &>(core_sampler);
}
}

template <vkb::BindingType bindingType>
inline std::type_index Sampler<bindingType>::get_type()
{
return typeid(Sampler<bindingType>);
}
} // namespace components
} // namespace scene_graph
} // namespace vkb
6 changes: 3 additions & 3 deletions framework/scene_graph/components/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2019, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -43,12 +43,12 @@ Image *Texture::get_image()
return image;
}

void Texture::set_sampler(Sampler &s)
void Texture::set_sampler(vkb::scene_graph::components::SamplerC &s)
{
sampler = &s;
}

Sampler *Texture::get_sampler()
vkb::scene_graph::components::SamplerC *Texture::get_sampler()
{
assert(sampler && "Texture has no sampler");
return sampler;
Expand Down
8 changes: 4 additions & 4 deletions framework/scene_graph/components/texture.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2019, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -47,14 +47,14 @@ class Texture : public Component

Image *get_image();

void set_sampler(Sampler &sampler);
void set_sampler(vkb::scene_graph::components::SamplerC &sampler);

Sampler *get_sampler();
vkb::scene_graph::components::SamplerC *get_sampler();

private:
Image *image{nullptr};

Sampler *sampler{nullptr};
vkb::scene_graph::components::SamplerC *sampler = nullptr;
};
} // namespace sg
} // namespace vkb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void DynamicMultisampleRasterization::load_assets()
VkDescriptorImageInfo imageInfo;
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = image->get_vk_image_view().get_handle();
imageInfo.sampler = texture->get_sampler()->vk_sampler.get_handle();
imageInfo.sampler = texture->get_sampler()->get_core_sampler().get_handle();

image_infos.push_back(imageInfo);
name_to_texture_id.emplace(name, static_cast<int32_t>(image_infos.size()) - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void FragmentDensityMap::setup_descriptor_set_main_pass()

VkDescriptorBufferInfo buffer_descriptor = create_descriptor(*mesh_data.vertex_ubo);
VkDescriptorImageInfo image_descriptor = vkb::initializers::descriptor_image_info(
mesh_data.base_color_texture->get_sampler()->vk_sampler.get_handle(),
mesh_data.base_color_texture->get_sampler()->get_core_sampler().get_handle(),
mesh_data.base_color_texture->get_image()->get_vk_image_view().get_handle(),
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
std::array<VkWriteDescriptorSet, 2> write_descriptor_sets =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ RaytracingExtended::RaytracingScene::RaytracingScene(vkb::core::DeviceC &device,
VkDescriptorImageInfo imageInfo;
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = image->get_vk_image_view().get_handle();
imageInfo.sampler = baseTextureIter->second->get_sampler()->vk_sampler.get_handle();
imageInfo.sampler = baseTextureIter->second->get_sampler()->get_core_sampler().get_handle();
imageInfos.push_back(imageInfo);
}

Expand Down
Loading