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

View file

@ -56,7 +56,7 @@ unsafe impl Packed for TexPushConstants {}
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct OutPushConstants {
pub pos: [[f32; 2]; 4],
pub vertices: DeviceAddress,
}
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(offset = 0) vec2 pos[4];
Vertices vertices;
} data;

View file

@ -1,16 +1,8 @@
#version 450
//#extension GL_EXT_debug_printf : enable
#include "out.common.glsl"
void main() {
vec2 pos;
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;
}
vec2 pos = data.vertices.pos[gl_InstanceIndex][gl_VertexIndex];
gl_Position = vec4(pos, 0.0, 1.0);
// debugPrintfEXT("X gl_Position = %v4f, pos = %v2f", gl_Position, pos);
}