[Flint] adding gen9 eu encoding
This commit is contained in:
+91
-44
@@ -7,6 +7,11 @@ const common_kmd = @import("../kmd.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
|
||||
const RelocationGroup = struct {
|
||||
source_handle: u32,
|
||||
entries: std.ArrayList(_i915.RelocationEntry) = .empty,
|
||||
};
|
||||
|
||||
const Mapping = struct {
|
||||
bytes: []align(std.heap.page_size_min) u8,
|
||||
|
||||
@@ -54,8 +59,19 @@ pub const Device = struct {
|
||||
return memory;
|
||||
}
|
||||
|
||||
pub fn submitBatch(self: *Device, io: std.Io, allocator: std.mem.Allocator, commands: []const u32, relocations: []const common_kmd.Relocation, syncs: []const common_kmd.SyncDependency) VkError!void {
|
||||
const trailer_words = 6;
|
||||
pub fn submitBatch(
|
||||
self: *Device,
|
||||
io: std.Io,
|
||||
allocator: std.mem.Allocator,
|
||||
engine: common_kmd.Engine,
|
||||
commands: []const u32,
|
||||
relocations: []const common_kmd.Relocation,
|
||||
syncs: []const common_kmd.SyncDependency,
|
||||
) VkError!void {
|
||||
const trailer_words: usize = switch (engine) {
|
||||
.blitter => 6,
|
||||
.render => if (commands.len % 2 == 0) 2 else 1,
|
||||
};
|
||||
const batch_size = (commands.len + trailer_words) * @sizeOf(u32);
|
||||
var batch = try self.allocateMemory(io, batch_size);
|
||||
defer batch.deinit(self, io);
|
||||
@@ -64,65 +80,93 @@ pub const Device = struct {
|
||||
const batch_map = try batch.map(self, io, 0, batch_size);
|
||||
const batch_words = std.mem.bytesAsSlice(u32, batch_map);
|
||||
@memcpy(batch_words[0..commands.len], commands);
|
||||
batch_words[commands.len + 0] = _i915.mi_flush_dw;
|
||||
batch_words[commands.len + 1] = 0;
|
||||
batch_words[commands.len + 2] = 0;
|
||||
batch_words[commands.len + 3] = 0;
|
||||
batch_words[commands.len + 4] = 0;
|
||||
batch_words[commands.len + 5] = 0x05000000;
|
||||
@memset(batch_words[commands.len..], 0);
|
||||
switch (engine) {
|
||||
.blitter => {
|
||||
batch_words[commands.len] = _i915.mi_flush_dw;
|
||||
batch_words[commands.len + 5] = _i915.mi_batch_buffer_end;
|
||||
},
|
||||
.render => batch_words[commands.len] = _i915.mi_batch_buffer_end,
|
||||
}
|
||||
batch.unmap();
|
||||
}
|
||||
try batch.flushRange(self, io, 0, batch_size);
|
||||
|
||||
var objects = std.ArrayList(_i915.ExecObject2).empty;
|
||||
defer objects.deinit(allocator);
|
||||
|
||||
var object_handles = std.ArrayList(u32).empty;
|
||||
defer object_handles.deinit(allocator);
|
||||
|
||||
for (relocations) |relocation| {
|
||||
if (std.mem.indexOfScalar(u32, object_handles.items, relocation.target_handle) == null) {
|
||||
object_handles.append(allocator, relocation.target_handle) catch return VkError.OutOfHostMemory;
|
||||
objects.append(allocator, .{
|
||||
.handle = relocation.target_handle,
|
||||
.relocation_count = 0,
|
||||
.relocs_ptr = 0,
|
||||
.alignment = 0,
|
||||
.offset = 0,
|
||||
.flags = if (relocation.write) _i915.exec_object_write else 0,
|
||||
.rsvd1 = 0,
|
||||
.rsvd2 = 0,
|
||||
}) catch return VkError.OutOfHostMemory;
|
||||
} else if (relocation.write) {
|
||||
const index = std.mem.indexOfScalar(u32, object_handles.items, relocation.target_handle).?;
|
||||
objects.items[index].flags |= _i915.exec_object_write;
|
||||
if (relocation.source_handle) |source| {
|
||||
if (std.mem.indexOfScalar(u32, object_handles.items, source) == null)
|
||||
object_handles.append(allocator, source) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
if (std.mem.indexOfScalar(u32, object_handles.items, relocation.target_handle) == null)
|
||||
object_handles.append(allocator, relocation.target_handle) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
if (std.mem.indexOfScalar(u32, object_handles.items, batch.handle) == null)
|
||||
object_handles.append(allocator, batch.handle) catch return VkError.OutOfHostMemory;
|
||||
|
||||
var i915_relocations = std.ArrayList(_i915.RelocationEntry).empty;
|
||||
defer i915_relocations.deinit(allocator);
|
||||
|
||||
var groups = std.ArrayList(RelocationGroup).empty;
|
||||
defer {
|
||||
for (groups.items) |*group| group.entries.deinit(allocator);
|
||||
groups.deinit(allocator);
|
||||
}
|
||||
for (relocations) |relocation| {
|
||||
i915_relocations.append(allocator, .{
|
||||
const source = relocation.source_handle orelse batch.handle;
|
||||
var group_index = std.mem.indexOfScalar(u32, object_handles.items, source) orelse return VkError.DeviceLost;
|
||||
for (groups.items, 0..) |group, index| {
|
||||
if (group.source_handle == source) {
|
||||
group_index = index;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
groups.append(allocator, .{ .source_handle = source }) catch return VkError.OutOfHostMemory;
|
||||
group_index = groups.items.len - 1;
|
||||
}
|
||||
|
||||
const domain: u32 = switch (relocation.domain) {
|
||||
.none => 0,
|
||||
.render => _i915.gem_domain_render,
|
||||
.instruction => _i915.gem_domain_instruction,
|
||||
};
|
||||
groups.items[group_index].entries.append(allocator, .{
|
||||
.target_handle = relocation.target_handle,
|
||||
.delta = relocation.delta,
|
||||
.offset = relocation.offset,
|
||||
.presumed_offset = 0,
|
||||
.read_domains = 0,
|
||||
.write_domain = 0,
|
||||
.read_domains = if (relocation.read) domain else 0,
|
||||
.write_domain = if (relocation.write) domain else 0,
|
||||
}) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
objects.append(allocator, .{
|
||||
.handle = batch.handle,
|
||||
.relocation_count = @intCast(i915_relocations.items.len),
|
||||
.relocs_ptr = @intFromPtr(i915_relocations.items.ptr),
|
||||
.alignment = 0,
|
||||
.offset = 0,
|
||||
.flags = 0,
|
||||
.rsvd1 = 0,
|
||||
.rsvd2 = 0,
|
||||
}) catch return VkError.OutOfHostMemory;
|
||||
var objects = std.ArrayList(_i915.ExecObject2).empty;
|
||||
defer objects.deinit(allocator);
|
||||
for (object_handles.items) |handle| {
|
||||
var flags: u64 = 0;
|
||||
for (relocations) |relocation| {
|
||||
if (relocation.target_handle == handle and relocation.write)
|
||||
flags |= _i915.exec_object_write;
|
||||
}
|
||||
|
||||
var relocation_count: u32 = 0;
|
||||
var relocs_ptr: u64 = 0;
|
||||
for (groups.items) |group| {
|
||||
if (group.source_handle == handle) {
|
||||
relocation_count = @intCast(group.entries.items.len);
|
||||
relocs_ptr = @intFromPtr(group.entries.items.ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
objects.append(allocator, .{
|
||||
.handle = handle,
|
||||
.relocation_count = relocation_count,
|
||||
.relocs_ptr = relocs_ptr,
|
||||
.alignment = 0,
|
||||
.offset = 0,
|
||||
.flags = flags,
|
||||
.rsvd1 = 0,
|
||||
.rsvd2 = 0,
|
||||
}) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
var exec_fences = std.ArrayList(_i915.ExecFence).empty;
|
||||
defer exec_fences.deinit(allocator);
|
||||
@@ -142,7 +186,10 @@ pub const Device = struct {
|
||||
.DR4 = 0,
|
||||
.num_cliprects = @intCast(exec_fences.items.len),
|
||||
.cliprects_ptr = if (exec_fences.items.len == 0) 0 else @intFromPtr(exec_fences.items.ptr),
|
||||
.flags = _i915.exec_blt | (if (exec_fences.items.len == 0) 0 else _i915.exec_fence_array),
|
||||
.flags = @as(u64, switch (engine) {
|
||||
.blitter => _i915.exec_blt,
|
||||
.render => _i915.exec_render,
|
||||
}) | (if (exec_fences.items.len == 0) 0 else _i915.exec_fence_array),
|
||||
.rsvd1 = 0,
|
||||
.rsvd2 = 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user