Skip to content

Commit

Permalink
fix compiling error
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed Sep 21, 2023
1 parent fca089c commit 9c8bf6d
Show file tree
Hide file tree
Showing 6 changed files with 3,043 additions and 5,310 deletions.
27 changes: 19 additions & 8 deletions native/cocos/bindings/jswrapper/napi/ScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ using HandleScope = napi_handle_scope;
namespace se {
class AutoHandleScope {
public:
// This interface needs to be implemented in NAPI, similar to V8.
// This interface needs to be implemented in NAPI, similar to V8.
// Ref:https://nodejs.org/docs/latest-v17.x/api/n-api.html#object-lifetime-management
AutoHandleScope();
~AutoHandleScope();

private:
HandleScope _handleScope;
};
using RegisterCallback = bool (*)(Object *);
using RegisterCallback = bool (*)(Object *);
using ExceptionCallback = std::function<void(const char *, const char *, const char *)>; // location, message, stack

class ScriptEngine {
Expand Down Expand Up @@ -197,7 +197,7 @@ class ScriptEngine {
Object *getGlobalObject() const;

static napi_env getEnv();
static void setEnv(napi_env env);
static void setEnv(napi_env env);

/**
* @brief Adds a callback for registering a native binding module.
Expand Down Expand Up @@ -256,19 +256,30 @@ class ScriptEngine {
*/
void mainLoopUpdate();

/**
* @brief
* This function asks ScriptEngine to interrupt lengthy JavaScript operations and run the provided callback, passing the supplied data to it.
* Once the callback completes, control returns to the JavaScript code. Multiple interrupt requests may be ongoing.
* This function can be called from a different thread without needing a Locker. The registered callback should not reenter the interrupted Isolate.
* @param callback the callback to be called when interruption happens.
* @param data the data to be passed to the callback
*/
void requestInterrupt(void (*callback)(void *), void *data) { /* NOT SUPPORTED BY NAPI*/
}

bool runByteCodeFile(const std::string &pathBc, Value *ret /* = nullptr */);

/**
* @brief Throw JS exception
*/
void throwException(const std::string &errorMessage);

/**
/**
* @brief for napi_new_instance, skip constructor.
*/
void _setNeedCallConstructor(bool need);

/**
/**
* @brief for napi_new_instance, skip constructor.
*/
bool _needCallConstructor();
Expand All @@ -283,7 +294,7 @@ class ScriptEngine {
void handlePromiseExceptions();

private:
FileOperationDelegate _fileOperationDelegate;
FileOperationDelegate _fileOperationDelegate;
std::vector<RegisterCallback> _registerCallbackArray;
std::vector<RegisterCallback> _permRegisterCallbackArray;

Expand All @@ -292,8 +303,8 @@ class ScriptEngine {
std::vector<std::function<void()>> _beforeCleanupHookArray;
std::vector<std::function<void()>> _afterCleanupHookArray;

Object * _globalObj = nullptr;
napi_env _env = nullptr;
Object *_globalObj = nullptr;
napi_env _env = nullptr;

bool _isValid{false};
bool _isGarbageCollecting{false};
Expand Down
53 changes: 27 additions & 26 deletions native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,32 +535,33 @@ void CCWGPUCommandBuffer::draw(const DrawInfo &info) {
bindStates();

auto *ia = static_cast<CCWGPUInputAssembler *>(_gpuCommandBufferObj->stateCache.inputAssembler);
if (ia->getIndirectBuffer()) {
auto *indirectBuffer = static_cast<CCWGPUBuffer *>(ia->getIndirectBuffer());
bool multiDrawIndirectSupport = false;

// indirectSupport not support, emscripten webgpu ver < 2021
// https://github.com/gpuweb/gpuweb/issues/1354
if (multiDrawIndirectSupport) {
// todo
} else {
if (info.indexCount) {
// indexedIndirect not supported, emsdk 2.0.26
uint32_t drawInfoCount = indirectBuffer->getCount();
for (size_t i = 0; i < drawInfoCount; i++) {
wgpuRenderPassEncoderDrawIndexedIndirect(_gpuCommandBufferObj->wgpuRenderPassEncoder,
indirectBuffer->gpuBufferObject()->wgpuBuffer,
indirectBuffer->getOffset() + i * sizeof(CCWGPUDrawIndexedIndirectObject));
}
} else {
uint32_t drawInfoCount = indirectBuffer->getCount();
for (size_t i = 0; i < drawInfoCount; i++) {
wgpuRenderPassEncoderDrawIndirect(_gpuCommandBufferObj->wgpuRenderPassEncoder,
indirectBuffer->gpuBufferObject()->wgpuBuffer,
indirectBuffer->getOffset() + i * sizeof(CCWGPUDrawIndirectObject));
}
}
}
// TODO(Zeqiang): implement indirect drawing
if (0) {
// auto *indirectBuffer = static_cast<CCWGPUBuffer *>(ia->getIndirectBuffer());
// bool multiDrawIndirectSupport = false;

// // indirectSupport not support, emscripten webgpu ver < 2021
// // https://github.com/gpuweb/gpuweb/issues/1354
// if (multiDrawIndirectSupport) {
// // todo
// } else {
// if (info.indexCount) {
// // indexedIndirect not supported, emsdk 2.0.26
// uint32_t drawInfoCount = indirectBuffer->getCount();
// for (size_t i = 0; i < drawInfoCount; i++) {
// wgpuRenderPassEncoderDrawIndexedIndirect(_gpuCommandBufferObj->wgpuRenderPassEncoder,
// indirectBuffer->gpuBufferObject()->wgpuBuffer,
// indirectBuffer->getOffset() + i * sizeof(CCWGPUDrawIndexedIndirectObject));
// }
// } else {
// uint32_t drawInfoCount = indirectBuffer->getCount();
// for (size_t i = 0; i < drawInfoCount; i++) {
// wgpuRenderPassEncoderDrawIndirect(_gpuCommandBufferObj->wgpuRenderPassEncoder,
// indirectBuffer->gpuBufferObject()->wgpuBuffer,
// indirectBuffer->getOffset() + i * sizeof(CCWGPUDrawIndirectObject));
// }
// }
// }
} else {
auto *indexBuffer = static_cast<CCWGPUBuffer *>(ia->getIndexBuffer());
bool drawIndexed = indexBuffer && info.indexCount;
Expand Down
5 changes: 5 additions & 0 deletions native/cocos/renderer/gfx-wgpu/WGPUCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class CCWGPUCommandBuffer final : public CommandBuffer {
void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override;
void nextSubpass() override;
void draw(const DrawInfo &info) override;

void drawIndirect(Buffer *buffer, uint32_t offset, uint32_t count, uint32_t stride) override{};
void drawIndexedIndirect(Buffer *buffer, uint32_t offset, uint32_t count, uint32_t stride) override{};
void copyBuffer(Buffer *srcBuffer, Buffer *dstBuffer, const BufferCopy *regions, uint32_t count) override{};

void updateBuffer(Buffer *buff, const void *data, uint32_t size) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override;
void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override;
Expand Down
3 changes: 1 addition & 2 deletions native/cocos/renderer/gfx-wgpu/WGPUExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ EMSCRIPTEN_BINDINGS(WEBGPU_DEVICE_WASM_EXPORT) {
EXPORT_STRUCT_POD(ShaderStage, stage, source);
EXPORT_STRUCT_POD(Attribute, name, format, isNormalized, stream, isInstanced, location);
EXPORT_STRUCT_POD(ShaderInfo, name, stages, attributes, blocks, buffers, samplerTextures, samplers, textures, images, subpassInputs);
EXPORT_STRUCT_NPOD(InputAssemblerInfo, attributes, vertexBuffers, indexBuffer, indirectBuffer);
EXPORT_STRUCT_NPOD(InputAssemblerInfo, attributes, vertexBuffers, indexBuffer);
EXPORT_STRUCT_NPOD(ColorAttachment, format, sampleCount, loadOp, storeOp, barrier);
EXPORT_STRUCT_NPOD(DepthStencilAttachment, format, sampleCount, depthLoadOp, depthStoreOp, stencilLoadOp, stencilStoreOp, barrier);
EXPORT_STRUCT_POD(SubpassInfo, inputs, colors, resolves, preserves, depthStencil, depthStencilResolve, depthResolveMode, stencilResolveMode);
Expand Down Expand Up @@ -349,7 +349,6 @@ EMSCRIPTEN_BINDINGS(WEBGPU_DEVICE_WASM_EXPORT) {
.property("attributes", &InputAssembler::getAttributes)
.property("vertexBuffers", &InputAssembler::getVertexBuffers)
.property("indexBuffer", &InputAssembler::getIndexBuffer)
.property("indirectBuffer", &InputAssembler::getIndirectBuffer)
.property("objectID", select_overload<uint32_t(void) const>(&InputAssembler::getObjectID));
class_<CCWGPUInputAssembler, base<InputAssembler>>("CCWGPUInputAssembler")
.constructor<>();
Expand Down
Loading

0 comments on commit 9c8bf6d

Please sign in to comment.