{"id":17020983,"url":"https://github.com/rover656/silkywebgpu","last_synced_at":"2025-03-22T17:18:08.729Z","repository":{"id":162859141,"uuid":"637350491","full_name":"Rover656/SilkyWebGPU","owner":"Rover656","description":"A light convenience abstraction sitting upon Silk.NET.","archived":false,"fork":false,"pushed_at":"2023-05-13T00:59:12.000Z","size":318,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T20:42:40.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rover656.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-07T09:35:24.000Z","updated_at":"2024-09-04T01:14:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"9391a5bf-e03a-4076-99eb-1a072805970c","html_url":"https://github.com/Rover656/SilkyWebGPU","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rover656%2FSilkyWebGPU","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rover656%2FSilkyWebGPU/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rover656%2FSilkyWebGPU/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rover656%2FSilkyWebGPU/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rover656","download_url":"https://codeload.github.com/Rover656/SilkyWebGPU/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244991196,"owners_count":20543627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T07:06:29.592Z","updated_at":"2025-03-22T17:18:08.720Z","avatar_url":"https://github.com/Rover656.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SilkyWebGPU\n\n\u003e **Warning**\n\u003e This library is highly unstable and prone to API surface changes. Here be dragons!\n\nSilkyWebGPU is a lightweight abstraction above Silk.NET's WebGPU bindings, mainly powered by source generators.\nThe abstractions aim to minimise the use of unsafe concepts throughout program code and attempts to handle marshalling of everything behind the scenes.\nChainable structs have been wrapped to ensure they can be constructed easily and sent to the underlying library safely.\n\n## ToDo\n- [x] More type support for the struct generator\n- [x] Ability to reverse chained structs back into managed\n- [ ] Allow passing `null` to ref userdatum now.\n- [ ] Tidy up the WGPU singleton, it's not a great design.\n- [ ] Implement Dawn extensions\n- [ ] Separate Dawn and WGPU extensions into separate output projects\n- [ ] Get this on Nuget\n\n## Why?\nI personally wasn't happy with how the raw API was laid out, so I decided to write this to wrap the Silk.NET APIs in a more C# friendly way. Here are some examples of before and after's.\n\n### Get Adapter\n*Before*\n```c#\n//Get adapter\nvar requestAdapterOptions = new RequestAdapterOptions\n{\n  CompatibleSurface = _Surface\n};\n\nwgpu.InstanceRequestAdapter\n(\n  _Instance,\n  requestAdapterOptions,\n  new PfnRequestAdapterCallback((_, adapter1, _, _) =\u003e _Adapter = adapter1),\n  null\n);\n```\n\n*After*\n```c#\n// Request adapter\nusing var requestAdapterOptions = new RequestAdapterOptions\n{\n  CompatibleSurface = _Surface\n};\n        \n_Adapter = await _Instance.RequestAdapter(requestAdapterOptions);\n```\n\n## Load Shader\n*Before*\n```c#\nvar wgslDescriptor = new ShaderModuleWGSLDescriptor\n{\n  Code = (byte*) SilkMarshal.StringToPtr(SHADER),\n  Chain = new ChainedStruct\n  {\n    SType = SType.ShaderModuleWgsldescriptor\n  }\n};\n\nvar shaderModuleDescriptor = new ShaderModuleDescriptor\n{\n  NextInChain = (ChainedStruct*) (\u0026wgslDescriptor),\n};\n\n_Shader = wgpu.DeviceCreateShaderModule(_Device, shaderModuleDescriptor);\n```\n\n*After*\n```c#\nusing var shaderModuleDescriptor = new ShaderModuleDescriptor\n{\n  Next = new ShaderModuleWGSLDescriptor\n  {\n    Code = SHADER\n  }\n};\n\n_Shader = _Device.CreateShaderModule(shaderModuleDescriptor);\n```\n\n## Create Render Pipeline\n*Before*\n```c#\nvar blendState = new BlendState\n{\n  Color = new BlendComponent\n  {\n    SrcFactor = BlendFactor.One,\n    DstFactor = BlendFactor.Zero,\n    Operation = BlendOperation.Add\n  },\n  Alpha = new BlendComponent\n  {\n    SrcFactor = BlendFactor.One,\n    DstFactor = BlendFactor.Zero,\n    Operation = BlendOperation.Add\n  }\n};\n\nvar colorTargetState = new ColorTargetState\n{\n  Format    = _SwapChainFormat,\n  Blend     = \u0026blendState,\n  WriteMask = ColorWriteMask.All\n};\n\nvar fragmentState = new FragmentState\n{\n  Module      = _Shader,\n  TargetCount = 1,\n  Targets     = \u0026colorTargetState,\n  EntryPoint  = (byte*) SilkMarshal.StringToPtr(\"fs_main\")\n};\n\nvar renderPipelineDescriptor = new RenderPipelineDescriptor\n{\n  Vertex = new VertexState\n  {\n    Module     = _Shader,\n    EntryPoint = (byte*) SilkMarshal.StringToPtr(\"vs_main\"),\n  },\n  Primitive = new PrimitiveState\n  {\n    Topology         = PrimitiveTopology.TriangleList,\n    StripIndexFormat = IndexFormat.Undefined,\n    FrontFace        = FrontFace.Ccw,\n    CullMode         = CullMode.None\n  },\n  Multisample = new MultisampleState\n  {\n    Count                  = 1,\n    Mask                   = ~0u,\n    AlphaToCoverageEnabled = false\n  },\n  Fragment     = \u0026fragmentState,\n  DepthStencil = null\n};\n\n_Pipeline = wgpu.DeviceCreateRenderPipeline(_Device, renderPipelineDescriptor);\n```\n\n*After*\n```c#\nvar blendState = new BlendState\n{\n  Color = new BlendComponent\n  {\n    SrcFactor = BlendFactor.One,\n    DstFactor = BlendFactor.Zero,\n    Operation = BlendOperation.Add\n  },\n  Alpha = new BlendComponent\n  {\n    SrcFactor = BlendFactor.One,\n    DstFactor = BlendFactor.Zero,\n    Operation = BlendOperation.Add\n  }\n};\n        \nusing var colorTargetState = new ColorTargetState\n{\n  Format    = _SwapChainFormat,\n  Blend     = blendState,\n  WriteMask = ColorWriteMask.All\n};\n\nusing var fragmentState = new FragmentState\n{\n  Module      = _Shader,\n  Targets     = new[] {colorTargetState},\n  EntryPoint  = \"fs_main\"\n};\n\nusing var renderPipelineDescriptor = new RenderPipelineDescriptor\n{\n  Vertex = new VertexState\n  {\n    Module     = _Shader,\n    EntryPoint = \"vs_main\",\n  },\n  Primitive = new PrimitiveState\n  {\n    Topology         = PrimitiveTopology.TriangleList,\n    StripIndexFormat = IndexFormat.Undefined,\n    FrontFace        = FrontFace.Ccw,\n    CullMode         = CullMode.None\n  },\n  Multisample = new MultisampleState\n  {\n    Count                  = 1,\n    Mask                   = ~0u,\n    AlphaToCoverageEnabled = false\n  },\n  Fragment     = fragmentState,\n  DepthStencil = null\n};\n\n_Pipeline = _Device.CreateRenderPipeline(renderPipelineDescriptor);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frover656%2Fsilkywebgpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frover656%2Fsilkywebgpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frover656%2Fsilkywebgpu/lists"}