Skip to content

Commit

Permalink
Fix the corruption in The Talos Principle2.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaojbao committed May 20, 2024
1 parent 8252cfa commit 0e7e05f
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 402 deletions.
25 changes: 0 additions & 25 deletions lgc/builder/InOutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,31 +513,6 @@ void BuilderImpl::markGenericInputOutputUsage(bool isOutput, unsigned location,
// Mark usage for interpolation info.
markInterpolationInfo(inOutInfo);
}

if (isOutput && m_shaderStage == ShaderStage::Mesh) {
// Record number of components for mesh shader outputs
for (unsigned i = 0; i < locationCount; ++i) {
unsigned numComponents = 0;
if (inOutInfo.getNumComponents() > 4) {
assert(locationCount % 2 == 0); // Must have even number of locations for 64-bit data type
assert(inOutInfo.getComponent() == 0); // Start component must be 0 in this case
// NOTE: For 64-bit vec3/vec4 data types, they will occupy two consecutive locations, we only record the number
// of components to the former one and skip the latter one.
if (i % 2 != 0)
continue;
numComponents = inOutInfo.getNumComponents();
} else {
numComponents = inOutInfo.getComponent() + inOutInfo.getNumComponents();
}

if (inOutInfo.isPerPrimitive())
resUsage->inOutUsage.mesh.primitiveOutputComponents[location + i] = {numComponents,
static_cast<BuiltInKind>(InvalidValue)};
else
resUsage->inOutUsage.mesh.vertexOutputComponents[location + i] = {numComponents,
static_cast<BuiltInKind>(InvalidValue)};
}
}
}

// =====================================================================================================================
Expand Down
7 changes: 3 additions & 4 deletions lgc/include/lgc/state/ResourceUsage.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,9 @@ struct ResourceUsage {
std::map<BuiltInKind, unsigned> vertexBuiltInExportSlots;
std::map<BuiltInKind, unsigned> primitiveBuiltInExportSlots;

// Map from output locations to their number of components: <location, <numComponents, forBuiltIn>> (including
// those special outputs to which built-ins are mapped)
std::map<unsigned, std::pair<unsigned, BuiltInKind>> vertexOutputComponents;
std::map<unsigned, std::pair<unsigned, BuiltInKind>> primitiveOutputComponents;
// Export count for generic outputs (excluding those special outputs to which the built-ins are mapped)
unsigned vertexGenericOutputExportCount = 0;
unsigned primitiveGenericOutputExportCount = 0;
} mesh;

struct {
Expand Down
29 changes: 20 additions & 9 deletions lgc/interface/lgc/LgcDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,30 @@ def GetMeshBuiltinInputOp : LgcOp<"get.mesh.builtin.input", [Memory<[]>, WillRet
}];
}

def WriteMeshOutputOp : LgcOp<"write.mesh.output", [Memory<[]>]> {
let arguments = (ins AttrI1:$is_primitive, AttrI32:$location, I32:$location_offset, I32:$component_index, I32:$prim_or_vertex_index, value:$output_value);
def WriteMeshVertexOutputOp : LgcOp<"write.mesh.vertex.output", [Memory<[]>]> {
let arguments = (ins I32:$output_offset, I32:$vertex_index, value:$output_value);
let results = (outs);

let summary = "Write mesh shader primitive/vertex outputs";
let summary = "Write mesh shader vertex outputs";
let description = [{
In the mesh shader, write mesh shader primitive/vertex outputs to LDS.
In the mesh shader, write mesh shader vertex outputs to LDS.

`is_primitive` indicates if this write is for a primitive output or for a vertex output.
`location` is the start location of this output.
`location_offset` is the relative location offset of this output, used by arrayed outputs.
`component_index` is the component index of this output when component addressing is involved.
`prim_or_vertex_index` is the primitive/vertex index specifying which primitive/vertex to write.
`output_offset` is the relative offset of this output (in dwords) within all outputs of the indexed vertex.
`vertex_index` is the vertex index specifying which vertex to write.
`output_value` is the output value to write.
}];
}

def WriteMeshPrimitiveOutputOp : LgcOp<"write.mesh.primitive.output", [Memory<[]>]> {
let arguments = (ins I32:$output_offset, I32:$primitive_index, value:$output_value);
let results = (outs);

let summary = "Write mesh shader primitive outputs";
let description = [{
In the mesh shader, write mesh shader primitive outputs to LDS.

`output_offset` is the relative offset of this output (in dwords) within all outputs of the indexed primitive.
`primitive_index` is the primitive index specifying which primitive to write.
`output_value` is the output value to write.
}];
}
Expand Down
Loading

0 comments on commit 0e7e05f

Please sign in to comment.