Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
Implement ShaderModule stub
Browse files Browse the repository at this point in the history
  • Loading branch information
abergmeier committed Nov 21, 2019
1 parent 617a4ac commit 8cef0e0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/broadcom/vulkan/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_query_pool, VkQueryPool)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_render_pass, VkRenderPass)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_sampler, VkSampler)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_semaphore, VkSemaphore)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_shader_module, VkShaderModule)

#endif // V3DVK_COMMON_H
1 change: 1 addition & 0 deletions src/broadcom/vulkan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ libv3dvk_files = files(
'v3dvk_macro.h',
'v3dvk_sampler.c',
'v3dvk_semaphore.c',
'v3dvk_shader.c',
'v3dvk_util.c',
'wsi.c',
)
Expand Down
50 changes: 50 additions & 0 deletions src/broadcom/vulkan/v3dvk_shader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#include "common.h"
#include "device.h"
#include "vk_alloc.h"
#include "v3dvk_error.h"
#include "v3dvk_shader.h"
#include "util/mesa-sha1.h"

VkResult
v3dvk_CreateShaderModule(VkDevice _device,
const VkShaderModuleCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkShaderModule *pShaderModule)
{
V3DVK_FROM_HANDLE(v3dvk_device, device, _device);
struct v3dvk_shader_module *module;

assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
assert(pCreateInfo->flags == 0);
assert(pCreateInfo->codeSize % 4 == 0);

module = vk_alloc2(&device->alloc, pAllocator,
sizeof(*module) + pCreateInfo->codeSize, 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (module == NULL)
return v3dvk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);

module->code_size = pCreateInfo->codeSize;
memcpy(module->code, pCreateInfo->pCode, pCreateInfo->codeSize);

_mesa_sha1_compute(module->code, module->code_size, module->sha1);

*pShaderModule = v3dvk_shader_module_to_handle(module);

return VK_SUCCESS;
}

void
v3dvk_DestroyShaderModule(VkDevice _device,
VkShaderModule _module,
const VkAllocationCallbacks *pAllocator)
{
V3DVK_FROM_HANDLE(v3dvk_device, device, _device);
V3DVK_FROM_HANDLE(v3dvk_shader_module, module, _module);

if (!module)
return;

vk_free2(&device->alloc, pAllocator, module);
}
15 changes: 15 additions & 0 deletions src/broadcom/vulkan/v3dvk_shader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#ifndef V3DVK_SHADER_H
#define V3DVK_SHADER_H

#include <stdint.h>

struct v3dvk_shader_module
{
unsigned char sha1[20];

uint32_t code_size;
const uint32_t *code[0];
};

#endif

0 comments on commit 8cef0e0

Please sign in to comment.