Next step towards multisampled text
This commit is contained in:
parent
f4a8e48d67
commit
de0a2bca70
1 changed files with 101 additions and 106 deletions
|
@ -193,7 +193,8 @@ impl GuiHandler {
|
|||
let render_targets =
|
||||
Self::create_render_targets(device, &context.images(), queue, text_sample_count)?;
|
||||
|
||||
let (text_objs, color_layout) = Self::init_text_objects(device, &render_targets)?;
|
||||
let (text_objs, color_layout) =
|
||||
Self::init_text_objects(device, &render_targets, text_sample_count)?;
|
||||
let rect_objs = Self::init_rectangle_objects(device, &render_targets)?;
|
||||
let single_color_objects = Self::init_single_color_objects(device, &render_targets)?;
|
||||
|
||||
|
@ -780,6 +781,7 @@ impl GuiHandler {
|
|||
|
||||
fn render(
|
||||
&self,
|
||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||
command_buffer_state: &CommandBufferState,
|
||||
render_target: &RenderTarget,
|
||||
single_color_objects: &GuiSeparator,
|
||||
|
@ -787,19 +789,6 @@ impl GuiHandler {
|
|||
text_objects: &GuiSeparator,
|
||||
index: usize,
|
||||
) -> Result<()> {
|
||||
if !command_buffer_state.valid.load(SeqCst) {
|
||||
let gui_command_buffer = &command_buffer_state.command_buffer;
|
||||
|
||||
let inheritance_info = render_target.inheritance_info();
|
||||
|
||||
let mut command_buffer_begin_info = VkCommandBufferBeginInfo::new(
|
||||
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
|
||||
| VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
|
||||
);
|
||||
command_buffer_begin_info.set_inheritance_info(&inheritance_info);
|
||||
|
||||
let mut buffer_recorder = gui_command_buffer.begin(command_buffer_begin_info)?;
|
||||
|
||||
let viewport = [VkViewport {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
|
@ -820,7 +809,7 @@ impl GuiHandler {
|
|||
let layers = self.layers.lock().unwrap();
|
||||
|
||||
for (_, elements) in layers.iter() {
|
||||
render_target.begin(&mut buffer_recorder, VK_SUBPASS_CONTENTS_INLINE, index);
|
||||
render_target.begin(buffer_recorder, VK_SUBPASS_CONTENTS_INLINE, index);
|
||||
|
||||
if !elements.is_colorables_empty() {
|
||||
buffer_recorder.bind_pipeline(&single_color_objects._pipeline)?;
|
||||
|
@ -832,8 +821,7 @@ impl GuiHandler {
|
|||
for colorable in elements.iter_colorables() {
|
||||
buffer_recorder.bind_vertex_buffer(colorable.buffer());
|
||||
|
||||
buffer_recorder
|
||||
.bind_descriptor_sets_minimal(&[&colorable.descriptor_set()]);
|
||||
buffer_recorder.bind_descriptor_sets_minimal(&[&colorable.descriptor_set()]);
|
||||
|
||||
buffer_recorder.draw_complete_single_instance(6);
|
||||
}
|
||||
|
@ -849,8 +837,7 @@ impl GuiHandler {
|
|||
for displayable in elements.iter_displayables() {
|
||||
buffer_recorder.bind_vertex_buffer(displayable.buffer());
|
||||
|
||||
buffer_recorder
|
||||
.bind_descriptor_sets_minimal(&[&displayable.descriptor_set()]);
|
||||
buffer_recorder.bind_descriptor_sets_minimal(&[&displayable.descriptor_set()]);
|
||||
|
||||
buffer_recorder.draw_complete_single_instance(6);
|
||||
}
|
||||
|
@ -859,14 +846,13 @@ impl GuiHandler {
|
|||
for iconizable in elements.iter_iconizables() {
|
||||
buffer_recorder.bind_vertex_buffer(iconizable.buffer());
|
||||
|
||||
buffer_recorder
|
||||
.bind_descriptor_sets_minimal(&[iconizable.descriptor_set()]);
|
||||
buffer_recorder.bind_descriptor_sets_minimal(&[iconizable.descriptor_set()]);
|
||||
|
||||
buffer_recorder.draw_complete_single_instance(6);
|
||||
}
|
||||
}
|
||||
|
||||
render_target.next_subpass(&mut buffer_recorder, VK_SUBPASS_CONTENTS_INLINE);
|
||||
render_target.next_subpass(buffer_recorder, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
if !elements.is_textables_empty() {
|
||||
buffer_recorder.bind_pipeline(&text_objects._pipeline)?;
|
||||
|
@ -894,10 +880,7 @@ impl GuiHandler {
|
|||
}
|
||||
}
|
||||
|
||||
render_target.end(&mut buffer_recorder);
|
||||
}
|
||||
|
||||
command_buffer_state.valid.store(true, SeqCst);
|
||||
render_target.end(buffer_recorder);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1214,7 +1197,7 @@ impl GuiHandler {
|
|||
SubPass::builder(target_images[0].width(), target_images[0].height())
|
||||
.add_target_info(CustomTarget {
|
||||
usage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.into(),
|
||||
format: target_images[0].vk_format(),
|
||||
format: VK_FORMAT_R8G8B8A8_UNORM,
|
||||
clear_on_load: false,
|
||||
store_on_save: true,
|
||||
attach_sampler: false,
|
||||
|
@ -1222,7 +1205,15 @@ impl GuiHandler {
|
|||
clear_value: ClearValue::Color([0.0, 0.0, 0.0, 0.0]),
|
||||
})
|
||||
.set_sample_count(sample_count)
|
||||
.add_resolve_targets(target_images.clone())
|
||||
.add_resolve_targets(CustomTarget {
|
||||
usage: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.into(),
|
||||
format: VK_FORMAT_R8G8B8A8_UNORM,
|
||||
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]),
|
||||
})
|
||||
.use_queue(queue.clone())
|
||||
.build(device)?,
|
||||
);
|
||||
|
@ -1282,6 +1273,7 @@ impl GuiHandler {
|
|||
fn init_text_objects(
|
||||
device: &Arc<Device>,
|
||||
render_targets: &TargetMode<RwLock<RenderTarget>>,
|
||||
sample_count: VkSampleCountFlags,
|
||||
) -> Result<(TargetMode<GuiSeparator>, Arc<DescriptorSetLayout>)> {
|
||||
// --- layout creation ---
|
||||
let descriptor_layout = DescriptorSetLayout::builder()
|
||||
|
@ -1331,6 +1323,7 @@ impl GuiHandler {
|
|||
&pipeline_layout,
|
||||
vertex_shader.clone(),
|
||||
fragment_shader.clone(),
|
||||
sample_count,
|
||||
1,
|
||||
)?,
|
||||
})
|
||||
|
@ -1382,6 +1375,7 @@ impl GuiHandler {
|
|||
&pipeline_layout,
|
||||
vertex_shader.clone(),
|
||||
fragment_shader.clone(),
|
||||
VK_SAMPLE_COUNT_1_BIT,
|
||||
0,
|
||||
)?,
|
||||
})
|
||||
|
@ -1431,6 +1425,7 @@ impl GuiHandler {
|
|||
&pipeline_layout,
|
||||
vertex_shader.clone(),
|
||||
fragment_shader.clone(),
|
||||
VK_SAMPLE_COUNT_1_BIT,
|
||||
0,
|
||||
)?,
|
||||
})
|
||||
|
@ -1445,13 +1440,14 @@ impl GuiHandler {
|
|||
pipeline_layout: &Arc<PipelineLayout>,
|
||||
vertex_shader: Arc<ShaderModule>,
|
||||
fragment_shader: Arc<ShaderModule>,
|
||||
sample_count: VkSampleCountFlags,
|
||||
sub_pass: u32,
|
||||
) -> Result<Arc<Pipeline>> {
|
||||
Pipeline::new_graphics()
|
||||
.set_vertex_shader(vertex_shader, binding_description, attribute_description)
|
||||
.set_fragment_shader(fragment_shader)
|
||||
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
|
||||
.default_multisample(VK_SAMPLE_COUNT_1_BIT)
|
||||
.default_multisample(sample_count)
|
||||
.default_color_blend(vec![VkPipelineColorBlendAttachmentState::default()])
|
||||
.default_rasterization(VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE)
|
||||
.build(device.clone(), pipeline_layout, render_pass, sub_pass)
|
||||
|
@ -1471,6 +1467,7 @@ impl GuiHandler {
|
|||
let command_buffer_state = &command_buffer_states[index];
|
||||
|
||||
self.render(
|
||||
buffer_recorder,
|
||||
command_buffer_state,
|
||||
render_target,
|
||||
single_color_objects,
|
||||
|
@ -1479,8 +1476,6 @@ impl GuiHandler {
|
|||
index,
|
||||
)?;
|
||||
|
||||
buffer_recorder.execute_commands(&[&command_buffer_state.command_buffer]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue