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
winit = {version = "0.24.0", features = ["serde"]}
wgpu = {git="https://github.com/gfx-rs/wgpu-rs.git"}
zerocopy = "0.3.0"
zerocopy = "0.3"
shaderc = "0.6.2"
# Ui
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"
enum-iterator = "0.6"
futures = "0.3"
glsl-include = "0.3.1"
guillotiere = "0.6"
hashbrown = {version = "0.9", features = ["rayon", "serde", "nightly"]}
image = {version = "0.23.12", default-features = false, features = ["ico", "png"]}

View File

@ -7,6 +7,8 @@ pub enum RenderError {
SwapChainError(wgpu::SwapChainError),
CustomError(String),
CouldNotFindAdapter,
ErrorInitializingCompiler,
ShaderError(shaderc::Error)
}
impl From<wgpu::RequestDeviceError> for RenderError {
@ -16,6 +18,11 @@ impl From<wgpu::RequestDeviceError> for RenderError {
impl From<wgpu::BufferAsyncError> for RenderError {
fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
}
impl From<wgpu::SwapChainError> for RenderError {
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.
#[allow(clippy::type_complexity)] // TODO: Pending review in #587
fn create_pipelines(
factory: &mut gfx_backend::Factory,
factory: &wgpu::Device,
shaders: &Shaders,
mode: &RenderMode,
has_shadow_views: bool,
@ -1951,17 +1951,37 @@ fn create_pipelines(
_ => shaders.cloud_regular,
};
let mut include_ctx = IncludeContext::new();
include_ctx.include("constants.glsl", &constants);
include_ctx.include("globals.glsl", &shaders.globals.read().0);
include_ctx.include("shadows.glsl", &shaders.shadows.read().0);
include_ctx.include("sky.glsl", &shaders.sky.read().0);
include_ctx.include("light.glsl", &shaders.light.read().0);
include_ctx.include("srgb.glsl", &shaders.srgb.read().0);
include_ctx.include("random.glsl", &shaders.random.read().0);
include_ctx.include("lod.glsl", &shaders.lod.read().0);
include_ctx.include("anti-aliasing.glsl", &anti_alias.read().0);
include_ctx.include("cloud.glsl", &cloud.read().0);
let mut compiler = shaderc::Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
let mut options = shaderc::CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
options.set_optimization_level(shaderc::OptimizationLevel::Performance);
options.set_include_callback(move |name,_,shader_name,_| {
Ok(shaderc::ResolvedInclude {
resolved_name: name,
content: match name {
"constants.glsl" => constants,
"globals.glsl" => globals,
"shadows.glsl" => shadows,
"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
let skybox_pipeline = create_pipeline(
@ -2165,35 +2185,11 @@ fn create_pipelines(
}
/// Create a new pipeline from the provided vertex shader and fragment shader.
fn create_pipeline<P: gfx::pso::PipelineInit>(
factory: &mut gfx_backend::Factory,
pipe: P,
vs: &str,
fs: &str,
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
fn create_pipeline(
device: &wgpu::Device,
desc: &wgpu::RenderPipelineDescriptor
) -> wgpu::RenderPipeline {
device.create_render_pipeline(desc)
}
/// Create a new shadow map pipeline.