summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
l---------LICENSE1
-rw-r--r--LICENSES/CC0-1.0.text121
-rw-r--r--Makefile2
-rw-r--r--fragment.frag2
-rw-r--r--glslv.mk2
-rw-r--r--nelem.h2
-rw-r--r--shaders.h4
-rw-r--r--strlist.c2
-rw-r--r--strlist.h2
-rw-r--r--validation.c13
-rw-r--r--validation.h2
-rw-r--r--vertex.vert2
-rw-r--r--vulkan.c59
14 files changed, 194 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index c76e195..7ba80af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+# SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+# SPDX-License-Identifier: CC0-1.0
*.o
*.spv
vulkan
diff --git a/LICENSE b/LICENSE
new file mode 120000
index 0000000..6e09630
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+LICENSES/CC0-1.0.text \ No newline at end of file
diff --git a/LICENSES/CC0-1.0.text b/LICENSES/CC0-1.0.text
new file mode 100644
index 0000000..0e259d4
--- /dev/null
+++ b/LICENSES/CC0-1.0.text
@@ -0,0 +1,121 @@
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
diff --git a/Makefile b/Makefile
index 366e666..4650cad 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+# SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+# SPDX-License-Identifier: CC0-1.0
-include config.mk
include glslv.mk
diff --git a/fragment.frag b/fragment.frag
index 91a094d..83b5fa6 100644
--- a/fragment.frag
+++ b/fragment.frag
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#version 450
#extension GL_ARB_separate_shader_objects : enable
diff --git a/glslv.mk b/glslv.mk
index 0e402f9..c0ced69 100644
--- a/glslv.mk
+++ b/glslv.mk
@@ -1,3 +1,5 @@
+# SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+# SPDX-License-Identifier: CC0-1.0
GLSLV ?= glslangValidator
COMPILE.spv = $(GLSLV) $(GLSLVFLAGS)
%.spv: %.vert
diff --git a/nelem.h b/nelem.h
index 99b5f77..de9c9ce 100644
--- a/nelem.h
+++ b/nelem.h
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#ifndef VULKAN_NELEM_H
#define VULKAN_NELEM_H
diff --git a/shaders.h b/shaders.h
index 7f36984..9c98aaa 100644
--- a/shaders.h
+++ b/shaders.h
@@ -1,8 +1,8 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#ifndef VULKAN_SHADERS_H
#define VULKAN_SHADERS_H
-#include <stddef.h>
-
extern char _binary_vertex_spv_start[];
extern char _binary_vertex_spv_end[];
#define vertex_spv_data _binary_vertex_spv_start
diff --git a/strlist.c b/strlist.c
index 58faa99..c802285 100644
--- a/strlist.c
+++ b/strlist.c
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#include <assert.h>
#include <stdlib.h>
#include <string.h>
diff --git a/strlist.h b/strlist.h
index 6c60a79..0b3baf1 100644
--- a/strlist.h
+++ b/strlist.h
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#ifndef VULKAN_STRLIST_H
#define VULKAN_STRLIST_H
diff --git a/validation.c b/validation.c
index c9d2f9f..257f166 100644
--- a/validation.c
+++ b/validation.c
@@ -1,12 +1,17 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
+#ifndef WITH_VALIDATION
+#define WITH_VALIDATION
+#endif
+
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <vulkan/vulkan.h>
-
#include "eprintf.h"
#include "nelem.h"
-#define WITH_VALIDATION
#include "validation.h"
static const char *vlayers[] = {
@@ -43,7 +48,7 @@ static bool havelayers(void)
instlrp = emalloc(ninstlrp * sizeof *instlrp);
vkEnumerateInstanceLayerProperties(&ninstlrp, instlrp);
- for (int vl = 0; vl < NELEM(vlayers); vl++) {
+ for (size_t vl = 0; vl < NELEM(vlayers); vl++) {
for (uint32_t il = 0; il < ninstlrp; il++)
if (strcmp(vlayers[vl], instlrp[il].layerName) == 0)
goto next;
@@ -95,6 +100,8 @@ void validation_destroycb(VkInstance inst, void *_cb)
PFN_vkDestroyDebugReportCallbackEXT func;
VkDebugReportCallbackEXT *cb = _cb;
+ assert(cb != NULL);
+
func = (PFN_vkDestroyDebugReportCallbackEXT)
vkGetInstanceProcAddr(inst, "vkDestroyDebugReportCallbackEXT");
if (func == NULL)
diff --git a/validation.h b/validation.h
index 44b1096..9c2485e 100644
--- a/validation.h
+++ b/validation.h
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#ifndef VULKAN_VALIDATION_H
#define VULKAN_VALIDATION_H
diff --git a/vertex.vert b/vertex.vert
index 39c5faa..4169618 100644
--- a/vertex.vert
+++ b/vertex.vert
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#version 450
#extension GL_ARB_separate_shader_objects : enable
diff --git a/vulkan.c b/vulkan.c
index c20a436..e2e37c9 100644
--- a/vulkan.c
+++ b/vulkan.c
@@ -1,3 +1,5 @@
+// SPDX-FileCopyrightText: 2018 Tomasz Kramkowski <tomasz@kramkow.ski>
+// SPDX-License-Identifier: CC0-1.0
#include <vulkan/vulkan.h>
#include <GLFW/glfw3.h>
#include <assert.h>
@@ -74,6 +76,8 @@ struct swpdtl {
static GLFWwindow *createwin(int width, int height, const char *title)
{
+ assert(title != NULL);
+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
@@ -115,8 +119,6 @@ static VkInstance createinst(void)
.enabledLayerCount = layers.count,
.ppEnabledLayerNames = layers.list,
};
-
-
res = vkCreateInstance(&info, NULL, &inst);
if (res != VK_SUCCESS)
eprintf("Could not create instance");
@@ -138,7 +140,7 @@ static bool hasdevexts(VkPhysicalDevice phy)
vkEnumerateDeviceExtensionProperties(phy, NULL, &nextprops, extprops);
for (uint32_t pi = 0; pi < nextprops; pi++) {
- for (int xi = 0; xi < NELEM(devexts); xi++) {
+ for (size_t xi = 0; xi < NELEM(devexts); xi++) {
if (strcmp(devexts[xi], extprops[pi].extensionName) == 0) {
hasext[xi] = true;
break;
@@ -148,7 +150,7 @@ static bool hasdevexts(VkPhysicalDevice phy)
free(extprops);
- for (int i = 0; i < NELEM(hasext); i++)
+ for (size_t i = 0; i < NELEM(hasext); i++)
if (!hasext[i])
return false;
@@ -158,6 +160,7 @@ static bool hasdevexts(VkPhysicalDevice phy)
static bool isdevsuitable(VkPhysicalDevice phy, const int *qf, const struct swpdtl *sdtl)
{
assert(qf != NULL);
+ assert(sdtl != NULL);
return qf[QF_GRAPHICS] >= 0 && qf[QF_PRESENT] >= 0 &&
hasdevexts(phy) && sdtl->fmts.count > 0 &&
@@ -219,6 +222,7 @@ static VkPhysicalDevice pickphy(int *qf, struct swpdtl *sdtl, VkInstance inst, V
uint32_t nphys;
assert(qf != NULL);
+ assert(sdtl != NULL);
vkEnumeratePhysicalDevices(inst, &nphys, NULL);
phys = emalloc(nphys * sizeof *phys);
@@ -247,9 +251,13 @@ static int loaddqcinfs(VkDeviceQueueCreateInfo *dqcinfs, const int *qf, const fl
{
int ndqcinfs = 0;
+ assert(dqcinfs != NULL);
+ assert(qf != NULL);
+ assert(prio != NULL);
+
for (int fi = 0; fi < QF_MAX; fi++) {
for (int cii = 0; cii < fi; cii++)
- if (dqcinfs[cii].queueFamilyIndex == qf[fi])
+ if (dqcinfs[cii].queueFamilyIndex == (uint32_t)qf[fi])
goto next;
dqcinfs[ndqcinfs++] = (VkDeviceQueueCreateInfo){
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
@@ -272,6 +280,8 @@ static VkDevice createdev(VkPhysicalDevice phy, const int *qf)
VkDevice dev;
VkResult res;
+ assert(qf != NULL);
+
ndqcinfs = loaddqcinfs(dqcinfs, qf, &(float){ 1 });
validation_info(&layers, NULL);
info = (VkDeviceCreateInfo){
@@ -328,14 +338,20 @@ static VkExtent2D getswpextent(const VkSurfaceCapabilitiesKHR *caps)
{
VkExtent2D extent = { WINWIDTH, WINHEIGHT };
+ assert(caps != NULL);
+
if (caps->currentExtent.width != UINT32_MAX)
return caps->currentExtent;
- if (extent.width > caps->maxImageExtent.width) extent.width = caps->maxImageExtent.width;
- if (extent.width < caps->minImageExtent.width) extent.width = caps->minImageExtent.width;
+ if (extent.width > caps->maxImageExtent.width)
+ extent.width = caps->maxImageExtent.width;
+ if (extent.width < caps->minImageExtent.width)
+ extent.width = caps->minImageExtent.width;
- if (extent.height > caps->maxImageExtent.height) extent.height = caps->maxImageExtent.height;
- if (extent.height < caps->minImageExtent.height) extent.height = caps->minImageExtent.height;
+ if (extent.height > caps->maxImageExtent.height)
+ extent.height = caps->maxImageExtent.height;
+ if (extent.height < caps->minImageExtent.height)
+ extent.height = caps->minImageExtent.height;
return extent;
}
@@ -382,7 +398,6 @@ static void createswp(struct swp *swp, VkSurfaceKHR surf, VkDevice dev, const in
.clipped = VK_TRUE,
.oldSwapchain = VK_NULL_HANDLE,
};
-
res = vkCreateSwapchainKHR(dev, &info, NULL, &swp->swp);
if (res != VK_SUCCESS)
eprintf("Could not create swapchain");
@@ -438,6 +453,8 @@ static void createviews(struct views *views, VkDevice dev, const struct swpimgs
static void destroyviews(struct views *views, VkDevice dev)
{
+ assert(views != NULL);
+
LIST_FOREACH(views, i) vkDestroyImageView(dev, views->list[i], NULL);
free(views->list);
}
@@ -455,7 +472,6 @@ static VkShaderModule createsmod(VkDevice dev, const void *data, size_t size)
.codeSize = size,
.pCode = data,
};
-
res = vkCreateShaderModule(dev, &smcinf, NULL, &smod);
if (res != VK_SUCCESS)
eprintf("Could not create shader module");
@@ -501,7 +517,6 @@ static VkRenderPass createpass(VkDevice dev, VkFormat fmt)
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
};
-
res = vkCreateRenderPass(dev, &info, NULL, &pass);
if (res != VK_SUCCESS)
eprintf("Could not create render pass");
@@ -527,7 +542,6 @@ static void createpipeline(struct ppln *ppln, VkDevice dev,
/* .pushConstantRangeCount = 0, */
/* .pPushConstantRanges = 0, */
};
-
res = vkCreatePipelineLayout(dev, &plcinf, NULL, &ppln->layout);
if (res != VK_SUCCESS)
eprintf("Could not create pipeline layout");
@@ -629,7 +643,6 @@ static void createpipeline(struct ppln *ppln, VkDevice dev,
.subpass = 0,
.basePipelineHandle = VK_NULL_HANDLE,
};
-
res = vkCreateGraphicsPipelines(dev, VK_NULL_HANDLE, 1, &gpcinf, NULL, &ppln->ppln);
if (res != VK_SUCCESS)
eprintf("Could not create graphics pipeline");
@@ -640,6 +653,8 @@ static void createpipeline(struct ppln *ppln, VkDevice dev,
static void destroyppln(struct ppln *ppln, VkDevice dev)
{
+ assert(ppln != NULL);
+
vkDestroyPipeline(dev, ppln->ppln, NULL);
vkDestroyPipelineLayout(dev, ppln->layout, NULL);
}
@@ -651,6 +666,7 @@ static void createfbs(struct fbs *fbs, VkDevice dev, const struct views *views,
assert(fbs != NULL);
assert(views != NULL);
+ assert(extent != NULL);
*fbs = (struct fbs){ .count = views->count };
LIST_REALLOC(fbs);
@@ -673,13 +689,15 @@ static void createfbs(struct fbs *fbs, VkDevice dev, const struct views *views,
static void destroyfbs(struct fbs *fbs, VkDevice dev)
{
+ assert(fbs != NULL);
+
LIST_FOREACH(fbs, i) vkDestroyFramebuffer(dev, fbs->list[i], NULL);
free(fbs->list);
}
static VkCommandPool createcpool(struct cmdbufs *cmdbufs, VkDevice dev, const int *qf,
const struct fbs *fbs, VkRenderPass pass,
- VkExtent2D *extent, const struct ppln *ppln)
+ const VkExtent2D *extent, const struct ppln *ppln)
{
VkCommandBufferAllocateInfo cbainf;
VkCommandPoolCreateInfo cpcinf;
@@ -688,6 +706,9 @@ static VkCommandPool createcpool(struct cmdbufs *cmdbufs, VkDevice dev, const in
assert(cmdbufs != NULL);
assert(qf != NULL);
+ assert(fbs != NULL);
+ assert(extent != NULL);
+ assert(ppln != NULL);
cpcinf = (VkCommandPoolCreateInfo){
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
@@ -716,6 +737,7 @@ static VkCommandPool createcpool(struct cmdbufs *cmdbufs, VkDevice dev, const in
.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
/* .pInheritanceInfo = NULL, */
});
+
vkCmdBeginRenderPass(cmdbufs->list[i], &(VkRenderPassBeginInfo){
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.renderPass = pass,
@@ -729,7 +751,9 @@ static VkCommandPool createcpool(struct cmdbufs *cmdbufs, VkDevice dev, const in
}
},
}, VK_SUBPASS_CONTENTS_INLINE);
- vkCmdBindPipeline(cmdbufs->list[i], VK_PIPELINE_BIND_POINT_GRAPHICS, ppln->ppln);
+
+ vkCmdBindPipeline(cmdbufs->list[i],
+ VK_PIPELINE_BIND_POINT_GRAPHICS, ppln->ppln);
vkCmdDraw(cmdbufs->list[i], 3, 1, 0, 0);
vkCmdEndRenderPass(cmdbufs->list[i]);
res = vkEndCommandBuffer(cmdbufs->list[i]);
@@ -762,6 +786,8 @@ void drawframe(VkDevice dev, VkSwapchainKHR swp, VkQueue graphq,
VkSubmitInfo sinf;
uint32_t i;
+ assert(cmdbufs != NULL);
+
vkAcquireNextImageKHR(dev, swp, UINT64_MAX, semavail, VK_NULL_HANDLE, &i);
sinf = (VkSubmitInfo){
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
@@ -786,7 +812,6 @@ void drawframe(VkDevice dev, VkSwapchainKHR swp, VkQueue graphq,
.pImageIndices = &i,
/* .pResults = NULL, */
};
-
vkQueuePresentKHR(presq, &pinf);
}