yes
This commit is contained in:
@@ -4,7 +4,7 @@ const base = @import("base");
|
||||
const zm = base.zm;
|
||||
const spv = @import("spv");
|
||||
|
||||
const VertexInterpolation = @import("rasterizer/common.zig").VertexInterpolation;
|
||||
const VertexInterpolationLocation = @import("rasterizer/common.zig").VertexInterpolationLocation;
|
||||
|
||||
const Renderer = @import("Renderer.zig");
|
||||
const SoftImage = @import("../SoftImage.zig");
|
||||
@@ -18,7 +18,7 @@ pub fn shaderInvocation(
|
||||
draw_call: *Renderer.DrawCall,
|
||||
batch_id: usize,
|
||||
position: zm.F32x4,
|
||||
inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolation,
|
||||
inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolationLocation,
|
||||
) SpvRuntimeError![spv.SPIRV_MAX_OUTPUT_LOCATIONS][@sizeOf(zm.F32x4)]u8 {
|
||||
var fragment_inputs = inputs;
|
||||
errdefer freeOwnedInputs(allocator, fragment_inputs);
|
||||
@@ -45,26 +45,28 @@ pub fn shaderInvocation(
|
||||
const entry = try rt.getEntryPointByName(shader.entry);
|
||||
|
||||
for (0..spv.SPIRV_MAX_OUTPUT_LOCATIONS) |location| {
|
||||
const result_word = rt.getResultByLocation(@intCast(location), .input) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => continue,
|
||||
else => return err,
|
||||
};
|
||||
|
||||
var input = fragment_inputs[location];
|
||||
if (input.blob.len == 0) {
|
||||
const memory_size = try rt.getResultMemorySize(result_word);
|
||||
const zeroes = allocator.alloc(u8, memory_size + INTERFACE_BLOB_PADDING) catch return SpvRuntimeError.OutOfMemory;
|
||||
@memset(zeroes, 0);
|
||||
fragment_inputs[location] = .{
|
||||
.blob = zeroes,
|
||||
.size = memory_size,
|
||||
.free_responsability = true,
|
||||
for (0..4) |component| {
|
||||
const result_word = rt.getResultByLocationComponent(@intCast(location), @intCast(component), .input) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => continue,
|
||||
else => return err,
|
||||
};
|
||||
input = fragment_inputs[location];
|
||||
}
|
||||
|
||||
if (input.blob.len != 0) {
|
||||
try rt.writeInput(input.blob, result_word);
|
||||
var input = fragment_inputs[location][component];
|
||||
if (input.blob.len == 0) {
|
||||
const memory_size = try rt.getResultMemorySize(result_word);
|
||||
const zeroes = allocator.alloc(u8, memory_size + INTERFACE_BLOB_PADDING) catch return SpvRuntimeError.OutOfMemory;
|
||||
@memset(zeroes, 0);
|
||||
fragment_inputs[location][component] = .{
|
||||
.blob = zeroes,
|
||||
.size = memory_size,
|
||||
.free_responsability = true,
|
||||
};
|
||||
input = fragment_inputs[location][component];
|
||||
}
|
||||
|
||||
if (input.blob.len != 0) {
|
||||
try rt.writeInput(input.blob, result_word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +82,29 @@ pub fn shaderInvocation(
|
||||
@memset(std.mem.asBytes(&outputs), 0);
|
||||
|
||||
for (0..spv.SPIRV_MAX_OUTPUT_LOCATIONS) |location| {
|
||||
var has_split_components = false;
|
||||
for (1..4) |component| {
|
||||
_ = rt.getResultByLocationComponent(@intCast(location), @intCast(component), .output) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => continue,
|
||||
else => return err,
|
||||
};
|
||||
has_split_components = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_split_components) {
|
||||
for (0..4) |component| {
|
||||
const result_word = rt.getResultByLocationComponent(@intCast(location), @intCast(component), .output) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => continue,
|
||||
else => return err,
|
||||
};
|
||||
const memory_size = try rt.getResultMemorySize(result_word);
|
||||
const offset = component * @sizeOf(f32);
|
||||
try rt.readOutput(outputs[location][offset .. offset + memory_size], result_word);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const result_word = rt.getResultByLocation(@intCast(location), .output) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => continue,
|
||||
else => return err,
|
||||
@@ -93,9 +118,11 @@ pub fn shaderInvocation(
|
||||
return outputs;
|
||||
}
|
||||
|
||||
fn freeOwnedInputs(allocator: std.mem.Allocator, inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolation) void {
|
||||
for (inputs) |input| {
|
||||
if (input.free_responsability)
|
||||
allocator.free(input.blob);
|
||||
fn freeOwnedInputs(allocator: std.mem.Allocator, inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolationLocation) void {
|
||||
for (inputs) |location| {
|
||||
for (location) |input| {
|
||||
if (input.free_responsability)
|
||||
allocator.free(input.blob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user