Comments (4)
This is already possible:
let buf: ArrayBuffer = new ArrayBuffer(VkInstanceCreateInfo.byteLength);
let instanceInfo: VkInstanceCreateInfo = new VkInstanceCreateInfo({
$memoryBuffer: buf,
$memoryOffset: 0x0
});
I've added this when adding support for sub-structures - e.g. VkRect2D, where offset
and extent
are VkOffset2D
structs using the same memory as VkRect2D
, but with a different offset.
You can check the Default Properties section in the docs, for example here, which shows the underlying methods and properties for low-level access.
What you're probably most interested in are the $memoryBuffer
and $memoryOffset
properties and the reflect
method, which synchronizes the JS Object with the ArrayBuffer.
Structs also come with a memoryLayout
object, which describes the byteOffset and byteLength of each struct member, e.g.:
VkInstanceCreateInfo.byteLength = 0x40;
VkInstanceCreateInfo.memoryLayout = {
sType: {
byteOffset: 0x0,
byteLength: 0x4
},
pNext: {
byteOffset: 0x8,
byteLength: 0x8
},
...
};
Also, if you're interested about how nvk works internally, checkout this file.
Edit:
I'm not sure your question is exactly about this, but I've also created a package callced nvk-struct-cache to mimic stack allocation when working with nvk, to reduce heap pressure.
from nvk.
I'm getting some skills and experience for professional purposes. Just interesting how work these worlds together. So, I trying to combine NVK with AssemblyScript (and run from that script language)…
UPDATE! Needs getAddressFromArrayBuffer
and getArrayBufferFromAddress
a public, because natively WebAssembly
can't handle alike C++ pointers (i.e. addressing "limited" local-memory). Ah, I found that way...
from nvk.
nvk extends the ArrayBuffer Object with additional low-level methods - see the docs here
Note that one minor problem with Wasm is that it is in a fixed 32bit world, while NAPI is 64bit, so when you fill a Vulkan struct in Wasm, the memory doesn't align correctly.
I don't know your Wasm setup, but you might do it like this (pseudo code):
Setup:
let heap = new ArrayBuffer(2<<15);
let heapU32 = new Uint32Array(heap);
let module = new WebAssembly.Module(buffer);
let instance = new WebAssembly.Instance(module);
In C or AssemblyScript:
int test() {
VkInstanceCreateInfo* info = (VkInstanceCreateInfo*) malloc(sizeof(VkInstanceCreateInfo));
return (int) info;
}
In JS:
let infoAddr = instance.test();
let infoAddrView = new VkInstanceCreateInfo({
$memoryBuffer: heap,
$memoryOffset: infoAddr
});
from nvk.
I already tried to use with AssemblyScript and custom methods (with structure's). I found some critical bugs when create VkInstanceCreateInfo
from WebAssembly memory with offset: no extension layers lists, application crash with that structure. I checked alignment, but has correct. Probably, there is internal "get" and "set" issues. Also in WASM structures I used globalify hack for pointers.
from nvk.
Related Issues (20)
- Typescript is broken? HOT 6
- Wrong parameter type in index.d.ts HOT 8
- pNext: "Member isn't allowed to be filled!" incorrect behavior when 'null'
- Empty arrays cause a crash when a structure gets flushed
- Add documentation for ArrayBuffer.getAddress and ArrayBuffer.fromAddress
- Add Cursor/Pointer Lock support
- ArrayBuffer members of structures are not correctly handled
- No render devices available in vmware HOT 2
- oculus support HOT 1
- BigInt.prototype.dereference doesn't actually dereference
- Running new VkDescriptorBufferInfo() in an electron render process causes crash on getArrayBufferFromAddress() in VkBuffer initialisation. HOT 3
- Drop Vk and VK_ prefixes? HOT 1
- Validation Layer name change to "VK_LAYER_KHRONOS_validation" HOT 4
- TypeScript types not working HOT 2
- Disabling rate limit / vsync using NVK
- Howto get humanized Vulkan driver version?
- Issue with BigUint64Array
- VkImageBlit and VkImageBlit2KHR srcOffsets and dstOffsets cause RangeError crash.
- Incorrect TypeScript signature for vkCmdBindVertexBuffers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvk.