Skip to content

Commit

Permalink
fix shaders not compiling due to pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
hakasapl committed Jul 26, 2024
1 parent 9deade9 commit 2249c88
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed parallax or complex material texture paths not being set correctly for some edge case NIFs
- Fixed aspect ratio checks happening more than once for the same pair
- Output directory + data dir path checking is done using std::filesystem now instead of string comparison
- Fixed bugs where shaders wouldn't compile when in wrong working directory

## [0.4.6] - 2024-07-23

Expand Down
4 changes: 3 additions & 1 deletion include/ParallaxGenD3D/ParallaxGenD3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ParallaxGenD3D

std::filesystem::path output_dir;

std::filesystem::path exe_path;

// GPU objects
Microsoft::WRL::ComPtr<ID3D11Device> pDevice; // GPU device
Microsoft::WRL::ComPtr<ID3D11DeviceContext> pContext; // GPU context
Expand All @@ -45,7 +47,7 @@ class ParallaxGenD3D
std::unordered_map<std::filesystem::path, DirectX::TexMetadata> dds_metadata_cache;

public:
ParallaxGenD3D(ParallaxGenDirectory* pgd, std::filesystem::path output_dir);
ParallaxGenD3D(ParallaxGenDirectory* pgd, const std::filesystem::path output_dir, const std::filesystem::path exe_path);

bool checkIfAspectRatioMatches(const std::filesystem::path& dds_path_1, const std::filesystem::path& dds_path_2, bool& check_aspect);

Expand Down
2 changes: 2 additions & 0 deletions src/ParallaxGen/ParallaxGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ bool ParallaxGen::shouldEnableComplexMaterial(const filesystem::path& nif_file,
// verify that maps match each other
string diffuse_map;
uint32_t diffuse_result = nif.GetTextureSlot(shape, diffuse_map, 0);
// TODO how do we integrate this properly?
// TODO probably a struct in the Task class that defines error states
bool same_aspect = false;
pgd3d->checkIfAspectRatioMatches(diffuse_map, cm_map, same_aspect);
if (!same_aspect) {
Expand Down
9 changes: 6 additions & 3 deletions src/ParallaxGenD3D/ParallaxGenD3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ using namespace std;
using Microsoft::WRL::ComPtr;
using namespace ParallaxGenUtil;

ParallaxGenD3D::ParallaxGenD3D(ParallaxGenDirectory* pgd, std::filesystem::path output_dir)
ParallaxGenD3D::ParallaxGenD3D(ParallaxGenDirectory* pgd, const filesystem::path output_dir, const filesystem::path exe_path)
{
// Constructor
this->pgd = pgd;

// Set output directory
this->output_dir = output_dir;
this->exe_path = exe_path;
}

bool ParallaxGenD3D::checkIfAspectRatioMatches(const std::filesystem::path& dds_path_1, const std::filesystem::path& dds_path_2, bool& check_aspect)
Expand Down Expand Up @@ -79,7 +80,7 @@ void ParallaxGenD3D::initGPU()
void ParallaxGenD3D::initShaders()
{
// MergeToComplexMaterial.hlsl
if (!createComputeShader(L"shaders/MergeToComplexMaterial.hlsl", shader_MergeToComplexMaterial)) {
if (!createComputeShader(L"MergeToComplexMaterial.hlsl", shader_MergeToComplexMaterial)) {
spdlog::critical("Failed to create compute shader. Exiting.");
ParallaxGenUtil::exitWithUserInput(1);
}
Expand All @@ -93,9 +94,11 @@ ComPtr<ID3DBlob> ParallaxGenD3D::compileShader(const std::filesystem::path& file
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

filesystem::path shader_abs_path = exe_path / "shaders" / filename;

ComPtr<ID3DBlob> pCSBlob;
ComPtr<ID3DBlob> pErrorBlob;
HRESULT hr = D3DCompileFromFile(filename.c_str(), nullptr, nullptr, "main", "cs_5_0", dwShaderFlags, 0, pCSBlob.ReleaseAndGetAddressOf(), pErrorBlob.ReleaseAndGetAddressOf());
HRESULT hr = D3DCompileFromFile(shader_abs_path.c_str(), nullptr, nullptr, "main", "cs_5_0", dwShaderFlags, 0, pCSBlob.ReleaseAndGetAddressOf(), pErrorBlob.ReleaseAndGetAddressOf());
if (FAILED(hr)) {
if (pErrorBlob) {
spdlog::critical(L"Failed to compile shader {}: {}, {}", filename.wstring(), ParallaxGenUtil::convertToWstring(getHRESULTErrorMessage(hr)), static_cast<wchar_t*>(pErrorBlob->GetBufferPointer()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void mainRunner(int argc, char** argv)
// Create relevant objects
BethesdaGame bg = BethesdaGame(bg_type, game_dir, true);
ParallaxGenDirectory pgd = ParallaxGenDirectory(bg);
ParallaxGenD3D pgd3d = ParallaxGenD3D(&pgd, output_dir);
ParallaxGenD3D pgd3d = ParallaxGenD3D(&pgd, output_dir, EXE_PATH);
ParallaxGen pg = ParallaxGen(output_dir, &pgd, &pgd3d, optimize_meshes, ignore_parallax, ignore_complex_material);

// Check if GPU needs to be initialized
Expand Down

0 comments on commit 2249c88

Please sign in to comment.