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.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
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();
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;
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()));
ID3D11VertexShader* shader = nullptr;
throwIfFailed(device->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader));
ComPtr<ID3D11VertexShader> 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;
}
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;
logD("Compiling pixel shader");
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()));
ID3D11PixelShader* shader = nullptr;
throwIfFailed(device->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader));
ComPtr<ID3D11PixelShader> 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;
}
UINT Utils::GetShaderFlags() noexcept
constexpr UINT Utils::GetShaderFlags()
{
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
if constexpr(DebugBuild){

View file

@ -6,16 +6,10 @@ namespace T5M {
namespace Renderer {
namespace Utils {
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]]UINT GetShaderFlags() 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) noexcept;
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());
};
[[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);
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);
}
}
}