Began porting pipeline creation

This commit is contained in:
Capucho 2020-08-28 12:54:15 +01:00 committed by Avi Weinstock
parent 5d487b2299
commit 574a930864
3 changed files with 46 additions and 43 deletions

View File

@ -43,7 +43,8 @@ anim = {package = "veloren-voxygen-anim", path = "anim"}
# Graphics # Graphics
winit = {version = "0.24.0", features = ["serde"]} winit = {version = "0.24.0", features = ["serde"]}
wgpu = {git="https://github.com/gfx-rs/wgpu-rs.git"} wgpu = {git="https://github.com/gfx-rs/wgpu-rs.git"}
zerocopy = "0.3.0" zerocopy = "0.3"
shaderc = "0.6.2"
# Ui # Ui
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"} conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
@ -81,7 +82,6 @@ directories-next = "2.0"
dot_vox = "4.0" dot_vox = "4.0"
enum-iterator = "0.6" enum-iterator = "0.6"
futures = "0.3" futures = "0.3"
glsl-include = "0.3.1"
guillotiere = "0.6" guillotiere = "0.6"
hashbrown = {version = "0.9", features = ["rayon", "serde", "nightly"]} hashbrown = {version = "0.9", features = ["rayon", "serde", "nightly"]}
image = {version = "0.23.12", default-features = false, features = ["ico", "png"]} image = {version = "0.23.12", default-features = false, features = ["ico", "png"]}

View File

@ -7,6 +7,8 @@ pub enum RenderError {
SwapChainError(wgpu::SwapChainError), SwapChainError(wgpu::SwapChainError),
CustomError(String), CustomError(String),
CouldNotFindAdapter, CouldNotFindAdapter,
ErrorInitializingCompiler,
ShaderError(shaderc::Error)
} }
impl From<wgpu::RequestDeviceError> for RenderError { impl From<wgpu::RequestDeviceError> for RenderError {
@ -16,6 +18,11 @@ impl From<wgpu::RequestDeviceError> for RenderError {
impl From<wgpu::BufferAsyncError> for RenderError { impl From<wgpu::BufferAsyncError> for RenderError {
fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) } fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
} }
impl From<wgpu::SwapChainError> for RenderError { impl From<wgpu::SwapChainError> for RenderError {
fn from(err: wgpu::SwapChainError) -> Self { Self::SwapChainError(err) } fn from(err: wgpu::SwapChainError) -> Self { Self::SwapChainError(err) }
} }
impl From<shaderc::Error> for RenderError {
fn from(err: shaderc::Error) -> Self { Self::ShaderError(err) }
}

View File

@ -1876,7 +1876,7 @@ impl Renderer {
/// Creates all the pipelines used to render. /// Creates all the pipelines used to render.
#[allow(clippy::type_complexity)] // TODO: Pending review in #587 #[allow(clippy::type_complexity)] // TODO: Pending review in #587
fn create_pipelines( fn create_pipelines(
factory: &mut gfx_backend::Factory, factory: &wgpu::Device,
shaders: &Shaders, shaders: &Shaders,
mode: &RenderMode, mode: &RenderMode,
has_shadow_views: bool, has_shadow_views: bool,
@ -1951,17 +1951,37 @@ fn create_pipelines(
_ => shaders.cloud_regular, _ => shaders.cloud_regular,
}; };
let mut include_ctx = IncludeContext::new(); let mut compiler = shaderc::Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
include_ctx.include("constants.glsl", &constants); let mut options = shaderc::CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
include_ctx.include("globals.glsl", &shaders.globals.read().0); options.set_optimization_level(shaderc::OptimizationLevel::Performance);
include_ctx.include("shadows.glsl", &shaders.shadows.read().0); options.set_include_callback(move |name,_,shader_name,_| {
include_ctx.include("sky.glsl", &shaders.sky.read().0); Ok(shaderc::ResolvedInclude {
include_ctx.include("light.glsl", &shaders.light.read().0); resolved_name: name,
include_ctx.include("srgb.glsl", &shaders.srgb.read().0); content: match name {
include_ctx.include("random.glsl", &shaders.random.read().0); "constants.glsl" => constants,
include_ctx.include("lod.glsl", &shaders.lod.read().0); "globals.glsl" => globals,
include_ctx.include("anti-aliasing.glsl", &anti_alias.read().0); "shadows.glsl" => shadows,
include_ctx.include("cloud.glsl", &cloud.read().0); "sky.glsl" => sky,
"light.glsl" => light,
"srgb.glsl" => srgb,
"random.glsl" => &random,
"lod.glsl" => &lod,
"anti-aliasing.glsl" => &anti_alias,
"cloud.glsl" => &cloud,
other => return Err(format!("Include {} is not defined",other))
}
} )
});
let figure_vert = &shaders.figure_vert.read().0;
let terrain_point_shadow_vert = &shaders.terrain_point_shadow_vert.read().0;
let terrain_directed_shadow_vert = &shaders.terrain_directed_shadow_vert.read().0;
let figure_directed_shadow_vert = &shadows.figure_directed_shadow_vert.read().0;
let directed_shadow_frag = &shaders.directed_shadow_frag.read().0;
// Construct a pipeline for rendering skyboxes // Construct a pipeline for rendering skyboxes
let skybox_pipeline = create_pipeline( let skybox_pipeline = create_pipeline(
@ -2165,35 +2185,11 @@ fn create_pipelines(
} }
/// Create a new pipeline from the provided vertex shader and fragment shader. /// Create a new pipeline from the provided vertex shader and fragment shader.
fn create_pipeline<P: gfx::pso::PipelineInit>( fn create_pipeline(
factory: &mut gfx_backend::Factory, device: &wgpu::Device,
pipe: P, desc: &wgpu::RenderPipelineDescriptor
vs: &str, ) -> wgpu::RenderPipeline {
fs: &str, device.create_render_pipeline(desc)
ctx: &IncludeContext,
cull_face: gfx::state::CullFace,
) -> Result<GfxPipeline<P>, RenderError> {
let vs = ctx.expand(vs)?;
let fs = ctx.expand(fs)?;
let program = factory.link_program(vs.as_bytes(), fs.as_bytes())?;
let result = Ok(GfxPipeline {
pso: factory.create_pipeline_from_program(
&program,
gfx::Primitive::TriangleList,
gfx::state::Rasterizer {
front_face: gfx::state::FrontFace::CounterClockwise,
cull_face,
method: gfx::state::RasterMethod::Fill,
offset: None,
samples: Some(gfx::state::MultiSample),
},
pipe,
)?,
});
result
} }
/// Create a new shadow map pipeline. /// Create a new shadow map pipeline.