Vk_Vertex, Vk_Vertex2 - vertex formats for single/multi textured geometry correspondingly.
This commit is contained in:
parent
8a4cce66ed
commit
886ea847ca
|
|
@ -488,12 +488,21 @@ static VkPipeline create_pipeline(const Vk_Pipeline_Desc& desc) {
|
||||||
vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
vertex_input_state.pNext = nullptr;
|
vertex_input_state.pNext = nullptr;
|
||||||
vertex_input_state.flags = 0;
|
vertex_input_state.flags = 0;
|
||||||
auto bindings = Vertex::get_bindings();
|
if (desc.shader_type == Vk_Shader_Type::single_texture) {
|
||||||
|
auto bindings = Vk_Vertex::get_bindings();
|
||||||
vertex_input_state.vertexBindingDescriptionCount = (uint32_t)bindings.size();
|
vertex_input_state.vertexBindingDescriptionCount = (uint32_t)bindings.size();
|
||||||
vertex_input_state.pVertexBindingDescriptions = bindings.data();
|
vertex_input_state.pVertexBindingDescriptions = bindings.data();
|
||||||
auto attribs = Vertex::get_attributes();
|
auto attribs = Vk_Vertex::get_attributes();
|
||||||
vertex_input_state.vertexAttributeDescriptionCount = (uint32_t)attribs.size();
|
vertex_input_state.vertexAttributeDescriptionCount = (uint32_t)attribs.size();
|
||||||
vertex_input_state.pVertexAttributeDescriptions = attribs.data();
|
vertex_input_state.pVertexAttributeDescriptions = attribs.data();
|
||||||
|
} else {
|
||||||
|
auto bindings = Vk_Vertex2::get_bindings();
|
||||||
|
vertex_input_state.vertexBindingDescriptionCount = (uint32_t)bindings.size();
|
||||||
|
vertex_input_state.pVertexBindingDescriptions = bindings.data();
|
||||||
|
auto attribs = Vk_Vertex2::get_attributes();
|
||||||
|
vertex_input_state.vertexAttributeDescriptionCount = (uint32_t)attribs.size();
|
||||||
|
vertex_input_state.pVertexAttributeDescriptions = attribs.data();
|
||||||
|
}
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state;
|
VkPipelineInputAssemblyStateCreateInfo input_assembly_state;
|
||||||
input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,11 @@
|
||||||
|
|
||||||
#include "vulkan/vulkan.h"
|
#include "vulkan/vulkan.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../../game/q_shared.h"
|
||||||
|
|
||||||
bool initialize_vulkan(HWND hwnd);
|
bool initialize_vulkan(HWND hwnd);
|
||||||
void deinitialize_vulkan();
|
void deinitialize_vulkan();
|
||||||
|
|
||||||
|
|
@ -53,6 +56,71 @@ struct Vk_Pipeline_Desc {
|
||||||
VkPipeline vk_find_pipeline(const Vk_Pipeline_Desc& desc);
|
VkPipeline vk_find_pipeline(const Vk_Pipeline_Desc& desc);
|
||||||
void vk_destroy_pipelines();
|
void vk_destroy_pipelines();
|
||||||
|
|
||||||
|
// Vertex formats
|
||||||
|
struct Vk_Vertex {
|
||||||
|
vec3_t pos;
|
||||||
|
vec4_t color;
|
||||||
|
vec2_t st;
|
||||||
|
|
||||||
|
static std::array<VkVertexInputBindingDescription, 1> get_bindings() {
|
||||||
|
VkVertexInputBindingDescription binding_desc;
|
||||||
|
binding_desc.binding = 0;
|
||||||
|
binding_desc.stride = sizeof(Vk_Vertex);
|
||||||
|
binding_desc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
return {binding_desc};
|
||||||
|
}
|
||||||
|
static std::array<VkVertexInputAttributeDescription, 3> get_attributes() {
|
||||||
|
VkVertexInputAttributeDescription position_attrib;
|
||||||
|
position_attrib.location = 0;
|
||||||
|
position_attrib.binding = 0;
|
||||||
|
position_attrib.format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||||
|
position_attrib.offset = offsetof(struct Vk_Vertex, pos);
|
||||||
|
|
||||||
|
VkVertexInputAttributeDescription color_attrib;
|
||||||
|
color_attrib.location = 1;
|
||||||
|
color_attrib.binding = 0;
|
||||||
|
color_attrib.format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||||
|
color_attrib.offset = offsetof(struct Vk_Vertex, color);
|
||||||
|
|
||||||
|
VkVertexInputAttributeDescription st_attrib;
|
||||||
|
st_attrib.location = 2;
|
||||||
|
st_attrib.binding = 0;
|
||||||
|
st_attrib.format = VK_FORMAT_R32G32_SFLOAT;
|
||||||
|
st_attrib.offset = offsetof(struct Vk_Vertex, st);
|
||||||
|
|
||||||
|
return {position_attrib, color_attrib, st_attrib};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Vk_Vertex2 : Vk_Vertex {
|
||||||
|
vec2_t st2;
|
||||||
|
|
||||||
|
static std::array<VkVertexInputBindingDescription, 1> get_bindings() {
|
||||||
|
VkVertexInputBindingDescription binding_desc;
|
||||||
|
binding_desc.binding = 0;
|
||||||
|
binding_desc.stride = sizeof(Vk_Vertex2);
|
||||||
|
binding_desc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
return {binding_desc};
|
||||||
|
}
|
||||||
|
static std::array<VkVertexInputAttributeDescription, 4> get_attributes() {
|
||||||
|
auto vk_vertex_attribs = Vk_Vertex::get_attributes();
|
||||||
|
|
||||||
|
std::array<VkVertexInputAttributeDescription, 4> result;
|
||||||
|
result[0] = vk_vertex_attribs[0];
|
||||||
|
result[1] = vk_vertex_attribs[1];
|
||||||
|
result[2] = vk_vertex_attribs[2];
|
||||||
|
|
||||||
|
VkVertexInputAttributeDescription st2_attrib;
|
||||||
|
st2_attrib.location = 3;
|
||||||
|
st2_attrib.binding = 0;
|
||||||
|
st2_attrib.format = VK_FORMAT_R32G32_SFLOAT;
|
||||||
|
st2_attrib.offset = offsetof(struct Vk_Vertex2, st2);
|
||||||
|
result[3] = st2_attrib;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Shaders.
|
// Shaders.
|
||||||
extern unsigned char single_texture_vert_spv[];
|
extern unsigned char single_texture_vert_spv[];
|
||||||
extern long long single_texture_vert_spv_size;
|
extern long long single_texture_vert_spv_size;
|
||||||
|
|
|
||||||
|
|
@ -583,19 +583,19 @@ void Vulkan_Demo::render_tess(const shaderStage_t* stage) {
|
||||||
fflush(logfile);
|
fflush(logfile);
|
||||||
|
|
||||||
void* data;
|
void* data;
|
||||||
VkResult result = vkMapMemory(get_device(), tess_vertex_buffer_memory, tess_vertex_buffer_offset, tess.numVertexes * sizeof(Vertex), 0, &data);
|
VkResult result = vkMapMemory(get_device(), tess_vertex_buffer_memory, tess_vertex_buffer_offset, tess.numVertexes * sizeof(Vk_Vertex), 0, &data);
|
||||||
check_vk_result(result, "vkMapMemory");
|
check_vk_result(result, "vkMapMemory");
|
||||||
Vertex* v = (Vertex*)data;
|
Vk_Vertex* v = (Vk_Vertex*)data;
|
||||||
for (int i = 0; i < tess.numVertexes; i++, v++) {
|
for (int i = 0; i < tess.numVertexes; i++, v++) {
|
||||||
v->pos.x = tess.xyz[i][0];
|
v->pos[0] = tess.xyz[i][0];
|
||||||
v->pos.y = tess.xyz[i][1];
|
v->pos[1] = tess.xyz[i][1];
|
||||||
v->pos.z = tess.xyz[i][2];
|
v->pos[2] = tess.xyz[i][2];
|
||||||
v->color[0] = tess.svars.colors[i][0] / 255.0f;
|
v->color[0] = tess.svars.colors[i][0] / 255.0f;
|
||||||
v->color[1] = tess.svars.colors[i][1] / 255.0f;
|
v->color[1] = tess.svars.colors[i][1] / 255.0f;
|
||||||
v->color[2] = tess.svars.colors[i][2] / 255.0f;
|
v->color[2] = tess.svars.colors[i][2] / 255.0f;
|
||||||
v->color[3] = tess.svars.colors[i][3] / 255.0f;
|
v->color[3] = tess.svars.colors[i][3] / 255.0f;
|
||||||
v->tex_coord[0] = tess.svars.texcoords[0][i][0];
|
v->st[0] = tess.svars.texcoords[0][i][0];
|
||||||
v->tex_coord[1] = tess.svars.texcoords[0][i][1];
|
v->st[1] = tess.svars.texcoords[0][i][1];
|
||||||
}
|
}
|
||||||
vkUnmapMemory(get_device(), tess_vertex_buffer_memory);
|
vkUnmapMemory(get_device(), tess_vertex_buffer_memory);
|
||||||
|
|
||||||
|
|
@ -653,7 +653,7 @@ void Vulkan_Demo::render_tess(const shaderStage_t* stage) {
|
||||||
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, stage->vk_pipeline);
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, stage->vk_pipeline);
|
||||||
|
|
||||||
vkCmdDrawIndexed(command_buffer, tess.numIndexes, 1, 0, 0, 0);
|
vkCmdDrawIndexed(command_buffer, tess.numIndexes, 1, 0, 0, 0);
|
||||||
tess_vertex_buffer_offset += tess.numVertexes * sizeof(Vertex);
|
tess_vertex_buffer_offset += tess.numVertexes * sizeof(Vk_Vertex);
|
||||||
tess_index_buffer_offset += tess.numIndexes * sizeof(uint32_t);
|
tess_index_buffer_offset += tess.numIndexes * sizeof(uint32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -662,21 +662,21 @@ void Vulkan_Demo::render_tess_multi(const shaderStage_t* stage) {
|
||||||
fflush(logfile);
|
fflush(logfile);
|
||||||
|
|
||||||
void* data;
|
void* data;
|
||||||
VkResult result = vkMapMemory(get_device(), tess_vertex_buffer_memory, tess_vertex_buffer_offset, tess.numVertexes * sizeof(Vertex), 0, &data);
|
VkResult result = vkMapMemory(get_device(), tess_vertex_buffer_memory, tess_vertex_buffer_offset, tess.numVertexes * sizeof(Vk_Vertex2), 0, &data);
|
||||||
check_vk_result(result, "vkMapMemory");
|
check_vk_result(result, "vkMapMemory");
|
||||||
Vertex* v = (Vertex*)data;
|
Vk_Vertex2* v = (Vk_Vertex2*)data;
|
||||||
for (int i = 0; i < tess.numVertexes; i++, v++) {
|
for (int i = 0; i < tess.numVertexes; i++, v++) {
|
||||||
v->pos.x = tess.xyz[i][0];
|
v->pos[0] = tess.xyz[i][0];
|
||||||
v->pos.y = tess.xyz[i][1];
|
v->pos[1] = tess.xyz[i][1];
|
||||||
v->pos.z = tess.xyz[i][2];
|
v->pos[2] = tess.xyz[i][2];
|
||||||
v->color[0] = tess.svars.colors[i][0] / 255.0f;
|
v->color[0] = tess.svars.colors[i][0] / 255.0f;
|
||||||
v->color[1] = tess.svars.colors[i][1] / 255.0f;
|
v->color[1] = tess.svars.colors[i][1] / 255.0f;
|
||||||
v->color[2] = tess.svars.colors[i][2] / 255.0f;
|
v->color[2] = tess.svars.colors[i][2] / 255.0f;
|
||||||
v->color[3] = tess.svars.colors[i][3] / 255.0f;
|
v->color[3] = tess.svars.colors[i][3] / 255.0f;
|
||||||
v->tex_coord[0] = tess.svars.texcoords[0][i][0];
|
v->st[0] = tess.svars.texcoords[0][i][0];
|
||||||
v->tex_coord[1] = tess.svars.texcoords[0][i][1];
|
v->st[1] = tess.svars.texcoords[0][i][1];
|
||||||
v->tex_coord2[0] = tess.svars.texcoords[1][i][0];
|
v->st2[0] = tess.svars.texcoords[1][i][0];
|
||||||
v->tex_coord2[1] = tess.svars.texcoords[1][i][1];
|
v->st2[1] = tess.svars.texcoords[1][i][1];
|
||||||
}
|
}
|
||||||
vkUnmapMemory(get_device(), tess_vertex_buffer_memory);
|
vkUnmapMemory(get_device(), tess_vertex_buffer_memory);
|
||||||
|
|
||||||
|
|
@ -741,6 +741,6 @@ void Vulkan_Demo::render_tess_multi(const shaderStage_t* stage) {
|
||||||
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, stage->vk_pipeline);
|
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, stage->vk_pipeline);
|
||||||
|
|
||||||
vkCmdDrawIndexed(command_buffer, tess.numIndexes, 1, 0, 0, 0);
|
vkCmdDrawIndexed(command_buffer, tess.numIndexes, 1, 0, 0, 0);
|
||||||
tess_vertex_buffer_offset += tess.numVertexes * sizeof(Vertex);
|
tess_vertex_buffer_offset += tess.numVertexes * sizeof(Vk_Vertex2);
|
||||||
tess_index_buffer_offset += tess.numIndexes * sizeof(uint32_t);
|
tess_index_buffer_offset += tess.numIndexes * sizeof(uint32_t);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,49 +12,6 @@
|
||||||
#include "vk.h"
|
#include "vk.h"
|
||||||
#include "tr_local.h"
|
#include "tr_local.h"
|
||||||
|
|
||||||
struct Vertex {
|
|
||||||
glm::vec3 pos;
|
|
||||||
glm::vec4 color;
|
|
||||||
glm::vec2 tex_coord;
|
|
||||||
glm::vec2 tex_coord2;
|
|
||||||
|
|
||||||
static std::array<VkVertexInputBindingDescription, 1> get_bindings() {
|
|
||||||
VkVertexInputBindingDescription binding_desc;
|
|
||||||
binding_desc.binding = 0;
|
|
||||||
binding_desc.stride = sizeof(Vertex);
|
|
||||||
binding_desc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
|
||||||
return {binding_desc};
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::array<VkVertexInputAttributeDescription, 4> get_attributes() {
|
|
||||||
VkVertexInputAttributeDescription position_attrib;
|
|
||||||
position_attrib.location = 0;
|
|
||||||
position_attrib.binding = 0;
|
|
||||||
position_attrib.format = VK_FORMAT_R32G32B32_SFLOAT;
|
|
||||||
position_attrib.offset = offsetof(struct Vertex, pos);
|
|
||||||
|
|
||||||
VkVertexInputAttributeDescription color_attrib;
|
|
||||||
color_attrib.location = 1;
|
|
||||||
color_attrib.binding = 0;
|
|
||||||
color_attrib.format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
||||||
color_attrib.offset = offsetof(struct Vertex, color);
|
|
||||||
|
|
||||||
VkVertexInputAttributeDescription tex_coord_attrib;
|
|
||||||
tex_coord_attrib.location = 2;
|
|
||||||
tex_coord_attrib.binding = 0;
|
|
||||||
tex_coord_attrib.format = VK_FORMAT_R32G32_SFLOAT;
|
|
||||||
tex_coord_attrib.offset = offsetof(struct Vertex, tex_coord);
|
|
||||||
|
|
||||||
VkVertexInputAttributeDescription tex_coord2_attrib;
|
|
||||||
tex_coord2_attrib.location = 3;
|
|
||||||
tex_coord2_attrib.binding = 0;
|
|
||||||
tex_coord2_attrib.format = VK_FORMAT_R32G32_SFLOAT;
|
|
||||||
tex_coord2_attrib.offset = offsetof(struct Vertex, tex_coord2);
|
|
||||||
|
|
||||||
return {position_attrib, color_attrib, tex_coord_attrib, tex_coord2_attrib};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Vulkan_Demo {
|
class Vulkan_Demo {
|
||||||
public:
|
public:
|
||||||
Vulkan_Demo(int window_width, int window_height);
|
Vulkan_Demo(int window_width, int window_height);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user