1use std::hash::Hash;
2
3use uuid::Uuid;
4
5use crate::context::Context;
6
7#[derive(Clone, Debug)]
11pub struct Shader {
12 id: Uuid,
13 shader: wgpu::ShaderModule,
14}
15
16impl Shader {
17 pub fn new(desc: wgpu::ShaderModuleDescriptor, context: &Context) -> Self {
21 Self {
22 id: Uuid::new_v4(),
23 shader: context.device().create_shader_module(desc),
24 }
25 }
26
27 pub fn entry_point(&self, entry_point: &str) -> EntryPoint {
29 EntryPoint {
30 id: self.id,
31 shader: self.shader.clone(),
32 entry_point: entry_point.to_string(),
33 }
34 }
35}
36
37#[derive(Clone, Debug)]
39pub struct EntryPoint {
40 id: Uuid,
41 pub(crate) shader: wgpu::ShaderModule,
42 pub(crate) entry_point: String,
43}
44
45impl Eq for EntryPoint {}
46
47impl PartialEq for EntryPoint {
48 fn eq(&self, other: &Self) -> bool {
49 self.id == other.id && self.entry_point == other.entry_point
50 }
51}
52
53impl Hash for EntryPoint {
54 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
55 state.write_usize(&self.shader as *const wgpu::ShaderModule as usize);
56 self.entry_point.hash(state);
57 }
58}