public TonClientRustAdapter(string configJson, ILogger <TonClientRustAdapter> logger) { _logger = logger; _logger.LogTrace("Creating context with options: {config}", configJson); using var optionsInteropJson = configJson.ToInteropStringDisposable(); IntPtr resultPtr = RustInteropInterface.tc_create_context(optionsInteropJson); _logger.LogTrace("Reading context creation result"); InteropString resultInterop = RustInteropInterface.tc_read_string(resultPtr); var resultJson = resultInterop.ToString(); RustInteropInterface.tc_destroy_string(resultPtr); _logger.LogTrace("Got context creation result: {result}", resultJson); var createContextResult = JsonSerializer.Deserialize <CreateContextResponse>(resultJson, JsonOptionsProvider.JsonSerializerOptions); if (createContextResult?.ContextNumber == null) { throw new TonClientException($"Raw result: {resultJson}", new NullReferenceException("Result of context creation or context number is null")); } ClientError error = createContextResult.Error; if (error != null) { throw TonClientException.CreateExceptionWithCodeWithData(error.Code, error.Data?.ToObject <Dictionary <string, object> >(), error.Message); } _contextNumber = (uint)createContextResult.ContextNumber; }
public void NotEqualsTest() { InteropString interopString = "String"; InteropString interopString2 = "String2"; Assert.IsFalse(interopString.Equals(interopString2)); }
public void EqualsTest() { InteropString interopString = "String"; InteropString interopString2 = "String"; Assert.IsTrue(interopString.Equals(interopString2)); }
public void LengthTest() { InteropString interopString = ""; Assert.AreEqual(0, interopString.Length); interopString = "abc"; Assert.AreEqual(3, interopString.Length); }
void CreateInstance(InstanceCreateInfo mInfo) { InteropString appName = null; InteropString engineName = null; Marshalled <VkApplicationInfo> appInfoMarshalled = null; var extensionsMarshalled = new NativeStringArray(mInfo.extensions); var layersMarshalled = new NativeStringArray(mInfo.layers); var info = new VkInstanceCreateInfo(); info.sType = VkStructureType.InstanceCreateInfo; info.enabledExtensionCount = (uint)extensionsMarshalled.Count; info.ppEnabledExtensionNames = extensionsMarshalled.Address; info.enabledLayerCount = (uint)layersMarshalled.Count; info.ppEnabledLayerNames = layersMarshalled.Address; if (mInfo.applicationInfo != null) { var appInfo = new VkApplicationInfo(); appInfo.sType = VkStructureType.ApplicationInfo; appInfo.apiVersion = mInfo.applicationInfo.apiVersion; appInfo.engineVersion = mInfo.applicationInfo.engineVersion; appInfo.applicationVersion = mInfo.applicationInfo.applicationVersion; appName = new InteropString(mInfo.applicationInfo.applicationName); appInfo.pApplicationName = appName.Address; engineName = new InteropString(mInfo.applicationInfo.engineName); appInfo.pEngineName = engineName.Address; appInfoMarshalled = new Marshalled <VkApplicationInfo>(appInfo); info.pApplicationInfo = appInfoMarshalled.Address; } using (appName) //appName, engineName, and appInfoMarshalled may be null using (engineName) using (appInfoMarshalled) using (extensionsMarshalled) using (layersMarshalled) { var result = createInstance(ref info, alloc, out instance); if (result != VkResult.Success) { throw new InstanceException(string.Format("Error creating instance: {0}", result)); } } }
internal VkPipelineShaderStageCreateInfo GetNative(DisposableList <IDisposable> marshalled) { var result = new VkPipelineShaderStageCreateInfo(); result.sType = VkStructureType.PipelineShaderStageCreateInfo; result.stage = stage; result.module = module.Native; var strInterop = new InteropString(name); result.pName = strInterop.Address; marshalled.Add(strInterop); if (specializationInfo != null) { result.pSpecializationInfo = specializationInfo.GetNative(marshalled); } return(result); }
void CreateInstance() { var appName = new InteropString("Hello Triangle"); var appInfo = new VkApplicationInfo(); appInfo.sType = CSGL.Vulkan.VkStructureType.ApplicationInfo; appInfo.pApplicationName = appName.Address; appInfo.applicationVersion = new CSGL.Vulkan.VkVersion(1, 0, 0); appInfo.engineVersion = new CSGL.Vulkan.VkVersion(0, 0, 1); appInfo.apiVersion = new CSGL.Vulkan.VkVersion(1, 0, 0); var appInfoNative = new Native <VkApplicationInfo>(appInfo); var info = new VkInstanceCreateInfo(); info.sType = CSGL.Vulkan.VkStructureType.InstanceCreateInfo; info.pApplicationInfo = appInfoNative.Address; var extensions = GLFW.GetRequiredInstanceExceptions(); var extensionsNative = new NativeStringArray(extensions); info.ppEnabledExtensionNames = extensionsNative.Address; info.enabledExtensionCount = (uint)extensions.Count; var layersNative = new NativeStringArray(layers); info.ppEnabledLayerNames = layersNative.Address; info.enabledLayerCount = (uint)layers.Length; var result = VK.CreateInstance(ref info, alloc, out instance); appName.Dispose(); appInfoNative.Dispose(); extensionsNative.Dispose(); layersNative.Dispose(); }
void CreateGraphicsPipeline() { VkShaderModule vert = CreateShaderModule(File.ReadAllBytes("vert.spv")); VkShaderModule frag = CreateShaderModule(File.ReadAllBytes("frag.spv")); InteropString entry = new InteropString("main"); var vertInfo = new VkPipelineShaderStageCreateInfo(); vertInfo.sType = CSGL.Vulkan.VkStructureType.PipelineShaderStageCreateInfo; vertInfo.stage = CSGL.Vulkan.VkShaderStageFlags.VertexBit; vertInfo.module = vert; vertInfo.pName = entry.Address; var fragInfo = new VkPipelineShaderStageCreateInfo(); fragInfo.sType = CSGL.Vulkan.VkStructureType.PipelineShaderStageCreateInfo; fragInfo.stage = CSGL.Vulkan.VkShaderStageFlags.FragmentBit; fragInfo.module = frag; fragInfo.pName = entry.Address; var shaderStages = new NativeArray <VkPipelineShaderStageCreateInfo>(2); shaderStages[0] = vertInfo; shaderStages[1] = fragInfo; var vertexInputInfo = new VkPipelineVertexInputStateCreateInfo(); vertexInputInfo.sType = CSGL.Vulkan.VkStructureType.PipelineVertexInputStateCreateInfo; var vertexInputNative = new Native <VkPipelineVertexInputStateCreateInfo>(vertexInputInfo); var inputAssembly = new VkPipelineInputAssemblyStateCreateInfo(); inputAssembly.sType = CSGL.Vulkan.VkStructureType.PipelineInputAssemblyStateCreateInfo; inputAssembly.topology = CSGL.Vulkan.VkPrimitiveTopology.TriangleList; var inputAssemblyNative = new Native <VkPipelineInputAssemblyStateCreateInfo>(inputAssembly); var viewport = new VkViewport(); viewport.width = swapchainExtent.width; viewport.height = swapchainExtent.height; viewport.minDepth = 0f; viewport.maxDepth = 1f; var viewportNative = new Native <VkViewport>(viewport); var scissor = new VkRect2D(); scissor.extent = swapchainExtent; var scissorNative = new Native <VkRect2D>(scissor); var viewportState = new VkPipelineViewportStateCreateInfo(); viewportState.sType = CSGL.Vulkan.VkStructureType.PipelineViewportStateCreateInfo; viewportState.viewportCount = 1; viewportState.pViewports = viewportNative.Address; viewportState.scissorCount = 1; viewportState.pScissors = scissorNative.Address; var viewportStateNative = new Native <VkPipelineViewportStateCreateInfo>(viewportState); var rasterizer = new VkPipelineRasterizationStateCreateInfo(); rasterizer.sType = CSGL.Vulkan.VkStructureType.PipelineRasterizationStateCreateInfo; rasterizer.polygonMode = CSGL.Vulkan.VkPolygonMode.Fill; rasterizer.lineWidth = 1f; rasterizer.cullMode = CSGL.Vulkan.VkCullModeFlags.BackBit; rasterizer.frontFace = CSGL.Vulkan.VkFrontFace.Clockwise; var rasterizerNative = new Native <VkPipelineRasterizationStateCreateInfo>(rasterizer); var multisampling = new VkPipelineMultisampleStateCreateInfo(); multisampling.sType = CSGL.Vulkan.VkStructureType.PipelineMultisampleStateCreateInfo; multisampling.rasterizationSamples = CSGL.Vulkan.VkSampleCountFlags._1_Bit; multisampling.minSampleShading = 1f; var multisamplingNative = new Native <VkPipelineMultisampleStateCreateInfo>(multisampling); var colorBlendAttachment = new VkPipelineColorBlendAttachmentState(); colorBlendAttachment.colorWriteMask = CSGL.Vulkan.VkColorComponentFlags.RBit | CSGL.Vulkan.VkColorComponentFlags.GBit | CSGL.Vulkan.VkColorComponentFlags.BBit | CSGL.Vulkan.VkColorComponentFlags.ABit; colorBlendAttachment.srcColorBlendFactor = CSGL.Vulkan.VkBlendFactor.One; colorBlendAttachment.dstColorBlendFactor = CSGL.Vulkan.VkBlendFactor.Zero; colorBlendAttachment.colorBlendOp = CSGL.Vulkan.VkBlendOp.Add; colorBlendAttachment.srcAlphaBlendFactor = CSGL.Vulkan.VkBlendFactor.One; colorBlendAttachment.dstAlphaBlendFactor = CSGL.Vulkan.VkBlendFactor.Zero; colorBlendAttachment.alphaBlendOp = CSGL.Vulkan.VkBlendOp.Add; var colorBlendAttachmentNative = new Native <VkPipelineColorBlendAttachmentState>(colorBlendAttachment); var colorBlending = new VkPipelineColorBlendStateCreateInfo(); colorBlending.sType = CSGL.Vulkan.VkStructureType.PipelineColorBlendStateCreateInfo; colorBlending.logicOp = CSGL.Vulkan.VkLogicOp.Copy; colorBlending.attachmentCount = 1; colorBlending.pAttachments = colorBlendAttachmentNative.Address; var colorBlendingNative = new Native <VkPipelineColorBlendStateCreateInfo>(colorBlending); var pipelineLayoutInfo = new VkPipelineLayoutCreateInfo(); pipelineLayoutInfo.sType = CSGL.Vulkan.VkStructureType.PipelineLayoutCreateInfo; if (pipelineLayout != VkPipelineLayout.Null) { VK.DestroyPipelineLayout(device, pipelineLayout, alloc); } var result = VK.CreatePipelineLayout(device, ref pipelineLayoutInfo, alloc, out pipelineLayout); var info = new VkGraphicsPipelineCreateInfo(); info.sType = CSGL.Vulkan.VkStructureType.GraphicsPipelineCreateInfo; info.stageCount = 2; info.pStages = shaderStages.Address; info.pVertexInputState = vertexInputNative.Address; info.pInputAssemblyState = inputAssemblyNative.Address; info.pViewportState = viewportStateNative.Address; info.pRasterizationState = rasterizerNative.Address; info.pMultisampleState = multisamplingNative.Address; info.pColorBlendState = colorBlendingNative.Address; info.layout = pipelineLayout; info.renderPass = renderPass; info.subpass = 0; info.basePipelineHandle = VkPipeline.Null; info.basePipelineIndex = -1; var infoNative = new Native <VkGraphicsPipelineCreateInfo>(info); var temp = new Native <VkPipeline>(); if (pipeline != VkPipeline.Null) { VK.DestroyPipeline(device, pipeline, alloc); } result = VK.CreateGraphicsPipelines(device, VkPipelineCache.Null, 1, infoNative.Address, alloc, temp.Address); pipeline = temp.Value; infoNative.Dispose(); temp.Dispose(); entry.Dispose(); shaderStages.Dispose(); vertexInputNative.Dispose(); inputAssemblyNative.Dispose(); viewportNative.Dispose(); scissorNative.Dispose(); viewportStateNative.Dispose(); rasterizerNative.Dispose(); multisamplingNative.Dispose(); colorBlendingNative.Dispose(); colorBlendAttachmentNative.Dispose(); VK.DestroyShaderModule(device, vert, alloc); VK.DestroyShaderModule(device, frag, alloc); }
public void ImplicitStringConversion() { InteropString interopString = "String"; Assert.AreEqual <String>("String", interopString); }