Improve HLSL compile.

This commit is contained in:
Anish Bhobe 2024-07-01 21:22:40 +02:00
parent ccb0aa5fbe
commit d9b0e82be7
2 changed files with 8 additions and 15 deletions

View File

@ -2,6 +2,9 @@ function(add_shader TARGET SHADER)
find_package(Vulkan REQUIRED COMPONENTS dxc)
get_filename_component(shader-ext ${SHADER} LAST_EXT)
get_filename_component(shader-inner ${SHADER} NAME_WLE)
get_filename_component(shader-type ${shader-inner} LAST_EXT)
string(REPLACE "." "" shader-type ${shader-type})
set(current-shader-path ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER})
set(current-output-path ${CMAKE_CURRENT_BINARY_DIR}/${SHADER}.spv)
@ -13,7 +16,7 @@ function(add_shader TARGET SHADER)
message("Marked as hlsl file. ${current-output-path}")
add_custom_command(
OUTPUT ${current-output-path}
COMMAND Vulkan::dxc_exe -spirv -T vs_6_0 -E main ${current-shader-path} -Fo ${current-output-path}
COMMAND Vulkan::dxc_exe -spirv -T "${shader-type}_6_0" -E main ${current-shader-path} -Fo ${current-output-path}
DEPENDS ${current-shader-path}
IMPLICIT_DEPENDS CXX ${current-shader-path}
VERBATIM)

View File

@ -14,7 +14,6 @@
#include "aster/swapchain.h"
#include <EASTL/array.h>
#include <EASTL/optional.h>
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
constexpr auto VERTEX_SHADER_FILE = "shader/triangle.vs.hlsl.spv";
@ -23,7 +22,7 @@ constexpr auto FRAGMENT_SHADER_FILE = "shader/white.frag.glsl.spv";
bool IsSuitableDevice(const PhysicalDevice *physicalDevice);
PhysicalDevice FindSuitableDevice(const PhysicalDevices &physicalDevices);
QueueAllocation FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice);
eastl::optional<eastl::vector<u32>> ReadFile(cstr fileName);
eastl::vector<u32> ReadFile(cstr fileName);
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
struct Frame
@ -296,15 +295,14 @@ FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice)
THEN_ABORT(vk::Result::eErrorUnknown);
}
eastl::optional<eastl::vector<u32>>
eastl::vector<u32>
ReadFile(cstr fileName)
{
FILE *filePtr = fopen(fileName, "rb");
if (!filePtr)
{
ERROR("Invalid read of {}", fileName);
return eastl::nullopt;
ERROR("Invalid read of {}", fileName) THEN_ABORT(-1);
}
eastl::vector<u32> outputVec;
@ -490,15 +488,7 @@ CreatePipeline(const Device *device, const Swapchain *swapchain, cstr vertexShad
vk::ShaderModule
CreateShader(const Device *device, cstr shaderFile)
{
eastl::vector<u32> shaderCode;
if (auto res = ReadFile(shaderFile))
{
shaderCode = res.value();
}
else
{
ERROR("Could not open {}.", shaderFile) THEN_ABORT(-1);
}
eastl::vector<u32> shaderCode = ReadFile(shaderFile);
const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = {
.codeSize = shaderCode.size() * sizeof(u32),