upload metal buffers
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "core/commands/command_buffer/metal_command_buffer.h"
|
#include "core/commands/command_buffer/metal_command_buffer.h"
|
||||||
#include "core/pipelines/graphics_pipeline/metal_graphics_pipeline.h"
|
#include "core/pipelines/graphics_pipeline/metal_graphics_pipeline.h"
|
||||||
#include "core/buffer/metal_buffer.h"
|
#include "core/buffer/metal_buffer.h"
|
||||||
|
#include "core/uniforms/metal_uniform.h"
|
||||||
#import <Metal/MTLRenderCommandEncoder.h>
|
#import <Metal/MTLRenderCommandEncoder.h>
|
||||||
|
|
||||||
void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) {
|
void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) {
|
||||||
@@ -111,11 +112,16 @@ void gnCommandDrawIndexedFn(gnCommandBufferHandle buffer, gnIndexType type, int
|
|||||||
baseVertex:vertexOffset
|
baseVertex:vertexOffset
|
||||||
baseInstance:firstInstance
|
baseInstance:firstInstance
|
||||||
];
|
];
|
||||||
|
}
|
||||||
// [encoder drawIndexedPrimitives:(MTLPrimitiveType)
|
|
||||||
// indexCount:indexCount
|
void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform) {
|
||||||
// indexType:((type == GN_UINT32) ? MTLIndexTypeUInt32 : MTLIndexTypeUInt16)
|
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
|
||||||
// indexBuffer:buffer->commandBuffer->indexBuffer->buffer->buffer
|
if (uniform->uniform->type == GN_UNIFORM_BUFFER_DESCRIPTOR) {
|
||||||
// indexBufferOffset:firstIndex
|
gnBufferUniformInfo info = *(gnBufferUniformInfo*)uniform->uniform->data;
|
||||||
// ];
|
|
||||||
|
[encoder setVertexBuffer:info.buffer->buffer->buffer
|
||||||
|
offset:info.offset
|
||||||
|
atIndex:(info.binding + 1)
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,6 @@ gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOu
|
|||||||
spvc_result res = spvc_compiler_compile(compiler, &result);
|
spvc_result res = spvc_compiler_compile(compiler, &result);
|
||||||
if (res != SPVC_SUCCESS)
|
if (res != SPVC_SUCCESS)
|
||||||
return GN_FAILED_TO_CONVERT_SHADER_CODE;
|
return GN_FAILED_TO_CONVERT_SHADER_CODE;
|
||||||
// this is where to use result
|
|
||||||
|
|
||||||
NSError* error = nil;
|
NSError* error = nil;
|
||||||
MTLCompileOptions* mtloptions = nil;
|
MTLCompileOptions* mtloptions = nil;
|
||||||
|
7
rendering_api/metal/src/core/uniforms/metal_uniform.c
Normal file
7
rendering_api/metal/src/core/uniforms/metal_uniform.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <core/uniforms/gryphn_uniform.h>
|
||||||
|
#include "metal_uniform.h"
|
||||||
|
|
||||||
|
void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) {
|
||||||
|
uniform->uniform->data = malloc(sizeof(gnBufferUniformInfo));
|
||||||
|
memcpy(uniform->uniform->data, info, sizeof(gnBufferUniformInfo));
|
||||||
|
}
|
8
rendering_api/metal/src/core/uniforms/metal_uniform.h
Normal file
8
rendering_api/metal/src/core/uniforms/metal_uniform.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "core/uniforms/gryphn_uniform.h"
|
||||||
|
#include <core/uniforms/gryphn_uniform_pool.h>
|
||||||
|
|
||||||
|
typedef struct gnPlatformUniform_t {
|
||||||
|
gnUniformType type;
|
||||||
|
void* data;
|
||||||
|
} gnPlatformUniform;
|
19
rendering_api/metal/src/core/uniforms/vulkan_uniform_pool.c
Normal file
19
rendering_api/metal/src/core/uniforms/vulkan_uniform_pool.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <core/uniforms/gryphn_uniform_pool.h>
|
||||||
|
#include <core/uniforms/gryphn_uniform.h>
|
||||||
|
#include "metal_uniform.h"
|
||||||
|
|
||||||
|
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformLayout layout) {
|
||||||
|
gnUniform* uniforms = malloc(sizeof(gnUniform) * layout.uniformBindingCount);
|
||||||
|
for (int i = 0; i < layout.uniformBindingCount; i++) {
|
||||||
|
uniforms[i] = malloc(sizeof(struct gnUniform_t));
|
||||||
|
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
|
||||||
|
uniforms[i]->uniform->type = layout.uniformBindings[i].type;
|
||||||
|
}
|
||||||
|
return uniforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gnDestroyUniformPoolFn(gnUniformPool pool) { }
|
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
#include <core/uniforms/gryphn_uniform_pool.h>
|
||||||
|
|
||||||
|
struct gnPlatformUniformPool_t {
|
||||||
|
};
|
@@ -47,11 +47,11 @@ gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformLa
|
|||||||
.pSetLayouts = pool->uniformPool->pools[pool->uniformPool->poolCount].layouts
|
.pSetLayouts = pool->uniformPool->pools[pool->uniformPool->poolCount].layouts
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorSet* sets = malloc(sizeof(VkDescriptorSet) * pool->uniformPool->pools[pool->uniformPool->poolCount].layoutCount);
|
VkDescriptorSet* sets = malloc(sizeof(VkDescriptorSet) * layout.uniformBindingCount);
|
||||||
if (vkAllocateDescriptorSets(pool->device->outputDevice->device, &allocInfo, sets) != VK_SUCCESS)
|
if (vkAllocateDescriptorSets(pool->device->outputDevice->device, &allocInfo, sets) != VK_SUCCESS)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
gnUniform* uniforms = malloc(sizeof(gnUniform) * pool->uniformPool->pools[pool->uniformPool->poolCount].layoutCount);
|
gnUniform* uniforms = malloc(sizeof(gnUniform) * layout.uniformBindingCount);
|
||||||
for (int i = 0; i < pool->uniformPool->pools[pool->uniformPool->poolCount].layoutCount; i++) {
|
for (int i = 0; i < pool->uniformPool->pools[pool->uniformPool->poolCount].layoutCount; i++) {
|
||||||
uniforms[i] = malloc(sizeof(struct gnUniform_t));
|
uniforms[i] = malloc(sizeof(struct gnUniform_t));
|
||||||
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
|
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
#include "core/gryphn_handles.h"
|
#include "core/gryphn_handles.h"
|
||||||
|
|
||||||
typedef struct gnBufferUniformInfo {
|
typedef struct gnBufferUniformInfo {
|
||||||
gnUniform uniform;
|
|
||||||
uint32_t binding;
|
uint32_t binding;
|
||||||
gnBuffer buffer;
|
gnBuffer buffer;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
|
Reference in New Issue
Block a user