|
| 1 | +/* |
| 2 | + * Copyright 2019-2023 Diligent Graphics LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * In no event and under no legal theory, whether in tort (including negligence), |
| 17 | + * contract, or otherwise, unless required by applicable law (such as deliberate |
| 18 | + * and grossly negligent acts) or agreed to in writing, shall any Contributor be |
| 19 | + * liable for any damages, including any direct, indirect, special, incidental, |
| 20 | + * or consequential damages of any character arising as a result of this License or |
| 21 | + * out of the use or inability to use the software (including but not limited to damages |
| 22 | + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and |
| 23 | + * all other commercial damages or losses), even if such Contributor has been advised |
| 24 | + * of the possibility of such damages. |
| 25 | + */ |
| 26 | + |
| 27 | +using System; |
| 28 | +using System.Runtime.CompilerServices; |
| 29 | +using System.Runtime.InteropServices; |
| 30 | + |
| 31 | +namespace Diligent; |
| 32 | + |
| 33 | +public partial struct ShaderUnpackInfo |
| 34 | +{ |
| 35 | + public delegate void ModifyShaderDelegate(ref ShaderDesc desc); |
| 36 | + |
| 37 | + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })] |
| 38 | + internal static unsafe void ModifyShaderDescImpl(IntPtr nativeDesc, IntPtr userData) |
| 39 | + { |
| 40 | + ShaderDesc desc = default; |
| 41 | + desc.__MarshalFrom(ref *(ShaderDesc.__Native*)nativeDesc); |
| 42 | + Marshal.GetDelegateForFunctionPointer<ModifyShaderDelegate>(userData)(ref desc); |
| 43 | + desc.__MarshalTo(ref *(ShaderDesc.__Native*)nativeDesc); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +public partial struct PipelineStateUnpackInfo |
| 48 | +{ |
| 49 | + public delegate void ModifyPipelineStateDelegate(PipelineStateCreateInfo createInfo); |
| 50 | + |
| 51 | + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })] |
| 52 | + internal static unsafe void ModifyPipelineStateCreateInfoImpl(IntPtr nativeCI, IntPtr userData) |
| 53 | + { |
| 54 | + // TODO DRY |
| 55 | + switch (((PipelineStateCreateInfo.__Native*)nativeCI)->PSODesc.PipelineType) |
| 56 | + { |
| 57 | + case PipelineType.Mesh: |
| 58 | + case PipelineType.Graphics: |
| 59 | + { |
| 60 | + var pipelineCI = new GraphicsPipelineStateCreateInfo(ref *(GraphicsPipelineStateCreateInfo.__Native*)nativeCI); |
| 61 | + Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI); |
| 62 | + pipelineCI.__MarshalTo(ref *(GraphicsPipelineStateCreateInfo.__Native*)nativeCI); |
| 63 | + break; |
| 64 | + } |
| 65 | + case PipelineType.Compute: |
| 66 | + { |
| 67 | + var pipelineCI = new ComputePipelineStateCreateInfo(ref *(ComputePipelineStateCreateInfo.__Native*)nativeCI); |
| 68 | + Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI); |
| 69 | + pipelineCI.__MarshalTo(ref *(ComputePipelineStateCreateInfo.__Native*)nativeCI); |
| 70 | + break; |
| 71 | + } |
| 72 | + case PipelineType.RayTracing: |
| 73 | + { |
| 74 | + var pipelineCI = new RayTracingPipelineStateCreateInfo(ref *(RayTracingPipelineStateCreateInfo.__Native*)nativeCI); |
| 75 | + Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI); |
| 76 | + pipelineCI.__MarshalTo(ref *(RayTracingPipelineStateCreateInfo.__Native*)nativeCI); |
| 77 | + break; |
| 78 | + } |
| 79 | + case PipelineType.Tile: |
| 80 | + { |
| 81 | + var pipelineCI = new TilePipelineStateCreateInfo(ref *(TilePipelineStateCreateInfo.__Native*)nativeCI); |
| 82 | + Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI); |
| 83 | + pipelineCI.__MarshalTo(ref *(TilePipelineStateCreateInfo.__Native*)nativeCI); |
| 84 | + break; |
| 85 | + } |
| 86 | + default: |
| 87 | + throw new InvalidOperationException(); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +public partial struct RenderPassUnpackInfo |
| 93 | +{ |
| 94 | + public delegate void ModifyRenderPassDelegate(ref RenderPassDesc desc); |
| 95 | + |
| 96 | + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })] |
| 97 | + internal static unsafe void ModifyRenderPassDescImpl(IntPtr nativeDesc, IntPtr userData) |
| 98 | + { |
| 99 | + var desc = new RenderPassDesc { }; |
| 100 | + desc.__MarshalFrom(ref *(RenderPassDesc.__Native*)nativeDesc); |
| 101 | + Marshal.GetDelegateForFunctionPointer<ModifyRenderPassDelegate>(userData)(ref desc); |
| 102 | + desc.__MarshalTo(ref *(RenderPassDesc.__Native*)nativeDesc); |
| 103 | + } |
| 104 | +} |
0 commit comments