Skip to content

Commit

Permalink
Support more ImageBufferKind with gfx
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakor Gyula authored and dati91 committed Oct 25, 2018
1 parent 21d7e6d commit 653f372
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
30 changes: 18 additions & 12 deletions webrender/build_gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ fn process_glsl_for_spirv(file_path: &Path, file_name: &str) -> Option<PipelineR
let mut descriptor_set_layouts: Vec<DescriptorSetLayoutBinding> = Vec::new();
let mut vertex_offset = 0;
let mut instance_offset = 0;
let mut color_texture_kind = "texture2DArray";
// Since the .vert and .frag files for the same shader use the same layout qualifiers
// we extract layout datas from .vert files only.
let write_ron = file_name.ends_with(".vert");
Expand All @@ -191,6 +192,14 @@ fn process_glsl_for_spirv(file_path: &Path, file_name: &str) -> Option<PipelineR
let mut l = line.unwrap();
let trimmed = l.trim_left();

if trimmed.contains("#define WR_FEATURE_TEXTURE_2D") {
color_texture_kind = "texture2D";
}

if trimmed.contains("#define WR_FEATURE_TEXTURE_RECT") {
color_texture_kind = "texture2DRect";
}

// Replace uniforms in shader:
// Sampler uniforms are splitted to texture + sampler.
// Other types occur in a group. These are replaced with a static string for now.
Expand All @@ -205,6 +214,7 @@ fn process_glsl_for_spirv(file_path: &Path, file_name: &str) -> Option<PipelineR
&mut new_data,
&mut sampler_mapping,
write_ron,
color_texture_kind,
);

// Replace non-sampler uniforms with a structure.
Expand Down Expand Up @@ -287,38 +297,30 @@ fn replace_sampler_definition_with_texture_and_sampler(
new_data: &mut String,
sampler_mapping: &mut HashMap<String, (String, i8)>,
write_ron: bool,
color_texture_kind: &str,
) {
// Get the name of the sampler.
let (sampler_name, code) = code.split_last().unwrap();

// Get the exact type of the sampler.
let (sampler_type, code) = code.split_last().unwrap();
let mut sampler_type = String::from(*sampler_type);
let mut code_str = String::new();
for i in 0 .. code.len() {
code_str.push_str(code[i]);
code_str.push(' ');
}

let texture_type = sampler_type.replace("sampler", "texture");
let mut texture_type = sampler_type.replace("sampler", "texture");
let texture_name = sampler_name.replacen('s', "t", 1);

// If the sampler is redefined we use the same binding index, but the sampler type gets updated.
// Note: This should be handled by parsing the defines and use them to determine which definition is correct.
// Since only sColor samplers are involved in this case, the last definition for these samplers
// which uses sampler/texture2DArray is good for us to go with.
// If the sampler is in the map we only update the shader code.
if let Some(&(_, binding)) = sampler_mapping.get(*sampler_name) {
let mut layout_str = format!(
"layout(set = 0, binding = {}) {}{} {};\n",
binding, code_str, texture_type, texture_name
);
new_data.push_str(&layout_str);
sampler_mapping.insert(
String::from(*sampler_name),
(
format!("{}({}, {})", sampler_type, texture_name, sampler_name),
binding,
),
);

layout_str = format!(
"layout(set = 0, binding = {}) {}sampler {};\n",
Expand All @@ -330,6 +332,10 @@ fn replace_sampler_definition_with_texture_and_sampler(

// Replace sampler definition with a texture and a sampler.
} else {
if texture_name.contains("tColor") {
texture_type = String::from(color_texture_kind);
sampler_type = color_texture_kind.replace("texture", "sampler");
}
let mut layout_str = format!(
"layout(set = 0, binding = {}) {}{} {};\n",
binding, code_str, texture_type, texture_name
Expand Down
30 changes: 30 additions & 0 deletions webrender/shaders.ron
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
"",// [0]
"ALPHA_PASS",// [1]
"ALPHA_PASS,DUAL_SOURCE_BLENDING",// [2]
"TEXTURE_2D",// [3]
"TEXTURE_2D,ALPHA_PASS",// [4]
"TEXTURE_2D,ALPHA_PASS,DUAL_SOURCE_BLENDING",// [5]
"TEXTURE_RECT",// [6]
"TEXTURE_RECT,ALPHA_PASS",// [7]
"TEXTURE_RECT,ALPHA_PASS,DUAL_SOURCE_BLENDING",// [8]
],
),// [5]
(
Expand Down Expand Up @@ -78,6 +84,30 @@
"YUV_PLANAR,YUV_REC709,ALPHA_PASS",// [9]
"YUV_INTERLEAVED,YUV_REC601,ALPHA_PASS",// [10]
"YUV_INTERLEAVED,YUV_REC709,ALPHA_PASS",// [11]
"TEXTURE_2D,YUV_NV12,YUV_REC601", // [12]
"TEXTURE_2D,YUV_NV12,YUV_REC709", // [13]
"TEXTURE_2D,YUV_PLANAR,YUV_REC601", // [14]
"TEXTURE_2D,YUV_PLANAR,YUV_REC709", // [15]
"TEXTURE_2D,YUV_INTERLEAVED,YUV_REC601", // [16]
"TEXTURE_2D,YUV_INTERLEAVED,YUV_REC709", // [17]
"TEXTURE_2D,YUV_NV12,YUV_REC601,ALPHA_PASS", // [18]
"TEXTURE_2D,YUV_NV12,YUV_REC709,ALPHA_PASS", // [19]
"TEXTURE_2D,YUV_PLANAR,YUV_REC601,ALPHA_PASS", // [20]
"TEXTURE_2D,YUV_PLANAR,YUV_REC709,ALPHA_PASS", // [21]
"TEXTURE_2D,YUV_INTERLEAVED,YUV_REC601,ALPHA_PASS", // [22]
"TEXTURE_2D,YUV_INTERLEAVED,YUV_REC709,ALPHA_PASS", // [23]
"TEXTURE_RECT,YUV_NV12,YUV_REC601", // [24]
"TEXTURE_RECT,YUV_NV12,YUV_REC709", // [25]
"TEXTURE_RECT,YUV_PLANAR,YUV_REC601", // [26]
"TEXTURE_RECT,YUV_PLANAR,YUV_REC709", // [27]
"TEXTURE_RECT,YUV_INTERLEAVED,YUV_REC601", // [28]
"TEXTURE_RECT,YUV_INTERLEAVED,YUV_REC709", // [29]
"TEXTURE_RECT,YUV_NV12,YUV_REC601,ALPHA_PASS", // [30]
"TEXTURE_RECT,YUV_NV12,YUV_REC709,ALPHA_PASS", // [31]
"TEXTURE_RECT,YUV_PLANAR,YUV_REC601,ALPHA_PASS", // [32]
"TEXTURE_RECT,YUV_PLANAR,YUV_REC709,ALPHA_PASS", // [33]
"TEXTURE_RECT,YUV_INTERLEAVED,YUV_REC601,ALPHA_PASS", // [34]
"TEXTURE_RECT,YUV_INTERLEAVED,YUV_REC709,ALPHA_PASS", // [35]
],
),// [8]
(
Expand Down
4 changes: 3 additions & 1 deletion webrender/src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ impl ImageBufferKind {
#[cfg(not(feature = "gleam"))]
fn has_platform_support(&self) -> bool {
match *self {
ImageBufferKind::Texture2D => true,
ImageBufferKind::Texture2DArray => true,
_ => false,
ImageBufferKind::TextureRect => true,
ImageBufferKind::TextureExternal => false,
}
}
}
Expand Down

0 comments on commit 653f372

Please sign in to comment.