Skip to content

Commit

Permalink
[WebGPU] ShaderModuleImpl::compilationInfo is not implemented
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263598
<radar://117424136>

Reviewed by Tadeu Zagallo.

Implement getCompilationInfo from WebCore.framework -> WebGPU.framework.

* Source/WebCore/Modules/WebGPU/Implementation/WebGPUShaderModuleImpl.cpp:
(WebCore::WebGPU::convertFromBacking):
(WebCore::WebGPU::compilationInfoCallback):
(WebCore::WebGPU::ShaderModuleImpl::compilationInfo):

Canonical link: https://commits.webkit.org/269725@main
  • Loading branch information
mwyrzykowski committed Oct 24, 2023
1 parent a36b56b commit ff9c8f8
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@

#if HAVE(WEBGPU_IMPLEMENTATION)

#include "WebGPUCompilationInfo.h"
#include "WebGPUCompilationMessage.h"
#include "WebGPUCompilationMessageType.h"
#include "WebGPUConvertToBackingContext.h"
#include <WebGPU/WebGPUExt.h>

#include <wtf/BlockPtr.h>

namespace WebCore::WebGPU {

ShaderModuleImpl::ShaderModuleImpl(WebGPUPtr<WGPUShaderModule>&& shaderModule, ConvertToBackingContext& convertToBackingContext)
Expand All @@ -41,9 +46,45 @@ ShaderModuleImpl::ShaderModuleImpl(WebGPUPtr<WGPUShaderModule>&& shaderModule, C

ShaderModuleImpl::~ShaderModuleImpl() = default;

void ShaderModuleImpl::compilationInfo(CompletionHandler<void(Ref<CompilationInfo>&&)>&&)
static CompilationMessageType convertFromBacking(WGPUCompilationMessageType type)
{
switch (type) {
case WGPUCompilationMessageType_Error:
return CompilationMessageType::Error;
case WGPUCompilationMessageType_Warning:
return CompilationMessageType::Warning;
case WGPUCompilationMessageType_Info:
return CompilationMessageType::Info;
case WGPUCompilationMessageType_Force32:
RELEASE_ASSERT_NOT_REACHED();
}
}

static void compilationInfoCallback(WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo* compilationInfo, void* userdata)
{
auto block = reinterpret_cast<void(^)(WGPUCompilationInfoRequestStatus, const WGPUCompilationInfo*)>(userdata);
block(status, compilationInfo);
Block_release(block); // Block_release is matched with Block_copy below in AdapterImpl::requestDevice().
}

void ShaderModuleImpl::compilationInfo(CompletionHandler<void(Ref<CompilationInfo>&&)>&& callback)
{
// FIXME: Implement this.
auto blockPtr = makeBlockPtr([callback = WTFMove(callback)](WGPUCompilationInfoRequestStatus, const WGPUCompilationInfo* compilationInfo) mutable {
Vector<Ref<CompilationMessage>> messages;
if (!compilationInfo || !compilationInfo->messageCount) {
callback(CompilationInfo::create(WTFMove(messages)));
return;
}

for (size_t i = 0; i < compilationInfo->messageCount; ++i) {
auto& message = compilationInfo->messages[i];
messages.append(CompilationMessage::create(String::fromLatin1(message.message), convertFromBacking(message.type), message.lineNum, message.linePos, message.offset, message.length));
}

callback(CompilationInfo::create(WTFMove(messages)));
});

wgpuShaderModuleGetCompilationInfo(m_backing.get(), &compilationInfoCallback, Block_copy(blockPtr.get()));
}

void ShaderModuleImpl::setLabelInternal(const String& label)
Expand Down

0 comments on commit ff9c8f8

Please sign in to comment.