#include "dawn/utils/WGPUHelpers.h"
#include <cstring>
#include <iomanip>
#include <limits>
#include <mutex>
#include <sstream>
#include "dawn/common/Constants.h"
#include "dawn/common/Log.h"
#include "dawn/common/Numeric.h"
#if TINT_BUILD_SPV_READER
#include "spirv-tools/optimizer.hpp"
#endif
namespace dawn::utils {
#if TINT_BUILD_SPV_READER
wgpu::ShaderModule CreateShaderModuleFromASM(
const wgpu::Device& device,
const char* source,
wgpu::DawnShaderModuleSPIRVOptionsDescriptor* spirv_options) {
wgpu::ShaderModule result = nullptr;
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
DAWN_ASSERT(context != nullptr);
spv_binary spirv = nullptr;
spv_diagnostic diagnostic = nullptr;
if (spvTextToBinary(context, source, strlen(source), &spirv, &diagnostic) == SPV_SUCCESS) {
DAWN_ASSERT(spirv != nullptr);
DAWN_ASSERT(spirv->wordCount <= std::numeric_limits<uint32_t>::max());
wgpu::ShaderModuleSPIRVDescriptor spirvDesc;
spirvDesc.codeSize = static_cast<uint32_t>(spirv->wordCount);
spirvDesc.code = spirv->code;
spirvDesc.nextInChain = spirv_options;
wgpu::ShaderModuleDescriptor descriptor;
descriptor.nextInChain = &spirvDesc;
result = device.CreateShaderModule(&descriptor);
} else {
DAWN_ASSERT(diagnostic != nullptr);
dawn::WarningLog() << "CreateShaderModuleFromASM SPIRV assembly error:"
<< diagnostic->position.line + 1 << ":"
<< diagnostic->position.column + 1 << ": " << diagnostic->error;
}
spvDiagnosticDestroy(diagnostic);
spvBinaryDestroy(spirv);
spvContextDestroy(context);
return result;
}
#endif
wgpu::ShaderModule CreateShaderModule(const wgpu::Device& device, const char* source) { … }
wgpu::ShaderModule CreateShaderModule(const wgpu::Device& device, const std::string& source) { … }
wgpu::Buffer CreateBufferFromData(const wgpu::Device& device,
const void* data,
uint64_t size,
wgpu::BufferUsage usage) { … }
ComboRenderPassDescriptor::ComboRenderPassDescriptor(
const std::vector<wgpu::TextureView>& colorAttachmentInfo,
wgpu::TextureView depthStencil) { … }
ComboRenderPassDescriptor::~ComboRenderPassDescriptor() = default;
ComboRenderPassDescriptor::ComboRenderPassDescriptor(const ComboRenderPassDescriptor& other) { … }
const ComboRenderPassDescriptor& ComboRenderPassDescriptor::operator=(
const ComboRenderPassDescriptor& otherRenderPass) { … }
void ComboRenderPassDescriptor::UnsetDepthStencilLoadStoreOpsForFormat(wgpu::TextureFormat format) { … }
BasicRenderPass::BasicRenderPass()
: … { … }
BasicRenderPass::BasicRenderPass(uint32_t texWidth,
uint32_t texHeight,
wgpu::Texture colorAttachment,
wgpu::TextureFormat textureFormat)
: … { … }
BasicRenderPass CreateBasicRenderPass(const wgpu::Device& device,
uint32_t width,
uint32_t height,
wgpu::TextureFormat format) { … }
wgpu::ImageCopyBuffer CreateImageCopyBuffer(wgpu::Buffer buffer,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage) { … }
wgpu::ImageCopyTexture CreateImageCopyTexture(wgpu::Texture texture,
uint32_t mipLevel,
wgpu::Origin3D origin,
wgpu::TextureAspect aspect) { … }
wgpu::TextureDataLayout CreateTextureDataLayout(uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage) { … }
wgpu::PipelineLayout MakeBasicPipelineLayout(const wgpu::Device& device,
const wgpu::BindGroupLayout* bindGroupLayout) { … }
wgpu::PipelineLayout MakePipelineLayout(const wgpu::Device& device,
std::vector<wgpu::BindGroupLayout> bgls) { … }
wgpu::BindGroupLayout MakeBindGroupLayout(
const wgpu::Device& device,
std::initializer_list<BindingLayoutEntryInitializationHelper> entriesInitializer) { … }
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
uint32_t entryBinding,
wgpu::ShaderStage entryVisibility,
wgpu::BufferBindingType bufferType,
bool bufferHasDynamicOffset,
uint64_t bufferMinBindingSize) { … }
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
uint32_t entryBinding,
wgpu::ShaderStage entryVisibility,
wgpu::SamplerBindingType samplerType) { … }
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
uint32_t entryBinding,
wgpu::ShaderStage entryVisibility,
wgpu::TextureSampleType textureSampleType,
wgpu::TextureViewDimension textureViewDimension,
bool textureMultisampled) { … }
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
uint32_t entryBinding,
wgpu::ShaderStage entryVisibility,
wgpu::StorageTextureAccess storageTextureAccess,
wgpu::TextureFormat format,
wgpu::TextureViewDimension textureViewDimension) { … }
#ifndef __EMSCRIPTEN__
wgpu::ExternalTextureBindingLayout kExternalTextureBindingLayout = …;
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
uint32_t entryBinding,
wgpu::ShaderStage entryVisibility,
wgpu::ExternalTextureBindingLayout* bindingLayout) { … }
BindingInitializationHelper::BindingInitializationHelper(
uint32_t binding,
const wgpu::ExternalTexture& externalTexture)
: … { … }
#endif
BindingLayoutEntryInitializationHelper::BindingLayoutEntryInitializationHelper(
const wgpu::BindGroupLayoutEntry& entry)
: … { … }
BindingInitializationHelper::BindingInitializationHelper(uint32_t binding,
const wgpu::Sampler& sampler)
: … { … }
BindingInitializationHelper::BindingInitializationHelper(uint32_t binding,
const wgpu::TextureView& textureView)
: … { … }
BindingInitializationHelper::BindingInitializationHelper(uint32_t binding,
const wgpu::Buffer& buffer,
uint64_t offset,
uint64_t size)
: … { … }
BindingInitializationHelper::BindingInitializationHelper(const BindingInitializationHelper&) =
default;
BindingInitializationHelper::~BindingInitializationHelper() = default;
wgpu::BindGroupEntry BindingInitializationHelper::GetAsBinding() const { … }
wgpu::BindGroup MakeBindGroup(
const wgpu::Device& device,
const wgpu::BindGroupLayout& layout,
std::initializer_list<BindingInitializationHelper> entriesInitializer) { … }
ColorSpaceConversionInfo GetYUVBT709ToRGBSRGBColorSpaceConversionInfo() { … }
ColorSpaceConversionInfo GetNoopRGBColorSpaceConversionInfo() { … }
bool BackendRequiresCompat(wgpu::BackendType backend) { … }
}