blade: always create texture views for atlas tiles

This commit is contained in:
Dzmitry Malyshau 2024-02-04 12:15:41 -08:00
parent aae532987f
commit 61fa5e93a8
2 changed files with 24 additions and 24 deletions

View file

@ -32,15 +32,14 @@ struct BladeAtlasState {
impl BladeAtlasState { impl BladeAtlasState {
fn destroy(&mut self) { fn destroy(&mut self) {
for texture in self.monochrome_textures.drain(..) { for mut texture in self.monochrome_textures.drain(..) {
self.gpu.destroy_texture(texture.raw); texture.destroy(&self.gpu);
} }
for texture in self.polychrome_textures.drain(..) { for mut texture in self.polychrome_textures.drain(..) {
self.gpu.destroy_texture(texture.raw); texture.destroy(&self.gpu);
} }
for texture in self.path_textures.drain(..) { for mut texture in self.path_textures.drain(..) {
self.gpu.destroy_texture(texture.raw); texture.destroy(&self.gpu);
self.gpu.destroy_texture_view(texture.raw_view.unwrap());
} }
self.upload_belt.destroy(&self.gpu); self.upload_belt.destroy(&self.gpu);
} }
@ -48,7 +47,7 @@ impl BladeAtlasState {
pub struct BladeTextureInfo { pub struct BladeTextureInfo {
pub size: gpu::Extent, pub size: gpu::Extent,
pub raw_view: Option<gpu::TextureView>, pub raw_view: gpu::TextureView,
} }
impl BladeAtlas { impl BladeAtlas {
@ -198,17 +197,13 @@ impl BladeAtlasState {
dimension: gpu::TextureDimension::D2, dimension: gpu::TextureDimension::D2,
usage, usage,
}); });
let raw_view = if usage.contains(gpu::TextureUsage::TARGET) { let raw_view = self.gpu.create_texture_view(gpu::TextureViewDesc {
Some(self.gpu.create_texture_view(gpu::TextureViewDesc { name: "",
name: "", texture: raw,
texture: raw, format,
format, dimension: gpu::ViewDimension::D2,
dimension: gpu::ViewDimension::D2, subresources: &Default::default(),
subresources: &Default::default(), });
}))
} else {
None
};
let textures = match kind { let textures = match kind {
AtlasTextureKind::Monochrome => &mut self.monochrome_textures, AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
@ -270,7 +265,7 @@ struct BladeAtlasTexture {
id: AtlasTextureId, id: AtlasTextureId,
allocator: BucketedAtlasAllocator, allocator: BucketedAtlasAllocator,
raw: gpu::Texture, raw: gpu::Texture,
raw_view: Option<gpu::TextureView>, raw_view: gpu::TextureView,
format: gpu::TextureFormat, format: gpu::TextureFormat,
} }
@ -293,6 +288,11 @@ impl BladeAtlasTexture {
Some(tile) Some(tile)
} }
fn destroy(&mut self, gpu: &gpu::Context) {
gpu.destroy_texture(self.raw);
gpu.destroy_texture_view(self.raw_view);
}
fn bytes_per_pixel(&self) -> u8 { fn bytes_per_pixel(&self) -> u8 {
self.format.block_info().size self.format.block_info().size
} }

View file

@ -336,7 +336,7 @@ impl BladeRenderer {
let vertex_buf = self.instance_belt.alloc_data(&vertices, &self.gpu); let vertex_buf = self.instance_belt.alloc_data(&vertices, &self.gpu);
let mut pass = self.command_encoder.render(gpu::RenderTargetSet { let mut pass = self.command_encoder.render(gpu::RenderTargetSet {
colors: &[gpu::RenderTarget { colors: &[gpu::RenderTarget {
view: tex_info.raw_view.unwrap(), view: tex_info.raw_view,
init_op: gpu::InitOp::Clear(gpu::TextureColor::OpaqueBlack), init_op: gpu::InitOp::Clear(gpu::TextureColor::OpaqueBlack),
finish_op: gpu::FinishOp::Store, finish_op: gpu::FinishOp::Store,
}], }],
@ -426,7 +426,7 @@ impl BladeRenderer {
0, 0,
&ShaderPathsData { &ShaderPathsData {
globals, globals,
t_sprite: tex_info.raw_view.unwrap(), t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler, s_sprite: self.atlas_sampler,
b_path_sprites: instance_buf, b_path_sprites: instance_buf,
}, },
@ -457,7 +457,7 @@ impl BladeRenderer {
0, 0,
&ShaderMonoSpritesData { &ShaderMonoSpritesData {
globals, globals,
t_sprite: tex_info.raw_view.unwrap(), t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler, s_sprite: self.atlas_sampler,
b_mono_sprites: instance_buf, b_mono_sprites: instance_buf,
}, },
@ -475,7 +475,7 @@ impl BladeRenderer {
0, 0,
&ShaderPolySpritesData { &ShaderPolySpritesData {
globals, globals,
t_sprite: tex_info.raw_view.unwrap(), t_sprite: tex_info.raw_view,
s_sprite: self.atlas_sampler, s_sprite: self.atlas_sampler,
b_poly_sprites: instance_buf, b_poly_sprites: instance_buf,
}, },