simple-nvk
Version:
Graphic libary, using Javascript and Node-Vulkan.<br> It has similarities to WebGPU in some places.<br> ## Features Abstractions of Vulkan features like staged buffers.<br> Much shorter to write than Vulkan.<br> ## Install ````console npm install s
62 lines (54 loc) • 2.91 kB
JavaScript
import { assertVulkan } from "../utils.mjs"
import Handle from "./handle.mjs";
export default class RenderPassHandle extends Handle {
constructor(owner, { backgroundColor = [0, 0, 0, 1] }) {
super(owner);
let renderPass = new VkRenderPass();
let attachmentDescription = new VkAttachmentDescription();
attachmentDescription.flags = 0;
attachmentDescription.format = VK_FORMAT_B8G8R8A8_UNORM;
attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
attachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
let attachmentReference = new VkAttachmentReference();
attachmentReference.attachment = 0;
attachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
let subpassDescription = new VkSubpassDescription();
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpassDescription.inputAttachmentCount = 0;
subpassDescription.pInputAttachments = null;
subpassDescription.colorAttachmentCount = 1;
subpassDescription.pColorAttachments = [attachmentReference];
subpassDescription.pResolveAttachments = null;
subpassDescription.pDepthStencilAttachment = null;
subpassDescription.preserveAttachmentCount = 0;
subpassDescription.pPreserveAttachments = null;
let subpassDependency = new VkSubpassDependency();
subpassDependency.srcSubpass = VK_SUBPASS_EXTERNAL;
subpassDependency.dstSubpass = 0;
subpassDependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
subpassDependency.srcAccessMask = 0;
subpassDependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
subpassDependency.dependencyFlags = 0;
let renderPassCreateInfo = new VkRenderPassCreateInfo();
renderPassCreateInfo.attachmentCount = 1;
renderPassCreateInfo.pAttachments = [attachmentDescription];
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = [subpassDescription];
renderPassCreateInfo.dependencyCount = 1;
renderPassCreateInfo.pDependencies = [subpassDependency];
let result = vkCreateRenderPass(this.device, renderPassCreateInfo, null, renderPass);
assertVulkan(result);
this.vkRenderPass = renderPass;
this.backgroundColor = backgroundColor;
}
destroy(){
this.super_destroy();
vkDestroyRenderPass(this.device, this.vkRenderPass, null);
}
}