Minor cleanup

This commit is contained in:
Nils Gaitzsch 2020-08-10 20:44:12 +02:00
parent a752f49d57
commit f137d54f07
3 changed files with 22 additions and 18 deletions

View file

@ -172,7 +172,7 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
shadowSamplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL; shadowSamplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
shadowSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; shadowSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
Utils::throwIfFailed(m_device->CreateSamplerState(&shadowSamplerDesc,m_shadowSampler.GetAddressOf())); Utils::throwIfFailed(m_device->CreateSamplerState(&shadowSamplerDesc,m_shadowSampler.GetAddressOf()));
Utils::setName(m_shadowSampler.Get(), "ShadowSampler"); m_shadowSampler->SetPrivateData(WKPDID_D3DDebugObjectName, sizeof("ShadowSampler") + 1, "ShadowSampler");
initialiseBars(); initialiseBars();
initQuad(m_device.Get()); initQuad(m_device.Get());
} }

View file

@ -17,26 +17,36 @@ namespace T5M::Renderer::Utils {
} }
ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO * defines, ComPtr<ID3D10Blob>& bytecode) noexcept { ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO * defines, ComPtr<ID3D10Blob>& bytecode) {
ComPtr<ID3D10Blob> errors; ComPtr<ID3D10Blob> errors;
logD("Compiling vertex shader"); logD("Compiling vertex shader");
throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(),errors.GetAddressOf())); throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(),errors.GetAddressOf()));
ID3D11VertexShader* shader = nullptr; ComPtr<ID3D11VertexShader> shader;
throwIfFailed(device->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader)); throwIfFailed(device->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, shader.GetAddressOf()));
if constexpr(DebugBuild){
char buffer[100];
size_t sz = std::wcstombs(buffer, fileName.c_str(), 100);
shader->SetPrivateData(WKPDID_D3DDebugObjectName, sz, buffer);
}
return shader; return shader;
} }
ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const wstring& fileName, const string& function, const string& model, const D3D_SHADER_MACRO* defines, ComPtr<ID3D10Blob>& bytecode) noexcept { ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const wstring& fileName, const string& function, const string& model, const D3D_SHADER_MACRO* defines, ComPtr<ID3D10Blob>& bytecode) {
ComPtr<ID3D10Blob> errors; ComPtr<ID3D10Blob> errors;
logD("Compiling pixel shader"); logD("Compiling pixel shader");
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_SKIP_OPTIMIZATION; UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_SKIP_OPTIMIZATION;
throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(), errors.GetAddressOf())); throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(), errors.GetAddressOf()));
ID3D11PixelShader* shader = nullptr; ComPtr<ID3D11PixelShader> shader;
throwIfFailed(device->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader)); throwIfFailed(device->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, shader.GetAddressOf()));
if constexpr(DebugBuild){
char buffer[100];
size_t sz = std::wcstombs(buffer, fileName.c_str(), 100);
shader->SetPrivateData(WKPDID_D3DDebugObjectName, sz, buffer);
}
return shader; return shader;
} }
UINT Utils::GetShaderFlags() noexcept constexpr UINT Utils::GetShaderFlags()
{ {
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
if constexpr(DebugBuild){ if constexpr(DebugBuild){

View file

@ -6,16 +6,10 @@ namespace T5M {
namespace Renderer { namespace Renderer {
namespace Utils { namespace Utils {
void throwIfFailed(const HRESULT& res) noexcept; void throwIfFailed(const HRESULT& res) noexcept;
[[nodiscard]]Microsoft::WRL::ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode) noexcept; [[nodiscard]] Microsoft::WRL::ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode);
[[nodiscard]]UINT GetShaderFlags() noexcept; constexpr [[nodiscard]] UINT GetShaderFlags();
[[nodiscard]]Microsoft::WRL::ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode) noexcept; [[nodiscard]] Microsoft::WRL::ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode);
template<typename T>
void setName(T* object, const std::string& name)
{
ID3D11DeviceChild* childPtr = nullptr;
object->QueryInterface<ID3D11DeviceChild>(&childPtr);
childPtr->SetPrivateData(WKPDID_D3DDebugObjectName, name.length(), name.c_str());
};
} }
} }
} }