drafting push constants
This commit is contained in:
+6
-14
@@ -75,7 +75,6 @@ input_locations: [lib.SPIRV_MAX_INPUT_LOCATIONS]SpvWord,
|
|||||||
output_locations: [lib.SPIRV_MAX_OUTPUT_LOCATIONS]SpvWord,
|
output_locations: [lib.SPIRV_MAX_OUTPUT_LOCATIONS]SpvWord,
|
||||||
bindings: [lib.SPIRV_MAX_SET][lib.SPIRV_MAX_SET_BINDINGS]SpvWord,
|
bindings: [lib.SPIRV_MAX_SET][lib.SPIRV_MAX_SET_BINDINGS]SpvWord,
|
||||||
builtins: std.EnumMap(spv.SpvBuiltIn, SpvWord),
|
builtins: std.EnumMap(spv.SpvBuiltIn, SpvWord),
|
||||||
push_constants: []Value,
|
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: ModuleOptions) ModuleError!Self {
|
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: ModuleOptions) ModuleError!Self {
|
||||||
var self: Self = std.mem.zeroInit(Self, .{
|
var self: Self = std.mem.zeroInit(Self, .{
|
||||||
@@ -198,12 +197,7 @@ fn findAccessChainToMember(self: *const Self, base_id: SpvWord, member_index: Sp
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn applyInterfaceDecoration(
|
fn applyInterfaceDecoration(self: *Self, storage_class: spv.SpvStorageClass, decoration: Result.Decoration, id: SpvWord) ModuleError!void {
|
||||||
self: *Self,
|
|
||||||
storage_class: spv.SpvStorageClass,
|
|
||||||
decoration: Result.Decoration,
|
|
||||||
id: SpvWord,
|
|
||||||
) ModuleError!void {
|
|
||||||
switch (storage_class) {
|
switch (storage_class) {
|
||||||
.Input => switch (decoration.rtype) {
|
.Input => switch (decoration.rtype) {
|
||||||
.BuiltIn => self.builtins.put(
|
.BuiltIn => self.builtins.put(
|
||||||
@@ -225,12 +219,7 @@ fn applyInterfaceDecoration(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn applyStructMemberInterfaceDecorations(
|
fn applyStructMemberInterfaceDecorations(self: *Self, storage_class: spv.SpvStorageClass, type_word: SpvWord, id: SpvWord) ModuleError!void {
|
||||||
self: *Self,
|
|
||||||
storage_class: spv.SpvStorageClass,
|
|
||||||
type_word: SpvWord,
|
|
||||||
id: SpvWord,
|
|
||||||
) ModuleError!void {
|
|
||||||
switch (storage_class) {
|
switch (storage_class) {
|
||||||
.Input, .Output => {},
|
.Input, .Output => {},
|
||||||
else => return,
|
else => return,
|
||||||
@@ -281,7 +270,10 @@ fn applyDecorations(self: *Self) ModuleError!void {
|
|||||||
try self.applyInterfaceDecoration(v.storage_class, decoration, @intCast(id));
|
try self.applyInterfaceDecoration(v.storage_class, decoration, @intCast(id));
|
||||||
|
|
||||||
switch (v.storage_class) {
|
switch (v.storage_class) {
|
||||||
.StorageBuffer, .Uniform, .UniformConstant => {
|
.StorageBuffer,
|
||||||
|
.Uniform,
|
||||||
|
.UniformConstant,
|
||||||
|
=> {
|
||||||
switch (decoration.rtype) {
|
switch (decoration.rtype) {
|
||||||
.Binding => binding = decoration.literal_1,
|
.Binding => binding = decoration.literal_1,
|
||||||
.DescriptorSet => set = decoration.literal_1,
|
.DescriptorSet => set = decoration.literal_1,
|
||||||
|
|||||||
@@ -240,6 +240,17 @@ fn pass(self: *Self, allocator: std.mem.Allocator, op_set: ?std.EnumSet(spv.SpvO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn populatePushConstants(self: *Self, blob: []const u8) RuntimeError!void {
|
||||||
|
for (self.results) |*result| {
|
||||||
|
if (result.variant == null or std.meta.activeTag(result.variant.?) != .Variable)
|
||||||
|
continue;
|
||||||
|
const variable = &result.variant.?.Variable;
|
||||||
|
if (variable.storage_class != .PushConstant)
|
||||||
|
continue;
|
||||||
|
_ = try variable.value.writeConst(blob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn writeDescriptorSet(self: *const Self, input: []const u8, set: SpvWord, binding: SpvWord, descriptor_index: SpvWord) RuntimeError!void {
|
pub fn writeDescriptorSet(self: *const Self, input: []const u8, set: SpvWord, binding: SpvWord, descriptor_index: SpvWord) RuntimeError!void {
|
||||||
if (set < lib.SPIRV_MAX_SET and binding < lib.SPIRV_MAX_SET_BINDINGS) {
|
if (set < lib.SPIRV_MAX_SET and binding < lib.SPIRV_MAX_SET_BINDINGS) {
|
||||||
const value = &self.results[self.mod.bindings[set][binding]].variant.?.Variable.value;
|
const value = &self.results[self.mod.bindings[set][binding]].variant.?.Variable.value;
|
||||||
|
|||||||
+12
-3
@@ -143,9 +143,13 @@ pub const Value = union(Type) {
|
|||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, results: []const Result, target_type: SpvWord, is_externally_visible: bool) RuntimeError!Self {
|
pub fn init(allocator: std.mem.Allocator, results: []const Result, target_type: SpvWord, is_externally_visible: bool) RuntimeError!Self {
|
||||||
const resolved = results[target_type].resolveTypeWordOrNull() orelse target_type;
|
const resolved = results[target_type].resolveTypeWordOrNull() orelse target_type;
|
||||||
const member_count = results[resolved].getMemberCounts();
|
return initUnresolved(allocator, results, resolved, is_externally_visible);
|
||||||
|
}
|
||||||
|
|
||||||
return switch (results[resolved].variant.?) {
|
pub fn initUnresolved(allocator: std.mem.Allocator, results: []const Result, target_type: SpvWord, is_externally_visible: bool) RuntimeError!Self {
|
||||||
|
const member_count = results[target_type].getMemberCounts();
|
||||||
|
|
||||||
|
return switch (results[target_type].variant.?) {
|
||||||
.Type => |t| switch (t) {
|
.Type => |t| switch (t) {
|
||||||
.Void => .{ .Void = .{} },
|
.Void => .{ .Void = .{} },
|
||||||
.Bool => .{ .Bool = false },
|
.Bool => .{ .Bool = false },
|
||||||
@@ -233,12 +237,17 @@ pub const Value = union(Type) {
|
|||||||
},
|
},
|
||||||
.Image => .{
|
.Image => .{
|
||||||
.Image = .{
|
.Image = .{
|
||||||
.type_word = resolved,
|
.type_word = target_type,
|
||||||
.driver_image = undefined,
|
.driver_image = undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.Sampler => RuntimeError.ToDo,
|
.Sampler => RuntimeError.ToDo,
|
||||||
.SampledImage => RuntimeError.ToDo,
|
.SampledImage => RuntimeError.ToDo,
|
||||||
|
.Pointer => .{
|
||||||
|
.Pointer = .{
|
||||||
|
.ptr = undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
else => RuntimeError.InvalidSpirV,
|
else => RuntimeError.InvalidSpirV,
|
||||||
},
|
},
|
||||||
else => RuntimeError.InvalidSpirV,
|
else => RuntimeError.InvalidSpirV,
|
||||||
|
|||||||
+2
-1
@@ -1197,7 +1197,7 @@ fn setupAccessChain(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runt
|
|||||||
.target = var_type,
|
.target = var_type,
|
||||||
.base = base_id,
|
.base = base_id,
|
||||||
.indexes = indexes,
|
.indexes = indexes,
|
||||||
.value = try Value.init(allocator, rt.results, var_type, false),
|
.value = try Value.initUnresolved(allocator, rt.results, var_type, false),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -3267,6 +3267,7 @@ fn opVariable(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) R
|
|||||||
const externally_visible_data_storages = [_]spv.SpvStorageClass{
|
const externally_visible_data_storages = [_]spv.SpvStorageClass{
|
||||||
.Uniform,
|
.Uniform,
|
||||||
.StorageBuffer,
|
.StorageBuffer,
|
||||||
|
.PushConstant,
|
||||||
};
|
};
|
||||||
|
|
||||||
const is_externally_visible = std.mem.containsAtLeastScalar(spv.SpvStorageClass, &externally_visible_data_storages, 1, storage_class);
|
const is_externally_visible = std.mem.containsAtLeastScalar(spv.SpvStorageClass, &externally_visible_data_storages, 1, storage_class);
|
||||||
|
|||||||
Reference in New Issue
Block a user