1
0
Fork 0
forked from wry/wry

vulkan: store out vertices in buffer

This commit is contained in:
Julian Orth 2025-02-27 16:14:22 +01:00
parent 10be846e4c
commit 73611fd287
4 changed files with 34 additions and 31 deletions

View file

@ -164,6 +164,7 @@ pub(super) struct Memory {
fill_targets: Vec<Point>, fill_targets: Vec<Point>,
tex_targets: Vec<[Point; 2]>, tex_targets: Vec<[Point; 2]>,
data_buffer: Vec<u8>, data_buffer: Vec<u8>,
out_address: DeviceAddress,
} }
type Point = [[f32; 2]; 4]; type Point = [[f32; 2]; 4];
@ -644,6 +645,17 @@ impl VulkanRenderer {
zone!("create_data_buffer"); zone!("create_data_buffer");
let memory = &mut *self.memory.borrow_mut(); let memory = &mut *self.memory.borrow_mut();
let buf = &mut memory.data_buffer; let buf = &mut memory.data_buffer;
{
memory.out_address = buf.len() as _;
for region in &memory.paint_regions[RenderPass::BlendBuffer] {
buf.extend_from_slice(uapi::as_bytes(&[
[region.x2, region.y1],
[region.x1, region.y1],
[region.x2, region.y2],
[region.x1, region.y2],
]));
}
}
if buf.is_empty() { if buf.is_empty() {
return Ok(()); return Ok(());
} }
@ -661,6 +673,7 @@ impl VulkanRenderer {
} }
} }
} }
memory.out_address += buffer.buffer.address;
memory.used_buffers.push(buffer); memory.used_buffers.push(buffer);
Ok(()) Ok(())
} }
@ -1075,6 +1088,10 @@ impl VulkanRenderer {
out out
} }
}; };
let push = OutPushConstants {
vertices: memory.out_address,
};
let instances = memory.paint_regions[RenderPass::BlendBuffer].len() as u32;
let dev = &self.device.device; let dev = &self.device.device;
unsafe { unsafe {
dev.cmd_bind_pipeline(buf, PipelineBindPoint::GRAPHICS, pipeline.pipeline); dev.cmd_bind_pipeline(buf, PipelineBindPoint::GRAPHICS, pipeline.pipeline);
@ -1086,26 +1103,14 @@ impl VulkanRenderer {
&[1], &[1],
&[bb.descriptor_buffer_offset.get()], &[bb.descriptor_buffer_offset.get()],
); );
} dev.cmd_push_constants(
for region in &memory.paint_regions[RenderPass::BlendBuffer] { buf,
let push = OutPushConstants { pipeline.pipeline_layout,
pos: [ ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT,
[region.x2, region.y1], 0,
[region.x1, region.y1], uapi::as_bytes(&push),
[region.x2, region.y2], );
[region.x1, region.y2], dev.cmd_draw(buf, 4, instances, 0, 0);
],
};
unsafe {
dev.cmd_push_constants(
buf,
pipeline.pipeline_layout,
ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT,
0,
uapi::as_bytes(&push),
);
dev.cmd_draw(buf, 4, 1, 0, 0);
}
} }
Ok(()) Ok(())
} }

View file

@ -56,7 +56,7 @@ unsafe impl Packed for TexPushConstants {}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[repr(C)] #[repr(C)]
pub struct OutPushConstants { pub struct OutPushConstants {
pub pos: [[f32; 2]; 4], pub vertices: DeviceAddress,
} }
unsafe impl Packed for OutPushConstants {} unsafe impl Packed for OutPushConstants {}

View file

@ -1,3 +1,9 @@
#extension GL_EXT_buffer_reference : require
layout(buffer_reference, buffer_reference_align = 8, std430) buffer Vertices {
vec2 pos[][4];
};
layout(push_constant, std430) uniform Data { layout(push_constant, std430) uniform Data {
layout(offset = 0) vec2 pos[4]; Vertices vertices;
} data; } data;

View file

@ -1,16 +1,8 @@
#version 450 #version 450
//#extension GL_EXT_debug_printf : enable
#include "out.common.glsl" #include "out.common.glsl"
void main() { void main() {
vec2 pos; vec2 pos = data.vertices.pos[gl_InstanceIndex][gl_VertexIndex];
switch (gl_VertexIndex) {
case 0: pos = data.pos[0]; break;
case 1: pos = data.pos[1]; break;
case 2: pos = data.pos[2]; break;
case 3: pos = data.pos[3]; break;
}
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
// debugPrintfEXT("X gl_Position = %v4f, pos = %v2f", gl_Position, pos);
} }