2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2018 The Dawn Authors
|
2018-01-09 18:50:07 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "backend/vulkan/ShaderModuleVk.h"
|
|
|
|
|
2018-06-18 20:18:50 +00:00
|
|
|
#include "backend/vulkan/DeviceVk.h"
|
2018-01-09 18:50:07 +00:00
|
|
|
#include "backend/vulkan/FencedDeleter.h"
|
|
|
|
|
|
|
|
#include <spirv-cross/spirv_cross.hpp>
|
|
|
|
|
|
|
|
namespace backend { namespace vulkan {
|
|
|
|
|
|
|
|
ShaderModule::ShaderModule(ShaderModuleBuilder* builder) : ShaderModuleBase(builder) {
|
|
|
|
std::vector<uint32_t> spirv = builder->AcquireSpirv();
|
|
|
|
|
|
|
|
// Use SPIRV-Cross to extract info from the SPIRV even if Vulkan consumes SPIRV. We want to
|
|
|
|
// have a translation step eventually anyway.
|
|
|
|
spirv_cross::Compiler compiler(spirv);
|
|
|
|
ExtractSpirvInfo(compiler);
|
|
|
|
|
|
|
|
VkShaderModuleCreateInfo createInfo;
|
|
|
|
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
|
|
|
createInfo.pNext = nullptr;
|
|
|
|
createInfo.flags = 0;
|
|
|
|
createInfo.codeSize = spirv.size() * sizeof(uint32_t);
|
|
|
|
createInfo.pCode = spirv.data();
|
|
|
|
|
|
|
|
Device* device = ToBackend(GetDevice());
|
|
|
|
|
|
|
|
if (device->fn.CreateShaderModule(device->GetVkDevice(), &createInfo, nullptr, &mHandle) !=
|
|
|
|
VK_SUCCESS) {
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderModule::~ShaderModule() {
|
|
|
|
Device* device = ToBackend(GetDevice());
|
|
|
|
|
|
|
|
if (mHandle != VK_NULL_HANDLE) {
|
|
|
|
device->GetFencedDeleter()->DeleteWhenUnused(mHandle);
|
|
|
|
mHandle = VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VkShaderModule ShaderModule::GetHandle() const {
|
|
|
|
return mHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
}} // namespace backend::vulkan
|