载入中...
搜索中...
未找到
PointGraphScript.cpp
浏览该文件的文档.
2
3#include "common/Assert.h"
9
10#include <simplesquirrel/simplesquirrel.hpp>
11#include <squirrel.h>
12
13#include <functional>
14
15namespace eve::procgen {
16namespace {
17
18SQInteger sqPointGraphConnect(HSQUIRRELVM vm) {
19 const SQInteger n = sq_gettop(vm);
20 if (n < 3 || n > 4) return sq_throwerror(vm, "PointGraph.connect expects (from, to [, inputIndex=0])");
21 PointGraph* self = nullptr;
22 if (SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*>(&self), nullptr)) || !self)
23 return sq_throwerror(vm, "invalid PointGraph");
24 const SQChar* from = nullptr;
25 const SQChar* to = nullptr;
26 SQInteger inputIndex = 0;
27 if (SQ_FAILED(sq_getstring(vm, 2, &from)) || SQ_FAILED(sq_getstring(vm, 3, &to)))
28 return sq_throwerror(vm, "PointGraph.connect expects string node ids");
29 if (n >= 4 && SQ_FAILED(sq_getinteger(vm, 4, &inputIndex)))
30 return sq_throwerror(vm, "PointGraph.connect inputIndex must be an integer");
31 sq_pushbool(vm, self->connect(from ? from : "", to ? to : "", static_cast<int>(inputIndex)) ? SQTrue : SQFalse);
32 return 1;
33}
34
35SQInteger sqPointGraphDisconnect(HSQUIRRELVM vm) {
36 const SQInteger n = sq_gettop(vm);
37 if (n < 2 || n > 3) return sq_throwerror(vm, "PointGraph.disconnect expects (to [, inputIndex=0])");
38 PointGraph* self = nullptr;
39 if (SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*>(&self), nullptr)) || !self)
40 return sq_throwerror(vm, "invalid PointGraph");
41 const SQChar* to = nullptr;
42 SQInteger inputIndex = 0;
43 if (SQ_FAILED(sq_getstring(vm, 2, &to))) return sq_throwerror(vm, "PointGraph.disconnect expects a string node id");
44 if (n >= 3 && SQ_FAILED(sq_getinteger(vm, 3, &inputIndex)))
45 return sq_throwerror(vm, "PointGraph.disconnect inputIndex must be an integer");
46 sq_pushbool(vm, self->disconnect(to ? to : "", static_cast<int>(inputIndex)) ? SQTrue : SQFalse);
47 return 1;
48}
49
50void addOptionalTrailingInt(ssq::Class& cls, const char* name, SQFUNCTION func, SQInteger minParams,
51 const SQChar* typemask) {
52 HSQUIRRELVM vm = cls.getHandle();
53 sq_pushobject(vm, cls.getRaw());
54 sq_pushstring(vm, name, -1);
55 sq_newclosure(vm, func, 0);
56 sq_setparamscheck(vm, -minParams, typemask);
57 sq_newslot(vm, -3, SQFalse);
58 sq_poptop(vm);
59}
60
61} // namespace
62
63void exposePointGraph(ssq::Table& table) {
64 auto graph = table.addClass<PointGraph>(
65 "ProcgenPointGraph", std::function<PointGraph*()>([]() -> PointGraph* { return nullptr; }),
66 true);
67 graph.addFunc("addNode", &PointGraph::addNode);
68 graph.addFunc("removeNode", &PointGraph::removeNode);
69 graph.addFunc("hasNode", &PointGraph::hasNode);
70 graph.addFunc("getNodeCount", &PointGraph::getNodeCount);
71 graph.addFunc("getNodeId", &PointGraph::getNodeId);
72 graph.addFunc("getNodeOperation", &PointGraph::getNodeOperation);
73 addOptionalTrailingInt(graph, "connect", sqPointGraphConnect, 3, _SC("xssi"));
74 addOptionalTrailingInt(graph, "disconnect", sqPointGraphDisconnect, 2, _SC("xsi"));
75 graph.addFunc("getInputNode", &PointGraph::getInputNode);
76 graph.addFunc("setNodePoints", &PointGraph::setNodePoints);
77 graph.addFunc("setNodeSpatial", &PointGraph::setNodeSpatial);
78 graph.addFunc("setNodeBiomeRules", &PointGraph::setNodeBiomeRules);
79 graph.addFunc("setNodeShapeGrammar", &PointGraph::setNodeShapeGrammar);
80 graph.addFunc("setNodeFloat", &PointGraph::setNodeFloat);
81 graph.addFunc("setNodeInt", &PointGraph::setNodeInt);
82 graph.addFunc("setNodeString", &PointGraph::setNodeString);
83 graph.addFunc("exposeParameter", &PointGraph::exposeParameter);
84 graph.addFunc("getParameterCount", &PointGraph::getParameterCount);
85 graph.addFunc("getParameterName", &PointGraph::getParameterName);
86 graph.addFunc("getParameterKind", &PointGraph::getParameterKind);
87 graph.addFunc("hasParameterOverride", &PointGraph::hasParameterOverride);
88 graph.addFunc("setParameterFloat", &PointGraph::setParameterFloat);
89 graph.addFunc("setParameterInt", &PointGraph::setParameterInt);
90 graph.addFunc("setParameterString", &PointGraph::setParameterString);
91 graph.addFunc("getParameterFloat", &PointGraph::getParameterFloat);
92 graph.addFunc("getParameterInt", &PointGraph::getParameterInt);
93 graph.addFunc("getParameterString", &PointGraph::getParameterString);
94 graph.addFunc("clearParameterOverride", &PointGraph::clearParameterOverride);
95 graph.addFunc("setNodeSubgraph", &PointGraph::setNodeSubgraph);
96 graph.addFunc("execute", &PointGraph::execute);
97 graph.addFunc("executeResult", [vm = graph.getHandle()](PointGraph* self, const std::string& output) {
98 auto result = self->executeResult(output);
99 if (!result.ok()) return eve::script::projectStatusResult(vm, result.status());
100 auto* module = liveProcgen();
101 if (!module)
102 return eve::script::projectStatusResult(
103 vm, Status::failure(Diagnostic::error(DiagnosticCode::StaleHandle, "Procgen module is no longer loaded",
104 "executeResult")));
105 auto reference = module->newPointSetHandle();
106 if (!reference.ok()) return eve::script::projectStatusResult(vm, reference.status());
107 // The module registry owns the complete snapshot, including point attributes.
108 // Use the same handle-backed proxy as sampling and checked publication.
109 auto snapshot = module->resolvePointSet(reference.value());
110 EV_ASSERT(snapshot.isBound(), "new PointSet handle must resolve on the owning script thread");
111 *snapshot = std::move(result).takeValue();
112 return makeOwnedPointSetProxy(vm, std::move(reference));
113 });
114 graph.addFunc("validateResult", [vm = graph.getHandle()](PointGraph* self) {
115 return eve::script::projectResult(vm, self->validateResult());
116 });
117 graph.addFunc("setExecutionNodeBudget", &PointGraph::setExecutionNodeBudget);
118 graph.addFunc("getExecutionNodeBudget", &PointGraph::getExecutionNodeBudget);
119 graph.addFunc("setMaxNodeOutputPoints", &PointGraph::setMaxNodeOutputPoints);
120 graph.addFunc("getMaxNodeOutputPoints", &PointGraph::getMaxNodeOutputPoints);
121 graph.addFunc("setComputePolicy", &PointGraph::setComputePolicy);
122 graph.addFunc("getComputePolicy", &PointGraph::getComputePolicy);
123 graph.addFunc("setComputeMinimumPoints", &PointGraph::setComputeMinimumPoints);
124 graph.addFunc("getComputeMinimumPoints", &PointGraph::getComputeMinimumPoints);
125 graph.addFunc("requestCancel", &PointGraph::requestCancel);
126 graph.addFunc("resetCancellation", &PointGraph::resetCancellation);
127 graph.addFunc("wasCancelled", &PointGraph::wasCancelled);
128 graph.addFunc("validate", &PointGraph::validate);
129 graph.addFunc("getError", &PointGraph::getError);
130 graph.addFunc("clearCache", &PointGraph::clearCache);
131 graph.addFunc("getRevision", &PointGraph::getRevision);
132 graph.addFunc("getExecutionCount", &PointGraph::getExecutionCount);
133 graph.addFunc("getCacheHitCount", &PointGraph::getCacheHitCount);
134 graph.addFunc("getCompiledSegmentCount", &PointGraph::getCompiledSegmentCount);
135 graph.addFunc("getExecutionPlanBuildCount", &PointGraph::getExecutionPlanBuildCount);
136 graph.addFunc("getMetricCount", &PointGraph::getMetricCount);
137 graph.addFunc("getMetricNodeId", &PointGraph::getMetricNodeId);
138 graph.addFunc("getMetricOutputCount", &PointGraph::getMetricOutputCount);
139 graph.addFunc("getMetricMilliseconds", &PointGraph::getMetricMilliseconds);
140 graph.addFunc("isMetricCacheHit", &PointGraph::isMetricCacheHit);
141 graph.addFunc("getMetricBackend", &PointGraph::getMetricBackend);
142 graph.addFunc("getComputeFallbackReason", &PointGraph::getComputeFallbackReason);
143 graph.addFunc("getComputeUploadCount", &PointGraph::getComputeUploadCount);
144 graph.addFunc("getComputeDispatchCount", &PointGraph::getComputeDispatchCount);
145 graph.addFunc("getComputeReadbackCount", &PointGraph::getComputeReadbackCount);
146 graph.addFunc("getComputeBufferReuseCount", &PointGraph::getComputeBufferReuseCount);
147 graph.addFunc("getComputePeakBufferBytes", &PointGraph::getComputePeakBufferBytes);
148 graph.addFunc("getLastFusedTransformCount", &PointGraph::getLastFusedTransformCount);
149 graph.addFunc("getMetricMinX", &PointGraph::getMetricMinX);
150 graph.addFunc("getMetricMinY", &PointGraph::getMetricMinY);
151 graph.addFunc("getMetricMinZ", &PointGraph::getMetricMinZ);
152 graph.addFunc("getMetricMaxX", &PointGraph::getMetricMaxX);
153 graph.addFunc("getMetricMaxY", &PointGraph::getMetricMaxY);
154 graph.addFunc("getMetricMaxZ", &PointGraph::getMetricMaxZ);
155 graph.addFunc("getMetricAverageDensity", &PointGraph::getMetricAverageDensity);
156 graph.addFunc("getNodeOutput", &PointGraph::getNodeOutput);
157 graph.addFunc("debugReport", &PointGraph::debugReport);
158 graph.addFunc("serializeDefinition", &PointGraph::serializeDefinition);
159 graph.addFunc("deserializeDefinition", &PointGraph::deserializeDefinition);
160 graph.addFunc("instantiate", &PointGraph::instantiate);
161 graph.addFunc("getOperationCount", [](PointGraph*) { return PointGraph::getOperationCount(); });
162 graph.addFunc("getOperationId",
163 [](PointGraph*, int index) { return PointGraph::getOperationId(index); });
164 graph.addFunc("getOperationInputCount", [](PointGraph*, const std::string& operation) {
166 });
167 graph.addFunc("getOperationParamCount", [](PointGraph*, const std::string& operation) {
169 });
170 graph.addFunc("getOperationParamKey",
171 [](PointGraph*, const std::string& operation, int index) {
173 });
174 graph.addFunc("getOperationParamKind",
175 [](PointGraph*, const std::string& operation, int index) {
177 });
178 graph.addFunc("getOperationParamDefault",
179 [](PointGraph*, const std::string& operation, int index) {
181 });
182}
183
184} // namespace eve::procgen
ActionParameterOperation operation
EVEngine assertion entry point, backed by zeroerr.
std::string output
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
glm::vec3 n
Definition Grass.cpp:63
std::string to
std::string from
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:173
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
uint32_t index
EVENGINE_API_DOMAINS public API.
Definition PointGraph.h:67
void resetCancellation()
Resets cancellation.
uint64_t getComputePeakBufferBytes() const
Return peak bytes reserved in each reusable point-compute buffer.
static std::string getOperationParamDefault(const std::string &operation, int index)
Returns the operation param default.
bool setParameterFloat(const std::string &name, float value)
Override an exposed floating-point parameter for this graph instance.
float getMetricMinZ(int index) const
Return the cached minimum output Z coordinate.
uint64_t getComputeBufferReuseCount() const
Return executions that reused allocated point-compute buffers.
bool setNodeFloat(const std::string &id, const std::string &key, float value)
Sets the node float.
bool removeNode(const std::string &id)
Remove a node and every edge that references it.
void setExecutionNodeBudget(int nodes)
Limit uncached nodes evaluated by one execute call; zero disables the limit.
PointGraph * instantiate() const
Create an independent runtime instance without external inputs or overrides.
bool exposeParameter(const std::string &name, const std::string &nodeId, const std::string &key)
Expose one reflected node parameter for per-instance overrides.
float getMetricMilliseconds(int index) const
Returns the metric milliseconds.
void clearCache()
Clears cache.
static int getOperationCount()
Returns the operation count.
bool setNodeString(const std::string &id, const std::string &key, const std::string &value)
Sets the node string.
bool wasCancelled() const
Was cancelled.
float getMetricMaxX(int index) const
Return the cached maximum output X coordinate.
int getMetricCount() const
Returns the metric count.
std::string getInputNode(const std::string &nodeId, int inputIndex) const
Returns the input node.
std::string getNodeOperation(const std::string &id) const
Returns the node operation.
std::string serializeDefinition() const
Serialize graph topology, parameters and nested graphs.
uint64_t getRevision() const
Monotonic topology/parameter revision used by asset and preview caches.
std::string getComputeFallbackReason() const
Return why the latest eligible GPU node used the CPU fallback.
int getComputeMinimumPoints() const
Return the minimum point count for automatic GPU dispatch.
PointSet * getNodeOutput(const std::string &id) const
Copy the cached/debug output of a node after execution.
uint64_t getComputeReadbackCount() const
Return successful point-compute readbacks for this graph executor.
void requestCancel()
Cancel subsequent execution until resetCancellation is called.
int getExecutionCount() const
Returns the execution count.
uint64_t getExecutionPlanBuildCount() const
Return how many execution plans this graph instance has compiled.
int getNodeCount() const
Returns the node count.
bool setComputePolicy(const std::string &policy)
Select auto, gpu, or cpu point execution; GPU failures fall back to CPU.
PointSet * execute(const std::string &outputId)
Compatibility-only projection of executeResult; caller deletes the result, nullptr means failure.
int getLastFusedTransformCount() const
Return logical transforms in the latest successful fused dispatch.
bool isMetricCacheHit(int index) const
True when metric cache hit.
std::string getComputePolicy() const
Return the configured point compute policy.
bool validate()
Compatibility-only bool projection of validateResult; diagnostics are rendered by getError().
static int getOperationParamCount(const std::string &operation)
Returns the operation param count.
int getMaxNodeOutputPoints() const
Return the per-node point output limit; zero means unlimited.
bool deserializeDefinition(const std::string &definition)
Transactionally replace this graph from serializeDefinition output.
static std::string getOperationId(int index)
Returns the operation id.
int getExecutionNodeBudget() const
Returns the execution node budget.
std::string getMetricBackend(int index) const
Return cpu, vulkan, or webgpu for one evaluated node.
float getMetricAverageDensity(int index) const
Return the mean point density of one node output.
bool setNodeSubgraph(const std::string &id, PointGraph *graph, const std::string &inputNode, const std::string &outputNode)
Assign an immutable nested graph.
void setMaxNodeOutputPoints(int points)
Limit points produced by any node; zero disables the limit.
int getParameterCount() const
Return the number of exposed graph parameters.
int getCompiledSegmentCount() const
Return logical CPU/GPU segments in the execution plan compiled for the latest output.
float getMetricMinY(int index) const
Return the cached minimum output Y coordinate.
bool setNodeSpatial(const std::string &id, SpatialData *spatial)
Assign copied spatial data to a spatial sample, filter, projection, or biome node.
float getMetricMaxY(int index) const
Return the cached maximum output Y coordinate.
uint64_t getComputeUploadCount() const
Return successful point-compute uploads for this graph executor.
bool clearParameterOverride(const std::string &name)
Remove an instance override and restore the asset default.
static std::string getOperationParamKind(const std::string &operation, int index)
Returns the operation param kind.
float getParameterFloat(const std::string &name, float fallback) const
Return the effective floating-point parameter value.
std::string getParameterName(int index) const
Return an exposed parameter name by stable insertion index.
std::string getError() const
Render the last compatibility execute/validate or legacy authoring error; canonical Result calls do n...
int getCacheHitCount() const
Returns the cache hit count.
std::string getParameterKind(const std::string &name) const
Return the reflected kind of an exposed parameter.
bool hasParameterOverride(const std::string &name) const
Report whether an instance override is active.
bool setNodeInt(const std::string &id, const std::string &key, int value)
Sets the node int.
float getMetricMaxZ(int index) const
Return the cached maximum output Z coordinate.
std::string getMetricNodeId(int index) const
Returns the metric node id.
std::string getNodeId(int index) const
Returns the node id.
float getMetricMinX(int index) const
Return cached output bounds for editor/debug visualization.
bool setNodeShapeGrammar(const std::string &id, ShapeGrammar *grammar)
Assign a copied shape grammar to a grammar.generate node.
bool setNodePoints(const std::string &id, PointSet *points)
Assign a copied PointSet to an input node.
std::string getParameterString(const std::string &name, const std::string &fallback) const
Return the effective string parameter value.
uint64_t getComputeDispatchCount() const
Return successful point-compute dispatches for this graph executor.
bool setParameterString(const std::string &name, const std::string &value)
Override an exposed string parameter for this graph instance.
int getParameterInt(const std::string &name, int fallback) const
Return the effective integer or Boolean parameter value.
static std::string getOperationParamKey(const std::string &operation, int index)
Returns the operation param key.
bool hasNode(const std::string &id) const
True when node.
int getMetricOutputCount(int index) const
Returns the metric output count.
bool setParameterInt(const std::string &name, int value)
Override an exposed integer or Boolean parameter for this graph instance.
bool addNode(const std::string &id, const std::string &operation)
Add a node using one of the operations returned by operationAt().
bool setNodeBiomeRules(const std::string &id, BiomeRules *rules)
Assign copied biome rules to a biome.generate node.
std::string debugReport() const
Debug report.
void setComputeMinimumPoints(int points)
Set the minimum point count for auto GPU dispatch.
static int getOperationInputCount(const std::string &operation)
Returns the operation input count.
void exposePointGraph(ssq::Table &table)
Register PointGraph script types on the Procgen module table.