Replies: 1 comment
-
(work-in-progress) // shader.wgsl
struct VertexOutput {
@builtin(position) position: vec4f,
uv: vec2f,
}
@vertex
fn main(
@location(0) position: vec3f,
@location(1) normal: vec3f,
@location(2) uv: vec2f,
) -> VertexOutput {
...
} // shader.ts
/* generated via tgpu-cli by TypeGPU */
const VertexOutput = {
position: builtin.position,
uv: vec2f,
};
const main = tgpu
.vertexFn([vec3f, vec3f, vec2f], VertexOutput)
.does(/* wgsl */`(
@location(0) position: vec3f,
@location(1) normal: vec3f,
@location(2) uv: vec2f,
) -> VertexOutput {
...
}
`)
.$uses({ get VertexOutput() { return main.Output; } }); // main.ts
import tgpu from 'typegpu';
import { looseArray, looseStruct, vec3f, vec2f, unorm8x2 } from 'typegpu/data';
import { vertexMain } from './shader.ts';
const VertexData = looseStruct({
position: vec3f,
normal: vec3f,
uv: unorm8x2,
});
const vertexLayout = tgpu.vertexLayout((n) => looseArray(VertexData, n), 'vertex');
const { attrib } = vertexLayout;
const vertexBuffer = tgpu
.createBuffer(vertexLayout.schemaForCount(512))
.$usage('vertex');
const renderPipeline = tgpu
.withVertex(vertexMain, [attrib.position, attrib.normal, attrib.uv])
.withFragment(...)
.createPipeline();
renderPipeline
.with(vertexLayout, vertexBuffer)
.draw(...); The completeness of the current approachThe following properties have to be known before creating a pipeline: type GPURenderPipelineDescriptor = {
vertex: GPUVertexState;
primitive?: GPUPrimitiveState;
depthStencil?: GPUDepthStencilState;
multisample?: GPUMultisampleState;
fragment?: GPUFragmentState;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When inferring vertex buffers form a
.wgsl
shader we face an ambiguity problem. For example:There is not enough information here to properly define what buffers we are dealing with. Is it one vertex buffer with three attributes? Are there three vertex buffers with one attribute each? Furthermore, we don't even know if it's a
vertex
orinstance
vertex buffer. Since there is no way to infer this information we need the user to somehow pass it.Beta Was this translation helpful? Give feedback.
All reactions