mirror of
				https://github.com/PancakeTAS/lsfg-vk.git
				synced 2025-10-30 07:01:10 +00:00 
			
		
		
		
	refactor: remaining pools
This commit is contained in:
		
							parent
							
								
									24f7b66e99
								
							
						
					
					
						commit
						dd91eebb6d
					
				
					 6 changed files with 85 additions and 5 deletions
				
			
		|  | @ -3,6 +3,8 @@ | |||
| #include "vk/core/descriptorpool.hpp" | ||||
| #include "vk/core/device.hpp" | ||||
| #include "vk/core/instance.hpp" | ||||
| #include "vk/pool/buffer_pool.hpp" | ||||
| #include "vk/pool/sampler_pool.hpp" | ||||
| #include "vk/pool/shader_pool.hpp" | ||||
| #include "vk/registry/shader_registry.hpp" | ||||
| 
 | ||||
|  | @ -21,9 +23,12 @@ namespace LSFG { | |||
| 
 | ||||
|         VK::Registry::ShaderRegistry registry; | ||||
| 
 | ||||
|         VK::Pool::BufferPool bpool; | ||||
|         VK::Pool::SamplerPool apool; | ||||
|         VK::Pool::ShaderPool spool; | ||||
| 
 | ||||
|         float flow{1.0F}; | ||||
|         bool hdr{false}; | ||||
|     }; | ||||
| 
 | ||||
|     ///
 | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ namespace VK::Pool { | |||
|         ///
 | ||||
|         /// Get or create a buffer.
 | ||||
|         ///
 | ||||
|         /// @param device Vulkan device.
 | ||||
|         /// @param flow Flow scale
 | ||||
|         /// @param hdr Whether HDR is enabled
 | ||||
|         /// @param timestamp Timestamp of the frame
 | ||||
|  |  | |||
							
								
								
									
										42
									
								
								framegen/include/vk/pool/sampler_pool.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								framegen/include/vk/pool/sampler_pool.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include "vk/core/sampler.hpp" | ||||
| 
 | ||||
| #include <vulkan/vulkan_core.h> | ||||
| 
 | ||||
| #include <unordered_map> | ||||
| #include <cstdint> | ||||
| 
 | ||||
| namespace VK::Pool { | ||||
| 
 | ||||
|     ///
 | ||||
|     /// Pool of initialized samplers.
 | ||||
|     ///
 | ||||
|     class SamplerPool { | ||||
|     public: | ||||
|         ///
 | ||||
|         /// Create a sampler pool.
 | ||||
|         ///
 | ||||
|         SamplerPool() noexcept = default; | ||||
| 
 | ||||
|         ///
 | ||||
|         /// Get or create a sampler.
 | ||||
|         ///
 | ||||
|         /// @param device Vulkan device.
 | ||||
|         /// @param type Address mode
 | ||||
|         /// @param compare Compare operation
 | ||||
|         /// @param white Whether to use a white border color
 | ||||
|         /// @return Preallocated sampler
 | ||||
|         ///
 | ||||
|         /// @throws VK::vulkan_error if sampler creation fails.
 | ||||
|         ///
 | ||||
|         [[nodiscard]] const Core::Sampler& getOrCreate( | ||||
|             const Core::Device& device, | ||||
|             VkSamplerAddressMode type = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, | ||||
|             VkCompareOp compare = VK_COMPARE_OP_NEVER, | ||||
|             bool white = false); | ||||
|     private: | ||||
|         std::unordered_map<uint64_t, Core::Sampler> samplers; | ||||
|     }; | ||||
| 
 | ||||
| } | ||||
|  | @ -19,6 +19,8 @@ Instance::Instance(const std::filesystem::path& dll) { | |||
|         .device = Core::Device(vkd.instance, 0, false), | ||||
|         .dpool = Core::DescriptorPool(vkd.device), | ||||
|         .registry = Registry::ShaderRegistry(), | ||||
|         .bpool = Pool::BufferPool(), | ||||
|         .apool = Pool::SamplerPool(), | ||||
|         .spool = Pool::ShaderPool() | ||||
|     }; | ||||
|     this->vkd = std::make_unique<VKD>(std::move(vkd)); | ||||
|  |  | |||
|  | @ -13,12 +13,12 @@ using namespace LSFG::V31N::Shaderchain; | |||
| using namespace VK; | ||||
| 
 | ||||
| Mipmaps::Mipmaps(LSFG::VKD& vkd, const Core::Image& in1, const Core::Image& in2) { | ||||
|     // TODO: logic for buffer and sampler
 | ||||
|     Core::Sampler sampler{vkd.device, | ||||
|     auto sampler = vkd.apool.getOrCreate(vkd.device, | ||||
|         VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, | ||||
|         VK_COMPARE_OP_NEVER, | ||||
|         false}; | ||||
|     Core::Buffer buffer{vkd.device, nullptr, 0, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT}; | ||||
|         VK_COMPARE_OP_NEVER, false); | ||||
|     auto buffer = vkd.bpool.getOrCreate(vkd.device, | ||||
|         vkd.flow, vkd.hdr, 0.0F, false, false); | ||||
| 
 | ||||
| 
 | ||||
|     // create output images
 | ||||
|     const VkExtent2D extent{ | ||||
|  |  | |||
							
								
								
									
										30
									
								
								framegen/src/vk/pool/sampler_pool.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								framegen/src/vk/pool/sampler_pool.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,30 @@ | |||
| #include "vk/pool/sampler_pool.hpp" | ||||
| #include "vk/core/sampler.hpp" | ||||
| #include "vk/core/device.hpp" | ||||
| 
 | ||||
| #include <vulkan/vulkan_core.h> | ||||
| 
 | ||||
| #include <cstdint> | ||||
| #include <utility> | ||||
| 
 | ||||
| using namespace VK::Pool; | ||||
| 
 | ||||
| const VK::Core::Sampler& SamplerPool::getOrCreate( | ||||
|         const Core::Device& device, VkSamplerAddressMode type, | ||||
|         VkCompareOp compare, bool white) { | ||||
|     uint64_t hash = 0; | ||||
|     hash |= static_cast<uint64_t>(type) << 0; | ||||
|     hash |= static_cast<uint64_t>(compare) << 8; | ||||
|     hash |= static_cast<uint64_t>(white) << 16; | ||||
| 
 | ||||
|     const auto it = samplers.find(hash); | ||||
|     if (it != samplers.end()) { | ||||
|         return it->second; | ||||
|     } | ||||
| 
 | ||||
|     // create sampler
 | ||||
|     Core::Sampler sampler(device, type, compare, white); | ||||
| 
 | ||||
|     const auto i = samplers.emplace(hash, std::move(sampler)); | ||||
|     return i.first->second; | ||||
| } | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 PancakeTAS
						PancakeTAS