Start implementing generator

This commit is contained in:
hodasemi 2024-03-24 21:40:35 +01:00
parent e0def0d91a
commit e87b6a4ec6
2 changed files with 74 additions and 2 deletions

View file

@ -109,3 +109,75 @@ impl ElementCreator {
todo!()
}
}
struct Generator {
device: Arc<Device>,
queue: Arc<Mutex<Queue>>,
max_supported_sample_count: VkSampleCountFlags,
vertex_shader: Arc<ShaderModule<shader_type::Vertex>>,
fragment_shader: Arc<ShaderModule<shader_type::Fragment>>,
}
impl Generator {
fn new(device: Arc<Device>, queue: Arc<Mutex<Queue>>) -> Result<Self> {
Ok(Self {
max_supported_sample_count: device.max_supported_sample_count(VK_SAMPLE_COUNT_16_BIT),
vertex_shader: ShaderModule::from_slice(
device.clone(),
include_bytes!("generator.vert.spv"),
)?,
fragment_shader: ShaderModule::from_slice(
device.clone(),
include_bytes!("generator.frag.spv"),
)?,
device,
queue,
})
}
fn generate(&self, definition: ElementDefinition) -> Result<Arc<Image>> {
let image = self.create_image(definition.width, definition.height)?;
todo!()
}
fn create_image(&self, width: u32, height: u32) -> Result<Arc<Image>> {
let image = Image::empty(
width,
height,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_SAMPLE_COUNT_1_BIT,
)
.format(VK_FORMAT_R8G8B8A8_UNORM)
.attach_sampler(Sampler::nearest_sampler().build(&self.device)?)
.build(&self.device, &self.queue)?;
image.convert_layout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)?;
Ok(image)
}
fn render_target(&self, image: &Arc<Image>) -> Result<RenderTarget> {
RenderTarget::builder()
.add_sub_pass(
SubPass::builder(image.width(), image.height())
.add_target_info(CustomTarget {
usage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.into(),
format: image.vk_format(),
clear_on_load: true,
store_on_save: true,
attach_sampler: false,
use_as_input: false,
clear_value: ClearValue::Color([0.0, 0.0, 0.0, 0.0]),
})
.set_sample_count(self.max_supported_sample_count)
.add_resolve_targets((vec![image.clone()], true))
.use_queue(image.queue().clone())
.build(image.device())?,
)
.build(image.device())
}
}

View file

@ -1581,8 +1581,8 @@ impl GuiHandler {
device: &Arc<Device>,
render_pass: &Arc<RenderPass>,
pipeline_layout: &Arc<PipelineLayout>,
vertex_shader: Arc<ShaderModule<{ ShaderType::Vertex as u8 }>>,
fragment_shader: Arc<ShaderModule<{ ShaderType::Fragment as u8 }>>,
vertex_shader: Arc<ShaderModule<shader_type::Vertex>>,
fragment_shader: Arc<ShaderModule<shader_type::Fragment>>,
sample_count: VkSampleCountFlags,
sub_pass: u32,
) -> Result<Arc<Pipeline>> {