Fix Windows compilation using GN and clang-cl.

This includes a bunch of fixes for clang warnings in Windows specific
code that was only compiled by MSVC previously. This also tidies up some
BUILD.gn issues on Windows.
This commit is contained in:
Corentin Wallez 2018-08-13 17:50:22 +02:00 committed by Corentin Wallez
parent 3bb0bb940e
commit 5b61abce09
18 changed files with 50 additions and 45 deletions

View File

@ -356,6 +356,7 @@ source_set("libdawn_native_sources") {
libs += [ libs += [
"d3d12.lib", "d3d12.lib",
"dxgi.lib", "dxgi.lib",
"dxguid.lib",
"d3dcompiler.lib", "d3dcompiler.lib",
] ]
sources += [ sources += [
@ -751,7 +752,7 @@ test("dawn_unittests") {
] ]
if (dawn_enable_d3d12) { if (dawn_enable_d3d12) {
sources += [ "src/tests/unittests/d3d12CopySplitTests.cpp" ] sources += [ "src/tests/unittests/d3d12/CopySplitTests.cpp" ]
} }
} }

View File

@ -24,8 +24,8 @@
// (resp. false) to help it generate code that leads to better branch prediction. // (resp. false) to help it generate code that leads to better branch prediction.
// - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR. // - DAWN_UNUSED(EXPR): Prevents unused variable/expression warnings on EXPR.
// Clang and GCC // Clang and GCC, check for __clang__ too to catch clang-cl masquarading as MSVC
#if defined(__GNUC__) #if defined(__GNUC__) || defined(__clang__)
# if defined(__clang__) # if defined(__clang__)
# define DAWN_COMPILER_CLANG # define DAWN_COMPILER_CLANG
# else # else

View File

