Commit c6fa53e5 authored by Lukas Tietze's avatar Lukas Tietze

Tests

parent 07d89e95
......@@ -12,6 +12,8 @@ layout(push_constant) uniform Constants
uint rngSeed;
};
layout(binding = 8) uniform sampler2D texSampler;
layout(location = 0) rayPayloadInNV HitPayload payload;
hitAttributeNV vec3 attribs;
......@@ -54,6 +56,10 @@ void main()
VertexPosition(v1) * barycentrics.y +
VertexPosition(v2) * barycentrics.z;
vec2 texCoord = VertexTexCoord(v0) * barycentrics.x +
VertexTexCoord(v1) * barycentrics.y +
VertexTexCoord(v2) * barycentrics.z;
N = normalize(vec3(obj.transformInverseTranspose * vec4(N, 0.0)));
worldPos = vec3(obj.transformInverseTranspose * vec4(worldPos, 1.0));
......@@ -68,6 +74,7 @@ void main()
float reflectivity = MaterialRefractionIndex(mat) - 1;
vec3 reflection = payload.value;
vec3 texture = texture(texSampler, texCoord).rgb;
payload.value = MaterialEmission(mat) + reflectivity * reflection + (1 - reflectivity) * res;
payload.value = (MaterialEmission(mat) + reflectivity * reflection + (1 - reflectivity) * res);
}
......@@ -18,13 +18,13 @@ layout(binding = 2, set = 0) uniform SimpleSceneDescriptionBlock {
layout(location = 0) rayPayloadNV HitPayload payload;
layout(binding = 8) uniform sampler2D texSampler;
void main()
{
uint rayFlags = gl_RayFlagsOpaqueNV;
uint cullMask = 0xff;
vec3 res = vec3(0);
uint seed = tea(gl_LaunchIDNV.y * gl_LaunchSizeNV.x + gl_LaunchIDNV.x, rngSeed);
vec2 offset = vec2(rnd(seed), rnd(seed));
const vec2 inUv = (vec2(gl_LaunchIDNV.xy) + offset) / vec2(gl_LaunchSizeNV.xy);
......@@ -37,6 +37,7 @@ void main()
origin.xyz, RayTMin,
direction.xyz, RayTMax, 0);
vec3 res = payload.value;
imageStore(image, ivec2(gl_LaunchIDNV.xy), vec4( payload.value, 0));
imageStore(image, ivec2(gl_LaunchIDNV.xy), vec4(res, 0));
}
\ No newline at end of file
......@@ -10,97 +10,149 @@ class CgContext;
namespace lib
{
class StagedBuffer
{
private:
vk::Buffer deviceBuffer;
vk::DeviceMemory deviceMemory;
vk::Buffer hostBuffer;
vk::DeviceMemory hostMemory;
vk::DeviceSize size;
CgContext *parent;
vk::MemoryPropertyFlags memoryPropertyFlags;
vk::BufferUsageFlags bufferUsageFlags;
std::vector<uint32_t> familyIndices;
vk::SharingMode sharingMode;
public:
StagedBuffer(const StagedBuffer &copy) = delete;
StagedBuffer(StagedBuffer &&other);
StagedBuffer(CgContext *parent,
const std::vector<uint32_t> &familyIndices,
vk::BufferUsageFlags bufferUsageFlags,
vk::MemoryPropertyFlags memoryPropertyFlags);
~StagedBuffer();
StagedBuffer &operator=(const StagedBuffer &copy) = delete;
StagedBuffer &operator=(StagedBuffer &&other);
void Destroy();
std::tuple<vk::Buffer, vk::DeviceMemory, vk::Buffer, vk::DeviceMemory> Disown();
void ScheduleTransfer(vk::CommandBuffer &commandBuffer) const;
const vk::Buffer &GetDeviceBufferHandle() const;
const vk::DeviceMemory &GetDeviceMemoryHandle() const;
const vk::Buffer &GetHostBufferHandle() const;
const vk::DeviceMemory &GetHostMemoryHandle() const;
vk::DeviceSize GetSize() const;
void BufferData(vk::CommandBuffer &commandBuffer, const void *data) const;
void BufferData(vk::CommandBuffer &commandBuffer, const void *data, vk::DeviceSize size);
void BufferDataHostOnly(const void *data) const;
void BufferDataHostOnly(const void *data, vk::DeviceSize size);
void Allocate(vk::DeviceSize size);
template <typename T>
void BufferDataHostOnly(const std::vector<T> &data)
{
this->BufferDataHostOnly(static_cast<const void *>(data.data()),
static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T, std::enable_if_t<std::is_class_v<T>, int> = 0>
void BufferDataHostOnly(vk::CommandBuffer &commandBuffer, const T &data)
{
this->BufferDataHostOnly(static_cast<const void *>(&data),
static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void BufferData(vk::CommandBuffer &commandBuffer, const std::vector<T> &data)
{
this->BufferData(commandBuffer,
static_cast<const void *>(data.data()),
static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T, std::enable_if_t<std::is_class_v<T>, int> = 0>
void BufferData(vk::CommandBuffer &commandBuffer, const T &data)
{
this->BufferData(commandBuffer,
static_cast<const void *>(&data),
static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void AllocateFor(const std::vector<T> &data)
{
this->Allocate(static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T>
void AllocateFor(const T &data)
{
this->Allocate(static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void AllocateFor()
/**
* @brief Stell ein Paar von Buffer + Staging-Buffer dar, das genutzt werden kann um Daten zu streamen.
*/
class StagedBuffer
{
this->Allocate(static_cast<vk::DeviceSize>(sizeof(T)));
}
};
private:
/**
* @brief Die Handle f眉r den ger盲teseitigen Buffer.
*/
vk::Buffer deviceBuffer;
/**
* @brief Die Handle f眉r den ger盲teseitigen Speicher.
*/
vk::DeviceMemory deviceMemory;
/**
* @brief Die Handle f眉r den host-seitigen Buffer.
*/
vk::Buffer hostBuffer;
/**
* @brief Die Handle f眉r den host-seitigen Speicher.
*/
vk::DeviceMemory hostMemory;
/**
* @brief Die Gr枚脽e des Buffers.
*/
vk::DeviceSize size;
/**
* @brief Der zugeh枚rige CgContext.
*/
CgContext *parent;
/**
* @brief Flags f眉r Speichereigenschaften.
*/
vk::MemoryPropertyFlags memoryPropertyFlags;
/**
* @brief Flags f眉r die Nutzung des Buffers.
*/
vk::BufferUsageFlags bufferUsageFlags;
/**
* @brief Indices der Queue-Familien, die den Buffer nutzen k枚nnen.
*/
std::vector<uint32_t> familyIndices;
/**
* @brief Teilungsmodus.
*/
vk::SharingMode sharingMode;
public:
/**
* @brief Gel枚schter Copy-Konstruktor.
*
* @param copy
*/
StagedBuffer(const StagedBuffer &copy) = delete;
/**
* @brief Initialisiert eine neue Instanz der Staged Buffer Klasse.
*
* @param other
*/
StagedBuffer(StagedBuffer &&other);
StagedBuffer(CgContext *parent,
const std::vector<uint32_t> &familyIndices,
vk::BufferUsageFlags bufferUsageFlags,
vk::MemoryPropertyFlags memoryPropertyFlags);
~StagedBuffer();
StagedBuffer &operator=(const StagedBuffer &copy) = delete;
StagedBuffer &operator=(StagedBuffer &&other);
void Destroy();
std::tuple<vk::Buffer, vk::DeviceMemory, vk::Buffer, vk::DeviceMemory> Disown();
void ScheduleTransfer(vk::CommandBuffer &commandBuffer) const;
const vk::Buffer &GetDeviceBufferHandle() const;
const vk::DeviceMemory &GetDeviceMemoryHandle() const;
const vk::Buffer &GetHostBufferHandle() const;
const vk::DeviceMemory &GetHostMemoryHandle() const;
vk::DeviceSize GetSize() const;
void BufferData(vk::CommandBuffer &commandBuffer, const void *data) const;
void BufferData(vk::CommandBuffer &commandBuffer, const void *data, vk::DeviceSize size);
void BufferDataHostOnly(const void *data) const;
void BufferDataHostOnly(const void *data, vk::DeviceSize size);
void Allocate(vk::DeviceSize size);
template <typename T>
void BufferDataHostOnly(const std::vector<T> &data)
{
this->BufferDataHostOnly(static_cast<const void *>(data.data()),
static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T, std::enable_if_t<std::is_class_v<T>, int> = 0>
void BufferDataHostOnly(const T &data)
{
this->BufferDataHostOnly(static_cast<const void *>(&data),
static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void BufferData(vk::CommandBuffer &commandBuffer, const std::vector<T> &data)
{
this->BufferData(commandBuffer,
static_cast<const void *>(data.data()),
static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T, std::enable_if_t<std::is_class_v<T>, int> = 0>
void BufferData(vk::CommandBuffer &commandBuffer, const T &data)
{
this->BufferData(commandBuffer,
static_cast<const void *>(&data),
static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void AllocateFor(const std::vector<T> &data)
{
this->Allocate(static_cast<vk::DeviceSize>(data.size() * sizeof(T)));
}
template <typename T>
void AllocateFor(const T &data)
{
this->Allocate(static_cast<vk::DeviceSize>(sizeof(T)));
}
template <typename T>
void AllocateFor()
{
this->Allocate(static_cast<vk::DeviceSize>(sizeof(T)));
}
};
} // namespace lib
std::ostream &operator<<(std::ostream &s, const lib::StagedBuffer &b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment