Skip to content

Commit

Permalink
refactor: rename render pipeline to graphics pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
SkillerRaptor committed May 20, 2024
1 parent 280024b commit fb6ad4e
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 102 deletions.
10 changes: 5 additions & 5 deletions crates/hyper_engine/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hyper_platform::window::{self, Window, WindowDescriptor};
use hyper_rhi::{
graphics_device::{GraphicsApi, GraphicsDevice, GraphicsDeviceDescriptor},
render_pass::RenderPassDescriptor,
render_pipeline::{RenderPipeline, RenderPipelineDescriptor},
graphics_pipeline::{GraphicsPipeline, GraphicsPipelineDescriptor},
shader_module::{ShaderModuleDescriptor, ShaderModuleError, ShaderStage},
surface::{Surface, SurfaceDescriptor},
};
Expand All @@ -37,7 +37,7 @@ pub struct ApplicationDescriptor<'a> {

pub struct Application {
// Rendering
render_pipeline: RenderPipeline,
graphics_pipeline: GraphicsPipeline,
surface: Surface,
graphics_device: GraphicsDevice,

Expand Down Expand Up @@ -86,7 +86,7 @@ impl Application {
stage: ShaderStage::Pixel,
})?;

let render_pipeline = graphics_device.create_render_pipeline(&RenderPipelineDescriptor {
let graphics_pipeline = graphics_device.create_graphics_pipeline(&GraphicsPipelineDescriptor {
vertex_shader: &vertex_shader,
pixel_shader: &pixel_shader,
});
Expand All @@ -97,7 +97,7 @@ impl Application {
);

Ok(Self {
render_pipeline,
graphics_pipeline,
surface,
graphics_device,

Expand Down Expand Up @@ -149,7 +149,7 @@ impl Application {
texture: &swapchain_texture,
});

render_pass.bind_pipeline(&self.render_pipeline);
render_pass.bind_pipeline(&self.graphics_pipeline);
render_pass.draw(3, 1, 0, 0);
}

Expand Down
12 changes: 6 additions & 6 deletions crates/hyper_rhi/src/d3d12/graphics_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ use crate::{
d3d12::{
resource_heap::{ResourceHeap, ResourceHeapDescriptor, ResourceHeapType},
CommandList,
RenderPipeline,
GraphicsPipeline,
ShaderModule,
ShaderModuleError,
Surface,
Texture,
},
graphics_device::GraphicsDeviceDescriptor,
render_pipeline::RenderPipelineDescriptor,
graphics_pipeline::GraphicsPipelineDescriptor,
shader_module::ShaderModuleDescriptor,
surface::SurfaceDescriptor,
texture::TextureDescriptor,
Expand Down Expand Up @@ -356,11 +356,11 @@ impl GraphicsDevice {
Surface::new(self, descriptor)
}

pub(crate) fn create_render_pipeline(
pub(crate) fn create_graphics_pipeline(
&self,
descriptor: &RenderPipelineDescriptor,
) -> RenderPipeline {
RenderPipeline::new(self, descriptor)
descriptor: &GraphicsPipelineDescriptor,
) -> GraphicsPipeline {
GraphicsPipeline::new(self, descriptor)
}

pub(crate) fn create_texture(&self, descriptor: &TextureDescriptor) -> Texture {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ use windows::Win32::Graphics::{
Dxgi::Common::{DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_SAMPLE_DESC},
};

use crate::{d3d12::GraphicsDevice, render_pipeline::RenderPipelineDescriptor};
use crate::{d3d12::GraphicsDevice, graphics_pipeline::GraphicsPipelineDescriptor};

pub struct RenderPipeline {
pub struct GraphicsPipeline {
pipeline_state: ID3D12PipelineState,
}

impl RenderPipeline {
impl GraphicsPipeline {
pub(crate) fn new(
graphics_device: &GraphicsDevice,
descriptor: &RenderPipelineDescriptor,
descriptor: &GraphicsPipelineDescriptor,
) -> Self {
let vertex_shader = descriptor.vertex_shader.d3d12_shader_module().unwrap();
let vertex_shader_code = vertex_shader.code();
Expand Down Expand Up @@ -100,7 +100,7 @@ impl RenderPipeline {
.device()
.CreateGraphicsPipelineState(&descriptor)
}
.expect("failed to create render pipeline state");
.expect("failed to create graphics pipeline state");

Self { pipeline_state }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hyper_rhi/src/d3d12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

pub(crate) mod command_list;
pub(crate) mod graphics_device;
pub(crate) mod graphics_pipeline;
pub(crate) mod render_pass;
pub(crate) mod render_pipeline;
pub(crate) mod shader_module;
pub(crate) mod surface;
pub(crate) mod texture;
Expand All @@ -18,8 +18,8 @@ mod resource_heap;

pub(crate) use command_list::*;
pub(crate) use graphics_device::*;
pub(crate) use graphics_pipeline::*;
pub(crate) use render_pass::*;
pub(crate) use render_pipeline::*;
pub(crate) use shader_module::*;
pub(crate) use surface::*;
pub(crate) use texture::*;
6 changes: 3 additions & 3 deletions crates/hyper_rhi/src/d3d12/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use windows::Win32::{
use crate::{
d3d12::{GraphicsDevice, Texture},
render_pass::RenderPassDescriptor,
render_pipeline::RenderPipeline,
graphics_pipeline::GraphicsPipeline,
};

pub(crate) struct RenderPass {
Expand All @@ -53,8 +53,8 @@ impl RenderPass {
}
}

pub(crate) fn bind_pipeline(&self, pipeline: &RenderPipeline) {
let pipeline = pipeline.d3d12_render_pipeline().unwrap();
pub(crate) fn bind_pipeline(&self, pipeline: &GraphicsPipeline) {
let pipeline = pipeline.d3d12_graphics_pipeline().unwrap();

let width = self.texture.width();
let height = self.texture.height();
Expand Down
11 changes: 7 additions & 4 deletions crates/hyper_rhi/src/graphics_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hyper_platform::window::Window;
use crate::d3d12;
use crate::{
command_list::CommandList,
render_pipeline::{RenderPipeline, RenderPipelineDescriptor},
graphics_pipeline::{GraphicsPipeline, GraphicsPipelineDescriptor},
shader_module::{ShaderModule, ShaderModuleDescriptor, ShaderModuleError},
surface::{Surface, SurfaceDescriptor},
texture::{Texture, TextureDescriptor},
Expand Down Expand Up @@ -77,14 +77,17 @@ impl GraphicsDevice {
}
}

pub fn create_render_pipeline(&self, descriptor: &RenderPipelineDescriptor) -> RenderPipeline {
pub fn create_graphics_pipeline(
&self,
descriptor: &GraphicsPipelineDescriptor,
) -> GraphicsPipeline {
match &self.inner {
#[cfg(target_os = "windows")]
GraphicsDeviceInner::D3D12(inner) => {
RenderPipeline::new_d3d12(inner.create_render_pipeline(descriptor))
GraphicsPipeline::new_d3d12(inner.create_graphics_pipeline(descriptor))
}
GraphicsDeviceInner::Vulkan(inner) => {
RenderPipeline::new_vulkan(inner.create_render_pipeline(descriptor))
GraphicsPipeline::new_vulkan(inner.create_graphics_pipeline(descriptor))
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions crates/hyper_rhi/src/graphics_pipeline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2024, SkillerRaptor
*
* SPDX-License-Identifier: MIT
*/

#[cfg(target_os = "windows")]
use crate::d3d12;
use crate::{shader_module::ShaderModule, vulkan};

#[derive(Clone)]
pub struct GraphicsPipelineDescriptor<'a> {
pub vertex_shader: &'a ShaderModule,
pub pixel_shader: &'a ShaderModule,
}

enum GraphicsPipelineInner {
#[cfg(target_os = "windows")]
D3D12(d3d12::GraphicsPipeline),
Vulkan(vulkan::GraphicsPipeline),
}

pub struct GraphicsPipeline {
inner: GraphicsPipelineInner,
}

impl GraphicsPipeline {
#[cfg(target_os = "windows")]
pub(crate) fn new_d3d12(graphics_pipeline: d3d12::GraphicsPipeline) -> Self {
Self {
inner: GraphicsPipelineInner::D3D12(graphics_pipeline),
}
}

pub(crate) fn new_vulkan(graphics_pipeline: vulkan::GraphicsPipeline) -> Self {
Self {
inner: GraphicsPipelineInner::Vulkan(graphics_pipeline),
}
}

#[cfg(target_os = "windows")]
pub(crate) fn d3d12_graphics_pipeline(&self) -> Option<&d3d12::GraphicsPipeline> {
match &self.inner {
#[cfg(target_os = "windows")]
GraphicsPipelineInner::D3D12(inner) => Some(inner),
GraphicsPipelineInner::Vulkan(_) => None,
}
}

pub(crate) fn vulkan_graphics_pipeline(&self) -> Option<&vulkan::GraphicsPipeline> {
match &self.inner {
#[cfg(target_os = "windows")]
GraphicsPipelineInner::D3D12(_) => None,
GraphicsPipelineInner::Vulkan(inner) => Some(inner),
}
}
}
2 changes: 1 addition & 1 deletion crates/hyper_rhi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

pub mod command_list;
pub mod graphics_device;
pub mod graphics_pipeline;
pub mod render_pass;
pub mod render_pipeline;
pub mod shader_module;
pub mod surface;
pub mod texture;
Expand Down
4 changes: 2 additions & 2 deletions crates/hyper_rhi/src/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::Debug;

#[cfg(target_os = "windows")]
use crate::d3d12;
use crate::{render_pipeline::RenderPipeline, texture::Texture, vulkan};
use crate::{graphics_pipeline::GraphicsPipeline, texture::Texture, vulkan};

#[derive(Clone)]
pub struct RenderPassDescriptor<'a> {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl RenderPass {
}
}

pub fn bind_pipeline(&self, pipeline: &RenderPipeline) {
pub fn bind_pipeline(&self, pipeline: &GraphicsPipeline) {
match &self.inner {
#[cfg(target_os = "windows")]
RenderPassInner::D3D12(inner) => inner.bind_pipeline(pipeline),
Expand Down
57 changes: 0 additions & 57 deletions crates/hyper_rhi/src/render_pipeline.rs

This file was deleted.

12 changes: 6 additions & 6 deletions crates/hyper_rhi/src/vulkan/graphics_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use raw_window_handle::{DisplayHandle, HasDisplayHandle};
use crate::{
bindings::BindingsOffset,
graphics_device::GraphicsDeviceDescriptor,
render_pipeline::RenderPipelineDescriptor,
graphics_pipeline::GraphicsPipelineDescriptor,
shader_module::ShaderModuleDescriptor,
surface::SurfaceDescriptor,
texture::TextureDescriptor,
vulkan::{CommandList, RenderPipeline, ShaderModule, ShaderModuleError, Surface, Texture},
vulkan::{CommandList, GraphicsPipeline, ShaderModule, ShaderModuleError, Surface, Texture},
};

pub(crate) struct FrameData {
Expand Down Expand Up @@ -716,11 +716,11 @@ impl GraphicsDevice {
Surface::new(self, descriptor)
}

pub(crate) fn create_render_pipeline(
pub(crate) fn create_graphics_pipeline(
&self,
descriptor: &RenderPipelineDescriptor,
) -> RenderPipeline {
RenderPipeline::new(self, descriptor)
descriptor: &GraphicsPipelineDescriptor,
) -> GraphicsPipeline {
GraphicsPipeline::new(self, descriptor)
}

pub(crate) fn create_shader_module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ use std::ffi::CString;

use ash::vk;

use crate::{render_pipeline::RenderPipelineDescriptor, vulkan::GraphicsDevice};
use crate::{graphics_pipeline::GraphicsPipelineDescriptor, vulkan::GraphicsDevice};

pub(crate) struct RenderPipeline {
pub(crate) struct GraphicsPipeline {
pipeline: vk::Pipeline,

graphics_device: GraphicsDevice,
}

impl RenderPipeline {
impl GraphicsPipeline {
pub(crate) fn new(
graphics_device: &GraphicsDevice,
descriptor: &RenderPipelineDescriptor,
descriptor: &GraphicsPipelineDescriptor,
) -> Self {
let vertex_shader = descriptor.vertex_shader.vulkan_shader_module().unwrap();
let vertex_shader_entry =
Expand Down Expand Up @@ -139,7 +139,7 @@ impl RenderPipeline {
graphics_device
.device()
.create_graphics_pipelines(vk::PipelineCache::null(), &[create_info], None)
.expect("failed to create render pipeline")[0]
.expect("failed to create graphics pipeline")[0]
};

Self {
Expand All @@ -154,7 +154,7 @@ impl RenderPipeline {
}
}

impl Drop for RenderPipeline {
impl Drop for GraphicsPipeline {
fn drop(&mut self) {
unsafe {
self.graphics_device
Expand Down
Loading

0 comments on commit fb6ad4e

Please sign in to comment.