vulkan: store tex vertices in buffer
This commit is contained in:
parent
73611fd287
commit
9534da89a2
4 changed files with 100 additions and 47 deletions
|
|
@ -22,8 +22,9 @@ use {
|
||||||
semaphore::VulkanSemaphore,
|
semaphore::VulkanSemaphore,
|
||||||
shaders::{
|
shaders::{
|
||||||
FILL_FRAG, FILL_VERT, FillPushConstants, LEGACY_FILL_FRAG, LEGACY_FILL_VERT,
|
FILL_FRAG, FILL_VERT, FillPushConstants, LEGACY_FILL_FRAG, LEGACY_FILL_VERT,
|
||||||
LEGACY_TEX_FRAG, LEGACY_TEX_VERT, LegacyFillPushConstants, OUT_FRAG, OUT_VERT,
|
LEGACY_TEX_FRAG, LEGACY_TEX_VERT, LegacyFillPushConstants, LegacyTexPushConstants,
|
||||||
OutPushConstants, TEX_FRAG, TEX_VERT, TexPushConstants, VulkanShader,
|
OUT_FRAG, OUT_VERT, OutPushConstants, TEX_FRAG, TEX_VERT, TexPushConstants,
|
||||||
|
TexVertex, VulkanShader,
|
||||||
},
|
},
|
||||||
transfer_functions::{TF_LINEAR, TF_SRGB},
|
transfer_functions::{TF_LINEAR, TF_SRGB},
|
||||||
},
|
},
|
||||||
|
|
@ -183,6 +184,8 @@ struct VulkanTexOp {
|
||||||
alpha: f32,
|
alpha: f32,
|
||||||
source_type: TexSourceType,
|
source_type: TexSourceType,
|
||||||
copy_type: TexCopyType,
|
copy_type: TexCopyType,
|
||||||
|
range_address: DeviceAddress,
|
||||||
|
instances: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VulkanFillOp {
|
struct VulkanFillOp {
|
||||||
|
|
@ -376,18 +379,23 @@ impl VulkanRenderer {
|
||||||
let fill_opaque = create_fill_pipeline(false)?;
|
let fill_opaque = create_fill_pipeline(false)?;
|
||||||
let fill_alpha = create_fill_pipeline(true)?;
|
let fill_alpha = create_fill_pipeline(true)?;
|
||||||
let create_tex_pipeline = |src_has_alpha, has_alpha_mult| {
|
let create_tex_pipeline = |src_has_alpha, has_alpha_mult| {
|
||||||
self.device
|
let push_size = if self.device.descriptor_buffer.is_some() {
|
||||||
.create_pipeline::<TexPushConstants>(PipelineCreateInfo {
|
size_of::<TexPushConstants>()
|
||||||
format,
|
} else {
|
||||||
vert: self.tex_vert_shader.clone(),
|
size_of::<LegacyTexPushConstants>()
|
||||||
frag: self.tex_frag_shader.clone(),
|
};
|
||||||
blend: src_has_alpha || has_alpha_mult,
|
let info = PipelineCreateInfo {
|
||||||
src_has_alpha,
|
format,
|
||||||
has_alpha_mult,
|
vert: self.tex_vert_shader.clone(),
|
||||||
eotf,
|
frag: self.tex_frag_shader.clone(),
|
||||||
oetf,
|
blend: src_has_alpha || has_alpha_mult,
|
||||||
frag_descriptor_set_layout: Some(self.tex_descriptor_set_layout.clone()),
|
src_has_alpha,
|
||||||
})
|
has_alpha_mult,
|
||||||
|
eotf,
|
||||||
|
oetf,
|
||||||
|
frag_descriptor_set_layout: Some(self.tex_descriptor_set_layout.clone()),
|
||||||
|
};
|
||||||
|
self.device.create_pipeline2(info, push_size)
|
||||||
};
|
};
|
||||||
let tex_opaque = create_tex_pipeline(false, false)?;
|
let tex_opaque = create_tex_pipeline(false, false)?;
|
||||||
let tex_alpha = create_tex_pipeline(true, false)?;
|
let tex_alpha = create_tex_pipeline(true, false)?;
|
||||||
|
|
@ -527,8 +535,16 @@ impl VulkanRenderer {
|
||||||
}
|
}
|
||||||
mops.push(VulkanOp::Fill(f));
|
mops.push(VulkanOp::Fill(f));
|
||||||
}
|
}
|
||||||
VulkanOp::Tex(_) => {
|
VulkanOp::Tex(mut c) => {
|
||||||
mops.push(op);
|
c.range_address = memory.data_buffer.len() as DeviceAddress;
|
||||||
|
c.instances = c.range.len() as u32;
|
||||||
|
for &[pos, tex_pos] in &memory.tex_targets[c.range.clone()] {
|
||||||
|
let vertex = TexVertex { pos, tex_pos };
|
||||||
|
memory
|
||||||
|
.data_buffer
|
||||||
|
.extend_from_slice(uapi::as_bytes(&vertex));
|
||||||
|
}
|
||||||
|
mops.push(VulkanOp::Tex(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -630,6 +646,8 @@ impl VulkanRenderer {
|
||||||
alpha: ct.alpha.unwrap_or_default(),
|
alpha: ct.alpha.unwrap_or_default(),
|
||||||
source_type,
|
source_type,
|
||||||
copy_type,
|
copy_type,
|
||||||
|
range_address: 0,
|
||||||
|
instances: 0,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -669,7 +687,9 @@ impl VulkanRenderer {
|
||||||
VulkanOp::Fill(f) => {
|
VulkanOp::Fill(f) => {
|
||||||
f.range_address += buffer.buffer.address;
|
f.range_address += buffer.buffer.address;
|
||||||
}
|
}
|
||||||
VulkanOp::Tex(_) => {}
|
VulkanOp::Tex(c) => {
|
||||||
|
c.range_address += buffer.buffer.address;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -988,6 +1008,10 @@ impl VulkanRenderer {
|
||||||
.image_view(tex.texture_view)
|
.image_view(tex.texture_view)
|
||||||
.image_layout(ImageLayout::SHADER_READ_ONLY_OPTIMAL);
|
.image_layout(ImageLayout::SHADER_READ_ONLY_OPTIMAL);
|
||||||
if let Some(db) = &self.device.descriptor_buffer {
|
if let Some(db) = &self.device.descriptor_buffer {
|
||||||
|
let push = TexPushConstants {
|
||||||
|
vertices: c.range_address,
|
||||||
|
alpha: c.alpha,
|
||||||
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
db.cmd_set_descriptor_buffer_offsets(
|
db.cmd_set_descriptor_buffer_offsets(
|
||||||
buf,
|
buf,
|
||||||
|
|
@ -997,6 +1021,14 @@ impl VulkanRenderer {
|
||||||
&[0],
|
&[0],
|
||||||
&[tex.descriptor_buffer_offset.get()],
|
&[tex.descriptor_buffer_offset.get()],
|
||||||
);
|
);
|
||||||
|
dev.cmd_push_constants(
|
||||||
|
buf,
|
||||||
|
pipeline.pipeline_layout,
|
||||||
|
ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT,
|
||||||
|
0,
|
||||||
|
uapi::as_bytes(&push),
|
||||||
|
);
|
||||||
|
dev.cmd_draw(buf, 4, c.instances, 0, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let write_descriptor_set = WriteDescriptorSet::default()
|
let write_descriptor_set = WriteDescriptorSet::default()
|
||||||
|
|
@ -1011,22 +1043,22 @@ impl VulkanRenderer {
|
||||||
slice::from_ref(&write_descriptor_set),
|
slice::from_ref(&write_descriptor_set),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
for &[pos, tex_pos] in &memory.tex_targets[c.range.clone()] {
|
||||||
for &[pos, tex_pos] in &memory.tex_targets[c.range.clone()] {
|
let push = LegacyTexPushConstants {
|
||||||
let push = TexPushConstants {
|
pos,
|
||||||
pos,
|
tex_pos,
|
||||||
tex_pos,
|
alpha: c.alpha,
|
||||||
alpha: c.alpha,
|
};
|
||||||
};
|
unsafe {
|
||||||
unsafe {
|
dev.cmd_push_constants(
|
||||||
dev.cmd_push_constants(
|
buf,
|
||||||
buf,
|
pipeline.pipeline_layout,
|
||||||
pipeline.pipeline_layout,
|
ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT,
|
||||||
ShaderStageFlags::VERTEX | ShaderStageFlags::FRAGMENT,
|
0,
|
||||||
0,
|
uapi::as_bytes(&push),
|
||||||
uapi::as_bytes(&push),
|
);
|
||||||
);
|
dev.cmd_draw(buf, 4, 1, 0, 0);
|
||||||
dev.cmd_draw(buf, 4, 1, 0, 0);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,33 @@ pub struct LegacyFillPushConstants {
|
||||||
|
|
||||||
unsafe impl Packed for LegacyFillPushConstants {}
|
unsafe impl Packed for LegacyFillPushConstants {}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct TexVertex {
|
||||||
|
pub pos: [[f32; 2]; 4],
|
||||||
|
pub tex_pos: [[f32; 2]; 4],
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Packed for TexVertex {}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct TexPushConstants {
|
pub struct TexPushConstants {
|
||||||
|
pub vertices: DeviceAddress,
|
||||||
|
pub alpha: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Packed for TexPushConstants {}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct LegacyTexPushConstants {
|
||||||
pub pos: [[f32; 2]; 4],
|
pub pos: [[f32; 2]; 4],
|
||||||
pub tex_pos: [[f32; 2]; 4],
|
pub tex_pos: [[f32; 2]; 4],
|
||||||
pub alpha: f32,
|
pub alpha: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Packed for TexPushConstants {}
|
unsafe impl Packed for LegacyTexPushConstants {}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
|
#extension GL_EXT_buffer_reference : require
|
||||||
|
|
||||||
|
struct Vertex {
|
||||||
|
vec2 pos[4];
|
||||||
|
vec2 tex_pos[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(buffer_reference, buffer_reference_align = 8, std430) buffer Vertices {
|
||||||
|
Vertex vertices[];
|
||||||
|
};
|
||||||
|
|
||||||
layout(push_constant, std430) uniform Data {
|
layout(push_constant, std430) uniform Data {
|
||||||
layout(offset = 0) vec2 pos[4];
|
Vertices vertices;
|
||||||
layout(offset = 32) vec2 tex_pos[4];
|
float mul;
|
||||||
layout(offset = 64) float mul;
|
|
||||||
} data;
|
} data;
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,11 @@
|
||||||
#version 450
|
#version 450
|
||||||
//#extension GL_EXT_debug_printf : enable
|
|
||||||
|
|
||||||
#include "tex.common.glsl"
|
#include "tex.common.glsl"
|
||||||
|
|
||||||
layout(location = 0) out vec2 tex_pos;
|
layout(location = 0) out vec2 tex_pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 pos;
|
Vertex vertex = data.vertices.vertices[gl_InstanceIndex];
|
||||||
switch (gl_VertexIndex) {
|
gl_Position = vec4(vertex.pos[gl_VertexIndex], 0.0, 1.0);
|
||||||
case 0: pos = data.pos[0]; tex_pos = data.tex_pos[0]; break;
|
tex_pos = vertex.tex_pos[gl_VertexIndex];
|
||||||
case 1: pos = data.pos[1]; tex_pos = data.tex_pos[1]; break;
|
|
||||||
case 2: pos = data.pos[2]; tex_pos = data.tex_pos[2]; break;
|
|
||||||
case 3: pos = data.pos[3]; tex_pos = data.tex_pos[3]; break;
|
|
||||||
}
|
|
||||||
gl_Position = vec4(pos, 0.0, 1.0);
|
|
||||||
// debugPrintfEXT("gl_Position = %v4f, tex_pos = %v2f", gl_Position, tex_pos);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue