Last active
October 19, 2024 03:57
-
-
Save btipling/a9f3f7b8c21692ec787696fae7bd470d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const needle: []const u8 = "layout(bindless_sampler)"; | |
const needle_len: usize = needle.len; | |
pub fn disableBindless( | |
bytes: []u8, | |
locations: []const usize, | |
) ![]u8 { | |
var buf: [50]u8 = undefined; | |
var loc: usize = 0; | |
var i: usize = 0; | |
var line_num: usize = 0; | |
while (i < bytes.len) { | |
if (loc >= locations.len) break; | |
if (bytes[i] != '\n') { | |
i += 1; | |
continue; | |
} | |
line_num += 1; | |
const line_start = i + 1; | |
var j: usize = line_start + 1; | |
while (j < bytes.len) { | |
if (loc >= locations.len) break; | |
if (bytes[j] != '\n') { | |
j += 1; | |
continue; | |
} | |
if (line_num == 1) { | |
// comment out extension header | |
bytes[line_start] = '/'; | |
bytes[line_start + 1] = '/'; | |
} | |
if (line_start + needle_len > bytes.len) break; | |
const line = bytes[line_start..j]; | |
var zeroed = " " ** needle_len; | |
var replacement_buf: [needle_len]u8 = undefined; | |
@memcpy(&replacement_buf, zeroed[0..]); | |
if (line.len < needle_len) break; | |
if (!std.mem.eql(u8, line[0..needle_len], needle)) break; | |
const replacement = try std.fmt.bufPrint( | |
&buf, | |
"layout(binding={d})", | |
.{locations[loc]}, | |
); | |
@memcpy(replacement_buf[0..replacement.len], replacement[0..replacement.len]); | |
@memcpy(bytes[line_start .. line_start + needle_len], replacement_buf[0..]); | |
loc += 1; | |
j += 1; | |
break; | |
} | |
i += 1; | |
} | |
return bytes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.earth_normal_map = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; | |
self.earth_normal_map.?.texture_unit = 2; | |
self.earth_texture = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; | |
self.earth_texture.?.texture_unit = 3; | |
self.earth_height_map = rhi.Texture.init(self.ctx.args.disable_bindless) catch null; | |
self.earth_height_map.?.texture_unit = 16; | |
const disable_bindless = rhi.Texture.disableBindless(self.ctx.args.disable_bindless); | |
const frag_bindings = [_]usize{ 0, 1, 2, 3, 16 }; | |
const vert_bindings = [_]usize{16}; | |
{ | |
var s: rhi.Shader = .{ | |
.program = prog, | |
.instance_data = true, | |
.frag_body = if (!disable_bindless) frag else rhi.Shader.disableBindless( | |
frag, | |
frag_bindings[0..], | |
) catch @panic("bindless"), | |
.bindless_vertex = !disable_bindless, | |
.fragment_shader = .disabled, | |
}; | |
s.attach(self.allocator, rhi.Shader.single_vertex( | |
if (!disable_bindless) vert else rhi.Shader.disableBindless(vert, vert_bindings[0..]) catch @panic("bindless"), | |
)[0..]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment