Improve HLSL compile.
This commit is contained in:
parent
ccb0aa5fbe
commit
d9b0e82be7
|
|
@ -2,6 +2,9 @@ function(add_shader TARGET SHADER)
|
||||||
find_package(Vulkan REQUIRED COMPONENTS dxc)
|
find_package(Vulkan REQUIRED COMPONENTS dxc)
|
||||||
|
|
||||||
get_filename_component(shader-ext ${SHADER} LAST_EXT)
|
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-shader-path ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER})
|
||||||
set(current-output-path ${CMAKE_CURRENT_BINARY_DIR}/${SHADER}.spv)
|
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}")
|
message("Marked as hlsl file. ${current-output-path}")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${current-output-path}
|
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}
|
DEPENDS ${current-shader-path}
|
||||||
IMPLICIT_DEPENDS CXX ${current-shader-path}
|
IMPLICIT_DEPENDS CXX ${current-shader-path}
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include "aster/swapchain.h"
|
#include "aster/swapchain.h"
|
||||||
|
|
||||||
#include <EASTL/array.h>
|
#include <EASTL/array.h>
|
||||||
#include <EASTL/optional.h>
|
|
||||||
|
|
||||||
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
|
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
|
||||||
constexpr auto VERTEX_SHADER_FILE = "shader/triangle.vs.hlsl.spv";
|
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);
|
bool IsSuitableDevice(const PhysicalDevice *physicalDevice);
|
||||||
PhysicalDevice FindSuitableDevice(const PhysicalDevices &physicalDevices);
|
PhysicalDevice FindSuitableDevice(const PhysicalDevices &physicalDevices);
|
||||||
QueueAllocation FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice);
|
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);
|
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
|
||||||
|
|
||||||
struct Frame
|
struct Frame
|
||||||
|
|
@ -296,15 +295,14 @@ FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice)
|
||||||
THEN_ABORT(vk::Result::eErrorUnknown);
|
THEN_ABORT(vk::Result::eErrorUnknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
eastl::optional<eastl::vector<u32>>
|
eastl::vector<u32>
|
||||||
ReadFile(cstr fileName)
|
ReadFile(cstr fileName)
|
||||||
{
|
{
|
||||||
FILE *filePtr = fopen(fileName, "rb");
|
FILE *filePtr = fopen(fileName, "rb");
|
||||||
|
|
||||||
if (!filePtr)
|
if (!filePtr)
|
||||||
{
|
{
|
||||||
ERROR("Invalid read of {}", fileName);
|
ERROR("Invalid read of {}", fileName) THEN_ABORT(-1);
|
||||||
return eastl::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eastl::vector<u32> outputVec;
|
eastl::vector<u32> outputVec;
|
||||||
|
|
@ -490,15 +488,7 @@ CreatePipeline(const Device *device, const Swapchain *swapchain, cstr vertexShad
|
||||||
vk::ShaderModule
|
vk::ShaderModule
|
||||||
CreateShader(const Device *device, cstr shaderFile)
|
CreateShader(const Device *device, cstr shaderFile)
|
||||||
{
|
{
|
||||||
eastl::vector<u32> shaderCode;
|
eastl::vector<u32> shaderCode = ReadFile(shaderFile);
|
||||||
if (auto res = ReadFile(shaderFile))
|
|
||||||
{
|
|
||||||
shaderCode = res.value();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERROR("Could not open {}.", shaderFile) THEN_ABORT(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = {
|
const vk::ShaderModuleCreateInfo shaderModuleCreateInfo = {
|
||||||
.codeSize = shaderCode.size() * sizeof(u32),
|
.codeSize = shaderCode.size() * sizeof(u32),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue