Move DXBC ShaderType to enum class in common header

This commit is contained in:
baldurk
2019-10-18 20:57:35 +01:00
parent cd020007d2
commit 2a21bd8d5e
10 changed files with 113 additions and 70 deletions
@@ -581,7 +581,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha)
auto dxbc = it->second->GetDXBC();
RDCASSERT(dxbc);
RDCASSERT(dxbc->m_Type == D3D11_ShaderType_Pixel);
RDCASSERT(dxbc->m_Type == DXBC::ShaderType::Pixel);
if(m_pDevice->GetResourceManager()->HasLiveResource(cfg.customShaderId))
{
+27 -27
View File
@@ -266,7 +266,7 @@ public:
const char *opString, ShaderVariable &output);
private:
D3D11_ShaderType GetShaderType() { return m_dxbc ? m_dxbc->m_Type : D3D11_ShaderType_Pixel; }
DXBC::ShaderType GetShaderType() { return m_dxbc ? m_dxbc->m_Type : DXBC::ShaderType::Pixel; }
WrappedID3D11Device *m_pDevice;
DXBC::DXBCContainer *m_dxbc;
const ShaderDebug::GlobalState &m_globalState;
@@ -339,12 +339,12 @@ ShaderVariable D3D11DebugAPIWrapper::GetSampleInfo(DXBC::OperandType type, bool
ID3D11ShaderResourceView *srv = NULL;
switch(GetShaderType())
{
case D3D11_ShaderType_Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Compute: context->CSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Compute: context->CSGetShaderResources(slot, 1, &srv); break;
}
if(srv)
@@ -417,7 +417,7 @@ ShaderVariable D3D11DebugAPIWrapper::GetBufferInfo(DXBC::OperandType type, UINT
if(type == DXBC::TYPE_UNORDERED_ACCESS_VIEW)
{
ID3D11UnorderedAccessView *uav = NULL;
if(GetShaderType() == D3D11_ShaderType_Compute)
if(GetShaderType() == DXBC::ShaderType::Compute)
context->CSGetUnorderedAccessViews(slot, 1, &uav);
else
context->OMGetRenderTargetsAndUnorderedAccessViews(0, NULL, NULL, slot, 1, &uav);
@@ -460,12 +460,12 @@ ShaderVariable D3D11DebugAPIWrapper::GetBufferInfo(DXBC::OperandType type, UINT
ID3D11ShaderResourceView *srv = NULL;
switch(GetShaderType())
{
case D3D11_ShaderType_Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Compute: context->CSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Compute: context->CSGetShaderResources(slot, 1, &srv); break;
}
if(srv)
@@ -524,12 +524,12 @@ ShaderVariable D3D11DebugAPIWrapper::GetResourceInfo(DXBC::OperandType type, UIN
ID3D11ShaderResourceView *srv = NULL;
switch(GetShaderType())
{
case D3D11_ShaderType_Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case D3D11_ShaderType_Compute: context->CSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Vertex: context->VSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Hull: context->HSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Domain: context->DSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Geometry: context->GSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Pixel: context->PSGetShaderResources(slot, 1, &srv); break;
case DXBC::ShaderType::Compute: context->CSGetShaderResources(slot, 1, &srv); break;
}
if(srv)
@@ -693,7 +693,7 @@ ShaderVariable D3D11DebugAPIWrapper::GetResourceInfo(DXBC::OperandType type, UIN
else
{
ID3D11UnorderedAccessView *uav = NULL;
if(GetShaderType() == D3D11_ShaderType_Compute)
if(GetShaderType() == DXBC::ShaderType::Compute)
{
context->CSGetUnorderedAccessViews(slot, 1, &uav);
}
@@ -1273,27 +1273,27 @@ bool D3D11DebugAPIWrapper::CalculateSampleGather(
// fetch SRV and sampler from the shader stage we're debugging that this opcode wants to load from
switch(GetShaderType())
{
case D3D11_ShaderType_Vertex:
case DXBC::ShaderType::Vertex:
context->VSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->VSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
case D3D11_ShaderType_Hull:
case DXBC::ShaderType::Hull:
context->HSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->HSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
case D3D11_ShaderType_Domain:
case DXBC::ShaderType::Domain:
context->DSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->DSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
case D3D11_ShaderType_Geometry:
case DXBC::ShaderType::Geometry:
context->GSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->GSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
case D3D11_ShaderType_Pixel:
case DXBC::ShaderType::Pixel:
context->PSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->PSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
case D3D11_ShaderType_Compute:
case DXBC::ShaderType::Compute:
context->CSGetShaderResources(resourceData.slot, 1, &usedSRV);
context->CSGetSamplers(samplerData.slot, 1, &usedSamp);
break;
@@ -529,7 +529,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
DXBC::DXBCContainer *dxbc = shader->GetDXBC();
RDCASSERT(dxbc);
RDCASSERT(dxbc->m_Type == D3D11_ShaderType_Pixel);
RDCASSERT(dxbc->m_Type == DXBC::ShaderType::Pixel);
for(size_t i = 0; i < dxbc->m_CBuffers.size(); i++)
{
@@ -0,0 +1,56 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
namespace DXBC
{
// matches D3D11_SHADER_VERSION_TYPE from d3d11shader.h
enum class ShaderType
{
// D3D10 Shaders
Pixel = 0,
Vertex = 1,
Geometry = 2,
// D3D11 Shaders
Hull = 3,
Domain = 4,
Compute = 5,
// D3D12 Shaders
Library = 6,
RayGeneration = 7,
Intersection = 8,
AnyHit = 9,
ClosestHit = 10,
Miss = 11,
Callable = 12,
Mesh = 13,
Amplification = 14,
// Max value
Max,
};
};
@@ -566,9 +566,6 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
m_Disassembled = false;
m_Type = D3D11_ShaderType_Vertex;
m_Version.Major = 5;
m_Version.Minor = 0;
m_GuessedResources = true;
RDCASSERT(ByteCodeLength < UINT32_MAX);
@@ -590,7 +587,7 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
// default to vertex shader to support blobs without RDEF chunks (e.g. used with
// input layouts if they're super stripped down)
m_Type = D3D11_ShaderType_Vertex;
m_Type = DXBC::ShaderType::Vertex;
bool rdefFound = false;
@@ -613,19 +610,19 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
// for 0x501 it's "\x13\x13\D%"
if(h->targetShaderStage == 0xffff)
m_Type = D3D11_ShaderType_Pixel;
m_Type = DXBC::ShaderType::Pixel;
else if(h->targetShaderStage == 0xfffe)
m_Type = D3D11_ShaderType_Vertex;
m_Type = DXBC::ShaderType::Vertex;
else if(h->targetShaderStage == 0x4753) // 'GS'
m_Type = D3D11_ShaderType_Geometry;
m_Type = DXBC::ShaderType::Geometry;
else if(h->targetShaderStage == 0x4853) // 'HS'
m_Type = D3D11_ShaderType_Hull;
m_Type = DXBC::ShaderType::Hull;
else if(h->targetShaderStage == 0x4453) // 'DS'
m_Type = D3D11_ShaderType_Domain;
m_Type = DXBC::ShaderType::Domain;
else if(h->targetShaderStage == 0x4353) // 'CS'
m_Type = D3D11_ShaderType_Compute;
m_Type = DXBC::ShaderType::Compute;
m_SRVs.reserve(h->resources.count);
m_UAVs.reserve(h->resources.count);
@@ -988,10 +985,10 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
desc.compCount = (desc.regChannelMask & 0x1 ? 1 : 0) + (desc.regChannelMask & 0x2 ? 1 : 0) +
(desc.regChannelMask & 0x4 ? 1 : 0) + (desc.regChannelMask & 0x8 ? 1 : 0);
RDCASSERT(m_Type != (D3D11_ShaderType)-1);
RDCASSERT(m_Type != DXBC::ShaderType::Max);
// pixel shader outputs with registers are always targets
if(m_Type == D3D11_ShaderType_Pixel && output &&
if(m_Type == DXBC::ShaderType::Pixel && output &&
desc.systemValue == ShaderBuiltin::Undefined && desc.regIndex >= 0 && desc.regIndex <= 16)
desc.systemValue = ShaderBuiltin::ColorOutput;
@@ -1086,7 +1083,7 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
}
// make sure to fetch the dispatch threads dimension from disassembly
if(!m_Disassembled && m_Type == D3D11_ShaderType_Compute)
if(!m_Disassembled && m_Type == DXBC::ShaderType::Compute)
{
FetchComputeProperties();
}
+3 -15
View File
@@ -31,21 +31,9 @@
#include <vector>
#include "api/replay/renderdoc_replay.h"
#include "common/common.h"
#include "dxbc_common.h"
#include "dxbc_disassemble.h"
// matches D3D11_SHADER_VERSION_TYPE from d3d11shader.h
enum D3D11_ShaderType
{
D3D11_ShaderType_Pixel = 0,
D3D11_ShaderType_Vertex = 1,
D3D11_ShaderType_Geometry = 2,
// D3D11 Shaders
D3D11_ShaderType_Hull = 3,
D3D11_ShaderType_Domain = 4,
D3D11_ShaderType_Compute = 5,
};
// many thanks to winehq for information of format of RDEF, STAT and SIGN chunks:
// http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/d3dcompiler_43/reflection.c
namespace DXBC
@@ -343,10 +331,10 @@ class DXBCContainer
public:
DXBCContainer(const void *ByteCode, size_t ByteCodeLength);
~DXBCContainer() { SAFE_DELETE(m_DebugInfo); }
D3D11_ShaderType m_Type;
DXBC::ShaderType m_Type = DXBC::ShaderType::Max;
struct
{
uint32_t Major, Minor;
uint32_t Major = 0, Minor = 0;
} m_Version;
ShaderStatistics m_ShaderStats;
@@ -86,7 +86,7 @@ namespace VersionToken
static MaskedElement<uint32_t, 0x000000f0> MajorVersion;
static MaskedElement<uint32_t, 0x0000000f> MinorVersion;
static MaskedElement<D3D11_ShaderType, 0xffff0000> ProgramType;
static MaskedElement<DXBC::ShaderType, 0xffff0000> ProgramType;
};
namespace LengthToken
@@ -488,12 +488,12 @@ void DXBCContainer::MakeDisassemblyString()
switch(m_Type)
{
case D3D11_ShaderType_Pixel: m_Disassembly += "ps_"; break;
case D3D11_ShaderType_Vertex: m_Disassembly += "vs_"; break;
case D3D11_ShaderType_Geometry: m_Disassembly += "gs_"; break;
case D3D11_ShaderType_Hull: m_Disassembly += "hs_"; break;
case D3D11_ShaderType_Domain: m_Disassembly += "ds_"; break;
case D3D11_ShaderType_Compute: m_Disassembly += "cs_"; break;
case DXBC::ShaderType::Pixel: m_Disassembly += "ps_"; break;
case DXBC::ShaderType::Vertex: m_Disassembly += "vs_"; break;
case DXBC::ShaderType::Geometry: m_Disassembly += "gs_"; break;
case DXBC::ShaderType::Hull: m_Disassembly += "hs_"; break;
case DXBC::ShaderType::Domain: m_Disassembly += "ds_"; break;
case DXBC::ShaderType::Compute: m_Disassembly += "cs_"; break;
default: RDCERR("Unknown shader type: %u", m_Type); break;
}
@@ -203,12 +203,12 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, ShaderReflection *refl,
switch(dxbc->m_Type)
{
case D3D11_ShaderType_Pixel: refl->stage = ShaderStage::Pixel; break;
case D3D11_ShaderType_Vertex: refl->stage = ShaderStage::Vertex; break;
case D3D11_ShaderType_Geometry: refl->stage = ShaderStage::Geometry; break;
case D3D11_ShaderType_Hull: refl->stage = ShaderStage::Hull; break;
case D3D11_ShaderType_Domain: refl->stage = ShaderStage::Domain; break;
case D3D11_ShaderType_Compute: refl->stage = ShaderStage::Compute; break;
case DXBC::ShaderType::Pixel: refl->stage = ShaderStage::Pixel; break;
case DXBC::ShaderType::Vertex: refl->stage = ShaderStage::Vertex; break;
case DXBC::ShaderType::Geometry: refl->stage = ShaderStage::Geometry; break;
case DXBC::ShaderType::Hull: refl->stage = ShaderStage::Hull; break;
case DXBC::ShaderType::Domain: refl->stage = ShaderStage::Domain; break;
case DXBC::ShaderType::Compute: refl->stage = ShaderStage::Compute; break;
default:
RDCERR("Unexpected DXBC shader type %u", dxbc->m_Type);
refl->stage = ShaderStage::Vertex;
@@ -111,6 +111,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dxbc_common.h" />
<ClInclude Include="dxbc_compile.h" />
<ClInclude Include="dxbc_debug.h" />
<ClInclude Include="dxbc_disassemble.h" />
@@ -29,6 +29,7 @@
<Filter>official</Filter>
</ClInclude>
<ClInclude Include="dxbc_container.h" />
<ClInclude Include="dxbc_common.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="PCH">