@ -29,7 +29,8 @@ namespace dawn_native {
mDepthStencilAttachmentSet(builder->mDepthStencilAttachmentSet), mDepthStencilAttachmentSet(builder->mDepthStencilAttachmentSet),
mDepthStencilAttachment(builder->mDepthStencilAttachment), mDepthStencilAttachment(builder->mDepthStencilAttachment),
mWidth(builder->mWidth), mWidth(builder->mWidth),
mHeight(builder->mHeight) { mHeight(builder->mHeight),
mDevice(builder->GetDevice()) {
} }
std::bitset<kMaxColorAttachments> RenderPassDescriptorBase::GetColorAttachmentMask() const { std::bitset<kMaxColorAttachments> RenderPassDescriptorBase::GetColorAttachmentMask() const {
@ -77,6 +78,10 @@ namespace dawn_native {
return mHeight; return mHeight;
} }
DeviceBase* RenderPassDescriptorBase::GetDevice() const {
return mDevice;
}
// RenderPassDescriptorBuilder // RenderPassDescriptorBuilder
RenderPassDescriptorBuilder::RenderPassDescriptorBuilder(DeviceBase* device) : Builder(device) { RenderPassDescriptorBuilder::RenderPassDescriptorBuilder(DeviceBase* device) : Builder(device) {

View File

@ -61,6 +61,8 @@ namespace dawn_native {
uint32_t GetWidth() const; uint32_t GetWidth() const;
uint32_t GetHeight() const; uint32_t GetHeight() const;
DeviceBase* GetDevice() const;
private: private:
std::bitset<kMaxColorAttachments> mColorAttachmentsSet; std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<RenderPassColorAttachmentInfo, kMaxColorAttachments> mColorAttachments; std::array<RenderPassColorAttachmentInfo, kMaxColorAttachments> mColorAttachments;
@ -70,6 +72,8 @@ namespace dawn_native {
uint32_t mWidth; uint32_t mWidth;
uint32_t mHeight; uint32_t mHeight;
DeviceBase* mDevice;
}; };
class RenderPassDescriptorBuilder : public Builder<RenderPassDescriptorBase> { class RenderPassDescriptorBuilder : public Builder<RenderPassDescriptorBase> {

View File

@ -23,8 +23,7 @@
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
BindGroup::BindGroup(Device* device, BindGroupBuilder* builder) BindGroup::BindGroup(BindGroupBuilder* builder) : BindGroupBase(builder) {
: BindGroupBase(builder), mDevice(device) {
} }
void BindGroup::RecordDescriptors(const DescriptorHeapHandle& cbvUavSrvHeapStart, void BindGroup::RecordDescriptors(const DescriptorHeapHandle& cbvUavSrvHeapStart,
@ -43,7 +42,7 @@ namespace dawn_native { namespace d3d12 {
const auto& bindingOffsets = bgl->GetBindingOffsets(); const auto& bindingOffsets = bgl->GetBindingOffsets();
auto d3d12Device = mDevice->GetD3D12Device(); auto d3d12Device = ToBackend(GetDevice())->GetD3D12Device();
for (uint32_t binding : IterateBitSet(layout.mask)) { for (uint32_t binding : IterateBitSet(layout.mask)) {
switch (layout.types[binding]) { switch (layout.types[binding]) {
case dawn::BindingType::UniformBuffer: { case dawn::BindingType::UniformBuffer: {

View File

@ -27,7 +27,7 @@ namespace dawn_native { namespace d3d12 {
class BindGroup : public BindGroupBase { class BindGroup : public BindGroupBase {
public: public:
BindGroup(Device* device, BindGroupBuilder* builder); BindGroup(BindGroupBuilder* builder);
void RecordDescriptors(const DescriptorHeapHandle& cbvSrvUavHeapStart, void RecordDescriptors(const DescriptorHeapHandle& cbvSrvUavHeapStart,
uint32_t* cbvUavSrvHeapOffset, uint32_t* cbvUavSrvHeapOffset,
@ -39,11 +39,8 @@ namespace dawn_native { namespace d3d12 {
uint64_t GetHeapSerial() const; uint64_t GetHeapSerial() const;
private: private:
Device* mDevice;
uint32_t mCbvUavSrvHeapOffset; uint32_t mCbvUavSrvHeapOffset;
uint32_t mSamplerHeapOffset; uint32_t mSamplerHeapOffset;
uint32_t mCbvUavSrvCount = 0;
uint32_t mSamplerCount = 0;
uint64_t mHeapSerial = 0; uint64_t mHeapSerial = 0;
}; };

View File

@ -40,7 +40,7 @@ namespace dawn_native { namespace d3d12 {
ComPtr<ID3DBlob> compiledShader; ComPtr<ID3DBlob> compiledShader;
ComPtr<ID3DBlob> errors; ComPtr<ID3DBlob> errors;
if (FAILED(D3DCompile(hlslSource.c_str(), hlslSource.length(), nullptr, {nullptr}, nullptr, if (FAILED(D3DCompile(hlslSource.c_str(), hlslSource.length(), nullptr, nullptr, nullptr,
entryPoint.c_str(), "cs_5_1", compileFlags, 0, &compiledShader, entryPoint.c_str(), "cs_5_1", compileFlags, 0, &compiledShader,
&errors))) { &errors))) {
printf("%s\n", reinterpret_cast<char*>(errors->GetBufferPointer())); printf("%s\n", reinterpret_cast<char*>(errors->GetBufferPointer()));

View File

@ -76,8 +76,8 @@ namespace dawn_native { namespace d3d12 {
return desc; return desc;
} }
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder) DepthStencilState::DepthStencilState(DepthStencilStateBuilder* builder)
: DepthStencilStateBase(builder), mDevice(device) { : DepthStencilStateBase(builder) {
mDepthStencilDescriptor.DepthEnable = TRUE; mDepthStencilDescriptor.DepthEnable = TRUE;
mDepthStencilDescriptor.DepthWriteMask = mDepthStencilDescriptor.DepthWriteMask =
GetDepth().depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO; GetDepth().depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO;

View File

@ -25,12 +25,11 @@ namespace dawn_native { namespace d3d12 {
class DepthStencilState : public DepthStencilStateBase { class DepthStencilState : public DepthStencilStateBase {
public: public:
DepthStencilState(Device* device, DepthStencilStateBuilder* builder); DepthStencilState(DepthStencilStateBuilder* builder);
const D3D12_DEPTH_STENCIL_DESC& GetD3D12DepthStencilDescriptor() const; const D3D12_DEPTH_STENCIL_DESC& GetD3D12DepthStencilDescriptor() const;
private: private:
Device* mDevice;
D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor; D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor;
}; };

View File

@ -260,7 +260,7 @@ namespace dawn_native { namespace d3d12 {
} }
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) { BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
return new BindGroup(this, builder); return new BindGroup(builder);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) { const BindGroupLayoutDescriptor* descriptor) {
@ -282,10 +282,10 @@ namespace dawn_native { namespace d3d12 {
return new ComputePipeline(builder); return new ComputePipeline(builder);
} }
DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) { DepthStencilStateBase* Device::CreateDepthStencilState(DepthStencilStateBuilder* builder) {
return new DepthStencilState(this, builder); return new DepthStencilState(builder);
} }
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) { InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
return new InputState(this, builder); return new InputState(builder);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) { const PipelineLayoutDescriptor* descriptor) {
@ -296,7 +296,7 @@ namespace dawn_native { namespace d3d12 {
} }
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor( RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) { RenderPassDescriptorBuilder* builder) {
return new RenderPassDescriptor(this, builder); return new RenderPassDescriptor(builder);
} }
RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) { RenderPipelineBase* Device::CreateRenderPipeline(RenderPipelineBuilder* builder) {
return new RenderPipeline(builder); return new RenderPipeline(builder);
@ -305,7 +305,7 @@ namespace dawn_native { namespace d3d12 {
return new Sampler(this, descriptor); return new Sampler(this, descriptor);
} }
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) { ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
return new ShaderModule(this, builder); return new ShaderModule(builder);
} }
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) { SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
return new SwapChain(builder); return new SwapChain(builder);

View File

@ -60,8 +60,7 @@ namespace dawn_native { namespace d3d12 {
} }
} }
InputState::InputState(Device* device, InputStateBuilder* builder) InputState::InputState(InputStateBuilder* builder) : InputStateBase(builder) {
: InputStateBase(builder), mDevice(device) {
const auto& attributesSetMask = GetAttributesSetMask(); const auto& attributesSetMask = GetAttributesSetMask();
unsigned int count = 0; unsigned int count = 0;

View File

@ -25,12 +25,11 @@ namespace dawn_native { namespace d3d12 {
class InputState : public InputStateBase { class InputState : public InputStateBase {
public: public:
InputState(Device* device, InputStateBuilder* builder); InputState(InputStateBuilder* builder);
const D3D12_INPUT_LAYOUT_DESC& GetD3D12InputLayoutDescriptor() const; const D3D12_INPUT_LAYOUT_DESC& GetD3D12InputLayoutDescriptor() const;
private: private:
Device* mDevice;
D3D12_INPUT_LAYOUT_DESC mInputLayoutDescriptor; D3D12_INPUT_LAYOUT_DESC mInputLayoutDescriptor;
D3D12_INPUT_ELEMENT_DESC mInputElementDescriptors[kMaxVertexAttributes]; D3D12_INPUT_ELEMENT_DESC mInputElementDescriptors[kMaxVertexAttributes];
}; };

View File

@ -20,8 +20,10 @@
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
RenderPassDescriptor::RenderPassDescriptor(Device* device, RenderPassDescriptorBuilder* builder) RenderPassDescriptor::RenderPassDescriptor(RenderPassDescriptorBuilder* builder)
: RenderPassDescriptorBase(builder), mDevice(device) { : RenderPassDescriptorBase(builder) {
Device* device = ToBackend(GetDevice());
// Get and fill an RTV heap with the color attachments // Get and fill an RTV heap with the color attachments
uint32_t colorAttachmentCount = static_cast<uint32_t>(GetColorAttachmentMask().count()); uint32_t colorAttachmentCount = static_cast<uint32_t>(GetColorAttachmentMask().count());
if (colorAttachmentCount != 0) { if (colorAttachmentCount != 0) {

View File

@ -36,13 +36,12 @@ namespace dawn_native { namespace d3d12 {
D3D12_CPU_DESCRIPTOR_HANDLE dsv = {}; D3D12_CPU_DESCRIPTOR_HANDLE dsv = {};
}; };
RenderPassDescriptor(Device* device, RenderPassDescriptorBuilder* builder); RenderPassDescriptor(RenderPassDescriptorBuilder* builder);
OMSetRenderTargetArgs GetSubpassOMSetRenderTargetArgs(); OMSetRenderTargetArgs GetSubpassOMSetRenderTargetArgs();
D3D12_CPU_DESCRIPTOR_HANDLE GetRTVDescriptor(uint32_t attachmentSlot); D3D12_CPU_DESCRIPTOR_HANDLE GetRTVDescriptor(uint32_t attachmentSlot);
D3D12_CPU_DESCRIPTOR_HANDLE GetDSVDescriptor(); D3D12_CPU_DESCRIPTOR_HANDLE GetDSVDescriptor();
private: private:
Device* mDevice = nullptr;
DescriptorHeapHandle mRtvHeap = {}; DescriptorHeapHandle mRtvHeap = {};
DescriptorHeapHandle mDsvHeap = {}; DescriptorHeapHandle mDsvHeap = {};
}; };

View File

@ -44,8 +44,7 @@ namespace dawn_native { namespace d3d12 {
std::array<T, kNumBindingTypes> mMap{}; std::array<T, kNumBindingTypes> mMap{};
}; };
ShaderModule::ShaderModule(Device* device, ShaderModuleBuilder* builder) ShaderModule::ShaderModule(ShaderModuleBuilder* builder) : ShaderModuleBase(builder) {
: ShaderModuleBase(builder), mDevice(device) {
spirv_cross::CompilerHLSL compiler(builder->AcquireSpirv()); spirv_cross::CompilerHLSL compiler(builder->AcquireSpirv());
spirv_cross::CompilerGLSL::Options options_glsl; spirv_cross::CompilerGLSL::Options options_glsl;

View File

@ -23,13 +23,11 @@ namespace dawn_native { namespace d3d12 {
class ShaderModule : public ShaderModuleBase { class ShaderModule : public ShaderModuleBase {
public: public:
ShaderModule(Device* device, ShaderModuleBuilder* builder); ShaderModule(ShaderModuleBuilder* builder);
const std::string& GetHLSLSource() const; const std::string& GetHLSLSource() const;
private: private:
Device* mDevice;
std::string mHlslSource; std::string mHlslSource;
}; };

View File

@ -192,18 +192,18 @@ namespace {
}; };
return { return {
alignNonPow2(0, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(0, textureSpec.texelSize), rowPitch},
alignNonPow2(512, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(512, textureSpec.texelSize), rowPitch},
alignNonPow2(1024, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(1024, textureSpec.texelSize), rowPitch},
alignNonPow2(32, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(32, textureSpec.texelSize), rowPitch},
alignNonPow2(64, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(64, textureSpec.texelSize), rowPitch},
alignNonPow2(31, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(31, textureSpec.texelSize), rowPitch},
alignNonPow2(257, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(257, textureSpec.texelSize), rowPitch},
alignNonPow2(511, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(511, textureSpec.texelSize), rowPitch},
alignNonPow2(513, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(513, textureSpec.texelSize), rowPitch},
alignNonPow2(1023, textureSpec.texelSize), rowPitch, BufferSpec{alignNonPow2(1023, textureSpec.texelSize), rowPitch},
}; };
} }

View File

@ -45,7 +45,11 @@ config("spirv_cross_public") {
static_library("spirv_cross") { static_library("spirv_cross") {
public_configs = [ ":spirv_cross_public" ] public_configs = [ ":spirv_cross_public" ]
cflags_cc = [ "-Wno-implicit-fallthrough" ] cflags_cc = [
"-Wno-implicit-fallthrough",
"-Wno-return-type",
"-Wno-sign-compare",
]
sources = [ sources = [
"${spirv_cross_dir}/GLSL.std.450.h", "${spirv_cross_dir}/GLSL.std.450.h",