Ejemplo n.º 1
0
static vk::DescriptorSet create_descriptor_set(DevicePtr dptr, vk::DescriptorPool pool, vk::DescriptorSetLayout layout) {
	return dptr->vk_device().allocateDescriptorSets(vk::DescriptorSetAllocateInfo()
			.setDescriptorPool(pool)
			.setDescriptorSetCount(1)
			.setPSetLayouts(&layout)
		).front();
}
Ejemplo n.º 2
0
static vk::ShaderModule create_shader_module(DevicePtr dptr, const SpirVData& data) {
	if(data.is_empty()) {
		return vk::ShaderModule();
	}
	return dptr->vk_device().createShaderModule(vk::ShaderModuleCreateInfo()
			.setCodeSize(data.size())
			.setPCode(data.data())
		);
}
Ejemplo n.º 3
0
static vk::Buffer create_buffer(DevicePtr dptr, usize byte_size, vk::BufferUsageFlags usage) {
	y_debug_assert(byte_size);
	if(usage & vk::BufferUsageFlagBits::eUniformBuffer) {
		if(byte_size > dptr->vk_limits().maxUniformBufferRange) {
			y_fatal("Uniform buffer size exceeds maxUniformBufferRange (%).", dptr->vk_limits().maxUniformBufferRange);
		}
	}
	return dptr->vk_device().createBuffer(vk::BufferCreateInfo()
			.setSize(byte_size)
			.setUsage(usage)
			.setSharingMode(vk::SharingMode::eExclusive)
		);
}
Ejemplo n.º 4
0
static vk::DescriptorPool create_descriptor_pool(DevicePtr dptr, const std::unordered_map<vk::DescriptorType, u32>& binding_counts) {
	auto sizes = core::vector_with_capacity<vk::DescriptorPoolSize>(binding_counts.size());
	std::transform(binding_counts.begin(), binding_counts.end(), std::back_inserter(sizes), [](const auto& count) {
			return vk::DescriptorPoolSize()
					.setType(count.first)
					.setDescriptorCount(count.second)
				;
		});

	return dptr->vk_device().createDescriptorPool(vk::DescriptorPoolCreateInfo()
			.setPoolSizeCount(sizes.size())
			.setPPoolSizes(sizes.begin())
			.setMaxSets(1)
		);
}
Ejemplo n.º 5
0
static void update_sets(DevicePtr dptr, vk::DescriptorSet set, const core::Vector<vk::DescriptorSetLayoutBinding>& /*layout_binding*/, const core::ArrayView<Binding>& bindings) {
	auto writes = core::vector_with_capacity<vk::WriteDescriptorSet>(bindings.size());
	for(const auto& binding : bindings) {
		auto w = vk::WriteDescriptorSet()
				.setDstSet(set)
				.setDstBinding(u32(writes.size()))
				.setDstArrayElement(0)
				.setDescriptorCount(1)
				.setDescriptorType(binding.vk_descriptor_type())
			;

		if(binding.is_buffer()) {
			w.setPBufferInfo(&binding.descriptor_info().buffer);
		} else if(binding.is_image()) {
			w.setPImageInfo(&binding.descriptor_info().image);
		} else {
			y_fatal("Unknown descriptor type.");
		}

		writes << w;
	}
	dptr->vk_device().updateDescriptorSets(u32(writes.size()), writes.begin(), 0, nullptr);
}
Ejemplo n.º 6
0
static void bind_buffer_memory(DevicePtr dptr, vk::Buffer buffer, const DeviceMemory& memory) {
	dptr->vk_device().bindBufferMemory(buffer, memory.vk_memory(), memory.vk_offset());
}