<commit_before>#include "svgf/svgf_pt.h"

#include "kernel/context.cuh"
#include "kernel/light.cuh"
#include "kernel/material.cuh"
#include "kernel/intersect.cuh"
#include "kernel/bvh.cuh"
#include "kernel/compaction.h"
#include "kernel/pt_common.h"

#include <cuda_runtime.h>
#include <device_launch_parameters.h>

#include "cuda/helper_math.h"
#include "cuda/cudautil.h"
#include "cuda/cudamemory.h"

#include "aten4idaten.h"

// NOTE
// ddx, ddy
// http://mosapui.blog116.fc2.com/blog-entry-35.html
// https://www.gamedev.net/forums/topic/478820-derivative-instruction-details-ddx-ddy-or-dfdx-dfdy-etc/
// http://d.hatena.ne.jp/umonist/20110616/p1
// http://monsho.blog63.fc2.com/blog-entry-105.html

inline __device__ float ddx(
	int x, int y,
	int w, int h,
	idaten::SVGFPathTracing::AOV* aov)
{
	// NOTE
	// 2x2 pixelƂɌvZ.

	int leftX = x; 
	int rightX = x + 1;
	if ((x & 0x01) == 1) {
		leftX = x - 1;
		rightX = x;
	}

	rightX = min(rightX, w - 1);

	const int idxL = getIdx(leftX, y, w);
	const int idxR = getIdx(rightX, y, w);

#if 0
	float left = aov[idxL].depth;
	float right = aov[idxR].depth;
#else
	auto l_v0 = ((float4*)aov)[idxL * idaten::SVGFPathTracing::AOV_float4_size + 0];
	auto r_v0 = ((float4*)aov)[idxR * idaten::SVGFPathTracing::AOV_float4_size + 0];

	float left = l_v0.w;
	float right = r_v0.w;
#endif

	return right - left;
}

inline __device__ float ddy(
	int x, int y,
	int w, int h,
	idaten::SVGFPathTracing::AOV* aov)
{
	// NOTE
	// 2x2 pixelƂɌvZ.

	int topY = y;
	int bottomY = y + 1;
	if ((y & 0x01) == 1) {
		topY = y - 1;
		bottomY = y;
	}

	bottomY = min(bottomY, h - 1);

	int idxT = getIdx(x, topY, w);
	int idxB = getIdx(x, bottomY, w);

#if 0
	float top = aov[idxT].depth;
	float bottom = aov[idxB].depth;
#else
	auto t_v0 = ((float4*)aov)[idxT * idaten::SVGFPathTracing::AOV_float4_size + 0];
	auto b_v0 = ((float4*)aov)[idxB * idaten::SVGFPathTracing::AOV_float4_size + 0];

	float top = t_v0.w;
	float bottom = b_v0.w;
#endif

	return bottom - top;
}<commit_msg>Optimize.<commit_after>#include "svgf/svgf_pt.h"

#include "kernel/context.cuh"
#include "kernel/light.cuh"
#include "kernel/material.cuh"
#include "kernel/intersect.cuh"
#include "kernel/bvh.cuh"
#include "kernel/compaction.h"
#include "kernel/pt_common.h"

#include <cuda_runtime.h>
#include <device_launch_parameters.h>

#include "cuda/helper_math.h"
#include "cuda/cudautil.h"
#include "cuda/cudamemory.h"

#include "aten4idaten.h"

// NOTE
// ddx, ddy
// http://mosapui.blog116.fc2.com/blog-entry-35.html
// https://www.gamedev.net/forums/topic/478820-derivative-instruction-details-ddx-ddy-or-dfdx-dfdy-etc/
// http://d.hatena.ne.jp/umonist/20110616/p1
// http://monsho.blog63.fc2.com/blog-entry-105.html

inline __device__ float ddx(
	int x, int y,
	int w, int h,
	idaten::SVGFPathTracing::AOV* aov)
{
	// NOTE
	// 2x2 pixelƂɌvZ.

	int leftX = x; 
	int rightX = x + 1;

#if 0
	if ((x & 0x01) == 1) {
		leftX = x - 1;
		rightX = x;
	}
#else
	int offset = (x & 0x01);
	leftX -= offset;
	rightX -= offset;
#endif

	rightX = min(rightX, w - 1);

	const int idxL = getIdx(leftX, y, w);
	const int idxR = getIdx(rightX, y, w);

#if 0
	float left = aov[idxL].depth;
	float right = aov[idxR].depth;
#else
	auto l_v0 = ((float4*)aov)[idxL * idaten::SVGFPathTracing::AOV_float4_size + 0];
	auto r_v0 = ((float4*)aov)[idxR * idaten::SVGFPathTracing::AOV_float4_size + 0];

	float left = l_v0.w;
	float right = r_v0.w;
#endif

	return right - left;
}

inline __device__ float ddy(
	int x, int y,
	int w, int h,
	idaten::SVGFPathTracing::AOV* aov)
{
	// NOTE
	// 2x2 pixelƂɌvZ.

	int topY = y;
	int bottomY = y + 1;

#if 0
	if ((y & 0x01) == 1) {
		topY = y - 1;
		bottomY = y;
	}
#else
	int offset = (y & 0x01);
	topY -= offset;
	bottomY -= offset;
#endif

	bottomY = min(bottomY, h - 1);

	int idxT = getIdx(x, topY, w);
	int idxB = getIdx(x, bottomY, w);

#if 0
	float top = aov[idxT].depth;
	float bottom = aov[idxB].depth;
#else
	auto t_v0 = ((float4*)aov)[idxT * idaten::SVGFPathTracing::AOV_float4_size + 0];
	auto b_v0 = ((float4*)aov)[idxB * idaten::SVGFPathTracing::AOV_float4_size + 0];

	float top = t_v0.w;
	float bottom = b_v0.w;
#endif

	return bottom - top;
}
{'fraction_non_alphanumeric': 0.1707375478927203, 'fraction_numerical': 0.034482758620689655, 'mean_word_length': 3.6932584269662923, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5654810', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1902, 'n_words': 402}