Fix last of vertex rendering bugs
This commit is contained in:
parent
b9bb20c398
commit
83371003d1
1 changed files with 22 additions and 23 deletions
|
@ -48,6 +48,8 @@ static VkDeviceMemory vertex_memory = VK_NULL_HANDLE;
|
|||
struct ShaderProgramVulkan {
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
|
||||
uint8_t num_inputs;
|
||||
bool used_textures[2];
|
||||
};
|
||||
|
||||
std::unordered_map<uint32_t, ShaderProgramVulkan*> cached_shaders;
|
||||
|
@ -109,10 +111,10 @@ static std::string gfx_vulkan_create_vertex_shader(const CCFeatures features) {
|
|||
src += "layout(location = " + std::to_string(next_input++) + ") in vec2 uv;\n";
|
||||
}
|
||||
|
||||
if(needs_screenpos) {
|
||||
/*if(needs_screenpos) {
|
||||
src += "layout(location = " + std::to_string(next_input++) + ") in vec4 screen_pos;\n";
|
||||
}
|
||||
|
||||
*/
|
||||
if(uses_fog) {
|
||||
src += "layout(location = " + std::to_string(next_input++) + ") in vec4 fog;\n";
|
||||
}
|
||||
|
@ -291,6 +293,7 @@ static std::pair<VkPipeline, VkPipelineLayout> gfx_vulkan_create_pipeline(const
|
|||
|
||||
VkVertexInputBindingDescription binding = {};
|
||||
binding.stride = sizeof(float) * num_floats;
|
||||
binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo vertex_input_state = {};
|
||||
vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
|
@ -397,17 +400,23 @@ static struct ShaderProgram *gfx_vulkan_renderer_create_and_load_new_shader(uint
|
|||
|
||||
gfx_vulkan_renderer_load_shader(reinterpret_cast<ShaderProgram *>(shader));
|
||||
|
||||
shader->used_textures[0] = cc_features.used_textures[0];
|
||||
shader->used_textures[1] = cc_features.used_textures[1];
|
||||
shader->num_inputs = cc_features.num_inputs;
|
||||
|
||||
return reinterpret_cast<ShaderProgram *>(shader);
|
||||
}
|
||||
|
||||
static struct ShaderProgram *gfx_vulkan_renderer_lookup_shader(uint32_t shader_id) {
|
||||
return NULL;
|
||||
return reinterpret_cast<ShaderProgram *>(cached_shaders[shader_id]);
|
||||
}
|
||||
|
||||
static void gfx_vulkan_renderer_shader_get_info(struct ShaderProgram *prg, uint8_t *num_inputs, bool used_textures[2]) {
|
||||
*num_inputs = 0;
|
||||
used_textures[0] = false;
|
||||
used_textures[1] = false;
|
||||
ShaderProgramVulkan* vulkan = reinterpret_cast<ShaderProgramVulkan *>(prg);
|
||||
|
||||
*num_inputs = vulkan->num_inputs;
|
||||
used_textures[0] = vulkan->used_textures[0];
|
||||
used_textures[1] = vulkan->used_textures[1];
|
||||
}
|
||||
|
||||
static uint32_t gfx_vulkan_renderer_new_texture(void) {
|
||||
|
@ -839,13 +848,15 @@ static void gfx_vulkan_create_framebuffers() {
|
|||
}
|
||||
}
|
||||
|
||||
static void* mapped_data = nullptr;
|
||||
|
||||
static void gfx_vulkan_create_buffers() {
|
||||
vkDeviceWaitIdle(device);
|
||||
|
||||
// create buffer
|
||||
VkBufferCreateInfo create_info = {};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
create_info.size = 60000;
|
||||
create_info.size = 1048576;
|
||||
create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
|
||||
|
@ -866,6 +877,8 @@ static void gfx_vulkan_create_buffers() {
|
|||
vkAllocateMemory(device, &allocate_info, nullptr, &vertex_memory);
|
||||
|
||||
vkBindBufferMemory(device, vertex_buffer, vertex_memory, 0);
|
||||
|
||||
vkMapMemory(device, vertex_memory, 0, VK_WHOLE_SIZE, 0, &mapped_data);
|
||||
}
|
||||
|
||||
static void gfx_vulkan_renderer_init(void) {
|
||||
|
@ -973,23 +986,9 @@ static void gfx_vulkan_renderer_load_shader(struct ShaderProgram *new_prg) {
|
|||
}
|
||||
|
||||
static void gfx_vulkan_renderer_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris) {
|
||||
if(last_program != nullptr) {
|
||||
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, last_program->pipeline);
|
||||
}
|
||||
vkCmdBindPipeline(current_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, last_program->pipeline);
|
||||
|
||||
void* mapped_data = nullptr;
|
||||
vkMapMemory(device, vertex_memory, buf_vbo_offset, buf_vbo_len * sizeof(float), 0, &mapped_data);
|
||||
|
||||
memcpy(mapped_data, buf_vbo, buf_vbo_len * sizeof(float));
|
||||
|
||||
VkMappedMemoryRange range = {};
|
||||
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
range.memory = vertex_memory;
|
||||
range.size = buf_vbo_len * sizeof(float);
|
||||
range.offset = buf_vbo_offset;
|
||||
vkFlushMappedMemoryRanges(device, 1, &range);
|
||||
|
||||
vkUnmapMemory(device, vertex_memory);
|
||||
memcpy((uint8_t *)mapped_data + buf_vbo_offset, buf_vbo, buf_vbo_len * sizeof(float));
|
||||
|
||||
VkDeviceSize offsets[] = {static_cast<VkDeviceSize>(buf_vbo_offset)};
|
||||
vkCmdBindVertexBuffers(current_cmd, 0, 1, &vertex_buffer, offsets);
|
||||
|
|
Loading…
Add table
Reference in a new issue