Refactor ShaderModule creation to use a Builder pattern

BUG=dawn:270

Change-Id: Iedae1a5500b1eb65abb84ff59f68d829c5c22c2b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13500
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Ryan Harrison
2019-11-14 16:10:45 +00:00
committed by Commit Bot service account
parent 321c12255e
commit 58dbfcae38
11 changed files with 78 additions and 16 deletions

View File

@@ -99,7 +99,7 @@ namespace dawn_native { namespace opengl {
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor) {
return new ShaderModule(this, descriptor);
return ShaderModule::Create(this, descriptor);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {

View File

@@ -47,8 +47,29 @@ namespace dawn_native { namespace opengl {
return o.str();
}
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor) {
std::unique_ptr<ShaderModule> module(new ShaderModule(device, descriptor));
if (!module)
return DAWN_VALIDATION_ERROR("Unable to create ShaderModule");
DAWN_TRY(module->Initialize(descriptor));
return module.release();
}
const char* ShaderModule::GetSource() const {
return mGlslSource.c_str();
}
const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const {
return mCombinedInfo;
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)
: ShaderModuleBase(device, descriptor) {
}
MaybeError ShaderModule::Initialize(const ShaderModuleDescriptor* descriptor) {
spirv_cross::CompilerGLSL compiler(descriptor->code, descriptor->codeSize);
// If these options are changed, the values in DawnSPIRVCrossGLSLFastFuzzer.cpp need to be
// updated.
@@ -108,14 +129,7 @@ namespace dawn_native { namespace opengl {
}
mGlslSource = compiler.compile();
}
const char* ShaderModule::GetSource() const {
return mGlslSource.c_str();
}
const ShaderModule::CombinedSamplerInfo& ShaderModule::GetCombinedSamplerInfo() const {
return mCombinedInfo;
return {};
}
}} // namespace dawn_native::opengl

View File

@@ -40,7 +40,8 @@ namespace dawn_native { namespace opengl {
class ShaderModule : public ShaderModuleBase {
public:
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
static ResultOrError<ShaderModule*> Create(Device* device,
const ShaderModuleDescriptor* descriptor);
using CombinedSamplerInfo = std::vector<CombinedSampler>;
@@ -48,6 +49,9 @@ namespace dawn_native { namespace opengl {
const CombinedSamplerInfo& GetCombinedSamplerInfo() const;
private:
ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
MaybeError Initialize(const ShaderModuleDescriptor* descriptor);
CombinedSamplerInfo mCombinedInfo;
std::string mGlslSource;
};